Added a method to detect the UI Theme (#6542)
parent
ebdfe8184e
commit
0cfde5b86a
|
@ -4,13 +4,14 @@
|
|||
|
||||
package org.mozilla.fenix.ui
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import okhttp3.mockwebserver.MockWebServer
|
||||
import org.junit.Rule
|
||||
import org.junit.Before
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
||||
|
@ -43,6 +44,16 @@ class SettingsBasicsTest {
|
|||
mockWebServer.shutdown()
|
||||
}
|
||||
|
||||
private fun getUiTheme(): Boolean {
|
||||
val mode = activityTestRule.activity.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)
|
||||
|
||||
return when (mode) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> true // dark theme is set
|
||||
Configuration.UI_MODE_NIGHT_NO -> false // dark theme is not set, using light theme
|
||||
else -> false // default option is light theme
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// Walks through settings menu and sub-menus to ensure all items are present
|
||||
fun settingsMenuBasicsItemsTests() {
|
||||
|
@ -115,19 +126,18 @@ class SettingsBasicsTest {
|
|||
// Verify history and bookmarks are gone
|
||||
}
|
||||
|
||||
@Ignore("This is a stub test, ignore for now")
|
||||
@Test
|
||||
fun changeThemeSetting() {
|
||||
// Open 3dot (main) menu
|
||||
// Select settings
|
||||
// Verify default theme appears as "Light"
|
||||
// Select theme to enter theme sub-menu
|
||||
// Verify them sub-menu has 3 options: "Light", "Dark" and "Set by Battery Saver"
|
||||
// Select "Dark" theme
|
||||
// Verify them is changed to Dark
|
||||
// Optional:
|
||||
// Select "Set by battery saver"
|
||||
// Verify theme changes based on battery saver
|
||||
homeScreen {
|
||||
}.openThreeDotMenu {
|
||||
}.openSettings {
|
||||
}.openThemeSubMenu {
|
||||
verifyThemes()
|
||||
selectDarkMode()
|
||||
verifyDarkThemeApplied(getUiTheme())
|
||||
selectLightMode()
|
||||
verifyLightThemeApplied(getUiTheme())
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("This is a stub test, ignore for now")
|
||||
|
|
|
@ -6,14 +6,17 @@
|
|||
|
||||
package org.mozilla.fenix.ui.robots
|
||||
|
||||
import androidx.test.espresso.Espresso
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.action.ViewActions
|
||||
import androidx.test.espresso.assertion.ViewAssertions
|
||||
import androidx.test.espresso.matcher.ViewMatchers
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import org.hamcrest.CoreMatchers
|
||||
import org.hamcrest.CoreMatchers.allOf
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.mozilla.fenix.helpers.click
|
||||
|
||||
/**
|
||||
* Implementation of Robot Pattern for the settings Theme sub menu.
|
||||
|
@ -22,6 +25,14 @@ class SettingsSubMenuThemeRobot {
|
|||
|
||||
fun verifyThemes() = assertThemes()
|
||||
|
||||
fun verifyLightThemeApplied(expected: Boolean) = assertFalse("Light theme not selected", expected)
|
||||
|
||||
fun verifyDarkThemeApplied(expected: Boolean) = assertTrue("Dark theme not selected", expected)
|
||||
|
||||
fun selectDarkMode() = darkModeToggle().click()
|
||||
|
||||
fun selectLightMode() = lightModeToggle().click()
|
||||
|
||||
class Transition {
|
||||
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
|
||||
|
@ -36,9 +47,9 @@ class SettingsSubMenuThemeRobot {
|
|||
}
|
||||
|
||||
private fun assertThemes() {
|
||||
onView(ViewMatchers.withText("Light"))
|
||||
onView(withText("Light"))
|
||||
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
onView(ViewMatchers.withText("Dark"))
|
||||
onView(withText("Dark"))
|
||||
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
// Conditionally unavailable on API 25
|
||||
// onView(ViewMatchers.withText("Follow device theme"))
|
||||
|
@ -46,4 +57,8 @@ private fun assertThemes() {
|
|||
}
|
||||
|
||||
private fun goBackButton() =
|
||||
Espresso.onView(CoreMatchers.allOf(ViewMatchers.withContentDescription("Navigate up")))
|
||||
onView(allOf(ViewMatchers.withContentDescription("Navigate up")))
|
||||
|
||||
private fun darkModeToggle() = onView(withText("Dark"))
|
||||
|
||||
private fun lightModeToggle() = onView(withText("Light"))
|
||||
|
|
Loading…
Reference in New Issue