Merge branch 'feature/animation-speed'

This commit is contained in:
2026-11-07 02:46:38 +00:00
8 changed files with 375 additions and 0 deletions
@@ -0,0 +1,58 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.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';
class _Store implements AnimationSpeedStore {
double? saved;
@override
Future<double?> load() async => saved;
@override
Future<bool> save(double speed) async {
saved = speed;
return true;
}
}
void main() {
tearDown(() => timeDilation = 1);
for (final cupertino in [false, true]) {
testWidgets(
'native slider updates global speed and Reset restores normal ($cupertino)',
(tester) async {
final store = _Store();
final controller = AnimationSpeedController(store: store);
final section = SettingsAnimationSection(controller: controller);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: section))
: MaterialApp(home: Scaffold(body: section)),
);
if (cupertino) {
final slider = tester.widget<CupertinoSlider>(
find.byType(CupertinoSlider),
);
slider.onChanged!(1.8);
slider.onChangeEnd!(1.8);
} else {
final slider = tester.widget<Slider>(find.byType(Slider));
slider.onChanged!(1.8);
slider.onChangeEnd!(1.8);
}
await tester.pump();
expect(find.text('1.8×'), findsWidgets);
expect(timeDilation, closeTo(1 / 1.8, 0.001));
expect(store.saved, 1.8);
await tester.tap(find.text('Reset'));
await tester.pump();
expect(controller.speed, 1);
expect(timeDilation, 1);
expect(store.saved, 1);
expect(tester.takeException(), isNull);
controller.dispose();
},
);
}
}
@@ -0,0 +1,100 @@
import 'dart:async';
import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/motion/animation_speed.dart';
import 'package:pipelines_app/ui/motion/motion.dart';
class _Store implements AnimationSpeedStore {
double? value;
bool fail = false;
Completer<double?>? pending;
@override
Future<double?> load() async => pending == null ? value : pending!.future;
@override
Future<bool> save(double value) async {
this.value = value;
return !fail;
}
}
void main() {
tearDown(() => timeDilation = 1);
test(
'device preference restores speed, clamps values, resets and reports save failure',
() async {
final store = _Store()..value = 2;
final controller = AnimationSpeedController(store: store);
await controller.restore();
expect(controller.speed, 2);
expect(timeDilation, 0.5);
controller.setSpeed(0.1);
expect(controller.speed, 0.5);
expect(timeDilation, 2);
await controller.save();
expect(store.value, 0.5);
store.fail = true;
await controller.save();
expect(controller.saveFailed, isTrue);
store.fail = false;
await controller.reset();
expect(timeDilation, 1);
expect(store.value, 1);
expect(controller.saveFailed, isFalse);
controller.dispose();
},
);
test(
'late restore cannot overwrite a newer choice and invalid values are ignored',
() async {
final store = _Store()..pending = Completer<double?>();
final controller = AnimationSpeedController(store: store);
final restore = controller.restore();
controller.setSpeed(1.5);
store.pending!.complete(0.5);
await restore;
expect(controller.speed, 1.5);
controller.setSpeed(double.nan);
expect(controller.speed, 1.5);
controller.dispose();
},
);
testWidgets(
'animation clock changes ticker speed while wall timers and reduced motion stay independent',
(tester) async {
final controller = AnimationSpeedController(store: _Store());
await tester.pumpWidget(const SizedBox());
final animation = AnimationController(
vsync: tester,
duration: const Duration(seconds: 1),
);
controller.setSpeed(2);
animation.forward();
await tester.pump();
var elapsed = false;
final timer = Timer(
const Duration(milliseconds: 250),
() => elapsed = true,
);
await tester.pump(const Duration(milliseconds: 250));
expect(animation.value, closeTo(0.5, 0.02));
expect(elapsed, isTrue);
timer.cancel();
await tester.pumpWidget(
MediaQuery(
data: const MediaQueryData(disableAnimations: true),
child: Builder(
builder: (context) {
expect(Motion.of(context, Motion.standard), Duration.zero);
return const SizedBox();
},
),
),
);
animation.dispose();
controller.dispose();
timeDilation = 1;
},
);
}