Bug 1884329 - Remove redundant assertion functions from TabDrawerRobot

fenix/125.0
AndiAJ 3 months ago committed by mergify[bot]
parent 136f00e55f
commit c7631e9f90

@ -65,28 +65,26 @@ import org.mozilla.fenix.helpers.matchers.BottomSheetBehaviorStateMatcher
*/ */
class TabDrawerRobot { class TabDrawerRobot {
fun verifyBrowserTabsTrayURL(url: String) { fun verifyNormalBrowsingButtonIsSelected(isSelected: Boolean) = normalBrowsingButton().check(matches(isSelected(isSelected)))
mDevice.waitNotNull(
Until.findObject(By.res("$packageName:id/mozac_browser_tabstray_url")),
waitingTime,
)
onView(withId(R.id.mozac_browser_tabstray_url))
.check(matches(withText(containsString(url))))
}
fun verifyNormalBrowsingButtonIsDisplayed() = assertNormalBrowsingButton()
fun verifyNormalBrowsingButtonIsSelected(isSelected: Boolean) =
assertNormalBrowsingButtonIsSelected(isSelected)
fun verifyPrivateBrowsingButtonIsSelected(isSelected: Boolean) = fun verifyPrivateBrowsingButtonIsSelected(isSelected: Boolean) = privateBrowsingButton().check(matches(isSelected(isSelected)))
assertPrivateBrowsingButtonIsSelected(isSelected)
fun verifySyncedTabsButtonIsSelected(isSelected: Boolean) = fun verifySyncedTabsButtonIsSelected(isSelected: Boolean) =
syncedTabsButton().check(matches(isSelected(isSelected))) syncedTabsButton().check(matches(isSelected(isSelected)))
fun clickSyncedTabsButton() = syncedTabsButton().click() fun clickSyncedTabsButton() = syncedTabsButton().click()
fun verifyExistingOpenTabs(vararg titles: String) = assertExistingOpenTabs(*titles) fun verifyExistingOpenTabs(vararg tabTitles: String) {
var retries = 0
for (title in tabTitles) {
while (!tabItem(title).waitForExists(waitingTime) && retries++ < 3) {
tabsList()
.getChildByText(UiSelector().text(title), title, true)
assertUIObjectExists(tabItem(title), waitingTime = waitingTimeLong)
}
}
}
fun verifyOpenTabsOrder(position: Int, title: String) { fun verifyOpenTabsOrder(position: Int, title: String) {
mDevice.findObject( mDevice.findObject(
@ -101,26 +99,76 @@ class TabDrawerRobot {
.index(position - 1), .index(position - 1),
) )
} }
fun verifyNoExistingOpenTabs(vararg titles: String) = assertNoExistingOpenTabs(*titles) fun verifyNoExistingOpenTabs(vararg tabTitles: String) {
fun verifyCloseTabsButton(title: String) = assertCloseTabsButton(title) for (title in tabTitles) {
assertUIObjectExists(tabItem(title), exists = false)
fun verifyExistingTabList() = assertExistingTabList() }
}
fun verifyNoOpenTabsInNormalBrowsing() = assertNoOpenTabsInNormalBrowsing() fun verifyCloseTabsButton(title: String) =
fun verifyNoOpenTabsInPrivateBrowsing() = assertNoOpenTabsInPrivateBrowsing() assertUIObjectExists(itemWithDescription("Close tab").getFromParent(UiSelector().textContains(title)))
fun verifyPrivateModeSelected() = assertPrivateModeSelected()
fun verifyNormalModeSelected() = assertNormalModeSelected() fun verifyExistingTabList() {
fun verifyNormalBrowsingNewTabButton() = assertNormalBrowsingNewTabButton() mDevice.findObject(
fun verifyPrivateBrowsingNewTabButton() = assertPrivateBrowsingNewTabButton() UiSelector().resourceId("$packageName:id/tabsTray"),
fun verifyEmptyTabsTrayMenuButtons() = assertEmptyTabsTrayMenuButtons() ).waitForExists(waitingTime)
fun verifySelectTabsButton() = assertSelectTabsButton() assertUIObjectExists(itemWithResId("$packageName:id/tray_list_item"))
fun verifyTabTrayOverflowMenu(visibility: Boolean) = assertTabTrayOverflowButton(visibility) }
fun verifyTabsTrayCounter() = assertTabsTrayCounter()
fun verifyNoOpenTabsInNormalBrowsing() =
fun verifyTabTrayIsOpened() = assertTabTrayDoesExist() onView(
fun verifyTabTrayIsClosed() = assertTabTrayDoesNotExist() allOf(
fun verifyHalfExpandedRatio() = assertMinisculeHalfExpandedRatio() withId(R.id.tab_tray_empty_view),
fun verifyBehaviorState(expectedState: Int) = assertBehaviorState(expectedState) withText(R.string.no_open_tabs_description),
),
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
fun verifyNoOpenTabsInPrivateBrowsing() =
onView(
allOf(
withId(R.id.tab_tray_empty_view),
withText(R.string.no_private_tabs_description),
),
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
fun verifyPrivateModeSelected() = privateBrowsingButton().check(matches(ViewMatchers.isSelected()))
fun verifyNormalModeSelected() = normalBrowsingButton().check(matches(ViewMatchers.isSelected()))
fun verifyNormalBrowsingNewTabButton() =
onView(
allOf(
withId(R.id.new_tab_button),
withContentDescription(R.string.add_tab),
),
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
fun verifyPrivateBrowsingNewTabButton() =
onView(
allOf(
withId(R.id.new_tab_button),
withContentDescription(R.string.add_private_tab),
),
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
fun verifyEmptyTabsTrayMenuButtons() {
threeDotMenu().click()
tabsSettingsButton()
.inRoot(RootMatchers.isPlatformPopup())
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
recentlyClosedTabsButton()
.inRoot(RootMatchers.isPlatformPopup())
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
fun verifyTabTrayOverflowMenu(visibility: Boolean) =
onView(withId(R.id.tab_tray_overflow)).check(matches(withEffectiveVisibility(visibleOrGone(visibility))))
fun verifyTabsTrayCounter() = tabsTrayCounterBox().check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
fun verifyTabTrayIsOpened() = onView(withId(R.id.tab_wrapper)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
fun verifyTabTrayIsClosed() = onView(withId(R.id.tab_wrapper)).check(doesNotExist())
fun verifyHalfExpandedRatio() =
onView(withId(R.id.tab_wrapper)).check(matches(BottomSheetBehaviorHalfExpandedMaxRatioMatcher(0.001f)))
fun verifyBehaviorState(expectedState: Int) =
onView(withId(R.id.tab_wrapper)).check(matches(BottomSheetBehaviorStateMatcher(expectedState)))
fun verifyOpenedTabThumbnail() = fun verifyOpenedTabThumbnail() =
assertUIObjectExists(itemWithResId("$packageName:id/mozac_browser_tabstray_thumbnail")) assertUIObjectExists(itemWithResId("$packageName:id/mozac_browser_tabstray_thumbnail"))
@ -439,21 +487,6 @@ class TabDrawerRobot {
return Transition() return Transition()
} }
fun openRecentlyClosedTabs(interact: RecentlyClosedTabsRobot.() -> Unit): RecentlyClosedTabsRobot.Transition {
threeDotMenu().click()
mDevice.waitNotNull(
Until.findObject(text("Recently closed tabs")),
waitingTime,
)
val menuRecentlyClosedTabs = mDevice.findObject(text("Recently closed tabs"))
menuRecentlyClosedTabs.click()
RecentlyClosedTabsRobot().interact()
return RecentlyClosedTabsRobot.Transition()
}
fun clickSaveCollection(interact: CollectionRobot.() -> Unit): CollectionRobot.Transition { fun clickSaveCollection(interact: CollectionRobot.() -> Unit): CollectionRobot.Transition {
saveTabsToCollectionButton().click() saveTabsToCollectionButton().click()
@ -474,11 +507,6 @@ private fun tabMediaControlButton(action: String) =
private fun closeTabButton() = private fun closeTabButton() =
mDevice.findObject(UiSelector().descriptionContains("Close tab")) mDevice.findObject(UiSelector().descriptionContains("Close tab"))
private fun assertCloseTabsButton(title: String) =
assertUIObjectExists(
itemWithDescription("Close tab").getFromParent(UiSelector().textContains(title)),
)
private fun normalBrowsingButton() = onView( private fun normalBrowsingButton() = onView(
anyOf( anyOf(
withContentDescription(containsString("open tabs. Tap to switch tabs.")), withContentDescription(containsString("open tabs. Tap to switch tabs.")),
@ -493,125 +521,7 @@ private fun newTabButton() =
private fun threeDotMenu() = onView(withId(R.id.tab_tray_overflow)) private fun threeDotMenu() = onView(withId(R.id.tab_tray_overflow))
private fun assertExistingOpenTabs(vararg tabTitles: String) { private fun tabsList() =
var retries = 0
for (title in tabTitles) {
while (!tabItem(title).waitForExists(waitingTime) && retries++ < 3) {
tabsList
.getChildByText(UiSelector().text(title), title, true)
assertUIObjectExists(tabItem(title), waitingTime = waitingTimeLong)
}
}
}
private fun assertNoExistingOpenTabs(vararg tabTitles: String) {
for (title in tabTitles) {
assertUIObjectExists(tabItem(title), exists = false)
}
}
private fun assertExistingTabList() {
mDevice.findObject(
UiSelector().resourceId("$packageName:id/tabsTray"),
).waitForExists(waitingTime)
assertUIObjectExists(itemWithResId("$packageName:id/tray_list_item"))
}
private fun assertNoOpenTabsInNormalBrowsing() =
onView(
allOf(
withId(R.id.tab_tray_empty_view),
withText(R.string.no_open_tabs_description),
),
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
private fun assertNoOpenTabsInPrivateBrowsing() =
onView(
allOf(
withId(R.id.tab_tray_empty_view),
withText(R.string.no_private_tabs_description),
),
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
private fun assertNormalBrowsingNewTabButton() =
onView(
allOf(
withId(R.id.new_tab_button),
withContentDescription(R.string.add_tab),
),
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
private fun assertPrivateBrowsingNewTabButton() =
onView(
allOf(
withId(R.id.new_tab_button),
withContentDescription(R.string.add_private_tab),
),
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
private fun assertSelectTabsButton() =
onView(withText("Select tabs"))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
private fun assertNormalModeSelected() =
normalBrowsingButton()
.check(matches(ViewMatchers.isSelected()))
private fun assertPrivateModeSelected() =
privateBrowsingButton()
.check(matches(ViewMatchers.isSelected()))
private fun assertTabTrayOverflowButton(visible: Boolean) =
onView(withId(R.id.tab_tray_overflow))
.check(matches(withEffectiveVisibility(visibleOrGone(visible))))
private fun assertTabsTrayCounter() =
tabsTrayCounterBox().check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
private fun assertEmptyTabsTrayMenuButtons() {
threeDotMenu().click()
tabsSettingsButton()
.inRoot(RootMatchers.isPlatformPopup())
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
recentlyClosedTabsButton()
.inRoot(RootMatchers.isPlatformPopup())
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
private fun assertTabTrayDoesExist() {
onView(withId(R.id.tab_wrapper))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
private fun assertTabTrayDoesNotExist() {
onView(withId(R.id.tab_wrapper))
.check(doesNotExist())
}
private fun assertMinisculeHalfExpandedRatio() {
onView(withId(R.id.tab_wrapper))
.check(matches(BottomSheetBehaviorHalfExpandedMaxRatioMatcher(0.001f)))
}
private fun assertBehaviorState(expectedState: Int) {
onView(withId(R.id.tab_wrapper))
.check(matches(BottomSheetBehaviorStateMatcher(expectedState)))
}
private fun assertNormalBrowsingButton() {
normalBrowsingButton().check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
private fun assertNormalBrowsingButtonIsSelected(isSelected: Boolean) {
normalBrowsingButton().check(matches(isSelected(isSelected)))
}
private fun assertPrivateBrowsingButtonIsSelected(isSelected: Boolean) {
privateBrowsingButton().check(matches(isSelected(isSelected)))
}
private val tabsList =
UiScrollable(UiSelector().className("androidx.recyclerview.widget.RecyclerView")) UiScrollable(UiSelector().className("androidx.recyclerview.widget.RecyclerView"))
// This tab selector is used for actions that involve waiting and asserting the existence of the view // This tab selector is used for actions that involve waiting and asserting the existence of the view

Loading…
Cancel
Save