37 lines
1.3 KiB
Dart
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
|
||
|
|
},
|
||
|
|
);
|
||
|
|
}
|