Files
pipelines/app/test/ui/adaptive/segmented_bar_title_widget_test.dart
T
alan 009bf3d853 Pop the top bar's islands in and give its controls press feedback
Each island (Back, title, actions pill, each action) scales in from 0.85
with a gentle overshoot, staggered from the leading edge on first show and
at once when it newly appears; rebuilds and title changes keep it. Glass
fades its fill and blur together so backdrop grouping is unchanged.
Every tappable piece sinks to 0.94 under a stadium tint while pressed and
springs back. Reduced motion skips the animation.
2026-11-02 16:47:01 +00:00

152 lines
4.9 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/shell_bar.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
/// A bar whose main pill is an input (Search): the widget takes the title
/// pill's place and fills the bar, up to its cap, from the leading edge.
void main() {
void setSize(WidgetTester tester, double width) {
tester.view.physicalSize = Size(width, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
}
const fieldKey = Key('field');
Widget field(bool cupertino) => cupertino
? const CupertinoTextField(key: fieldKey, placeholder: 'Find')
: const TextField(key: fieldKey);
Rect pillOf(WidgetTester tester, Finder child) => tester.getRect(
find.ancestor(of: child, matching: find.byType(GlassPill)).first,
);
Widget page(bool cupertino, SegmentedBar bar) => cupertino
? CupertinoApp(
home: CupertinoPageScaffold(
navigationBar: bar,
child: const SizedBox.expand(),
),
)
: MaterialApp(
home: Scaffold(
extendBodyBehindAppBar: true,
appBar: bar,
body: const SizedBox.expand(),
),
);
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('$host: the widget replaces the title and fills a phone bar', (
tester,
) async {
setSize(tester, 390);
await tester.pumpWidget(
page(
cupertino,
SegmentedBar(
cupertino: cupertino,
title: 'Search',
titleWidget: field(cupertino),
titleWidgetMaxWidth: 840,
),
),
);
expect(find.text('Search'), findsNothing, reason: 'no title pill');
expect(
find.descendant(
of: find.byType(SegmentedBar),
matching: find.byType(GlassPill),
),
findsOneWidget,
reason: 'one pill: the field',
);
// Measured at rest, after the pieces' entrance.
await tester.pump(const Duration(seconds: 1));
final pill = pillOf(tester, find.byKey(fieldKey));
expect(pill.left, 12);
expect(pill.right, 390 - 12);
});
testWidgets('$host: on a wide bar the pill stops at its cap from the '
'leading edge, beside a Back and any actions', (tester) async {
setSize(tester, 1200);
await tester.pumpWidget(
page(
cupertino,
SegmentedBar(
cupertino: cupertino,
title: 'Search',
leading: SegmentedBackButton(
cupertino: cupertino,
onPressed: () {},
),
titleWidget: field(cupertino),
titleWidgetMaxWidth: 600,
actions: const [Icon(Icons.info_outline, key: Key('action'))],
),
),
);
// Measured at rest, after the pieces' entrance.
await tester.pump(const Duration(seconds: 1));
final pill = pillOf(tester, find.byKey(fieldKey));
final back = pillOf(tester, find.byType(SegmentedBackButton));
expect(pill.width, 600);
expect(pill.left, back.right + 8);
// The actions keep to the trailing edge.
expect(pillOf(tester, find.byKey(const Key('action'))).right, 1200 - 12);
});
testWidgets('$host: a shell tab publishing a field gets it in place of '
'the title, without the Search action', (tester) async {
setSize(tester, 560);
await tester.pumpWidget(
_shellApp(
cupertino,
AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.search,
onSearch: () {},
destinationBodies: {
AppDestination.search: (_) => ShellBar(
titleWidget: field(cupertino),
titleWidgetMaxWidth: 840,
child: const SizedBox.expand(),
),
},
),
),
);
await tester.pump();
final bar = find.byType(SegmentedBar);
expect(
find.descendant(of: bar, matching: find.byKey(fieldKey)),
findsOneWidget,
);
expect(
find.descendant(of: bar, matching: find.text('Search')),
findsNothing,
);
expect(find.byKey(const ValueKey('shell.search')), findsNothing);
// Measured at rest, after the pieces' entrance.
await tester.pump(const Duration(seconds: 1));
final pill = pillOf(tester, find.byKey(fieldKey));
expect(pill.left, 12);
expect(pill.right, 560 - 12);
});
}
}
Widget _shellApp(bool cupertino, Widget shell) =>
cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell);