159 lines
5.3 KiB
Dart
159 lines
5.3 KiB
Dart
import 'dart:math' as math;
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/ui/motion/quick_switch_animation.dart';
|
|
import 'package:pipelines_app/ui/motion/quick_switch_effect.dart';
|
|
|
|
void main() {
|
|
const full = Rect.fromLTWH(0, 0, 560, 635);
|
|
const peek = Rect.fromLTWH(0, 641, 560, 159);
|
|
|
|
test('both deck styles leave the front before changing stacking order', () {
|
|
for (final style in [
|
|
QuickSwitchAnimation.cardStack,
|
|
QuickSwitchAnimation.deckSlide,
|
|
]) {
|
|
expect(
|
|
quickSwitchRect(style, .3, full, peek, outgoing: true).size,
|
|
full.size,
|
|
);
|
|
expect(quickSwitchOutgoingOnTop(style, .49), isTrue);
|
|
expect(quickSwitchOutgoingOnTop(style, .5), isFalse);
|
|
final pose = quickSwitchPose(style, .5, outgoing: true);
|
|
expect(pose.translation.dx.abs(), greaterThan(1));
|
|
expect(pose.rotationX, 0);
|
|
expect(pose.rotationY, 0);
|
|
expect(pose.rotationZ.abs(), lessThan(math.pi / 12));
|
|
expect(quickSwitchRect(style, 1, full, peek, outgoing: true), peek);
|
|
}
|
|
});
|
|
|
|
test('deck reveals a full-size next card behind the front card', () {
|
|
for (final style in [
|
|
QuickSwitchAnimation.cardStack,
|
|
QuickSwitchAnimation.deckSlide,
|
|
]) {
|
|
for (final t in [0.0, .3, .5, 1.0]) {
|
|
expect(quickSwitchRect(style, t, peek, full, outgoing: false), full);
|
|
}
|
|
}
|
|
});
|
|
|
|
test(
|
|
'arc swap bows to opposite sides while both cards travel vertically',
|
|
() {
|
|
const style = QuickSwitchAnimation.arcSwap;
|
|
for (final t in [.25, .5, .75]) {
|
|
final outgoing = quickSwitchPose(style, t, outgoing: true);
|
|
final incoming = quickSwitchPose(style, t, outgoing: false);
|
|
expect(outgoing.translation.dx, lessThan(0));
|
|
expect(incoming.translation.dx, greaterThan(0));
|
|
expect(
|
|
outgoing.translation.dx,
|
|
closeTo(-incoming.translation.dx, 1e-9),
|
|
);
|
|
expect(outgoing.rotationX, 0);
|
|
expect(outgoing.rotationY, 0);
|
|
expect(outgoing.transform(full.size).entry(3, 2), 0);
|
|
expect(outgoing.opacity, 1);
|
|
expect(incoming.opacity, 1);
|
|
expect(
|
|
quickSwitchRect(style, t, full, peek, outgoing: true),
|
|
Rect.lerp(full, peek, t),
|
|
);
|
|
expect(
|
|
quickSwitchRect(style, t, peek, full, outgoing: false),
|
|
Rect.lerp(peek, full, t),
|
|
);
|
|
}
|
|
final quarter = quickSwitchPose(
|
|
style,
|
|
.25,
|
|
outgoing: false,
|
|
).translation.dx;
|
|
final middle = quickSwitchPose(style, .5, outgoing: false).translation.dx;
|
|
final threeQuarter = quickSwitchPose(
|
|
style,
|
|
.75,
|
|
outgoing: false,
|
|
).translation.dx;
|
|
expect(quarter, closeTo(threeQuarter, 1e-9));
|
|
expect(middle, greaterThan(quarter));
|
|
expect(middle, closeTo(.38, 1e-9));
|
|
},
|
|
);
|
|
|
|
test('every style settles without residual transforms or missing cards', () {
|
|
for (final style in QuickSwitchAnimation.values) {
|
|
for (final outgoing in [true, false]) {
|
|
for (final t in [0.0, 1.0]) {
|
|
final pose = quickSwitchPose(style, t, outgoing: outgoing);
|
|
expect(pose.translation, Offset.zero, reason: '$style at $t');
|
|
expect(pose.scale, 1, reason: '$style at $t');
|
|
expect(pose.opacity, 1, reason: '$style at $t');
|
|
expect(
|
|
pose.transform(full.size),
|
|
Matrix4.identity(),
|
|
reason: '$style at $t',
|
|
);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
test(
|
|
'flat deck depth keeps the same projection on the cheaper affine path',
|
|
() {
|
|
for (final depth in [-18.0, 0.0, 18.0]) {
|
|
final pose = QuickSwitchPose(
|
|
translation: const Offset(-.7, .04),
|
|
rotationZ: -.04,
|
|
depth: depth,
|
|
scale: .96,
|
|
);
|
|
final original = Matrix4.identity()
|
|
..setEntry(3, 2, .0012)
|
|
..translateByDouble(-.7 * 560, .04 * 635, depth, 1)
|
|
..rotateZ(-.04)
|
|
..scaleByDouble(.96, .96, .96, 1);
|
|
final affine = pose.transform(full.size);
|
|
expect(affine.entry(3, 2), 0);
|
|
for (final point in [
|
|
Offset.zero,
|
|
const Offset(560, 635),
|
|
const Offset(280, 320),
|
|
]) {
|
|
final expected = MatrixUtils.transformPoint(original, point);
|
|
final actual = MatrixUtils.transformPoint(affine, point);
|
|
expect(actual.dx, closeTo(expected.dx, .000001));
|
|
expect(actual.dy, closeTo(expected.dy, .000001));
|
|
}
|
|
}
|
|
},
|
|
);
|
|
|
|
test('all choices have finite bounded geometry throughout a transition', () {
|
|
for (final style in QuickSwitchAnimation.values) {
|
|
for (final outgoing in [true, false]) {
|
|
for (var i = 0; i <= 100; i++) {
|
|
final pose = quickSwitchPose(style, i / 100, outgoing: outgoing);
|
|
expect(pose.opacity, inInclusiveRange(0, 1));
|
|
expect(pose.scale, greaterThan(0));
|
|
expect(
|
|
pose.transform(full.size).storage.every((v) => v.isFinite),
|
|
isTrue,
|
|
);
|
|
final rect = quickSwitchRect(
|
|
style,
|
|
i / 100,
|
|
full,
|
|
peek,
|
|
outgoing: outgoing,
|
|
);
|
|
expect(rect.height, inInclusiveRange(peek.height, full.height));
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|