Merge branch 'worktree-agent-a82ec5e9fdf8ca159' into integrate/gaps-e
# Conflicts: # app/test/features/search/search_bar_layout_test.dart
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/templates_destination.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/templates/screen.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import '../features/pipelines/fixtures.dart';
|
||||
import 'pipelines_replies.dart';
|
||||
import 'templates_wiring_test.dart' show openSettings, openTemplates, pumpApp;
|
||||
|
||||
/// The app-level Templates page: one bar (Back + Refresh), the gallery and an
|
||||
/// open template reach the top edge, start below the bar at rest and scroll
|
||||
/// behind it. Cupertino draws inset-grouped rows on the grouped background.
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('$host: the gallery and detail scroll behind the bar', (
|
||||
tester,
|
||||
) async {
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
await pumpApp(
|
||||
tester,
|
||||
channel: channel,
|
||||
client: client,
|
||||
provider: provider,
|
||||
cupertino: cupertino,
|
||||
);
|
||||
await replyPipelines(tester, channel, PipelineFixture());
|
||||
await openSettings(tester, channel, provider);
|
||||
await openTemplates(tester, channel, provider);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final bar = find.ancestor(
|
||||
of: find.byKey(templatesPageBackKey),
|
||||
matching: find.byType(SegmentedBar),
|
||||
);
|
||||
final barBottom = tester.getRect(bar).bottom;
|
||||
// One bar: Back and Refresh are its pieces.
|
||||
expect(
|
||||
find.descendant(of: bar, matching: find.byKey(templatesRefreshKey)),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
final gallery = find.byKey(templatesGalleryKey);
|
||||
expect(tester.getTopLeft(gallery).dy, 0);
|
||||
final row = find.byKey(templateRowKey('release'));
|
||||
expect(tester.getTopLeft(row).dy, greaterThanOrEqualTo(barBottom - 8));
|
||||
// Scrolling moves the row up behind the bar.
|
||||
final before = tester.getTopLeft(row).dy;
|
||||
await tester.drag(gallery, const Offset(0, -40));
|
||||
await tester.pump();
|
||||
expect(tester.getTopLeft(row).dy, lessThanOrEqualTo(before));
|
||||
|
||||
if (cupertino) {
|
||||
final scaffold = tester.widget<CupertinoPageScaffold>(
|
||||
find
|
||||
.ancestor(
|
||||
of: gallery,
|
||||
matching: find.byType(CupertinoPageScaffold),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(scaffold.backgroundColor, AppColors.groupedBackground);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: gallery,
|
||||
matching: find.byType(CupertinoListSection),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
|
||||
await tester.tap(row);
|
||||
await tester.pumpAndSettle();
|
||||
final detail = find.byKey(templateDetailKey);
|
||||
expect(tester.getTopLeft(detail).dy, 0);
|
||||
expect(
|
||||
tester.getTopLeft(find.byKey(templateCreateActionKey)).dy,
|
||||
greaterThanOrEqualTo(barBottom - 8),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/decision_wording.dart';
|
||||
import 'package:pipelines_app/features/runs/screen.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
|
||||
class _DecisionGateway implements ApiGateway {
|
||||
final events = StreamController<JsonMap>.broadcast();
|
||||
@@ -73,16 +74,25 @@ void main() {
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(decisionWaitingTitle), findsOneWidget);
|
||||
// The web's decision banner spans the header at its 16px inset, with
|
||||
// The web's decision banner spans the header's glass strip (under
|
||||
// the top bar, 12 in from the pane) at the strip's 12px inset, with
|
||||
// Decide trailing.
|
||||
final banner = tester.getRect(
|
||||
find.byKey(const Key('run-decision-banner')),
|
||||
);
|
||||
final strip = tester.getRect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('run-detail-header')),
|
||||
matching: find.byType(GlassPill),
|
||||
),
|
||||
);
|
||||
final pane = tester.getRect(
|
||||
find.byKey(const ValueKey('list-detail-body')),
|
||||
);
|
||||
expect(banner.left, pane.left + 16);
|
||||
expect(banner.right, pane.right - 16);
|
||||
expect(strip.left, pane.left + 12);
|
||||
expect(strip.right, pane.right - 12);
|
||||
expect(banner.left, strip.left + 12);
|
||||
expect(banner.right, strip.right - 12);
|
||||
expect(
|
||||
tester.getCenter(find.byKey(decisionActionKey)).dx,
|
||||
greaterThan(banner.center.dx),
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import 'package:flutter/material.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 'run_detail_graph_support.dart';
|
||||
import 'run_detail_visit_support.dart';
|
||||
|
||||
/// The run detail and the stage page scroll behind their top bars: the run's
|
||||
/// status and actions are a glass strip under the bar (not a fixed block
|
||||
/// above the tab), and the stage page's bar names the stage while its
|
||||
/// sections, led by the facts, pass behind it.
|
||||
void main() {
|
||||
Rect pieceOf(WidgetTester tester, Finder owner) => tester.getRect(
|
||||
find.descendant(of: owner, matching: find.byType(GlassPill)).first,
|
||||
);
|
||||
|
||||
ScrollPosition positionIn(WidgetTester tester, Finder owner) => tester
|
||||
.state<ScrollableState>(
|
||||
find.descendant(of: owner, matching: find.byType(Scrollable)).first,
|
||||
)
|
||||
.position;
|
||||
|
||||
for (final platform in RunDetailTestPlatform.values) {
|
||||
testWidgets('${platform.name} run header floats under the bar and the '
|
||||
'tab scrolls behind both', (tester) async {
|
||||
await pumpRunDetail(tester, platform, size: const Size(390, 520));
|
||||
|
||||
final bar = pieceOf(tester, find.byType(SegmentedBar));
|
||||
final header = find.byKey(const Key('run-detail-header'));
|
||||
final strip = pieceOf(tester, header);
|
||||
// A glass strip just under the bar, at the bar's side inset.
|
||||
expect(strip.top, greaterThanOrEqualTo(bar.bottom));
|
||||
expect(strip.top - bar.bottom, lessThan(24));
|
||||
expect(strip.left, 12);
|
||||
expect(find.byKey(const Key('run-status-kicker')), findsWidgets);
|
||||
|
||||
// The tab fills the detail from the top edge; its content starts
|
||||
// below the strip at rest.
|
||||
final body = find.byKey(const Key('run-detail-tab-body-summary'));
|
||||
expect(tester.getTopLeft(body).dy, 0);
|
||||
final padding = MediaQuery.paddingOf(tester.element(body)).top;
|
||||
expect(padding, greaterThanOrEqualTo(strip.bottom));
|
||||
|
||||
// Scrolled, the content passes behind the strip and the bar.
|
||||
final position = positionIn(tester, body);
|
||||
expect(position.maxScrollExtent, greaterThan(0));
|
||||
final firstChild = find
|
||||
.descendant(of: body, matching: find.byType(Text))
|
||||
.first;
|
||||
final before = tester.getTopLeft(firstChild).dy;
|
||||
expect(before, greaterThanOrEqualTo(strip.bottom - 1));
|
||||
position.jumpTo(position.maxScrollExtent.clamp(0, 200).toDouble());
|
||||
await tester.pump();
|
||||
expect(tester.getTopLeft(firstChild).dy, lessThan(before));
|
||||
});
|
||||
|
||||
testWidgets('${platform.name} stage page names the stage in its bar and '
|
||||
'its Summary scrolls behind it', (tester) async {
|
||||
await openVisit(tester, platform, size: const Size(390, 844));
|
||||
|
||||
final bar = find.ancestor(
|
||||
of: find.byKey(const Key('run-visit-back')),
|
||||
matching: find.byType(SegmentedBar),
|
||||
);
|
||||
final heading = find.byKey(const Key('run-visit-title'));
|
||||
expect(
|
||||
find.descendant(of: bar, matching: heading),
|
||||
findsOneWidget,
|
||||
reason: 'the stage is the bar title',
|
||||
);
|
||||
expect(
|
||||
find.descendant(of: heading, matching: find.text('plan')),
|
||||
findsOneWidget,
|
||||
);
|
||||
final barBottom = pieceOf(tester, bar).bottom;
|
||||
|
||||
final summary = find.byKey(const Key('run-visit-body-summary'));
|
||||
expect(tester.getTopLeft(summary).dy, 0);
|
||||
final facts = find.byKey(const Key('run-visit-facts-grid'));
|
||||
final rest = tester.getTopLeft(facts).dy;
|
||||
expect(rest, greaterThanOrEqualTo(barBottom));
|
||||
// The tabs float at the bottom over the section.
|
||||
final tabs = pieceOf(tester, find.byKey(const Key('run-visit-tabs')));
|
||||
expect(tabs.bottom, 844 - 16);
|
||||
expect(tester.getRect(summary).bottom, 844);
|
||||
|
||||
// Open Input so the section is long enough to scroll, then scroll:
|
||||
// the facts pass behind the bar.
|
||||
await tester.tap(find.text('Input').first);
|
||||
await tester.pumpAndSettle();
|
||||
final position = positionIn(tester, summary);
|
||||
if (position.maxScrollExtent > 0) {
|
||||
position.jumpTo(position.maxScrollExtent.clamp(0, 60).toDouble());
|
||||
await tester.pump();
|
||||
expect(tester.getTopLeft(facts).dy, lessThan(rest));
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -13,17 +13,20 @@ Finder runDetailText(String text) => find.descendant(
|
||||
matching: find.text(text),
|
||||
);
|
||||
|
||||
/// Stage identity and visit coordinates are separate rendered fields now.
|
||||
/// The stage page's bar names the stage over its visit (and run): the title
|
||||
/// is keyed `run-visit-title` and the subtitle starts `Visit <sequence>`.
|
||||
void expectVisitHeading(WidgetTester tester, String stage, num sequence) {
|
||||
final pane = find.byKey(const Key('run-visit-pane'));
|
||||
expect(pane, findsOneWidget);
|
||||
final title = find.descendant(
|
||||
of: pane,
|
||||
matching: find.byKey(const Key('run-visit-title')),
|
||||
);
|
||||
expect(tester.widget<Text>(title).data, stage);
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
|
||||
final heading = find.byKey(const Key('run-visit-title'));
|
||||
expect(
|
||||
find.descendant(of: pane, matching: find.text('Visit $sequence')),
|
||||
find.descendant(of: heading, matching: find.text(stage)),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: heading,
|
||||
matching: find.textContaining(RegExp('^Visit $sequence( ·|\$)')),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,9 +16,22 @@ void main() {
|
||||
await openVisit(tester, platform);
|
||||
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
|
||||
// The page bar names the stage over its visit and run; the body does
|
||||
// not repeat them.
|
||||
final heading = find.byKey(const Key('run-visit-title'));
|
||||
expect(
|
||||
find.descendant(of: heading, matching: find.text('plan')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: heading,
|
||||
matching: find.text('Visit 1 · Run 77 · Visit run'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('plan'), findsOneWidget);
|
||||
expect(find.text('Visit 1'), findsOneWidget);
|
||||
expect(find.text('Run 77'), findsOneWidget);
|
||||
expect(find.text('Visit 1'), findsNothing);
|
||||
// Each fact as its label over its value; several share a line.
|
||||
for (final (label, value) in [
|
||||
('Status', 'completed'),
|
||||
@@ -36,20 +49,16 @@ void main() {
|
||||
expect(find.text('Verdict'), findsOneWidget);
|
||||
expect(find.text('Diagnostic'), findsOneWidget);
|
||||
|
||||
// Stage identity is a distinct, prominent heading; coordinates are
|
||||
// subordinate and the facts remain aligned with the heading.
|
||||
final titleFinder = find.byKey(const Key('run-visit-title'));
|
||||
final title = tester.getTopLeft(titleFinder).dx;
|
||||
final titleStyle = tester.widget<Text>(titleFinder).style!;
|
||||
expect(titleStyle.fontSize!, greaterThan(18));
|
||||
// The title is the bar's header; the facts lead the scrolled Summary
|
||||
// below the bar at rest.
|
||||
expect(
|
||||
tester.getTopLeft(find.text('Visit 1')).dy,
|
||||
greaterThan(tester.getTopLeft(titleFinder).dy),
|
||||
tester.getSemantics(find.text('plan')),
|
||||
matchesSemantics(isHeader: true, label: 'plan'),
|
||||
);
|
||||
expect(
|
||||
tester.getTopLeft(find.byKey(const Key('run-visit-facts-grid'))).dx,
|
||||
title,
|
||||
final facts = tester.getRect(
|
||||
find.byKey(const Key('run-visit-facts-grid')),
|
||||
);
|
||||
expect(facts.top, greaterThanOrEqualTo(tester.getRect(heading).bottom));
|
||||
// Status and duration share a line.
|
||||
expect(
|
||||
tester.getTopLeft(find.text('completed')).dy,
|
||||
@@ -109,7 +118,7 @@ void main() {
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('${platform.name} long stage identity wraps at 2x', (
|
||||
testWidgets('${platform.name} long stage identity fits the bar at 2x', (
|
||||
tester,
|
||||
) async {
|
||||
final run = visitRunFixture();
|
||||
@@ -123,12 +132,13 @@ void main() {
|
||||
scale: 2,
|
||||
);
|
||||
|
||||
// The bar's one-line title ellipsises a long stage instead of
|
||||
// overflowing.
|
||||
expect(
|
||||
find.text('review-generated-release-artifacts-and-verify-evidence'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Visit 1'), findsOneWidget);
|
||||
expect(find.text('Run 77'), findsOneWidget);
|
||||
expect(find.text('Visit 1 · Run 77 · Visit run'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/schedules/screen.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/list/schedule_list_toolbar.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/list/schedule_list_view.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
||||
|
||||
import 'schedule_list_test_support.dart';
|
||||
|
||||
/// The schedule list under a floating bar: search, filter and count are a
|
||||
/// glass strip under the bar, and the list scrolls behind both.
|
||||
void main() {
|
||||
Future<void> pump(WidgetTester tester, {required bool cupertino}) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = FakeSchedulesGateway(
|
||||
(type, fields) async => schedulesReply(longScheduleList(30)),
|
||||
);
|
||||
final screen = SchedulesScreen(gateway: gateway, onOpen: (_) {});
|
||||
final bar = SegmentedBar(cupertino: cupertino, title: 'Schedules');
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(navigationBar: bar, child: screen),
|
||||
)
|
||||
: MaterialApp(
|
||||
home: Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: bar,
|
||||
body: screen,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Rect pieceOf(WidgetTester tester, Finder owner) => tester.getRect(
|
||||
find.descendant(of: owner, matching: find.byType(GlassPill)).first,
|
||||
);
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('$host: the toolbar floats under the bar and the list '
|
||||
'scrolls behind it', (tester) async {
|
||||
await pump(tester, cupertino: cupertino);
|
||||
|
||||
final bar = pieceOf(tester, find.byType(SegmentedBar));
|
||||
final strip = pieceOf(tester, find.byKey(scheduleToolbarKey));
|
||||
expect(strip.top, greaterThanOrEqualTo(bar.bottom));
|
||||
expect(strip.top - bar.bottom, lessThan(24));
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(scheduleToolbarKey),
|
||||
matching: find.byKey(scheduleSearchFieldKey),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
final list = find.byKey(scheduleListKey);
|
||||
expect(tester.getTopLeft(list).dy, 0);
|
||||
final firstRow = find.byKey(const ValueKey('schedule-row-0-100'));
|
||||
final rest = tester.getTopLeft(firstRow).dy;
|
||||
expect(rest, greaterThanOrEqualTo(strip.bottom));
|
||||
|
||||
await tester.drag(list, const Offset(0, -120));
|
||||
await tester.pump();
|
||||
expect(tester.getTopLeft(firstRow).dy, lessThan(strip.bottom));
|
||||
});
|
||||
|
||||
testWidgets('$host: a query that empties the list keeps the field', (
|
||||
tester,
|
||||
) async {
|
||||
await pump(tester, cupertino: cupertino);
|
||||
final field = find.byKey(scheduleSearchFieldKey);
|
||||
await tester.tap(field);
|
||||
await tester.pump();
|
||||
final before = tester.element(field);
|
||||
await tester.enterText(field, 'no schedule matches this');
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('No schedules match this search.'), findsOneWidget);
|
||||
expect(tester.element(field), same(before));
|
||||
final editable = tester.state<EditableTextState>(
|
||||
find.descendant(of: field, matching: find.byType(EditableText)),
|
||||
);
|
||||
expect(editable.widget.focusNode.hasFocus, isTrue);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import 'package:pipelines_app/features/search/search_screen.dart';
|
||||
import 'package:pipelines_app/features/search/ui/search_bar_controls.dart';
|
||||
import 'package:pipelines_app/features/search/ui/search_bounds_note.dart';
|
||||
import 'package:pipelines_app/features/search/ui/search_layout.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
import 'package:pipelines_app/ui/layout/app_list_row.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
||||
|
||||
@@ -155,5 +156,54 @@ void main() {
|
||||
lessThanOrEqualTo(kSearchPillMaxWidth),
|
||||
);
|
||||
});
|
||||
|
||||
for (final width in [390.0, 1200.0]) {
|
||||
testWidgets('$host: at $width the field takes the title\'s place and '
|
||||
'the results line up with it', (tester) async {
|
||||
_size(tester, width);
|
||||
final gateway = ImmediateGateway((_, _) => response([pipeline]));
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
cupertino,
|
||||
SearchScreen(
|
||||
gateway: gateway,
|
||||
onOpen: (_) {},
|
||||
cupertino: cupertino,
|
||||
),
|
||||
),
|
||||
);
|
||||
await _search(tester, 'release');
|
||||
|
||||
final bar = find.byType(SegmentedBar);
|
||||
// No Search title pill: the field's pill is the bar's only piece.
|
||||
expect(
|
||||
find.descendant(of: bar, matching: find.text('Search')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(
|
||||
find.descendant(of: bar, matching: find.byType(GlassPill)),
|
||||
findsOneWidget,
|
||||
);
|
||||
final pill = tester.getRect(
|
||||
find.descendant(of: bar, matching: find.byType(GlassPill)),
|
||||
);
|
||||
expect(pill.left, kSearchContentInset);
|
||||
expect(
|
||||
pill.width,
|
||||
width - 2 * kSearchContentInset < kSearchPillMaxWidth
|
||||
? width - 2 * kSearchContentInset
|
||||
: kSearchPillMaxWidth,
|
||||
);
|
||||
// The field fills the pill beside Kind and the help.
|
||||
final field = tester.getRect(find.byKey(searchFieldKey));
|
||||
expect(field.width, greaterThan(pill.width * 0.6));
|
||||
// The result column shares the pill's edges.
|
||||
final row = tester.getRect(
|
||||
find.byKey(const ValueKey('search.result.pipeline:7')),
|
||||
);
|
||||
expect(row.left, pill.left);
|
||||
expect(row.right, pill.right);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart'
|
||||
as transport;
|
||||
import 'package:pipelines_app/features/settings/settings_group.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_screen.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_store.dart';
|
||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
|
||||
import 'fake_channel.dart';
|
||||
|
||||
/// Settings as the shell's tab: the page runs behind the shell's bar, and on
|
||||
/// Cupertino the grouped background reaches the top edge with the bar's
|
||||
/// scrim in the same colour, so no white band or seam shows under the bar.
|
||||
void main() {
|
||||
Future<void> pump(WidgetTester tester, {required bool cupertino}) async {
|
||||
await tester.binding.setSurfaceSize(const Size(560, 1000));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final factory = FakeChannelFactory();
|
||||
final client = transport.PipelinesClient(channelFactory: factory.call);
|
||||
addTearDown(client.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
platform: cupertino ? TargetPlatform.iOS : TargetPlatform.android,
|
||||
),
|
||||
home: AdaptiveShell(
|
||||
cupertino: cupertino,
|
||||
destination: AppDestination.settings,
|
||||
destinationBodies: {
|
||||
AppDestination.settings: (_) => SettingsScreen(
|
||||
client: client,
|
||||
store: MemorySettingsStore(),
|
||||
embedded: true,
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Color scrimOf(WidgetTester tester) => tester
|
||||
.widget<ColoredBox>(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byType(SegmentedBar),
|
||||
matching: find.byType(ColoredBox),
|
||||
)
|
||||
.first,
|
||||
)
|
||||
.color;
|
||||
|
||||
testWidgets('Cupertino: the grouped background runs under the bar', (
|
||||
tester,
|
||||
) async {
|
||||
await pump(tester, cupertino: true);
|
||||
|
||||
final grouped = AppColors.groupedBackground.color.toARGB32();
|
||||
expect(scrimOf(tester).toARGB32(), grouped);
|
||||
// The page's background starts at the top edge, behind the bar.
|
||||
final page = find.ancestor(
|
||||
of: find.byKey(const ValueKey<String>('settings.scroll')),
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) => widget is ColoredBox && widget.color.toARGB32() == grouped,
|
||||
),
|
||||
);
|
||||
expect(page, findsOneWidget);
|
||||
expect(tester.getTopLeft(page).dy, 0);
|
||||
// The groups start below the bar and scroll behind it.
|
||||
final bar = tester.getRect(find.byType(SegmentedBar));
|
||||
expect(
|
||||
tester.getTopLeft(find.byType(SettingsGroup).first).dy,
|
||||
greaterThanOrEqualTo(bar.bottom - 8),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Material: the bar keeps the shell page background', (
|
||||
tester,
|
||||
) async {
|
||||
await pump(tester, cupertino: false);
|
||||
|
||||
final context = tester.element(find.byType(SettingsGroup).first);
|
||||
expect(
|
||||
scrimOf(tester).toARGB32(),
|
||||
Theme.of(context).scaffoldBackgroundColor.toARGB32(),
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.getTopLeft(find.byKey(const ValueKey<String>('settings.scroll')))
|
||||
.dy,
|
||||
0,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
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',
|
||||
);
|
||||
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'))],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
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);
|
||||
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);
|
||||
Reference in New Issue
Block a user