63 lines
2.3 KiB
Dart
63 lines
2.3 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:ikar/core/config/app_message_status_size.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
setUp(() {
|
|
SharedPreferences.setMockInitialValues({});
|
|
AppMessageStatusSize.current.value = AppMessageStatusSize.defaultScale;
|
|
});
|
|
|
|
tearDown(() {
|
|
AppMessageStatusSize.current.value = AppMessageStatusSize.defaultScale;
|
|
});
|
|
|
|
test('a new installation keeps the current receipt size', () async {
|
|
expect(AppMessageStatusSize.current.value, 1.0);
|
|
expect(await AppMessageStatusSize.load(), 1.0);
|
|
expect(AppMessageStatusSize.current.value, 1.0);
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
expect(prefs.getDouble(AppMessageStatusSize.prefKey), isNull);
|
|
});
|
|
|
|
test('save and reload preserve a continuous intermediate size', () async {
|
|
await AppMessageStatusSize.save(1.237);
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
expect(prefs.getDouble(AppMessageStatusSize.prefKey), 1.237);
|
|
expect(AppMessageStatusSize.current.value, 1.237);
|
|
|
|
AppMessageStatusSize.current.value = AppMessageStatusSize.defaultScale;
|
|
expect(await AppMessageStatusSize.load(), 1.237);
|
|
expect(AppMessageStatusSize.current.value, 1.237);
|
|
});
|
|
|
|
for (final sample in [
|
|
(name: 'maximum', input: 2.0, expected: 1.5),
|
|
(name: 'minimum', input: 0.5, expected: 1.0),
|
|
(name: 'NaN', input: double.nan, expected: 1.0),
|
|
(name: 'positive infinity', input: double.infinity, expected: 1.0),
|
|
(name: 'negative infinity', input: double.negativeInfinity, expected: 1.0),
|
|
]) {
|
|
test('save normalizes ${sample.name} before persisting', () async {
|
|
await AppMessageStatusSize.save(sample.input);
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
expect(AppMessageStatusSize.current.value, sample.expected);
|
|
expect(prefs.getDouble(AppMessageStatusSize.prefKey), sample.expected);
|
|
});
|
|
|
|
test('load normalizes a stored ${sample.name}', () async {
|
|
SharedPreferences.setMockInitialValues({
|
|
AppMessageStatusSize.prefKey: sample.input,
|
|
});
|
|
|
|
expect(await AppMessageStatusSize.load(), sample.expected);
|
|
expect(AppMessageStatusSize.current.value, sample.expected);
|
|
});
|
|
}
|
|
}
|