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/detail_page.dart'; import 'package:pipelines_app/shell/list_detail.dart'; import 'package:pipelines_app/shell/shell_bar.dart'; import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart'; import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart'; import 'package:pipelines_app/ui/adaptive/glass_pill.dart'; import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'; /// Beside a list each pane owns its bar on one shared top row, and an open /// item's tabs float at the bottom of its own pane, beside (never on) the /// shell's tab bar over the list. void main() { Future setSize(WidgetTester tester, Size size) async { tester.view.physicalSize = size; tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); } Rect rectOf(Element element) { final box = element.renderObject! as RenderBox; return box.localToGlobal(Offset.zero) & box.size; } /// An open item: its title published to the pane's bar, its own tabs /// floating where the pane says, and a list padded clear of both bars. Widget item({bool cupertino = false}) => ShellBar( title: 'Open item', subtitle: 'Its context', actions: const [Icon(Icons.more_vert, semanticLabel: 'More')], child: Builder( builder: (context) { final edge = PageTabsEdge.of(context); return FloatingBarOverlay( edge: edge, bar: KeyedSubtree( key: const Key('item-tabs'), child: FloatingDestinationBar( cupertino: cupertino, edge: edge, currentIndex: 0, onTap: (_) {}, items: const [ FloatingDestinationItem(icon: Icon(Icons.notes), label: 'One'), FloatingDestinationItem( icon: Icon(Icons.timeline), label: 'Two', ), ], ), ), child: Builder( builder: (context) => ListView( key: const Key('item-list'), padding: withBarClearance(context, EdgeInsets.zero), children: [ for (var index = 0; index < 30; index++) SizedBox(height: 40, child: Text('item row $index')), ], ), ), ); }, ), ); Widget shell({bool cupertino = false, int attention = 0}) { final app = AdaptiveShell( cupertino: cupertino, attentionCount: attention, destinationBodies: { AppDestination.runs: (_) => ShellBadge( kind: ShellBadgeKind.running, count: 4, child: ListDetailPanes( list: ShellBar( actions: [const Icon(Icons.sort, semanticLabel: 'Sort')], child: ListView( children: [ for (var index = 0; index < 30; index++) SizedBox(height: 40, child: Text('list row $index')), ], ), ), detail: DetailPane( destination: AppDestination.runs, implyBack: false, builder: (_) => item(cupertino: cupertino), ), ), ), }, destination: AppDestination.runs, ); return cupertino ? CupertinoApp(home: app) : MaterialApp(home: app); } Finder shellBar() => find.byWidgetPredicate( (widget) => widget is SegmentedBar && widget.title == 'Runs', ); Finder paneBar() => find.descendant( of: find.byType(DetailPane), matching: find.byType(SegmentedBar), ); for (final cupertino in [false, true]) { final host = cupertino ? 'Cupertino' : 'Material'; testWidgets('$host 1200: the shell bar covers the list pane and the ' 'item\'s bar shares its row', (tester) async { await setSize(tester, const Size(1200, 800)); await tester.pumpWidget(shell(cupertino: cupertino)); await tester.pump(); await tester.pump(); final list = tester.getRect( find.byKey(const ValueKey('list-detail-list')), ); final body = tester.getRect( find.byKey(const ValueKey('list-detail-body')), ); final shellPills = find.descendant( of: shellBar(), matching: find.byType(GlassPill), ); for (final element in shellPills.evaluate()) { expect( rectOf(element).right, lessThanOrEqualTo(list.right), reason: 'no shell piece sits over the open item', ); } // Both titles on the same top row. final shellTitle = tester.getRect( find.descendant(of: shellBar(), matching: find.text('Runs')), ); final paneTitle = tester.getRect(find.text('Open item')); expect(paneTitle.left, greaterThanOrEqualTo(body.left)); final paneTop = tester.getRect( find.descendant(of: paneBar(), matching: find.byType(GlassPill)).first, ); final shellTop = tester.getRect(shellPills.first); expect(paneTop.top, shellTop.top); expect(paneTitle.top, lessThan(shellTitle.bottom)); // The title pill carries the item's context too. expect(find.text('Its context'), findsOneWidget); }); testWidgets('$host 1200: the item\'s tabs float at the bottom of its ' 'pane, the shell\'s tab bar under the list', (tester) async { await setSize(tester, const Size(1200, 800)); await tester.pumpWidget(shell(cupertino: cupertino)); await tester.pump(); await tester.pump(); final shellTabs = tester.getRect( find .ancestor( of: find.byKey(const ValueKey('shell.destination.runs')).first, matching: find.byKey(FloatingDestinationBar.rowKey), ) .first, ); final itemTabs = tester.getRect( find.descendant( of: find.byKey(const Key('item-tabs')), matching: find.byKey(FloatingDestinationBar.rowKey), ), ); final body = tester.getRect( find.byKey(const ValueKey('list-detail-body')), ); // The shell's tabs sit at the bottom of the list pane; the item's at // the bottom right of the detail pane, never on them. final list = tester.getRect( find.byKey(const ValueKey('list-detail-list')), ); expect(shellTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5)); expect(shellTabs.right, lessThanOrEqualTo(list.right)); expect(itemTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5)); expect(itemTabs.right, closeTo(1200 - kFloatingBarMargin, 0.5)); expect(itemTabs.left, greaterThanOrEqualTo(body.left)); expect(itemTabs.overlaps(shellTabs), isFalse); // The item's list starts below its bar and clears its tabs at rest. final paneBarPill = tester.getRect( find.descendant(of: paneBar(), matching: find.byType(GlassPill)).first, ); expect( tester.getTopLeft(find.text('item row 0')).dy, greaterThanOrEqualTo(paneBarPill.bottom), ); expect( MediaQuery.paddingOf( tester.element(find.byKey(const Key('item-list'))), ).bottom, greaterThanOrEqualTo(800 - itemTabs.top), ); }); } testWidgets('390: an open item is its own page with its tabs at the bottom', ( tester, ) async { await setSize(tester, const Size(390, 844)); await tester.pumpWidget( MaterialApp( home: DetailPane( destination: AppDestination.runs, builder: (_) => item(), ), ), ); await tester.pump(); final tabs = tester.getRect( find.descendant( of: find.byKey(const Key('item-tabs')), matching: find.byKey(FloatingDestinationBar.rowKey), ), ); expect(tabs.bottom, greaterThan(844 - 40)); // Content reaches the top edge and starts below the page's bar. final bar = tester.getRect( find.descendant(of: paneBar(), matching: find.byType(GlassPill)).first, ); expect(tester.getTopLeft(find.byKey(const Key('item-list'))).dy, 0); expect( tester.getTopLeft(find.text('item row 0')).dy, greaterThanOrEqualTo(bar.bottom), ); }); testWidgets('the Runs tab shows one indicator: attention outranks running', ( tester, ) async { await setSize(tester, const Size(1200, 800)); await tester.pumpWidget(shell(attention: 2)); await tester.pump(); await tester.pump(); expect(find.text('2'), findsOneWidget); expect(find.text('4'), findsNothing); await tester.pumpWidget(shell()); await tester.pump(); await tester.pump(); expect(find.text('4'), findsOneWidget); }); }