9bdabb32d9
Keep the Material-only shell path while preserving public cupertino parameters for callers. Narrow matching tests to Material hosts and behavior because the app always runs under MaterialApp.
147 lines
4.7 KiB
Dart
147 lines
4.7 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('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);
|
|
});
|
|
}
|