diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/LibraryMenuTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/LibraryMenuTest.kt new file mode 100644 index 000000000..f18ee32ba --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/LibraryMenuTest.kt @@ -0,0 +1,63 @@ +package org.mozilla.fenix.ui + +import org.junit.Rule +import org.junit.Test +import org.mozilla.fenix.helpers.HomeActivityTestRule +import org.mozilla.fenix.ui.robots.homeScreen + +class LibraryMenuTest { + + @get:Rule + val activityTestRule = HomeActivityTestRule() + + @Test + fun libraryMenuItemsTest() { + homeScreen { + }.openThreeDotMenu { + }.openLibrary { + verifyLibraryView() + verifyHistoryButton() + verifyBookmarksButton() + } + } + + @Test + fun closeMenuButtonTest() { + homeScreen { + }.openThreeDotMenu { + }.openLibrary { + }.closeMenu { + verifyHomeScreen() + } + } + + @Test + fun backButtonTest() { + homeScreen { + }.openThreeDotMenu { + }.openLibrary { + }.goBack { + verifyHomeScreen() + } + } + + @Test + fun bookmarksButtonTest() { + homeScreen { + }.openThreeDotMenu { + }.openLibrary { + }.openBookmarks { + verifyBookmarksMenuView() + } + } + + @Test + fun historyButtonTest() { + homeScreen { + }.openThreeDotMenu { + }.openLibrary { + }.openHistory { + verifyHistoryMenuView() + } + } +} diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BookmarksRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BookmarksRobot.kt new file mode 100644 index 000000000..b550d8d61 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BookmarksRobot.kt @@ -0,0 +1,41 @@ +package org.mozilla.fenix.ui.robots + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.espresso.matcher.ViewMatchers.withParent +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility +import androidx.test.espresso.matcher.ViewMatchers.Visibility +import androidx.test.espresso.matcher.ViewMatchers.withContentDescription +import org.hamcrest.Matchers.allOf +import org.mozilla.fenix.R +import org.mozilla.fenix.helpers.click + +class BookmarksRobot { + + fun verifyBookmarksMenuView() = assertBookmarksView() + + class Transition { + fun goBack(interact: LibraryRobot.() -> Unit): LibraryRobot.Transition { + goBackButton().click() + + LibraryRobot().interact() + return LibraryRobot.Transition() + } + } +} + +fun bookmarksMenu(interact: BookmarksRobot.() -> Unit): BookmarksRobot.Transition { + BookmarksRobot().interact() + return BookmarksRobot.Transition() +} + +private fun assertBookmarksView() { + onView(allOf( + withText("Bookmarks"), + withParent(withId(R.id.navigationToolbar)))) + .check(ViewAssertions.matches(withEffectiveVisibility(Visibility.VISIBLE))) +} + +private fun goBackButton() = onView(withContentDescription("Navigate up")) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HistoryRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HistoryRobot.kt new file mode 100644 index 000000000..f8465d671 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HistoryRobot.kt @@ -0,0 +1,39 @@ +package org.mozilla.fenix.ui.robots + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.espresso.matcher.ViewMatchers.withParent +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility +import androidx.test.espresso.matcher.ViewMatchers.Visibility +import androidx.test.espresso.matcher.ViewMatchers.withContentDescription +import org.hamcrest.Matchers.allOf +import org.mozilla.fenix.R +import org.mozilla.fenix.helpers.click + +class HistoryRobot { + + fun verifyHistoryMenuView() = assertHistoryView() + + class Transition { + fun goBack(interact: LibraryRobot.() -> Unit): LibraryRobot.Transition { + goBackButton().click() + + LibraryRobot().interact() + return LibraryRobot.Transition() + } + } +} + +fun historyMenu(interact: HistoryRobot.() -> Unit): HistoryRobot.Transition { + HistoryRobot().interact() + return HistoryRobot.Transition() +} + +private fun assertHistoryView() { + onView(allOf(withText("History"), withParent(withId(R.id.navigationToolbar)))) + .check(ViewAssertions.matches(withEffectiveVisibility(Visibility.VISIBLE))) +} + +private fun goBackButton() = onView(withContentDescription("Navigate up")) 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 index d0d72c2f5..407722bf8 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/LibraryRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/LibraryRobot.kt @@ -8,6 +8,8 @@ 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 @@ -15,12 +17,15 @@ import androidx.test.uiautomator.UiDevice import androidx.test.platform.app.InstrumentationRegistry import org.hamcrest.CoreMatchers.allOf import org.mozilla.fenix.R +import org.mozilla.fenix.helpers.click /** * Implementation of Robot Pattern for the your library menu. */ class LibraryRobot { fun verifyLibraryView() = assertLibraryView() + fun verifyBookmarksButton() = assertBookmarksButton() + fun verifyHistoryButton() = assertHistoryButton() class Transition { @@ -34,13 +39,53 @@ class LibraryRobot { HomeScreenRobot().interact() return HomeScreenRobot.Transition() } + + fun closeMenu(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition { + closeButton().click() + + HomeScreenRobot().interact() + return HomeScreenRobot.Transition() + } + + fun openBookmarks(interact: BookmarksRobot.() -> Unit): BookmarksRobot.Transition { + bookmarksButton().click() + + BookmarksRobot().interact() + return BookmarksRobot.Transition() + } + + fun openHistory(interact: HistoryRobot.() -> Unit): HistoryRobot.Transition { + historyButton().click() + + HistoryRobot().interact() + return HistoryRobot.Transition() + } } } +private fun goBackButton() = onView(allOf(withContentDescription("Navigate up"))) +private fun closeButton() = onView(withId(R.id.libraryClose)) +private fun bookmarksButton() = onView(allOf(withText("Bookmarks"))) +private fun historyButton() = onView(allOf(withText("History"))) private fun assertLibraryView() { - // verify that we are in the correct library view - onView(allOf(withId(R.id.libraryItemTitle))) - onView(allOf(withText("Bookmarks"))) + onView(allOf( + withText("Library"), + ViewMatchers.withParent(withId(R.id.navigationToolbar)))) + .check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) } -private fun goBackButton() = onView(allOf(withContentDescription("Navigate up"))) +private fun assertBookmarksButton() = bookmarksButton().check( + ViewAssertions.matches( + ViewMatchers.withEffectiveVisibility( + ViewMatchers.Visibility.VISIBLE + ) + ) +) + +private fun assertHistoryButton() = historyButton().check( + ViewAssertions.matches( + ViewMatchers.withEffectiveVisibility( + ViewMatchers.Visibility.VISIBLE + ) + ) +)