Add device-local quick switch animation settings
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_animation_section.dart';
|
||||
import 'package:pipelines_app/ui/motion/animation_speed.dart';
|
||||
import 'package:pipelines_app/ui/motion/quick_switch_animation.dart';
|
||||
|
||||
class _Store implements QuickSwitchAnimationStore {
|
||||
String? saved;
|
||||
bool success = true;
|
||||
@override
|
||||
Future<String?> load() async => saved;
|
||||
@override
|
||||
Future<bool> save(String value) async {
|
||||
saved = value;
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('chooses and saves quick switch animation ($cupertino)', (
|
||||
tester,
|
||||
) async {
|
||||
final store = _Store();
|
||||
final controller = QuickSwitchAnimationController(store: store);
|
||||
final speed = AnimationSpeedController();
|
||||
final child = SettingsAnimationSection(
|
||||
controller: speed,
|
||||
quickSwitchController: controller,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: child))
|
||||
: MaterialApp(home: Scaffold(body: child)),
|
||||
);
|
||||
expect(find.text('Quick switch animation'), findsOneWidget);
|
||||
expect(
|
||||
cupertino ? find.byType(CupertinoSlider) : find.byType(Slider),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(find.text('Tape'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Card stack').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.value, QuickSwitchAnimation.cardStack);
|
||||
expect(store.saved, 'cardStack');
|
||||
expect(
|
||||
find.text(QuickSwitchAnimation.cardStack.description),
|
||||
findsOneWidget,
|
||||
);
|
||||
store.success = false;
|
||||
await tester.tap(find.text('Card stack'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Swap').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text('Could not save; applies until reload.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
controller.dispose();
|
||||
speed.dispose();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/ui/motion/quick_switch_animation.dart';
|
||||
|
||||
class _Store implements QuickSwitchAnimationStore {
|
||||
String? saved;
|
||||
bool success = true;
|
||||
Completer<String?>? pending;
|
||||
@override
|
||||
Future<String?> load() async => pending == null ? saved : pending!.future;
|
||||
@override
|
||||
Future<bool> save(String value) async {
|
||||
saved = value;
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('persists every style and restores the device choice', () async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
for (final value in QuickSwitchAnimation.values) {
|
||||
final first = QuickSwitchAnimationController();
|
||||
await first.setAnimation(value);
|
||||
final second = QuickSwitchAnimationController();
|
||||
await second.restore();
|
||||
expect(second.value, value);
|
||||
first.dispose();
|
||||
second.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
test(
|
||||
'unknown preference uses tape; delayed restore preserves new choice',
|
||||
() async {
|
||||
final store = _Store()..saved = 'removed-style';
|
||||
final controller = QuickSwitchAnimationController(store: store);
|
||||
await controller.restore();
|
||||
expect(controller.value, QuickSwitchAnimation.tape);
|
||||
store.pending = Completer<String?>();
|
||||
final restore = controller.restore();
|
||||
await controller.setAnimation(QuickSwitchAnimation.cardStack);
|
||||
store.pending!.complete('swap');
|
||||
await restore;
|
||||
expect(controller.value, QuickSwitchAnimation.cardStack);
|
||||
controller.dispose();
|
||||
},
|
||||
);
|
||||
|
||||
test('failed save keeps current style and reports failure', () async {
|
||||
final store = _Store()..success = false;
|
||||
final controller = QuickSwitchAnimationController(store: store);
|
||||
await controller.setAnimation(QuickSwitchAnimation.swap);
|
||||
expect(controller.value, QuickSwitchAnimation.swap);
|
||||
expect(controller.saveFailed, isTrue);
|
||||
store.success = true;
|
||||
await controller.setAnimation(QuickSwitchAnimation.cardStack);
|
||||
expect(controller.saveFailed, isFalse);
|
||||
controller.dispose();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user