|
| 1 | +/* |
| 2 | + * WiFiAnalyzer |
| 3 | + * Copyright (C) 2026 VREM Software Development <VREMSoftwareDevelopment@gmail.com> |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 17 | + */ |
| 18 | +package com.vrem.wifianalyzer |
| 19 | + |
| 20 | +import androidx.appcompat.app.AppCompatDelegate |
| 21 | +import androidx.test.espresso.Espresso.onView |
| 22 | +import androidx.test.espresso.Espresso.pressBack |
| 23 | +import androidx.test.espresso.action.ViewActions.click |
| 24 | +import androidx.test.espresso.assertion.ViewAssertions.matches |
| 25 | +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed |
| 26 | +import androidx.test.espresso.matcher.ViewMatchers.withText |
| 27 | +import org.junit.Assert.assertEquals |
| 28 | + |
| 29 | +internal class ThemeInstrumentedTest : Runnable { |
| 30 | + override fun run() { |
| 31 | + verifyThemeSettings() |
| 32 | + |
| 33 | + listOf( |
| 34 | + "Dark" to AppCompatDelegate.MODE_NIGHT_YES, |
| 35 | + "Light" to AppCompatDelegate.MODE_NIGHT_NO, |
| 36 | + "System" to AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM, |
| 37 | + "Black" to AppCompatDelegate.MODE_NIGHT_YES, |
| 38 | + ).forEach { (themeName, expectedNightMode) -> |
| 39 | + changeThemeAndVerify(themeName, expectedNightMode) |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + private fun verifyThemeSettings() { |
| 44 | + selectMenuItem(R.id.nav_drawer_settings, "Settings") |
| 45 | + scrollToAndVerify("Theme") |
| 46 | + pressBack() |
| 47 | + } |
| 48 | + |
| 49 | + private fun changeThemeAndVerify( |
| 50 | + themeName: String, |
| 51 | + expectedNightMode: Int, |
| 52 | + ) { |
| 53 | + selectMenuItem(R.id.nav_drawer_settings, "Settings") |
| 54 | + scrollToAndVerify("Theme") |
| 55 | + onView(withText("Theme")).perform(click()) |
| 56 | + pauseShort() |
| 57 | + onView(withText(themeName)).check(matches(isDisplayed())) |
| 58 | + onView(withText(themeName)).perform(click()) |
| 59 | + pauseShort() |
| 60 | + assertEquals( |
| 61 | + "Theme $themeName should set night mode to $expectedNightMode", |
| 62 | + expectedNightMode, |
| 63 | + AppCompatDelegate.getDefaultNightMode(), |
| 64 | + ) |
| 65 | + } |
| 66 | +} |
0 commit comments