Bug 1878028 - Remove redundant assertion functions from HistoryRobot

fenix/124.1.0
AndiAJ 4 months ago committed by mergify[bot]
parent 28746c1ba7
commit 31df2b7167

@ -28,6 +28,7 @@ import org.mozilla.fenix.helpers.RecyclerViewIdlingResource
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.exitMenu
import org.mozilla.fenix.helpers.TestHelper.longTapSelectItem
import org.mozilla.fenix.helpers.TestHelper.verifySnackBarText
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.historyMenu
import org.mozilla.fenix.ui.robots.homeScreen
@ -128,7 +129,7 @@ class ComposeHistoryTest {
) {
clickDeleteHistoryButton(firstWebPage.url.toString())
}
verifyDeleteSnackbarText("Deleted")
verifySnackBarText(expectedText = "Deleted")
verifyEmptyHistoryView()
}
}
@ -153,7 +154,7 @@ class ComposeHistoryTest {
verifyDeleteConfirmationMessage()
selectEverythingOption()
confirmDeleteAllHistory()
verifyDeleteSnackbarText("Browsing data deleted")
verifySnackBarText(expectedText = "Browsing data deleted")
verifyEmptyHistoryView()
}
}

@ -31,6 +31,7 @@ import org.mozilla.fenix.helpers.SearchDispatcher
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestHelper.exitMenu
import org.mozilla.fenix.helpers.TestHelper.verifySnackBarText
import org.mozilla.fenix.ui.robots.clickContextMenuItem
import org.mozilla.fenix.ui.robots.clickPageObject
import org.mozilla.fenix.ui.robots.homeScreen
@ -472,7 +473,7 @@ class ComposeSearchTest {
}.openRecentlyVisitedSearchGroupHistoryList(queryString) {
clickDeleteAllHistoryButton()
confirmDeleteAllHistory()
verifyDeleteSnackbarText("Group deleted")
verifySnackBarText(expectedText = "Group deleted")
verifyHistoryItemExists(shouldExist = false, firstPageUrl.toString())
}.goBack {}
homeScreen {

@ -29,6 +29,7 @@ import org.mozilla.fenix.helpers.RecyclerViewIdlingResource
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.exitMenu
import org.mozilla.fenix.helpers.TestHelper.longTapSelectItem
import org.mozilla.fenix.helpers.TestHelper.verifySnackBarText
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.historyMenu
import org.mozilla.fenix.ui.robots.homeScreen
@ -131,7 +132,7 @@ class HistoryTest {
clickUndoDeleteButton()
verifyHistoryItemExists(true, firstWebPage.url.toString())
clickDeleteHistoryButton(firstWebPage.url.toString())
verifyDeleteSnackbarText("Deleted")
verifySnackBarText(expectedText = "Deleted")
verifyEmptyHistoryView()
}
}
@ -161,7 +162,7 @@ class HistoryTest {
verifyDeleteConfirmationMessage()
selectEverythingOption()
confirmDeleteAllHistory()
verifyDeleteSnackbarText("Browsing data deleted")
verifySnackBarText(expectedText = "Browsing data deleted")
verifyEmptyHistoryView()
}
}

@ -44,6 +44,7 @@ import org.mozilla.fenix.helpers.TestHelper.clickSnackbarButton
import org.mozilla.fenix.helpers.TestHelper.exitMenu
import org.mozilla.fenix.helpers.TestHelper.longTapSelectItem
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.verifySnackBarText
import org.mozilla.fenix.ui.robots.clickContextMenuItem
import org.mozilla.fenix.ui.robots.clickPageObject
import org.mozilla.fenix.ui.robots.homeScreen
@ -487,7 +488,7 @@ class SearchTest {
}.openRecentlyVisitedSearchGroupHistoryList(queryString) {
clickDeleteAllHistoryButton()
confirmDeleteAllHistory()
verifyDeleteSnackbarText("Group deleted")
verifySnackBarText("Group deleted")
verifyHistoryItemExists(shouldExist = false, firstPageUrl.toString())
}.goBack {}
homeScreen {

@ -19,7 +19,6 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.hamcrest.Matchers
import org.hamcrest.Matchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
@ -38,17 +37,26 @@ import org.mozilla.fenix.helpers.ext.waitNotNull
*/
class HistoryRobot {
fun verifyHistoryMenuView() = assertHistoryMenuView()
fun verifyHistoryMenuView() {
onView(
allOf(withText("History"), withParent(withId(R.id.navigationToolbar))),
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
fun verifyEmptyHistoryView() {
mDevice.findObject(
UiSelector().text("No history here"),
).waitForExists(waitingTime)
assertEmptyHistoryView()
onView(
allOf(
withId(R.id.history_empty_view),
withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE),
),
).check(matches(withText("No history here")))
}
fun verifyHistoryListExists() = assertHistoryListExists()
fun verifyHistoryListExists() = assertUIObjectExists(itemWithResId("$packageName:id/history_list"))
fun verifyVisitedTimeTitle() {
mDevice.waitNotNull(
@ -57,21 +65,24 @@ class HistoryRobot {
),
waitingTime,
)
assertVisitedTimeTitle()
onView(withId(R.id.header_title)).check(matches(withText("Today")))
}
fun verifyHistoryItemExists(shouldExist: Boolean, item: String) =
assertUIObjectExists(itemContainingText(item), exists = shouldExist)
fun verifyFirstTestPageTitle(title: String) = assertTestPageTitle(title)
fun verifyFirstTestPageTitle(title: String) =
testPageTitle()
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.check(matches(withText(title)))
fun verifyTestPageUrl(expectedUrl: Uri) = pageUrl(expectedUrl.toString()).check(matches(isDisplayed()))
fun verifyCopySnackBarText() = assertCopySnackBarText()
fun verifyDeleteConfirmationMessage() = assertDeleteConfirmationMessage()
fun verifyHomeScreen() = HomeScreenRobot().verifyHomeScreen()
fun verifyDeleteConfirmationMessage() =
assertUIObjectExists(
itemWithResIdContainingText("$packageName:id/title", getStringResource(R.string.delete_history_prompt_title)),
itemWithResIdContainingText("$packageName:id/body", getStringResource(R.string.delete_history_prompt_body_2)),
)
fun clickDeleteHistoryButton(item: String) {
deleteButton(item).click()
@ -98,9 +109,7 @@ class HistoryRobot {
.textContains(getStringResource(R.string.delete_browsing_data_prompt_cancel)),
).click()
fun verifyDeleteSnackbarText(text: String) = assertSnackBarText(text)
fun verifyUndoDeleteSnackBarButton() = assertUndoDeleteSnackBarButton()
fun verifyUndoDeleteSnackBarButton() = snackBarUndoButton().check(matches(withText("UNDO")))
fun clickUndoDeleteButton() {
snackBarUndoButton().click()
@ -130,7 +139,7 @@ class HistoryRobot {
}
fun openWebsite(url: Uri, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
assertHistoryListExists()
assertUIObjectExists(itemWithResId("$packageName:id/history_list"))
onView(withText(url.toString())).click()
BrowserRobot().interact()
@ -138,8 +147,8 @@ class HistoryRobot {
}
fun openRecentlyClosedTabs(interact: RecentlyClosedTabsRobot.() -> Unit): RecentlyClosedTabsRobot.Transition {
recentlyClosedTabsListButton.waitForExists(waitingTime)
recentlyClosedTabsListButton.click()
recentlyClosedTabsListButton().waitForExists(waitingTime)
recentlyClosedTabsListButton().click()
RecentlyClosedTabsRobot().interact()
return RecentlyClosedTabsRobot.Transition()
@ -168,50 +177,8 @@ private fun deleteButton(title: String) =
private fun deleteButton() = onView(withId(R.id.history_delete))
private fun snackBarText() = onView(withId(R.id.snackbar_text))
private fun assertHistoryMenuView() {
onView(
allOf(withText("History"), withParent(withId(R.id.navigationToolbar))),
)
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
private fun assertEmptyHistoryView() =
onView(
allOf(
withId(R.id.history_empty_view),
withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE),
),
)
.check(matches(withText("No history here")))
private fun assertHistoryListExists() =
mDevice.findObject(UiSelector().resourceId("$packageName:id/history_list")).waitForExists(waitingTime)
private fun assertVisitedTimeTitle() =
onView(withId(R.id.header_title)).check(matches(withText("Today")))
private fun assertTestPageTitle(title: String) = testPageTitle()
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.check(matches(withText(title)))
private fun assertDeleteConfirmationMessage() =
assertUIObjectExists(
itemWithResIdContainingText("$packageName:id/title", getStringResource(R.string.delete_history_prompt_title)),
itemWithResIdContainingText("$packageName:id/body", getStringResource(R.string.delete_history_prompt_body_2)),
)
private fun assertCopySnackBarText() = snackBarText().check(matches(withText("URL copied")))
private fun assertSnackBarText(text: String) =
snackBarText().check(matches(withText(Matchers.containsString(text))))
private fun snackBarUndoButton() = onView(withId(R.id.snackbar_btn))
private fun assertUndoDeleteSnackBarButton() =
snackBarUndoButton().check(matches(withText("UNDO")))
private fun deleteHistoryEverythingOption() =
mDevice
.findObject(
@ -220,5 +187,5 @@ private fun deleteHistoryEverythingOption() =
.resourceId("$packageName:id/everything_button"),
)
private val recentlyClosedTabsListButton =
private fun recentlyClosedTabsListButton() =
mDevice.findObject(UiSelector().resourceId("$packageName:id/recently_closed_tabs_header"))

Loading…
Cancel
Save