Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Espresso reading list test #5350

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/src/androidTest/java/org/wikipedia/base/BaseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ data class DataInjector(
val overrideEditsContribution: Int? = null,
val intentBuilder: (Intent.() -> Unit)? = null,
val showOneTimeCustomizeToolbarTooltip: Boolean = false,
val readingListShareTooltipShown: Boolean = true
val readingListShareTooltipShown: Boolean = true,
val otdEntryDialogShown: Boolean = true
)

abstract class BaseTest<T : AppCompatActivity>(
Expand All @@ -56,6 +57,7 @@ abstract class BaseTest<T : AppCompatActivity>(
Prefs.isInitialOnboardingEnabled = dataInjector.isInitialOnboardingEnabled
Prefs.showOneTimeCustomizeToolbarTooltip = dataInjector.showOneTimeCustomizeToolbarTooltip
Prefs.readingListShareTooltipShown = dataInjector.readingListShareTooltipShown
Prefs.otdEntryDialogShown = dataInjector.otdEntryDialogShown
dataInjector.overrideEditsContribution?.let {
Prefs.overrideSuggestedEditContribution = it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ class ListActions {
)
}

fun longClickOnItemInList(@IdRes listId: Int, position: Int) {
fun clickOnItemInList(textViewId: Int) {
onView(withId(textViewId))
.perform(click())
}

fun longClickOnItemInList(@IdRes listId: Int, position: Int) {
onView(withId(listId))
.perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
Expand Down Expand Up @@ -100,7 +105,8 @@ class ListActions {
recyclerViewId: Int = R.id.feed_view,
title: String,
textViewId: Int = R.id.view_card_header_title,
verticalOffset: Int = 200
verticalOffset: Int = 200,
action: (() -> Unit)? = null
) = apply {
var currentOccurrence = 0
onView(withId(recyclerViewId))
Expand Down Expand Up @@ -141,6 +147,7 @@ class ListActions {
})
}
}
action?.invoke()
}

fun verifyRecyclerViewItemCount(@IdRes viewId: Int, expectedCount: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.wikipedia.robots

import android.content.Context
import org.wikipedia.R
import org.wikipedia.base.base.BaseRobot

class DialogRobot : BaseRobot() {
Expand All @@ -15,4 +17,10 @@ class DialogRobot : BaseRobot() {
fun clickLogOutUser() = apply {
click.ifDialogShown("Log out", errorString = "Cannot click Log out.")
}

fun dismissPromptLogInToSyncDialog(context: Context) = apply {
click.ifDialogShown(
context.getString(R.string.reading_list_prompt_turned_sync_on_dialog_no_thanks),
errorString = "Cannot click")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ import org.wikipedia.base.TestConfig
import org.wikipedia.base.base.BaseRobot

class ReadingListRobot : BaseRobot() {

fun clickOnList(position: Int) = apply {
list.clickOnItemInList(
listId = R.id.recycler_view,
position
)
delay(TestConfig.DELAY_MEDIUM)
}

fun clickOnList(title: String) = apply {
list.scrollToRecyclerView(
recyclerViewId = R.id.recycler_view,
title = title,
textViewId = R.id.item_title,
action = {
click.onViewWithId(R.id.item_title)
}
)
delay(TestConfig.DELAY_SHORT)
}

fun saveArticleToReadingList() = apply {
click.onViewWithId(R.id.page_save)
delay(TestConfig.DELAY_SHORT)
Expand Down Expand Up @@ -58,6 +79,10 @@ class ReadingListRobot : BaseRobot() {
delay(TestConfig.DELAY_MEDIUM)
}

fun verifySavedArticleExists(title: String) = apply {
verify.viewWithTextDisplayed(title)
}

fun verifyArticleHasNotDownloaded() = apply {
delay(TestConfig.DELAY_MEDIUM)
onView(withId(R.id.reading_list_recycler_view))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.wikipedia.tests

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.junit.Test
import org.junit.runner.RunWith
import org.wikipedia.base.BaseTest
import org.wikipedia.main.MainActivity
import org.wikipedia.robots.DialogRobot
import org.wikipedia.robots.SystemRobot
import org.wikipedia.robots.feature.LoginRobot
import org.wikipedia.robots.feature.ReadingListRobot
import org.wikipedia.robots.feature.SearchRobot
import org.wikipedia.robots.navigation.BottomNavRobot

@LargeTest
@RunWith(AndroidJUnit4::class)
class ReadingListsTest : BaseTest<MainActivity>(
activityClass = MainActivity::class.java
) {
private val systemRobot = SystemRobot()
private val bottomNavRobot = BottomNavRobot()
private val loginRobot = LoginRobot()
private val searchRobot = SearchRobot()
private val readingListRobot = ReadingListRobot()
private val dialogRobot = DialogRobot()

@Test
fun runTest() {
systemRobot
.clickOnSystemDialogWithText("Allow")
// 1. saved article should be in the "Saved" reading list
search("watermelon")
readingListRobot
.saveArticleToReadingList()
.pressBack()
.pressBack()
.pressBack()
bottomNavRobot
.navigateToSavedPage()
readingListRobot
.clickOnList("Saved")
.verifySavedArticleExists("Watermelon")
.pressBack()
bottomNavRobot
.navigateToExploreFeed()
// 2. article saved to a custom list should be in the custom list in the reading list
search("lemon")
readingListRobot
.saveArticleToReadingList()
.addToReadingList(context)
.typeNameOfTheList("new", context)
.saveTheList(context)
.pressBack()
.pressBack()
.pressBack()
dialogRobot
.dismissPromptLogInToSyncDialog(context)
bottomNavRobot
.navigateToSavedPage()
readingListRobot
.clickOnList("new")
.verifySavedArticleExists("lemon")

// 3. can delete lists
// 4. unsaved article should not be in the "Saved" or "custom list" in the reading list
}

private fun search(title: String) {
searchRobot
.tapSearchView()
.typeTextInView(title)
.clickOnItemFromSearchList(0)
}
}
Loading