Files
app-flutter/test/palette_test.dart
T
mikkeli 78a6564f0a
/ crosscheck (push) Successful in 1s
CI / Analyze & Test (push) Successful in 19s
CI / Debug APK (push) Successful in 1m5s
Dark/bright: Auto (Android's dark theme), Dark or Bright, kept across restarts
Settings has a segmented Auto / Dark / Bright. Auto follows platformBrightness, so
Android's schedule too. The Dash's quick button holds the other variant; a long press
is auto again. The mode is kept with shared_preferences.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 22:14:29 +09:00

37 lines
1.3 KiB
Dart

import 'package:display/theme/palette.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final dispatcher = TestWidgetsFlutterBinding.instance.platformDispatcher;
tearDown(dispatcher.clearPlatformBrightnessTestValue);
test(
'auto follows Android, the quick switch holds one, and it is kept',
() async {
SharedPreferences.setMockInitialValues({});
final prefs = await SharedPreferences.getInstance();
Themes make() =>
Themes('t', Palette.fallbackDark, Palette.fallbackBright, prefs);
final t = make();
var notified = 0;
t.addListener(() => notified++);
expect(t.mode, VariantMode.auto);
dispatcher.platformBrightnessTestValue = Brightness.light;
expect(t.isDark, isFalse);
expect(notified, 1); // the binding tells its observers
t.toggle(); // bright showing: hold dark
expect((t.mode, t.isDark), (VariantMode.dark, true));
dispatcher.platformBrightnessTestValue = Brightness.dark;
dispatcher.platformBrightnessTestValue = Brightness.light;
expect(notified, 2); // fixed: Android's changes are ignored
expect(make().mode, VariantMode.dark); // kept for the next start
},
);
}