Test that the dashboard config and theme override persist

This commit is contained in:
Roland Geider
2026-12-03 13:47:49 +01:00
parent 8faf2b4f19
commit eb554e2705

View File

@@ -42,6 +42,13 @@ void main() {
container.dispose();
});
/// The settings as a fresh start of the app reads them back from the prefs.
Future<AppSettings> reloaded() async {
final fresh = ProviderContainer();
addTearDown(fresh.dispose);
return fresh.read(appSettingsProvider.future);
}
group('dashboard config', () {
test('initial config is default (all visible, default order)', () async {
final settings = await container.read(appSettingsProvider.future);
@@ -99,6 +106,54 @@ void main() {
expect(updated[1], initialFirst);
});
test('a visibility change survives a restart', () async {
await container.read(appSettingsProvider.future);
await container
.read(appSettingsProvider.notifier)
.setWidgetVisible(
DashboardWidget.routines,
false,
);
final items = (await reloaded()).dashboardItems;
expect(items.isWidgetVisible(DashboardWidget.routines), false);
expect(items.visibleWidgets, hasLength(DashboardWidget.values.length - 1));
expect(items.allWidgets, DashboardWidget.values);
});
test('a new order survives a restart', () async {
await container.read(appSettingsProvider.future);
await container.read(appSettingsProvider.notifier).setDashboardOrder(0, 1);
final items = (await reloaded()).dashboardItems;
expect(items.allWidgets, [
DashboardWidget.routines,
DashboardWidget.trophies,
DashboardWidget.nutrition,
DashboardWidget.weight,
DashboardWidget.measurements,
DashboardWidget.calendar,
]);
});
for (final (description, stored) in [
('is not JSON', 'not json'),
(
'lacks a field',
jsonEncode([
{'widget': 'routines'},
]),
),
]) {
test('a stored config that $description falls back to the default', () async {
await SharedPreferencesAsync().setString(PREFS_DASHBOARD_CONFIG, stored);
final items = (await reloaded()).dashboardItems;
expect(items.allWidgets, DashboardWidget.values);
expect(items.visibleWidgets, DashboardWidget.values);
});
}
test('loads config from prefs when present', () async {
// Use a dedicated in-memory prefs instance to avoid bleed from other tests.
SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty();
@@ -312,6 +367,18 @@ void main() {
expect(container.read(appSettingsProvider).requireValue.themeMode, ThemeMode.dark);
expect(await prefs.getBool(PREFS_USER_DARK_THEME), true);
});
test('going back to system removes the stored override', () async {
await container.read(appSettingsProvider.future);
final notifier = container.read(appSettingsProvider.notifier);
await notifier.setThemeMode(ThemeMode.dark);
await notifier.setThemeMode(ThemeMode.system);
expect(container.read(appSettingsProvider).requireValue.themeMode, ThemeMode.system);
expect(await SharedPreferencesAsync().getBool(PREFS_USER_DARK_THEME), isNull);
expect((await reloaded()).themeMode, ThemeMode.system);
});
});
group('keep data on logout', () {