Files
pipelines/app/test/ui/adaptive/segmented_bar_motion_test.dart
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

179 lines
6.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar_motion.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar_pieces.dart';
import 'package:pipelines_app/ui/motion/motion.dart';
/// The top bar's glass fades in with its blur, and its controls sink when
/// pressed (its entrance is in segmented_bar_entrance_test.dart).
void main() {
Widget page({
String title = 'Runs',
List<Widget> actions = const [],
VoidCallback? onTitle,
bool reduced = false,
VoidCallback? onBack,
}) {
final bar = SegmentedBar(
title: title,
onTitlePressed: onTitle,
leading: SegmentedBackButton(
key: const Key('back'),
onPressed: onBack ?? () {},
),
actions: actions,
);
final app = MaterialApp(
home: Scaffold(
extendBodyBehindAppBar: true,
appBar: bar,
body: const SizedBox.expand(),
),
);
return MediaQuery(
data: MediaQueryData(disableAnimations: reduced),
child: app,
);
}
/// The press scale of the control holding [of], or with [pill] of the
/// pill holding it.
double pressScale(WidgetTester tester, Finder of, {bool pill = false}) {
final presses = find.ancestor(
of: of,
matching: find.byType(SegmentedPress),
);
final press = pill ? presses.last : presses.first;
final transform = tester.widget<Transform>(
find.descendant(of: press, matching: find.byType(Transform)).first,
);
return transform.transform.storage[0];
}
Color pressTint(WidgetTester tester, Finder of) {
final press = find
.ancestor(of: of, matching: find.byType(SegmentedPress))
.first;
final box = tester.widget<DecoratedBox>(
find.descendant(of: press, matching: find.byType(DecoratedBox)).first,
);
return (box.decoration as ShapeDecoration).color!;
}
final back = find.byKey(const Key('back'));
final title = find.text('Runs');
{
const host = 'Material';
const icon = Icons.refresh;
Widget action(String key) =>
IconButton(key: Key(key), icon: Icon(icon), onPressed: () {});
testWidgets('$host: the glass fades in with its blur, not under a layer', (
tester,
) async {
await tester.pumpWidget(page());
// Back and the title are both still popping in.
await tester.pump(const Duration(milliseconds: 100));
final backdrops = tester.layers.whereType<BackdropFilterLayer>().toList();
expect(backdrops, hasLength(2), reason: 'Back and the title');
expect(backdrops.first.backdropKey, isNotNull, reason: 'still grouped');
expect(backdrops.last.backdropKey, same(backdrops.first.backdropKey));
for (final layer in backdrops) {
// No opacity layer above a blur: it would read nothing behind it.
for (ContainerLayer? up = layer.parent; up != null; up = up.parent) {
if (up is OpacityLayer) expect(up.alpha, anyOf(isNull, 255));
}
}
final mid = tester.widget<BackdropFilter>(
find.ancestor(of: back, matching: find.byType(BackdropFilter)).first,
);
await tester.pumpAndSettle();
final rest = tester.widget<BackdropFilter>(
find.ancestor(of: back, matching: find.byType(BackdropFilter)).first,
);
expect(mid.filter, isNot(rest.filter), reason: 'the blur fades in');
});
testWidgets(
'$host: Back sinks and tints while pressed, then springs back',
(tester) async {
var backs = 0;
await tester.pumpWidget(page(onBack: () => backs++));
await tester.pumpAndSettle();
expect(pressScale(tester, back), 1);
expect(pressTint(tester, back).a, 0);
final gesture = await tester.startGesture(tester.getCenter(back));
await tester.pump();
await tester.pump(Motion.barPressDuration);
expect(pressScale(tester, back), closeTo(Motion.barPressScale, 1e-6));
expect(pressTint(tester, back).a, greaterThan(0.1));
await gesture.up();
await tester.pumpAndSettle();
expect(pressScale(tester, back), closeTo(1, 1e-3));
expect(pressTint(tester, back).a, 0);
expect(backs, 1, reason: 'the tap still reaches Back');
},
);
testWidgets('$host: a quick tap still shows the whole press', (
tester,
) async {
await tester.pumpWidget(page(actions: [action('a')]));
await tester.pumpAndSettle();
final a = find.byKey(const Key('a'));
await tester.tap(a);
await tester.pump();
await tester.pump(const Duration(milliseconds: 80));
// A lone action is the whole pill: the pill sinks, not the icon.
expect(pressScale(tester, a, pill: true), lessThan(0.95));
expect(pressScale(tester, a), 1);
await tester.pumpAndSettle();
expect(pressScale(tester, a, pill: true), 1);
});
testWidgets('$host: beside others each action sinks on its own', (
tester,
) async {
var taps = 0;
await tester.pumpWidget(
page(onTitle: () => taps++, actions: [action('a'), action('b')]),
);
await tester.pumpAndSettle();
final a = find.byKey(const Key('a'));
final b = find.byKey(const Key('b'));
final gesture = await tester.startGesture(tester.getCenter(b));
await tester.pump();
await tester.pump(Motion.barPressDuration);
expect(pressScale(tester, b), closeTo(Motion.barPressScale, 1e-6));
expect(pressScale(tester, a), 1);
expect(pressScale(tester, back), 1);
await gesture.up();
await tester.pumpAndSettle();
// A pressable title sinks as a whole pill and still takes the tap.
await tester.tap(title);
await tester.pumpAndSettle();
expect(taps, 1);
});
testWidgets('$host: hit testing is unchanged at rest', (tester) async {
await tester.pumpWidget(page(actions: [action('a')]));
await tester.pumpAndSettle();
final pill = tester.getRect(
find.ancestor(of: back, matching: find.byType(GlassPill)).first,
);
expect(pill.left, 12);
expect(pill.height, segmentedPieceHeight());
// A tap between the pieces reaches no piece; on Back it reaches Back.
final backBox = tester.renderObject(back);
bool hitsBack(Offset at) =>
tester.hitTestOnBinding(at).path.any((e) => e.target == backBox);
expect(hitsBack(Offset(pill.right + 4, pill.center.dy)), isFalse);
expect(hitsBack(pill.center), isTrue);
});
}
}