c88a9e8ce8
Keep the shared UI primitive tests focused on the app's Material-only behavior and remove alternate-host fixtures that no longer represent supported rendering.
132 lines
4.1 KiB
Dart
132 lines
4.1 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(
|
|
cupertino: false,
|
|
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(
|
|
cupertino: false,
|
|
title: 'Search',
|
|
leading: SegmentedBackButton(cupertino: false, 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);
|
|
});
|
|
}
|