Repository navigation
Fix theme selection and add Settings validation tests - #188
Merged
Merged
Conversation
SelectedTheme was built from the theme's position in the list instead of its stored id, so the Black theme painted the regular dark surface instead of pure black, and isDark was forced on for Black, which made 'Follow system (Black)' ignore a light system theme. Pass the stored id and derive isDark from the mode alone. Add 201 unit tests (475 in total) for every Settings item and its consumers: Preferences, preference items, the Settings view model and screen, AppTheme, the sync scheduler and update check (Wi-Fi only, charging, notifications), the watch list, main and installed view models, and the Drive upload observer. Add on-device Compose tests (SettingsUiTest, ThemeRenderingUiTest) that drive the real Settings screen and read the persisted preferences back. Test infrastructure: FakeDfeApi can serve bulk details responses, StableStartupPreferencesRule accepts preference overrides, and the androidTest source set gets work-testing so on-device tests run against an isolated in-memory WorkManager. Co-authored-by: Copilot App <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the theme-selection fix and added Settings regression coverage.
No open issues 🎉
What changed in this PR
Fixes AppWatcher’s theme selection so Black uses pure-black surfaces and “Follow system (Black)” respects light mode. Adds layered Settings regression coverage from stored preferences through screen interactions to downstream consumers.
Changes:
- Corrects
SelectedThemeconstruction to use the stored theme ID and derive dark mode independently. - Adds preference, Compose, view-model, sync, notification, backup, and list-settings tests.
- Adds device-level persistence and theme-rendering checks with shared test helpers and WorkManager test support.
| File | Description |
|---|---|
app/src/test/java/com/anod/appwatcher/watchlist/WatchListStateViewModelSettingsTest.kt |
Tests list initialization and live settings changes. |
app/src/test/java/com/anod/appwatcher/watchlist/MainViewModelSettingsTest.kt |
Tests preference propagation and notification-driven scheduling. |
app/src/test/java/com/anod/appwatcher/sync/UpdateCheckWifiOnlyTest.kt |
Tests scheduled and manual refresh network policies. |
app/src/test/java/com/anod/appwatcher/sync/UpdateCheckNotificationSettingsTest.kt |
Tests notification filtering through the sync pipeline. |
app/src/test/java/com/anod/appwatcher/sync/UpdateCheckHarness.kt |
Provides shared sync test dependencies. |
app/src/test/java/com/anod/appwatcher/preferences/SettingsViewModelTest.kt |
Tests Settings actions, persistence, scheduling, and failures. |
app/src/test/java/com/anod/appwatcher/preferences/SettingsTestSupport.kt |
Adds shared bindings, fixtures, and test doubles. |
app/src/test/java/com/anod/appwatcher/preferences/SettingsScreenTestBase.kt |
Provides reusable Compose screen test support. |
app/src/test/java/com/anod/appwatcher/preferences/SettingsScreenTest.kt |
Tests displayed settings and control interactions. |
app/src/test/java/com/anod/appwatcher/preferences/SettingsScreenSceneTest.kt |
Tests navigation, permissions, backup, and restart integration. |
app/src/test/java/com/anod/appwatcher/preferences/SettingsScreenIconShapeTest.kt |
Tests icon-shape selection events. |
app/src/test/java/com/anod/appwatcher/preferences/SettingsScreenDriveSyncTest.kt |
Tests Drive controls and availability states. |
app/src/test/java/com/anod/appwatcher/preferences/SettingsScreenBackupTest.kt |
Tests document pickers, cancellation, and missing providers. |
app/src/test/java/com/anod/appwatcher/preferences/SettingsItemClickTest.kt |
Tests preference-click routing and updates. |
app/src/test/java/com/anod/appwatcher/preferences/SettingsConsumersTest.kt |
Tests notification filters and watchlist preference mapping. |
app/src/test/java/com/anod/appwatcher/preferences/PreferencesTest.kt |
Tests defaults, persistence, change events, and theme mapping. |
app/src/test/java/com/anod/appwatcher/preferences/PreferenceItemsTest.kt |
Tests Settings item structure, values, and enabled states. |
app/src/test/java/com/anod/appwatcher/preferences/PreferenceItemsDriveSyncTest.kt |
Tests Drive item values and summaries. |
app/src/test/java/com/anod/appwatcher/installed/InstalledListViewModelSettingsTest.kt |
Tests installed-list pull-to-refresh settings. |
app/src/test/java/com/anod/appwatcher/compose/AppThemeTest.kt |
Tests theme colors across system light and dark modes. |
app/src/test/java/com/anod/appwatcher/backup/gdrive/UploadServiceContentObserverTest.kt |
Tests upload scheduling and preference-based constraints. |
app/src/test/java/com/anod/appwatcher/accounts/FakeDfeApi.kt |
Adds configurable bulk-details responses. |
app/src/main/java/com/anod/appwatcher/preferences/Preferences.kt |
Fixes theme identity and dark-mode interpretation. |
app/src/androidTest/java/com/anod/appwatcher/ThemeRenderingUiTest.kt |
Checks painted Settings colors on a device. |
app/src/androidTest/java/com/anod/appwatcher/StableStartupPreferencesRule.kt |
Supports startup preference overrides and restoration. |
app/src/androidTest/java/com/anod/appwatcher/SettingsUiTest.kt |
Tests real-screen persistence, scheduling, and navigation. |
app/src/androidTest/java/com/anod/appwatcher/SettingsScreenRobot.kt |
Adds reusable device interaction and assertion helpers. |
app/src/androidTest/java/com/anod/appwatcher/IsolatedWorkManagerRule.kt |
Provides test WorkManager setup and schedule inspection. |
app/build.gradle.kts |
Adds WorkManager testing support for instrumentation. |
Review effort: Balanced
Android 13+ denies POST_NOTIFICATIONS to a fresh install, so on the CI emulator the two settings tests that need notifications (update frequency scheduling and the sample notification row) were reported as failed assumption violations. NotificationPermissionRule grants the permission before the activity starts, so the screen reads the allowed state. A device that already allows notifications is unchanged. The assumptions stay for a user who blocked the app in the system settings. Co-authored-by: Copilot App <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validates the Settings screen end to end and fills the test gaps around it: every setting is now covered from the stored preference, through the screen, to the code that consumes it. The tests exposed one real bug in the theme setting, which is fixed here.
Bug fix: theme selection
Preferences.selectedThemebuiltSelectedThemefrom the theme's position in the list (themeIndex) instead of its stored id, andSelectedTheme.isDarkwas forced on whenever Black was selected.THEME_BLACK, so it painted the regular dark surface (#0B0F0C) instead of pure black (#000000).The fix is two lines in
Preferences.kt: passtheme(the id) and deriveisDarkfrom the mode alone.AppThemealready ORs inisSystem && isSystemInDarkTheme()and only applies the black surfaces in the dark scheme, so nothing else changes.Tests
Unit tests: 274 → 475 (201 new, 0 failures)
PreferencesTest,PreferenceItemsTest,PreferenceItemsDriveSyncTest,SettingsItemClickTestSettingsViewModelTestSettingsScreenTest,SettingsScreenBackupTest,SettingsScreenDriveSyncTest,SettingsScreenIconShapeTest,SettingsScreenSceneTestSettingsConsumersTest,AppThemeTest,UpdateCheckWifiOnlyTest,UpdateCheckNotificationSettingsTest,WatchListStateViewModelSettingsTest,MainViewModelSettingsTest,InstalledListViewModelSettingsTest,UploadServiceContentObserverTestOn-device Compose tests (12):
SettingsUiTest(7) drives the real Settings screen and verifies persistence by readingWatcherPrefs.xml;ThemeRenderingUiTest(5 theme/mode variants) checks the painted colours.IsolatedWorkManagerRuleswaps in an in-memory WorkManager so the real sync and upload workers cannot run during the tests,NotificationPermissionRulegrants the notification permission that Android 13+ denies a fresh install (the update-check scheduling and sample-notification tests need it), andStableStartupPreferencesRuleaccepts preference overrides. The permission rule does nothing on a device that already allows notifications, and it leaves the grant in place because revoking a runtime permission kills the process that runs the tests.Test infrastructure:
FakeDfeApi.bulkDetailsResponseandandroidTestImplementation(libs.work.testing).Coverage (JaCoCo, line)
preferencessyncbackupwatchlistSettingsViewModelSettingsScreenUpdateCheckPreferenceItemsPreferences"Before" is the same run with only the 274 tests that were on
master. What is left uncovered in Settings: the@Preview, the notification-permission result callback and the SDK < 33 branch, and the Play Services-bound Drive sign-in, sign-out and sync-with-account flows.Do the tests catch regressions?
I mutated the production code (reverted after each run) and checked that a test fails: 16 unit mutations, 2 scene mutations, 4 on-device mutations (theme index, Wi-Fi-only ignored, pull-to-refresh setter, refresh-history routing) and one for the diagnostics log failure handling. All were caught.
On-device results
Pixel 6a, Android 17:
SettingsUiTest,ThemeRenderingUiTest,AppWatcherSmokeTestandSearchSurfacesUiTestpass (15/15) on 3 consecutive runs, and again after addingNotificationPermissionRule. One earlier run failed in the existingSearchSurfacesUiTestright after a fresh install; it did not recur in 6 later runs.CI emulator (API 33, the
instrumentationjob): 16 tests, 15 pass.SettingsUiTest7/7,ThemeRenderingUiTest5/5,AppWatcherSmokeTestandDiagnosticRecorderDeviceTestpass. The one failure is the existingSearchSurfacesUiTest.searchSurfaces_composeMeasureAndAcceptInput(No menu with item "Settings" was found, raised byAppWatcherUiTestSupport.openMenuContaining), which this PR does not touch.That test step is
continue-on-error, so the job shows green even when tests fail. The failure only appears as a check-run annotation (The process '/usr/bin/sh' failed with exit code 1), and that annotation is on all 38 earlier Android CI runs (2026-08-28 to 2026-10-30), includingmasterat this PR's base commit. So the step was already red before this PR. I could not tell which test failed onmaster, because its logs have expired.The first CI run of this PR also reported my two notification-dependent
SettingsUiTesttests as failed. A fresh API 33+ install denies notifications, so theirassumeTrueguards threw an assumption violation, which AGP's report counts as a failure.NotificationPermissionRulenow grants the permission up front, and both pass.Findings, not changed here
icon-stylebranch inonSettingsItemClickis dead code: that item is a placeholder.libIconShapeSelectoronClickLabels are off by one (lib submodule).libPreferencesScreenkeeps un-keyedrememberwidget state that can surviverender().notify_installed_uptodate) has no effect in the sync pipeline since Fix installed update reconciliation #164: a sync-produced update always has!installed || remote > installed. Pinned byappsAlreadyUpdatedOnTheDeviceAreNeverAnnouncedWhateverUpdatedNotificationsIs.SyncScheduler.execute) always uses a connected network and no charging requirement, regardless of the Wi-Fi-only and charging settings.UpdateCheckand the Drive account flows (Play Services), and crash-report collection (Firebase; only the toggle is tested).instrumentationstep has been failing on every run since at least 2026-08-28, hidden bycontinue-on-error(see On-device results).ktlintCheckreports one pre-existing unused import inAppItemStateTest.kt; it is untouched here.Running it
./gradlew :app:testDebugUnitTest./gradlew :app:installDebug :app:installDebugAndroidTest, thenadb shell am instrument -w -e class com.anod.appwatcher.SettingsUiTest,com.anod.appwatcher.ThemeRenderingUiTest com.anod.appwatcher.debug.test/androidx.test.runner.AndroidJUnitRunner. Prefer this overconnectedDebugAndroidTest, which removes the debug app (and its data) from the device after the run.