Files
pipelines/app/test/ui/adaptive/segmented_bar_entrance_test.dart
T
alan 9551eceaed Complete Material-only APIs and fixtures
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
2026-11-11 21:55:39 +00:00

200 lines
7.6 KiB
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({
String title = 'Runs',
List<Widget> actions = const [],
Object? actionsKey,
bool reduced = false,
}) {
final bar = SegmentedBar(
title: title,
leading: SegmentedBackButton(key: const Key('back'), onPressed: () {}),
actions: actions,
actionsKey: actionsKey,
);
final app = MaterialApp(
home: Scaffold(
extendBodyBehindAppBar: true,
appBar: bar,
body: const SizedBox.expand(),
),
);
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;
{
const host = 'Material';
const icon = 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(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(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(actions: [action('a')]));
await tester.pumpAndSettle();
await tester.pumpWidget(page(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(actions: [action('a')]));
await tester.pumpAndSettle();
await tester.pumpWidget(page(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(actionsKey: list, actions: [action('a')]));
await tester.pumpAndSettle();
// The same screen republishing its bar is not a new entrance.
await tester.pumpWidget(page(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(
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());
await tester.pumpAndSettle();
await tester.pumpWidget(page(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(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);
});
}
}