From 1e83f54a942efe8bc866da1ad67be6794f324701 Mon Sep 17 00:00:00 2001 From: ValentinTimisica Date: Mon, 11 May 2020 12:03:14 +0300 Subject: [PATCH] For #10343: Updates UI tests accordingly to 'Library' removal --- .../org/mozilla/fenix/ui/BookmarksTest.kt | 14 --- .../java/org/mozilla/fenix/ui/HistoryTest.kt | 11 --- .../org/mozilla/fenix/ui/LibraryMenuTest.kt | 90 ------------------ .../mozilla/fenix/ui/robots/LibraryRobot.kt | 93 ------------------- .../fenix/ui/robots/ThreeDotMenuMainRobot.kt | 13 --- .../DefaultBrowserToolbarControllerTest.kt | 22 ++++- 6 files changed, 18 insertions(+), 225 deletions(-) delete mode 100644 app/src/androidTest/java/org/mozilla/fenix/ui/LibraryMenuTest.kt delete mode 100644 app/src/androidTest/java/org/mozilla/fenix/ui/robots/LibraryRobot.kt diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/BookmarksTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/BookmarksTest.kt index e161c1703..22811485c 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/BookmarksTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/BookmarksTest.kt @@ -110,7 +110,6 @@ class BookmarksTest { browserScreen { createBookmark(defaultWebPage.url) }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) @@ -159,7 +158,6 @@ class BookmarksTest { browserScreen { createBookmark(defaultWebPage.url) }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) @@ -190,7 +188,6 @@ class BookmarksTest { browserScreen { createBookmark(defaultWebPage.url) }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) @@ -208,7 +205,6 @@ class BookmarksTest { browserScreen { createBookmark(defaultWebPage.url) }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) @@ -229,7 +225,6 @@ class BookmarksTest { browserScreen { createBookmark(defaultWebPage.url) }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) @@ -249,7 +244,6 @@ class BookmarksTest { browserScreen { createBookmark(defaultWebPage.url) }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) @@ -269,7 +263,6 @@ class BookmarksTest { browserScreen { createBookmark(defaultWebPage.url) }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) @@ -288,7 +281,6 @@ class BookmarksTest { browserScreen { createBookmark(defaultWebPage.url) }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) @@ -309,7 +301,6 @@ class BookmarksTest { browserScreen { createBookmark(defaultWebPage.url) }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) @@ -337,7 +328,6 @@ class BookmarksTest { }.openHomeScreen { closeTab() }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) @@ -361,7 +351,6 @@ class BookmarksTest { browserScreen { createBookmark(defaultWebPage.url) }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) @@ -387,7 +376,6 @@ class BookmarksTest { createBookmark(firstWebPage.url) createBookmark(secondWebPage.url) }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) @@ -414,7 +402,6 @@ class BookmarksTest { browserScreen { createBookmark(defaultWebPage.url) }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) @@ -471,7 +458,6 @@ class BookmarksTest { browserScreen { createBookmark(defaultWebPage.url) }.openThreeDotMenu { - }.openLibrary { }.openBookmarks { bookmarksListIdlingResource = RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list)) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/HistoryTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/HistoryTest.kt index 83ff17cad..2bc03ed5d 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/HistoryTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/HistoryTest.kt @@ -71,7 +71,6 @@ class HistoryTest { }.enterURLAndEnterToBrowser(firstWebPage.url) { verifyPageContent("Page content: 1") }.openThreeDotMenu { - }.openLibrary { }.openHistory { verifyHistoryMenuView() verifyVisitedTimeTitle() @@ -88,7 +87,6 @@ class HistoryTest { }.enterURLAndEnterToBrowser(firstWebPage.url) { verifyPageContent("Page content: 1") }.openThreeDotMenu { - }.openLibrary { }.openHistory { }.openThreeDotMenu { }.clickCopy { @@ -104,7 +102,6 @@ class HistoryTest { }.enterURLAndEnterToBrowser(firstWebPage.url) { verifyPageContent("Page content: 1") }.openThreeDotMenu { - }.openLibrary { }.openHistory { }.openThreeDotMenu { }.clickShare { @@ -123,7 +120,6 @@ class HistoryTest { }.enterURLAndEnterToBrowser(firstWebPage.url) { verifyPageContent("Page content: 1") }.openThreeDotMenu { - }.openLibrary { }.openHistory { }.openThreeDotMenu { }.clickOpenInNormalTab { @@ -141,7 +137,6 @@ class HistoryTest { }.enterURLAndEnterToBrowser(firstWebPage.url) { verifyPageContent("Page content: 1") }.openThreeDotMenu { - }.openLibrary { }.openHistory { }.openThreeDotMenu { }.clickOpenInPrivateTab { @@ -159,7 +154,6 @@ class HistoryTest { }.enterURLAndEnterToBrowser(firstWebPage.url) { verifyPageContent("Page content: 1") }.openThreeDotMenu { - }.openLibrary { }.openHistory { }.openThreeDotMenu { }.clickDelete { @@ -175,7 +169,6 @@ class HistoryTest { }.enterURLAndEnterToBrowser(firstWebPage.url) { verifyPageContent("Page content: 1") }.openThreeDotMenu { - }.openLibrary { }.openHistory { clickDeleteHistoryButton() verifyDeleteConfirmationMessage() @@ -192,7 +185,6 @@ class HistoryTest { }.enterURLAndEnterToBrowser(firstWebPage.url) { verifyPageContent("Page content: 1") }.openThreeDotMenu { - }.openLibrary { }.openHistory { longTapSelectItem(firstWebPage.url) } @@ -237,7 +229,6 @@ class HistoryTest { }.enterURLAndEnterToBrowser(firstWebPage.url) { verifyPageContent("Page content: 1") }.openThreeDotMenu { - }.openLibrary { }.openHistory { longTapSelectItem(firstWebPage.url) openActionBarOverflowOrOptionsMenu(activityTestRule.activity) @@ -264,7 +255,6 @@ class HistoryTest { }.enterURLAndEnterToBrowser(secondWebPage.url) { verifyPageContent("Page content: 2") }.openThreeDotMenu { - }.openLibrary { }.openHistory { longTapSelectItem(firstWebPage.url) longTapSelectItem(secondWebPage.url) @@ -288,7 +278,6 @@ class HistoryTest { }.enterURLAndEnterToBrowser(firstWebPage.url) { verifyPageContent("Page content: 1") }.openThreeDotMenu { - }.openLibrary { }.openHistory { longTapSelectItem(firstWebPage.url) } diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/LibraryMenuTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/LibraryMenuTest.kt deleted file mode 100644 index 4f06cb24b..000000000 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/LibraryMenuTest.kt +++ /dev/null @@ -1,90 +0,0 @@ -package org.mozilla.fenix.ui - -import okhttp3.mockwebserver.MockWebServer -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.mozilla.fenix.helpers.AndroidAssetDispatcher -import org.mozilla.fenix.helpers.HomeActivityTestRule -import org.mozilla.fenix.helpers.TestAssetHelper -import org.mozilla.fenix.ui.robots.navigationToolbar - -/** - * Tests for verifying basic functionality of Library accessed from browser screen - */ -class LibraryMenuTest { - - private lateinit var mockWebServer: MockWebServer - private lateinit var defaultWebPage: TestAssetHelper.TestAsset - - @get:Rule - val activityTestRule = HomeActivityTestRule() - - @Before - fun setUp() { - mockWebServer = MockWebServer().apply { - setDispatcher(AndroidAssetDispatcher()) - start() - } - defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) - } - - @After - fun tearDown() { - mockWebServer.shutdown() - } - - @Test - fun libraryMenuItemsTest() { - navigationToolbar { - }.enterURLAndEnterToBrowser(defaultWebPage.url) { - verifyPageContent(defaultWebPage.content) - }.openThreeDotMenu { - verifyLibraryButton() - }.openLibrary { - verifyLibraryView() - verifyHistoryButton() - verifyBookmarksButton() - } - } - - @Test - fun backButtonTest() { - navigationToolbar { - }.enterURLAndEnterToBrowser(defaultWebPage.url) { - verifyPageContent(defaultWebPage.content) - }.openThreeDotMenu { - verifyLibraryButton() - }.openLibrary { - }.goBack { - verifyBrowserScreen() - } - } - - @Test - fun bookmarksButtonTest() { - navigationToolbar { - }.enterURLAndEnterToBrowser(defaultWebPage.url) { - verifyPageContent(defaultWebPage.content) - }.openThreeDotMenu { - verifyLibraryButton() - }.openLibrary { - }.openBookmarks { - verifyBookmarksMenuView() - } - } - - @Test - fun historyButtonTest() { - navigationToolbar { - }.enterURLAndEnterToBrowser(defaultWebPage.url) { - verifyPageContent(defaultWebPage.content) - }.openThreeDotMenu { - verifyLibraryButton() - }.openLibrary { - }.openHistory { - verifyHistoryMenuView() - } - } -} diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/LibraryRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/LibraryRobot.kt deleted file mode 100644 index 4d9aa5b36..000000000 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/LibraryRobot.kt +++ /dev/null @@ -1,93 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -@file:Suppress("TooManyFunctions") - -package org.mozilla.fenix.ui.robots - -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.assertion.ViewAssertions -import androidx.test.espresso.matcher.ViewMatchers -import androidx.test.espresso.matcher.ViewMatchers.withContentDescription -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.espresso.matcher.ViewMatchers.withText -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.uiautomator.By -import androidx.test.uiautomator.UiDevice -import androidx.test.uiautomator.Until -import org.hamcrest.CoreMatchers.allOf -import org.mozilla.fenix.R -import org.mozilla.fenix.helpers.TestAssetHelper -import org.mozilla.fenix.helpers.click -import org.mozilla.fenix.helpers.ext.waitNotNull - -/** - * Implementation of Robot Pattern for the your library menu. - */ -class LibraryRobot { - fun verifyLibraryView() = assertLibraryView() - fun verifyBookmarksButton() = assertBookmarksButton() - fun verifyHistoryButton() = assertHistoryButton() - - class Transition { - - val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - - fun goBack(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition { - - mDevice.waitForIdle() - goBackButton().perform(click()) - - BrowserRobot().interact() - return BrowserRobot.Transition() - } - - fun openBookmarks(interact: BookmarksRobot.() -> Unit): BookmarksRobot.Transition { - mDevice.waitNotNull(Until.findObject(By.text("Bookmarks")), TestAssetHelper.waitingTime) - bookmarksButton().click() - - BookmarksRobot().interact() - return BookmarksRobot.Transition() - } - - fun openHistory(interact: HistoryRobot.() -> Unit): HistoryRobot.Transition { - mDevice.waitNotNull(Until.findObject(By.text("History")), TestAssetHelper.waitingTime) - historyButton().click() - - HistoryRobot().interact() - return HistoryRobot.Transition() - } - } -} - -private fun goBackButton() = onView(allOf(withContentDescription("Navigate up"))) -private fun bookmarksButton() = onView(allOf(withText("Bookmarks"))) -private fun historyButton() = onView(allOf(withText("History"))) - -private fun assertLibraryView() { - onView( - allOf( - withText("Library"), - ViewMatchers.withParent(withId(R.id.navigationToolbar)) - ) - ) - .check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) -} - -private fun assertBookmarksButton() = bookmarksButton().check( - ViewAssertions.matches( - ViewMatchers.withEffectiveVisibility( - ViewMatchers.Visibility.VISIBLE - ) - ) -) - -private fun assertHistoryButton() = historyButton().check( - ViewAssertions.matches( - ViewMatchers.withEffectiveVisibility( - ViewMatchers.Visibility.VISIBLE - ) - ) -) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt index c8bff8177..727b0228d 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt @@ -38,7 +38,6 @@ import org.mozilla.fenix.share.ShareFragment */ class ThreeDotMenuMainRobot { fun verifySettingsButton() = assertSettingsButton() - fun verifyLibraryButton() = assertLibraryButton() fun verifyHistoryButton() = assertHistoryButton() fun verifyBookmarksButton() = assertBookmarksButton() fun verifyHelpButton() = assertHelpButton() @@ -100,14 +99,6 @@ class ThreeDotMenuMainRobot { return SettingsRobot.Transition() } - fun openLibrary(interact: LibraryRobot.() -> Unit): LibraryRobot.Transition { - mDevice.waitNotNull(Until.findObject(By.text("Library")), waitingTime) - libraryButton().click() - - LibraryRobot().interact() - return LibraryRobot.Transition() - } - fun openBookmarks(interact: BookmarksRobot.() -> Unit): BookmarksRobot.Transition { mDevice.waitNotNull(Until.findObject(By.text("Bookmarks")), waitingTime) bookmarksButton().click() @@ -257,10 +248,6 @@ private fun assertSettingsButton() = settingsButton() .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) .check(matches(isCompletelyDisplayed())) -private fun libraryButton() = onView(allOf(withText(R.string.browser_menu_library))) -private fun assertLibraryButton() = libraryButton() - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) - private fun historyButton() = onView(allOf(withText(R.string.library_history))) private fun assertHistoryButton() = historyButton() .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt index 6c865ff12..18d7b0434 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt @@ -25,6 +25,7 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.runBlockingTest import kotlinx.coroutines.test.setMain +import mozilla.appservices.places.BookmarkRoot import mozilla.components.browser.session.Session import mozilla.components.browser.session.SessionManager import mozilla.components.browser.state.state.BrowserState @@ -287,14 +288,27 @@ class DefaultBrowserToolbarControllerTest { } @Test - fun handleToolbarLibraryPress() { - val item = ToolbarMenu.Item.Library + fun handleToolbarBookmarksPress() { + val item = ToolbarMenu.Item.Bookmarks controller.handleToolbarItemInteraction(item) - verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.LIBRARY)) } + verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.BOOKMARKS)) } verify { - val directions = BrowserFragmentDirections.actionBrowserFragmentToLibraryFragment() + val directions = BrowserFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id) + navController.nav(R.id.browserFragment, directions) + } + } + + @Test + fun handleToolbarHistoryPress() { + val item = ToolbarMenu.Item.History + + controller.handleToolbarItemInteraction(item) + + verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.HISTORY)) } + verify { + val directions = BrowserFragmentDirections.actionGlobalHistoryFragment() navController.nav(R.id.browserFragment, directions) } }