Files
SpotiFLAC-Mobile/test/app_motion_test.dart
T

85 lines
2.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_3_expressive/material_3_expressive.dart';
import 'package:spotiflac_android/theme/app_motion.dart';
import 'package:spotiflac_android/theme/app_theme.dart';
import 'package:spotiflac_android/theme/mornye_theme.dart';
void main() {
test('spring curves start at rest and settle within their duration', () {
for (final spring in [
M3EMotion.expressiveSpatialFast,
M3EMotion.expressiveSpatialDefault,
M3EMotion.expressiveSpatialSlow,
M3EMotion.effectsFast,
M3EMotion.effectsDefault,
]) {
final curve = SpringCurve(spring);
expect(curve.transform(0), 0);
expect(curve.transform(1), 1);
expect(curve.transform(0.98), closeTo(1, 0.01));
expect(curve.duration.inMilliseconds, inInclusiveRange(100, 1200));
}
});
test('spatial springs overshoot while effects springs do not', () {
double peak(SpringCurve curve) => [
for (var t = 0.0; t <= 1; t += 0.01) curve.transform(t),
].reduce((a, b) => a > b ? a : b);
expect(
peak(SpringCurve(M3EMotion.expressiveSpatialDefault)),
greaterThan(1),
);
expect(peak(SpringCurve(M3EMotion.effectsDefault)), lessThanOrEqualTo(1));
});
Future<AppMotionSpec> resolve(
WidgetTester tester, {
required ThemeData theme,
bool reduceMotion = false,
}) async {
late AppMotionSpec spec;
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: MediaQuery(
data: MediaQueryData(disableAnimations: reduceMotion),
child: Builder(
builder: (context) {
spec = AppMotion.spatial(
context,
const AppMotionSpec(
Duration(milliseconds: 250),
Curves.easeOutCubic,
),
);
return const SizedBox();
},
),
),
),
);
// MaterialApp animates theme changes between pumps.
await tester.pumpAndSettle();
return spec;
}
testWidgets(
'Material uses springs; Mornye and reduced motion keep fallback',
(tester) async {
expect(
(await resolve(tester, theme: AppTheme.light())).curve,
isA<SpringCurve>(),
);
for (final spec in [
await resolve(tester, theme: MornyeTheme.build(Brightness.light)),
await resolve(tester, theme: AppTheme.light(), reduceMotion: true),
]) {
expect(spec.curve, Curves.easeOutCubic);
expect(spec.duration, const Duration(milliseconds: 250));
}
},
);
}