05798a56c8
One shared pop (pop_entrance.dart: PopTransition, popWindow, PopEntrance) drives the floating tab buttons and the top bar, on Motion.tabEntrance* (0.6 -> 1, 260 ms, 70 ms stagger, ease-out-back, glass fading in). SegmentedEntrance and the barEntrance* constants are gone. Back, the title, the actions pill and each action pop in turn from the leading edge (SegmentedEntrancePlanner). A lone action pops once, with its pill. A newcomer pops alone. Rebuilds and title changes never replay it. The shell passes published actions one by one, keyed by their screen (actionsKey), not as one cross-fading Row. The chat thread's model and mode are separate actions. The folder picker now uses SegmentedBar.
224 lines
8.3 KiB
Dart
224 lines
8.3 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/ui/adaptive/pop_entrance.dart';
|
|
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
|
import 'package:pipelines_app/ui/motion/motion.dart';
|
|
|
|
/// Every piece of the top bar (Back, the title, the actions pill and each
|
|
/// action in it) pops in with the tab buttons' entrance, once.
|
|
void main() {
|
|
Widget page(
|
|
bool cupertino, {
|
|
String title = 'Runs',
|
|
List<Widget> actions = const [],
|
|
Object? actionsKey,
|
|
bool reduced = false,
|
|
}) {
|
|
final bar = SegmentedBar(
|
|
cupertino: cupertino,
|
|
title: title,
|
|
leading: SegmentedBackButton(
|
|
key: const Key('back'),
|
|
cupertino: cupertino,
|
|
onPressed: () {},
|
|
),
|
|
actions: actions,
|
|
actionsKey: actionsKey,
|
|
);
|
|
final Widget home = cupertino
|
|
? CupertinoPageScaffold(
|
|
navigationBar: bar,
|
|
child: const SizedBox.expand(),
|
|
)
|
|
: Scaffold(
|
|
extendBodyBehindAppBar: true,
|
|
appBar: bar,
|
|
body: const SizedBox.expand(),
|
|
);
|
|
final app = cupertino ? CupertinoApp(home: home) : MaterialApp(home: home);
|
|
return MediaQuery(
|
|
data: MediaQueryData(disableAnimations: reduced),
|
|
child: app,
|
|
);
|
|
}
|
|
|
|
/// The entrance scale of the piece holding [of]: its pill's, or with
|
|
/// [inner] its own inside the actions pill.
|
|
double scaleOf(WidgetTester tester, Finder of, {bool inner = false}) {
|
|
final entrances = find.ancestor(of: of, matching: find.byType(PopEntrance));
|
|
final entrance = inner ? entrances.first : entrances.last;
|
|
// The pop rises (a translation), then scales.
|
|
final transform = tester.widget<Transform>(
|
|
find.descendant(of: entrance, matching: find.byType(Transform)).at(1),
|
|
);
|
|
return transform.transform.storage[0];
|
|
}
|
|
|
|
final back = find.byKey(const Key('back'));
|
|
final title = find.text('Runs');
|
|
const begin = Motion.tabEntranceScaleBegin;
|
|
const step = Motion.tabEntranceStagger;
|
|
|
|
for (final cupertino in [false, true]) {
|
|
final host = cupertino ? 'Cupertino' : 'Material';
|
|
final icon = cupertino ? CupertinoIcons.refresh : Icons.refresh;
|
|
Widget action(String key) =>
|
|
IconButton(key: Key(key), icon: Icon(icon), onPressed: () {});
|
|
final a = find.byKey(const Key('a'));
|
|
final b = find.byKey(const Key('b'));
|
|
|
|
testWidgets('$host: each piece pops in turn, left to right, from 0.6', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
page(cupertino, actions: [action('a'), action('b')]),
|
|
);
|
|
expect(scaleOf(tester, back), begin);
|
|
expect(scaleOf(tester, title), begin);
|
|
expect(scaleOf(tester, a), begin, reason: 'the pill');
|
|
expect(scaleOf(tester, a, inner: true), begin);
|
|
expect(scaleOf(tester, b, inner: true), begin);
|
|
// Back, the title, the pill, then each action: one stagger apart.
|
|
await tester.pump(step * 2 + const Duration(milliseconds: 20));
|
|
final backNow = scaleOf(tester, back);
|
|
final titleNow = scaleOf(tester, title);
|
|
final pillNow = scaleOf(tester, a);
|
|
expect(backNow, greaterThan(titleNow), reason: 'Back leads');
|
|
expect(titleNow, greaterThan(pillNow), reason: 'the title follows');
|
|
expect(pillNow, greaterThan(begin), reason: 'the pill has started');
|
|
expect(scaleOf(tester, a, inner: true), begin, reason: 'a waits');
|
|
await tester.pump(step);
|
|
expect(scaleOf(tester, a, inner: true), greaterThan(begin));
|
|
expect(scaleOf(tester, b, inner: true), begin, reason: 'b waits for a');
|
|
await tester.pump(step);
|
|
expect(scaleOf(tester, b, inner: true), greaterThan(begin));
|
|
await tester.pumpAndSettle();
|
|
for (final scale in [
|
|
scaleOf(tester, back),
|
|
scaleOf(tester, title),
|
|
scaleOf(tester, a),
|
|
scaleOf(tester, a, inner: true),
|
|
scaleOf(tester, b, inner: true),
|
|
]) {
|
|
expect(scale, 1);
|
|
}
|
|
});
|
|
|
|
testWidgets('$host: a lone action pops as its pill, not twice', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(page(cupertino, actions: [action('a')]));
|
|
expect(scaleOf(tester, a), begin);
|
|
expect(scaleOf(tester, a, inner: true), 1);
|
|
await tester.pump(step * 2 + const Duration(milliseconds: 40));
|
|
expect(scaleOf(tester, a), greaterThan(begin));
|
|
expect(scaleOf(tester, a, inner: true), 1);
|
|
await tester.pumpAndSettle();
|
|
expect(scaleOf(tester, a), 1);
|
|
});
|
|
|
|
testWidgets('$host: a rebuild or new title does not replay it', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(page(cupertino, actions: [action('a')]));
|
|
await tester.pumpAndSettle();
|
|
await tester.pumpWidget(
|
|
page(cupertino, title: 'Other', actions: [action('a')]),
|
|
);
|
|
await tester.pump();
|
|
expect(scaleOf(tester, back), 1);
|
|
expect(scaleOf(tester, find.text('Other')), 1);
|
|
expect(scaleOf(tester, a), 1);
|
|
expect(scaleOf(tester, a, inner: true), 1);
|
|
expect(tester.hasRunningAnimations, isFalse);
|
|
});
|
|
|
|
testWidgets('$host: an action that becomes available pops in alone', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(page(cupertino, actions: [action('a')]));
|
|
await tester.pumpAndSettle();
|
|
await tester.pumpWidget(
|
|
page(cupertino, actions: [action('b'), action('a')]),
|
|
);
|
|
expect(scaleOf(tester, b, inner: true), begin);
|
|
// The pill, the action already there and the rest stay put.
|
|
expect(scaleOf(tester, a), 1);
|
|
expect(scaleOf(tester, a, inner: true), 1);
|
|
expect(scaleOf(tester, back), 1);
|
|
expect(scaleOf(tester, title), 1);
|
|
await tester.pump(Motion.tabEntranceDuration ~/ 2);
|
|
expect(scaleOf(tester, b, inner: true), greaterThan(0.9));
|
|
await tester.pumpAndSettle();
|
|
expect(scaleOf(tester, b, inner: true), 1);
|
|
});
|
|
|
|
testWidgets('$host: a tab switch keeps what stays, pops what is new', (
|
|
tester,
|
|
) async {
|
|
final list = Object();
|
|
await tester.pumpWidget(
|
|
page(cupertino, actionsKey: list, actions: [action('a')]),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
// The same screen republishing its bar is not a new entrance.
|
|
await tester.pumpWidget(
|
|
page(cupertino, actionsKey: list, actions: [action('a')]),
|
|
);
|
|
await tester.pump();
|
|
expect(tester.hasRunningAnimations, isFalse);
|
|
// Another screen's actions are new, though keyed alike; Back, the
|
|
// title and the pill stay.
|
|
await tester.pumpWidget(
|
|
page(
|
|
cupertino,
|
|
title: 'Chats',
|
|
actionsKey: Object(),
|
|
actions: [action('a'), action('b')],
|
|
),
|
|
);
|
|
expect(scaleOf(tester, back), 1);
|
|
expect(scaleOf(tester, find.text('Chats')), 1);
|
|
expect(scaleOf(tester, a), 1, reason: 'the pill stays');
|
|
expect(scaleOf(tester, a, inner: true), begin);
|
|
expect(scaleOf(tester, b, inner: true), begin);
|
|
await tester.pump(step);
|
|
expect(scaleOf(tester, a, inner: true), greaterThan(begin));
|
|
expect(scaleOf(tester, b, inner: true), begin);
|
|
await tester.pumpAndSettle();
|
|
expect(scaleOf(tester, b, inner: true), 1);
|
|
});
|
|
|
|
testWidgets('$host: a pill arriving later pops, then its actions', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(page(cupertino));
|
|
await tester.pumpAndSettle();
|
|
await tester.pumpWidget(
|
|
page(cupertino, actions: [action('a'), action('b')]),
|
|
);
|
|
expect(scaleOf(tester, back), 1);
|
|
await tester.pump(const Duration(milliseconds: 20));
|
|
expect(scaleOf(tester, a), greaterThan(begin), reason: 'at once');
|
|
expect(scaleOf(tester, a, inner: true), begin);
|
|
await tester.pump(step);
|
|
expect(scaleOf(tester, a, inner: true), greaterThan(begin));
|
|
expect(scaleOf(tester, b, inner: true), begin);
|
|
await tester.pumpAndSettle();
|
|
});
|
|
|
|
testWidgets('$host: reduced motion shows the bar at once', (tester) async {
|
|
await tester.pumpWidget(
|
|
page(cupertino, actions: [action('a'), action('b')], reduced: true),
|
|
);
|
|
expect(scaleOf(tester, back), 1);
|
|
expect(scaleOf(tester, title), 1);
|
|
expect(scaleOf(tester, a), 1);
|
|
expect(scaleOf(tester, a, inner: true), 1);
|
|
expect(scaleOf(tester, b, inner: true), 1);
|
|
expect(tester.hasRunningAnimations, isFalse);
|
|
});
|
|
}
|
|
}
|