Files
pipelines/app/test/ui/adaptive/segmented_bar_title_widget_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

130 lines
4.0 KiB
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');
const field = TextField(key: fieldKey);
Rect pillOf(WidgetTester tester, Finder child) => tester.getRect(
find.ancestor(of: child, matching: find.byType(GlassPill)).first,
);
Widget page(SegmentedBar bar) => MaterialApp(
home: Scaffold(
extendBodyBehindAppBar: true,
appBar: bar,
body: const SizedBox.expand(),
),
);
{
const host = 'Material';
testWidgets('$host: the widget replaces the title and fills a phone bar', (
tester,
) async {
setSize(tester, 390);
await tester.pumpWidget(
page(
SegmentedBar(
title: 'Search',
titleWidget: field,
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(
SegmentedBar(
title: 'Search',
leading: SegmentedBackButton(onPressed: () {}),
titleWidget: field,
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('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(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.search,
onSearch: () {},
destinationBodies: {
AppDestination.search: (_) => ShellBar(
titleWidget: const TextField(key: fieldKey),
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);
});
}