New UI test coverage for Swipe toolbar preference

This commit is contained in:
oana.horvath 2022-12-08 10:45:23 +02:00 committed by mergify[bot]
parent b22fe8d3e5
commit 2c1622650d
3 changed files with 65 additions and 7 deletions

View File

@ -4,8 +4,6 @@
package org.mozilla.fenix.ui
import java.time.LocalDate
import java.util.Locale
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
@ -37,6 +35,8 @@ import org.mozilla.fenix.ui.util.FRENCH_LANGUAGE_HEADER
import org.mozilla.fenix.ui.util.FRENCH_SYSTEM_LOCALE_OPTION
import org.mozilla.fenix.ui.util.FR_SETTINGS
import org.mozilla.fenix.ui.util.ROMANIAN_LANGUAGE_HEADER
import java.time.LocalDate
import java.util.Locale
/**
* Tests for verifying the General section of the Settings menu

View File

@ -8,7 +8,9 @@ import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
class SettingsCustomizeTest {
private lateinit var mockWebServer: MockWebServer
@ -41,7 +43,7 @@ class SettingsCustomizeTest {
}
@Test
fun changeThemeSetting() {
fun changeThemeSettingTest() {
// Goes through the settings and changes the default search engine, then verifies it changes.
homeScreen {
}.openThreeDotMenu {
@ -54,4 +56,30 @@ class SettingsCustomizeTest {
verifyLightThemeApplied(getUiTheme())
}
}
@Test
fun swipeToolbarGesturePreferenceOffTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openCustomizeSubMenu {
verifySwipeToolbarGesturePrefState(true)
clickSwipeToolbarToSwitchTabToggle()
verifySwipeToolbarGesturePrefState(false)
}.goBack {
}.goBack {}
navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
}.openTabDrawer {
}.openNewTab {
}.submitQuery(secondWebPage.url.toString()) {
swipeNavBarRight(secondWebPage.url.toString())
verifyUrl(secondWebPage.url.toString())
swipeNavBarLeft(secondWebPage.url.toString())
verifyUrl(secondWebPage.url.toString())
}
}
}

View File

@ -10,12 +10,19 @@ import android.os.Build
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.isNotChecked
import androidx.test.espresso.matcher.ViewMatchers.withClassName
import androidx.test.espresso.matcher.ViewMatchers.withText
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.Matchers.endsWith
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestHelper.getStringResource
import org.mozilla.fenix.helpers.TestHelper.hasCousin
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.click
@ -39,6 +46,26 @@ class SettingsSubMenuCustomizeRobot {
fun clickBottomToolbarToggle() = bottomToolbarToggle().click()
fun clickSwipeToolbarToSwitchTabToggle() = swipeToolbarToggle.click()
fun verifySwipeToolbarGesturePrefState(isEnabled: Boolean) {
swipeToolbarToggle
.check(
matches(
hasCousin(
allOf(
withClassName(endsWith("Switch")),
if (isEnabled) {
isChecked()
} else {
isNotChecked()
},
),
),
),
)
}
class Transition {
fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
mDevice.waitForIdle()
@ -52,11 +79,11 @@ class SettingsSubMenuCustomizeRobot {
private fun assertThemes() {
lightModeToggle()
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
darkModeToggle()
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
deviceModeToggle()
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
private fun darkModeToggle() = onView(withText("Dark"))
@ -73,5 +100,8 @@ private fun deviceModeToggle(): ViewInteraction {
return onView(withText(followDeviceThemeText))
}
private val swipeToolbarToggle =
onView(withText(getStringResource(R.string.preference_gestures_swipe_toolbar_switch_tabs)))
private fun goBackButton() =
onView(allOf(ViewMatchers.withContentDescription("Navigate up")))