From f9031dd0a2bbbbccc92308e1800c2ef046c672f6 Mon Sep 17 00:00:00 2001 From: AndiAJ Date: Fri, 9 Feb 2024 15:14:40 +0200 Subject: [PATCH] Bug 1879539 - Remove redundant assertion functions from LibrarySubMenusMultipleSelectionToolbarRobot --- ...rySubMenusMultipleSelectionToolbarRobot.kt | 93 +++++++------------ 1 file changed, 31 insertions(+), 62 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/LibrarySubMenusMultipleSelectionToolbarRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/LibrarySubMenusMultipleSelectionToolbarRobot.kt index a86f8802e..3c675bf05 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/LibrarySubMenusMultipleSelectionToolbarRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/LibrarySubMenusMultipleSelectionToolbarRobot.kt @@ -34,27 +34,46 @@ import org.mozilla.fenix.tabstray.TabsTrayTestTag */ class LibrarySubMenusMultipleSelectionToolbarRobot { - fun verifyMultiSelectionCheckmark() = assertMultiSelectionCheckmark() - - fun verifyMultiSelectionCheckmark(url: Uri) = assertMultiSelectionCheckmark(url) + fun verifyMultiSelectionCheckmark() = onView(withId(R.id.checkmark)).check(matches(isDisplayed())) + + fun verifyMultiSelectionCheckmark(url: Uri) = + onView( + allOf( + withId(R.id.checkmark), + withParent(withParent(withChild(allOf(withId(R.id.url), withText(url.toString()))))), + + // This is used as part of the `multiSelectionToolbarItemsTest` test. Somehow, in the view hierarchy, + // the match above is finding two checkmark views - one visible, one hidden, which is throwing off + // the matcher. This 'isDisplayed' check is a hacky workaround for this, we're explicitly ignoring + // the hidden one. Why are there two to begin with, though? + isDisplayed(), + ), + ).check(matches(isDisplayed())) - fun verifyMultiSelectionCounter() = assertMultiSelectionCounter() + fun verifyMultiSelectionCounter() = onView(withText("1 selected")).check(matches(isDisplayed())) - fun verifyShareHistoryButton() = assertShareHistoryButton() + fun verifyShareHistoryButton() = shareHistoryButton().check(matches(isDisplayed())) - fun verifyShareBookmarksButton() = assertShareBookmarksButton() + fun verifyShareBookmarksButton() = shareBookmarksButton().check(matches(isDisplayed())) - fun verifyShareOverlay() = assertShareOverlay() + fun verifyShareOverlay() = onView(withId(R.id.shareWrapper)).check(matches(isDisplayed())) - fun verifyShareAppsLayout() = assertShareAppsLayout() + fun verifyShareAppsLayout() { + val sendToDeviceTitle = mDevice.findObject( + UiSelector() + .instance(0) + .className(TextView::class.java), + ) + sendToDeviceTitle.waitForExists(TestAssetHelper.waitingTime) + } - fun verifyShareTabFavicon() = assertShareTabFavicon() + fun verifyShareTabFavicon() = onView(withId(R.id.share_tab_favicon)).check(matches(isDisplayed())) - fun verifyShareTabTitle() = assertShareTabTitle() + fun verifyShareTabTitle() = onView(withId(R.id.share_tab_title)).check(matches(isDisplayed())) - fun verifyShareTabUrl() = assertShareTabUrl() + fun verifyShareTabUrl() = onView(withId(R.id.share_tab_url)) - fun verifyCloseToolbarButton() = assertCloseToolbarButton() + fun verifyCloseToolbarButton() = closeToolbarButton().check(matches(isDisplayed())) fun clickShareHistoryButton() { shareHistoryButton().click() @@ -157,53 +176,3 @@ private fun openInNewTabButton() = onView(withText("Open in new tab")) private fun openInPrivateTabButton() = onView(withText("Open in private tab")) private fun deleteButton() = onView(withText("Delete")) - -private fun assertMultiSelectionCheckmark() = - onView(withId(R.id.checkmark)) - .check(matches(isDisplayed())) - -private fun assertMultiSelectionCheckmark(url: Uri) = - onView( - allOf( - withId(R.id.checkmark), - withParent(withParent(withChild(allOf(withId(R.id.url), withText(url.toString()))))), - - // This is used as part of the `multiSelectionToolbarItemsTest` test. Somehow, in the view hierarchy, - // the match above is finding two checkmark views - one visible, one hidden, which is throwing off - // the matcher. This 'isDisplayed' check is a hacky workaround for this, we're explicitly ignoring - // the hidden one. Why are there two to begin with, though? - isDisplayed(), - ), - ) - .check(matches(isDisplayed())) - -private fun assertMultiSelectionCounter() = - onView(withText("1 selected")).check(matches(isDisplayed())) - -private fun assertShareHistoryButton() = - shareHistoryButton().check(matches(isDisplayed())) - -private fun assertShareBookmarksButton() = - shareBookmarksButton().check(matches(isDisplayed())) - -private fun assertShareOverlay() = - onView(withId(R.id.shareWrapper)).check(matches(isDisplayed())) - -private fun assertShareAppsLayout() = { - val sendToDeviceTitle = mDevice.findObject( - UiSelector() - .instance(0) - .className(TextView::class.java), - ) - sendToDeviceTitle.waitForExists(TestAssetHelper.waitingTime) -} - -private fun assertShareTabTitle() = - onView(withId(R.id.share_tab_title)).check(matches(isDisplayed())) - -private fun assertShareTabFavicon() = - onView(withId(R.id.share_tab_favicon)).check(matches(isDisplayed())) - -private fun assertShareTabUrl() = onView(withId(R.id.share_tab_url)) - -private fun assertCloseToolbarButton() = closeToolbarButton().check(matches(isDisplayed()))