Files
pipelines/app/test/features/settings/settings_animation_section_test.dart
T

65 lines
2.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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: SingleChildScrollView(child: section),
),
)
: MaterialApp(
home: Scaffold(body: SingleChildScrollView(child: 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();
},
);
}
}