Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Closes #1908: Add ui test
Browse files Browse the repository at this point in the history
  • Loading branch information
dnarcese committed Apr 10, 2019
1 parent 3edd354 commit b652b53
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
83 changes: 83 additions & 0 deletions app/src/androidTest/java/org/mozilla/tv/firefox/ui/TooltipTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* 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/. */

package org.mozilla.tv.firefox.ui

import org.junit.Rule
import org.junit.Test
import org.mozilla.tv.firefox.helpers.MainActivityTestRule
import org.mozilla.tv.firefox.ui.robots.navigationOverlay

private const val TURBO_MODE_TEXT = "Turbo Mode"
private const val BACK_TEXT = "Navigate back"
private const val FORWARD_TEXT = "Navigate forward"
private const val RELOAD_TEXT = "Reload website"
private const val PIN_TEXT = "Pin to homescreen"
private const val DESKTOP_MODE_TEXT = "Request desktop version of this site"
private const val EXIT_TEXT = "Exit Firefox"
private const val SETTINGS_TEXT = "Settings"

/**
* A test for the nav bar tooltips including:
* - Each tooltip shows the correct string
* - The string dynamically updates the ON/OFF state (only applicable to Turbo Mode)
*/
class TooltipTest {

@get:Rule val activityTestRule = MainActivityTestRule()

/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.
@Test
fun tooltipTest() {
navigationOverlay {
// Url bar is focused on startup and next focus up will be turbo mode button
remoteUp()
assertTooltipText(TURBO_MODE_TEXT)
remoteCenter()
assertTooltipText(TURBO_MODE_TEXT)
}.openTileToBrowser(1) {
}.openOverlay {
}.openTileToBrowser(2) {
}.openOverlay {
// Focus back button
remoteUp()
assertTooltipText(BACK_TEXT)
}.goBack {
}.openOverlay {
// Focus forward button
remoteUp()
assertTooltipText(FORWARD_TEXT)
// Focus reload button
remoteRight()
assertTooltipText(RELOAD_TEXT)
// Focus pin button
remoteRight()
assertTooltipText(PIN_TEXT)
}.unpinSite {
}.openOverlay {
// This sequence focuses the pin button from the url bar
remoteUp()
remoteRight(2)
assertTooltipText(PIN_TEXT)
// Focus turbo mode button
remoteRight()
assertTooltipText(TURBO_MODE_TEXT)
// Focus desktop mode button
remoteRight()
assertTooltipText(DESKTOP_MODE_TEXT)
}.turnDesktopModeOn {
}.openOverlay {
// This sequence focuses the desktop mode button from the url bar
remoteUp()
remoteRight(4)
assertTooltipText(DESKTOP_MODE_TEXT)
// Focus exit button
remoteRight()
assertTooltipText(EXIT_TEXT)
// Focus settings button
remoteRight()
assertTooltipText(SETTINGS_TEXT)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.test.espresso.action.ViewActions.pressImeActionButton
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.RootMatchers.isPlatformPopup
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.withHint
import androidx.test.espresso.matcher.ViewMatchers.withId
Expand Down Expand Up @@ -39,11 +40,15 @@ class NavigationOverlayRobot {
private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

fun goBack() = backButton().click()
fun remoteBack() = device.pressBack()
fun goForward() = forwardButton().click()
fun reload() = reloadButton().click()
fun toggleTurbo() = turboButton().click()

fun remoteBack() = device.pressBack()
fun remoteUp() = device.pressDPadUp()
fun remoteRight(x: Int = 1) = repeat(x) { device.pressDPadRight() }
fun remoteCenter() = device.pressDPadCenter()

// The implementation of this method is arbitrary. We could run this check
// against any of its views
fun assertOverlayIsOpen() = urlBar().assertIsDisplayed(true)
Expand Down Expand Up @@ -97,6 +102,8 @@ class NavigationOverlayRobot {
fun disableSessionIdling(activityTestRule: MainActivityTestRule) { activityTestRule.loadingIdlingResource.ignoreLoading = true }
fun enableSessionIdling(activityTestRule: MainActivityTestRule) { activityTestRule.loadingIdlingResource.ignoreLoading = false }

fun assertTooltipText(text: String) = tooltip().check(matches(withText(text)))

class Transition {
private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

Expand Down Expand Up @@ -254,3 +261,4 @@ private fun homeTiles() = onView(withId(R.id.tileContainer))
private fun overlay() = onView(withId(R.layout.fragment_navigation_overlay))
private fun desktopModeButton() = onView(withId(R.id.desktopModeButton))
private fun pocketMegaTile() = onView(withId(R.id.pocketVideosContainer))
private fun tooltip() = onView(withId(R.id.tooltip)).inRoot(isPlatformPopup())

0 comments on commit b652b53

Please sign in to comment.