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? pending; @override Future load() async => pending == null ? saved : pending!.future; @override Future 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(); 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(); }); }