diff --git a/app/lib/shell/adaptive_shell.dart b/app/lib/shell/adaptive_shell.dart index e37da7b4..6d1137cd 100644 --- a/app/lib/shell/adaptive_shell.dart +++ b/app/lib/shell/adaptive_shell.dart @@ -8,6 +8,7 @@ import 'attention_badge.dart'; import 'destination.dart'; import 'list_detail.dart'; import 'navigation_rail.dart'; +import 'shell_navigation_bar.dart'; import 'shell_rail_scope.dart'; import 'list_pane_widths.dart'; import 'shell_bar.dart'; @@ -149,7 +150,6 @@ class _AdaptiveShellState extends State { // only after the outgoing page has finished its native animation. // Settings is shown as a page of the Pipelines tab: the tab bar keeps // Pipelines selected and the bar offers Back to it. - final index = shellTabDestinations.indexOf(shellTabFor(_selected)); final page = !shellTabDestinations.contains(_selected); final details = destinationDetails(_selected); final contents = AppDestination.values.map((destination) { @@ -175,23 +175,29 @@ class _AdaptiveShellState extends State { // Only the bar shows the registry's state, so a published bar or badge // rebuilds its bar alone; the destinations and scaffold stay as built. _bar.focus = _selected; - // One floating glass tab bar at every width: sized to its tabs at the - // right edge, near the thumb. Content keeps the whole width and scrolls - // behind it, learning the bar's height as its bottom media padding. + // A phone (narrower than the list-detail split) gets a full-width Material + // NavigationBar at the bottom, with Settings as its last destination. Wider + // windows without the rail keep the floating glass tab bar, which the list + // beside an open item needs (see below). Content keeps the whole width and + // scrolls behind the bar, learning its height as its bottom media padding. // Neither scaffold's structure depends on the width, so resizing never - // remounts a destination. - // - // While the tab shows its list beside an open item the bar moves under - // the leading edge of the list pane, so the open item - // keeps its whole height: the list clears the bar and the item clears - // only the system inset (see ListDetailPanes). The bar keeps its place - // in the tree, so a split never replays its entrance. + // remounts a destination. Pushed detail routes cover the shell, and a + // bar-less spec (a chat workspace) hides the bar. + final phone = !showsListBesideDetail(context); final bar = ListenableBuilder( listenable: Listenable.merge([_bar.badges, _bar.bar, _paneWidths]), builder: (context, _) { if (_bar.specFor(_selected)?.hideNavigation ?? false) { return const SizedBox.shrink(); } + if (phone) { + return ShellNavigationBar( + selected: _selected, + icon: (destination) => + _icon(destination, destinationDetails(destination).icon), + onSelected: _select, + ); + } // On a wide window the bar stays under the list column even when no // item is open (Search, a list alone), so it never jumps sides. A page // (Settings) has no list column, so its bar stays at the right edge. @@ -203,7 +209,7 @@ class _AdaptiveShellState extends State { alignment: AlignmentDirectional.bottomStart, child: FloatingDestinationBar( showLabels: true, - currentIndex: index, + currentIndex: shellTabDestinations.indexOf(shellTabFor(_selected)), onTap: (value) => _select(shellTabDestinations[value]), items: _destinationItems(), alignment: split ? AlignmentDirectional.bottomStart : null, diff --git a/app/lib/shell/shell_navigation_bar.dart b/app/lib/shell/shell_navigation_bar.dart new file mode 100644 index 00000000..dcab405f --- /dev/null +++ b/app/lib/shell/shell_navigation_bar.dart @@ -0,0 +1,64 @@ +import 'package:flutter/material.dart'; + +import 'destination.dart'; + +/// The destinations the phone's bottom bar offers, in order: the tabs, then +/// Settings. The rail pins Settings at its foot; a narrow window has no foot, +/// so Settings is the bar's last destination and is selected while it is open. +const List shellBarDestinations = [ + ...shellTabDestinations, + AppDestination.settings, +]; + +/// The phone layout's bottom navigation: a full-width Material +/// [NavigationBar] with an icon and a label per destination, the current +/// destination marked by the bar's indicator. +/// +/// [icon] builds each destination's icon (its running, needs-you or unread +/// badge included), the same builder the desktop rail uses, so both layouts +/// show the same counts. [selected] is the shell's destination. A re-tap of +/// the selected destination still calls [onSelected], which is how the shell's +/// destination-reselected hook fires. +/// +/// The bar keeps the bottom system inset (gesture bar) clear and leaves while +/// the keyboard is open, so a field's text is never covered by the bar. +class ShellNavigationBar extends StatelessWidget { + const ShellNavigationBar({ + super.key, + required this.selected, + required this.icon, + required this.onSelected, + }); + + final AppDestination selected; + final Widget Function(AppDestination destination) icon; + final ValueChanged onSelected; + + @override + Widget build(BuildContext context) { + // The keyboard takes the bottom of the window: the bar leaves with it. + if (MediaQuery.viewInsetsOf(context).bottom > 0) { + return const SizedBox.shrink(); + } + return SafeArea( + top: false, + child: NavigationBar( + key: const ValueKey('shell.navigation-bar'), + selectedIndex: shellBarDestinations.indexOf(selected), + onDestinationSelected: (value) => + onSelected(shellBarDestinations[value]), + destinations: [ + for (final destination in shellBarDestinations) + NavigationDestination( + icon: KeyedSubtree( + key: ValueKey('shell.destination.${destination.name}'), + child: icon(destination), + ), + label: destinationDetails(destination).label, + tooltip: destinationDetails(destination).label, + ), + ], + ), + ); + } +} diff --git a/app/notes/phone-navigation-bar.md b/app/notes/phone-navigation-bar.md new file mode 100644 index 00000000..bfbc0ca3 --- /dev/null +++ b/app/notes/phone-navigation-bar.md @@ -0,0 +1,64 @@ +# Phone bottom navigation bar + +Replaces the floating round destination pill on phone-width windows (narrower +than the 600 px list-detail split) with a full-width Material 3 `NavigationBar`: +Pipelines, Runs, Chat, Search, Settings, each with icon, label and the rail's +badges. Wider windows keep the floating bar (the list beside an open item needs +it) and the rail keeps its existing layout. + +## Changed paths +- `app/lib/shell/shell_navigation_bar.dart` (new): `ShellNavigationBar`, the + phone bar. Reuses `destinationDetails`, `shellTabDestinations` and the shell's + badge icon builder. Settings is its fifth destination. Wrapped in `SafeArea` + (bottom only). Returns nothing while the keyboard is open + (`viewInsets.bottom > 0`). +- `app/lib/shell/adaptive_shell.dart`: phone path uses the new bar; the floating + bar stays for wider non-rail windows; `hideNavigation` specs still hide the bar. + Pushed detail routes already cover the shell, so the bar stays hidden there. +- Tests: `test/shell/shell_navigation_bar_test.dart` (new, 7 cases), + `test/shell/shell_bar_test.dart`, `test/shell/floating_tab_bar_test.dart`, + `test/shell/attention_badge_test.dart`, `test/shell/navigation_rail_test.dart`, + `test/shell/split_destination_bar_test.dart`, + `test/application/settings_page_test.dart`, `test/widget_test.dart`, + `test/perf/background_work_bench_test.dart` (counts `ShellNavigationBar` + rebuilds now, since the pill is no longer built on phones). + +## Behaviour decisions +- Re-tap: `ShellNavigationBar` calls `onSelected` on every tap, including the + shown destination, so `AdaptiveShell._select` (and its `onDestinationSelected` + callback) fires on re-tap. Run 404's hook is not in this branch; nothing to + rename. +- Settings selected: the bar marks Settings (index 4) while the Settings page is + open. The Pipelines gear stays in the Pipelines toolbar. +- Keyboard: the bar leaves whenever the keyboard is open on a phone, not only in + chat. Chat on phone already hides it through its workspace `hideNavigation`. + +## Focused results +Command: `tool/memwatch/full.sh` with one quoted path list (new shell test, the +shell and application users of the bar, `widget_test`, two features/chat files, +perf bench). The verdict line named only those paths. +- Final run: 129 passed, 2 failed. Both failures are + `test/application/search_wiring_test.dart` ("field and artifact hits select + their run detail selection", "an abandoned selection does not replay on run + reopen"). They also fail on an untouched base worktree (HEAD 9bb87e51, detached + temporary worktree, removed afterwards), with the same `ok` EditableText + assertion. They are pre-existing and unrelated to the bar. +- New file alone: `shell_navigation_bar_test.dart` 7/7 passed. +- `tool/analyze.sh`: clean (0 errors, 0 warnings, 0 infos) after the final edits. + +## Affected UI states (not captured here) +- Phone (390 px) bar, each of Pipelines, Runs, Chat, Search, Settings selected: + covered by widget tests for selection, not rendered. +- Badges: running count on Runs, unread on Chat (widget tests). +- Keyboard open: bar absent (widget test). +- Pushed detail route: bar absent (existing test, `shell_bar_test.dart`). +- Chat workspace: bar absent (existing `hideNavigation`). +- Light and dark captures: NOT produced. Capture belongs to ui-review. + +## Limitations +- No device or browser verification of the bar. Its metrics (80 dp `NavigationBar` + height, SafeArea) and the gesture-inset clearance are verified only in widget + tests with the padding faked. +- Settings-as-destination on the phone bar is new behaviour; the Pipelines gear + is still present. +- Medium widths (600 px to the rail threshold) keep the floating pill, by design. diff --git a/app/test/application/settings_page_test.dart b/app/test/application/settings_page_test.dart index e27df3ca..ddd89d4e 100644 --- a/app/test/application/settings_page_test.dart +++ b/app/test/application/settings_page_test.dart @@ -46,9 +46,9 @@ void main() { return provider; } - int selectedTab(WidgetTester tester) => tester - .widget(find.byType(FloatingDestinationBar)) - .currentIndex; + // The phone's bar marks the destination shown: Settings while it is open. + int selectedTab(WidgetTester tester) => + tester.widget(find.byType(NavigationBar)).selectedIndex; // A phone's Pipelines bar keeps the gear; a wide window's rail offers // Settings instead (see the wide test below). @@ -60,17 +60,17 @@ void main() { location: '/pipelines', size: size, ); - // Four tabs; Settings is none of them. + // Four tabs and Settings as the bar's last destination. expect( tester - .widget(find.byType(FloatingDestinationBar)) - .items - .map((item) => item.label), - ['Pipelines', 'Runs', 'Chat', 'Search'], + .widget(find.byType(NavigationBar)) + .destinations + .map((item) => (item as NavigationDestination).label), + ['Pipelines', 'Runs', 'Chat', 'Search', 'Settings'], ); expect( find.byKey(const ValueKey('shell.destination.settings')), - findsNothing, + findsOneWidget, ); expect(find.byKey(const ValueKey('shell.back')), findsNothing); @@ -86,10 +86,10 @@ void main() { expect(find.text('Quick switch animation'), findsOneWidget); await selectSettingsTopic(tester, 'Connection'); expect(find.text('Server URL'), findsOneWidget); - // A page of Pipelines: Back in its bar, Pipelines still selected. + // A page of Pipelines: Back in its bar, Settings selected in the bar. expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); expect(find.byKey(const ValueKey('shell.search')), findsNothing); - expect(selectedTab(tester), 0); + expect(selectedTab(tester), 4); expect(tester.takeException(), isNull); await tester.tap(find.byKey(const ValueKey('shell.back'))); @@ -164,7 +164,7 @@ void main() { await tester.pump(); expect(find.byType(SettingsScreen), findsOneWidget); expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); - expect(selectedTab(tester), 0); + expect(selectedTab(tester), 4); final handled = await tester.binding.handlePopRoute(); expect(handled, isTrue, reason: 'Back closes the page, not the app'); diff --git a/app/test/perf/background_work_bench_test.dart b/app/test/perf/background_work_bench_test.dart index ce00e351..0287a521 100644 --- a/app/test/perf/background_work_bench_test.dart +++ b/app/test/perf/background_work_bench_test.dart @@ -13,7 +13,7 @@ import 'package:pipelines_app/features/runs/ui/runs_controller.dart'; import 'package:pipelines_app/features/runs/ui/runs_list.dart'; import 'package:pipelines_app/shell/adaptive_shell.dart'; import 'package:pipelines_app/shell/destination.dart'; -import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart'; +import 'package:pipelines_app/shell/shell_navigation_bar.dart'; import 'package:pipelines_app/ui/text/relative_time_label.dart'; class _Gateway implements ApiGateway { @@ -198,11 +198,11 @@ void main() { print( 'BENCH offstage activeTimers=$active labelRebuildsIn2Minutes=$tick ' 'burst50: runsListRebuilds=${rebuilds.of(RunsList)} ' - 'shellBarRebuilds=${rebuilds.of(FloatingDestinationBar)} ' + 'shellBarRebuilds=${rebuilds.of(ShellNavigationBar)} ' 'totalRebuilds=${rebuilds.total}', ); expect(tick, 0); - expect(rebuilds.of(FloatingDestinationBar), 0); + expect(rebuilds.of(ShellNavigationBar), 0); await tester.pumpWidget(const SizedBox()); expect(timers.active, 0); }); @@ -232,7 +232,7 @@ void main() { 'BENCH visibleBurst50 controllerNotifications=$notifications ' 'runsListRebuilds=${rebuilds.of(RunsList)} ' 'runRowRebuilds=${rebuilds.of(RunListRow)} ' - 'shellBarRebuilds=${rebuilds.of(FloatingDestinationBar)} ' + 'shellBarRebuilds=${rebuilds.of(ShellNavigationBar)} ' 'totalRebuilds=${rebuilds.total}', ); final top = rebuilds.counts.entries.toList() diff --git a/app/test/shell/attention_badge_test.dart b/app/test/shell/attention_badge_test.dart index fd70c6d0..78d64cf1 100644 --- a/app/test/shell/attention_badge_test.dart +++ b/app/test/shell/attention_badge_test.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/shell/adaptive_shell.dart'; -import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart'; /// The Runs tab keeps running work visible without an error counter. void main() { @@ -23,9 +22,9 @@ void main() { for (final width in [390.0, 1000.0]) { final mount = width < 600 ? 'bottom bar' : 'rail'; - // The rail (wide) or the floating bar (phone) carries the same counts. + // The rail (wide) or the phone's navigation bar carries the same counts. final navigation = width < 600 - ? find.byType(FloatingDestinationBar) + ? find.byType(NavigationBar) : find.byType(NavigationRail); testWidgets('$mount shows the count on the Runs tab', (tester) async { diff --git a/app/test/shell/floating_tab_bar_test.dart b/app/test/shell/floating_tab_bar_test.dart index 6a0a8dfc..bf524b5f 100644 --- a/app/test/shell/floating_tab_bar_test.dart +++ b/app/test/shell/floating_tab_bar_test.dart @@ -3,13 +3,14 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/shell/list_detail_policy.dart'; import 'package:pipelines_app/shell/adaptive_shell.dart'; import 'package:pipelines_app/shell/destination.dart'; +import 'package:pipelines_app/shell/shell_navigation_bar.dart'; import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart'; import 'package:pipelines_app/ui/adaptive/floating_destination_labels.dart'; import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart'; -/// Main navigation keeps visible captions and full-size targets, floating at -/// the trailing edge on a phone and the leading edge under the list on a wide -/// window. +/// Main navigation keeps visible captions and full-size targets: a full-width +/// navigation bar on a phone, and on a wide window a floating bar at the +/// leading edge under the list. void main() { Finder pill() => find.descendant( of: find.byType(FloatingDestinationBar), @@ -87,19 +88,18 @@ void main() { return MaterialApp(home: app); } - testWidgets('phone bar hugs its tabs at the bottom right too, and ' - 'taps beside it reach the content', (tester) async { + testWidgets('a phone shows a full-width navigation bar, and taps above it ' + 'reach the content', (tester) async { taps = 0; await setSize(tester, const Size(390, 844)); await tester.pumpWidget(shell()); - final rect = tester.getRect(pill()); - await expectLabeledTargets(tester, rect); - await expectNoSharedBackdrop(tester); - expect(rect.width, lessThanOrEqualTo(390 - 2 * 16)); - expect(rect.right, 390 - 16); - expect(rect.bottom, 844 - 16); + await tester.pumpAndSettle(); + final bar = tester.getRect(find.byType(NavigationBar)); + expect(bar.left, 0); + expect(bar.right, 390); + expect(find.byType(FloatingDestinationBar), findsNothing); expect(find.byType(NavigationRail), findsNothing); - await tester.tapAt(Offset(rect.left - 40, rect.center.dy)); + await tester.tapAt(Offset(195, bar.top - 40)); await tester.pump(); expect(taps, 1); await tester.tap(find.byKey(const ValueKey('shell.destination.chat'))); @@ -146,7 +146,9 @@ void main() { await setSize(tester, size); await tester.pumpWidget(shell()); await tester.pump(); - final rect = tester.getRect(pill()); + final rect = size.width < 600 + ? tester.getRect(find.byType(NavigationBar)) + : tester.getRect(pill()); // The content's bottom padding clears the whole bar and its margin. expect( contentBottomPadding, @@ -169,6 +171,7 @@ void main() { tester.view.physicalSize = const Size(640, 800); await tester.pump(); + expect(find.byType(NavigationBar), findsNothing); expect( tester.getRect(pill()).left, moreOrLessEquals(kFloatingBarMargin, epsilon: 0.5), @@ -178,17 +181,21 @@ void main() { tester.view.physicalSize = const Size(390, 844); await tester.pump(); - await expectLabeledTargets(tester, tester.getRect(pill())); - expect(tester.getRect(pill()).width, lessThanOrEqualTo(390 - 2 * 16)); - expect(tester.getRect(pill()).right, 390 - 16); + await tester.pumpAndSettle(); + expect(find.byType(FloatingDestinationBar), findsNothing); + expect(tester.getRect(find.byType(NavigationBar)).width, 390); expect(tester.state(find.byType(StatefulBuilder)), same(state)); }); - testWidgets('the bar respects the bottom safe area', (tester) async { + testWidgets('the navigation bar respects the bottom safe area', ( + tester, + ) async { await setSize(tester, const Size(390, 844)); tester.view.padding = const FakeViewPadding(bottom: 34); await tester.pumpWidget(shell()); - expect(tester.getRect(pill()).bottom, 844 - 34); + await tester.pumpAndSettle(); + // The bar sits above the gesture inset, its own surface ending there. + expect(tester.getRect(find.byType(NavigationBar)).bottom, 844 - 34); }); testWidgets('the selected tab is marked selected for assistive ' @@ -218,23 +225,25 @@ void main() { await tester.pumpWidget(shell()); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); - // Large captions wrap rather than shrinking the tap targets. - final bounds = tester.getRect(pill()); - await expectLabeledTargets(tester, bounds); - expect(bounds.width, lessThanOrEqualTo(320 - 2 * 16)); - for (final destination in shellTabDestinations) { - final caption = find.descendant( - of: find.byType(FloatingDestinationBar), - matching: find.text(destinationDetails(destination).label), + final bar = find.byType(NavigationBar); + expect(tester.getRect(bar).width, 320); + // Every destination keeps its label and a full-size target at 2x text. + for (final destination in shellBarDestinations) { + final label = destinationDetails(destination).label; + final caption = find.descendant(of: bar, matching: find.text(label)); + expect(caption, findsOneWidget); + expect( + tester.getRect(caption).overlaps(tester.getRect(bar)), + isTrue, + reason: label, ); - final text = tester.widget(caption); - final size = text.style!.fontSize!; - expect(tester.getSize(caption).height, greaterThanOrEqualTo(size * 2)); + final target = tester.getSize( + find.byType(NavigationDestination).at( + shellBarDestinations.indexOf(destination), + ), + ); + expect(target.width, greaterThanOrEqualTo(44), reason: label); + expect(target.height, greaterThanOrEqualTo(44), reason: label); } - expect( - bounds.height, - greaterThan(FloatingDestinationBar.selectedButtonSize()), - ); - expect(tester.getRect(pill()).right, 320 - 16); }); } diff --git a/app/test/shell/navigation_rail_test.dart b/app/test/shell/navigation_rail_test.dart index 3b6030f7..16597aef 100644 --- a/app/test/shell/navigation_rail_test.dart +++ b/app/test/shell/navigation_rail_test.dart @@ -175,23 +175,27 @@ void main() { expect(body.left, greaterThan(list.right)); }); - testWidgets('phone and narrow windows keep the floating bar and no rail', ( + testWidgets('a phone shows the navigation bar with Settings and no rail', ( tester, ) async { - for (final width in [390.0, 640.0]) { - await pumpShell(tester, width: width); - expect(rail(), findsNothing, reason: '$width'); - expect( - find.byKey(const ValueKey('shell.destination.settings')), - findsNothing, - reason: '$width', - ); - expect( - find.byType(FloatingDestinationBar), - findsOneWidget, - reason: '$width', - ); - } + await pumpShell(tester, width: 390); + expect(rail(), findsNothing); + expect(find.byType(NavigationBar), findsOneWidget); + expect( + find.byKey(const ValueKey('shell.destination.settings')), + findsOneWidget, + ); + expect(find.byType(FloatingDestinationBar), findsNothing); + }); + + testWidgets('a narrow window below the rail keeps the floating bar, no rail ' + 'and no navigation bar', (tester) async { + // 640 is wide enough for the list beside its open item, which keeps the + // floating bar under the list column. + await pumpShell(tester, width: 640); + expect(rail(), findsNothing); + expect(find.byType(NavigationBar), findsNothing); + expect(find.byType(FloatingDestinationBar), findsOneWidget); }); testWidgets('floating windows keep to the right of the rail on a wide ' diff --git a/app/test/shell/shell_bar_test.dart b/app/test/shell/shell_bar_test.dart index 542cf384..dffb5a8a 100644 --- a/app/test/shell/shell_bar_test.dart +++ b/app/test/shell/shell_bar_test.dart @@ -3,6 +3,7 @@ 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/shell/shell_navigation_bar.dart'; import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart'; Widget _app({required bool open, VoidCallback? back}) { @@ -45,7 +46,7 @@ void main() { expect(find.byKey(const Key('run-more')), findsNothing); }); - testWidgets('Search is the fourth tab; Settings is not a tab', ( + testWidgets('Search is the fourth tab; Settings is the bar\'s last item', ( tester, ) async { tester.view.physicalSize = const Size(390, 844); @@ -65,50 +66,47 @@ void main() { ); expect( find.byKey(const ValueKey('shell.destination.settings')), - findsNothing, + findsOneWidget, ); expect(find.byKey(const ValueKey('shell.search')), findsNothing); - expect(find.byType(FloatingDestinationBar), findsOneWidget); + expect(find.byType(NavigationBar), findsOneWidget); + expect(find.byType(FloatingDestinationBar), findsNothing); }); - testWidgets('floating tabs stay inset and select destinations', ( - tester, - ) async { + testWidgets('the phone bar is a full-width navigation bar that selects ' + 'destinations', (tester) async { tester.view.physicalSize = const Size(390, 844); tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); await tester.pumpWidget(_app(open: false)); - final destinationPill = find.descendant( - of: find.byType(FloatingDestinationBar), - matching: find.byKey(FloatingDestinationBar.rowKey), - ); - // Visible captions determine the width while full-size targets stay inset. - final rect = tester.getRect(destinationPill); - expect(rect.width, lessThanOrEqualTo(390 - 2 * 16)); + final bar = find.byType(NavigationBar); + final rect = tester.getRect(bar); + expect(rect.left, 0); + expect(rect.right, 390); + expect(rect.bottom, 844); expect( - tester - .widget(find.byType(FloatingDestinationBar)) - .showLabels, - isTrue, + tester.widget(bar).destinations, + hasLength(shellBarDestinations.length), ); - for (final destination in shellTabDestinations) { - final caption = find.descendant( - of: find.byType(FloatingDestinationBar), - matching: find.text(destinationDetails(destination).label), + expect(tester.widget(bar).selectedIndex, 1); + for (var index = 0; index < shellBarDestinations.length; index++) { + final label = destinationDetails(shellBarDestinations[index]).label; + expect( + find.descendant(of: bar, matching: find.text(label)), + findsOneWidget, ); - expect(caption, findsOneWidget); - expect(rect.contains(tester.getRect(caption).center), isTrue); + // Each destination's whole slot is its target, not just the icon. final target = tester.getSize( - find.byKey(ValueKey('shell.destination.${destination.name}')), + find.byType(NavigationDestination).at(index), ); - expect(target.width, greaterThanOrEqualTo(44)); - expect(target.height, greaterThanOrEqualTo(44)); + expect(target.width, greaterThanOrEqualTo(44), reason: label); + expect(target.height, greaterThanOrEqualTo(44), reason: label); } - expect(tester.getRect(destinationPill).right, 390 - 16); await tester.tap(find.byKey(const ValueKey('shell.destination.chat'))); await tester.pump(); expect(find.text('Chat — Not implemented'), findsOneWidget); + expect(tester.widget(bar).selectedIndex, 2); }); testWidgets('tabs show the running and unread counts their screens publish', ( @@ -163,7 +161,7 @@ void main() { ), ); await tester.pumpWidget(shell()); - expect(find.byType(FloatingDestinationBar), findsOneWidget); + expect(find.byType(NavigationBar), findsOneWidget); final navigator = tester.state(find.byType(Navigator)); navigator.push( MaterialPageRoute( @@ -171,16 +169,13 @@ void main() { ), ); await tester.pumpAndSettle(); - expect(find.byType(FloatingDestinationBar), findsNothing); - expect( - find.byType(FloatingDestinationBar, skipOffstage: false), - findsOneWidget, - ); + expect(find.byType(NavigationBar), findsNothing); + expect(find.byType(NavigationBar, skipOffstage: false), findsOneWidget); await navigator.maybePop(); await tester.pump(const Duration(milliseconds: 16)); - expect(find.byType(FloatingDestinationBar), findsOneWidget); + expect(find.byType(NavigationBar), findsOneWidget); await tester.pumpAndSettle(); - expect(find.byType(FloatingDestinationBar), findsOneWidget); + expect(find.byType(NavigationBar), findsOneWidget); }, ); } diff --git a/app/test/shell/shell_navigation_bar_test.dart b/app/test/shell/shell_navigation_bar_test.dart new file mode 100644 index 00000000..5e804115 --- /dev/null +++ b/app/test/shell/shell_navigation_bar_test.dart @@ -0,0 +1,196 @@ +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'; + +/// On a phone the destinations sit in a full-width Material NavigationBar at +/// the bottom: the four tabs and Settings, each with its icon and label, the +/// current one marked, and the badges the rail shows. +void main() { + Future pumpPhone( + WidgetTester tester, { + AppDestination destination = AppDestination.pipelines, + Map bodies = const {}, + int runningRunCount = 0, + ValueChanged? onDestinationSelected, + }) async { + tester.view.physicalSize = const Size(390, 844); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + await tester.pumpWidget( + MaterialApp( + home: AdaptiveShell( + destination: destination, + runningRunCount: runningRunCount, + onDestinationSelected: onDestinationSelected, + destinationBodies: bodies, + ), + ), + ); + await tester.pumpAndSettle(); + } + + Finder bar() => find.byType(NavigationBar); + + Finder inBar(Finder finder) => find.descendant(of: bar(), matching: finder); + + testWidgets('the bar offers the tabs and Settings, in order, with an icon and ' + 'a label each', (tester) async { + await pumpPhone(tester); + + expect(bar(), findsOneWidget); + final labels = tester + .widget(bar()) + .destinations + .map((item) => (item as NavigationDestination).label); + expect(labels, ['Pipelines', 'Runs', 'Chat', 'Search', 'Settings']); + for (final destination in AppDestination.values) { + expect( + inBar( + find.byKey(ValueKey('shell.destination.${destination.name}')), + ), + findsOneWidget, + reason: destination.name, + ); + expect( + inBar(find.byIcon(destinationDetails(destination).icon)), + findsOneWidget, + reason: destination.name, + ); + } + }); + + testWidgets('the selected indicator follows the shown destination, Settings ' + 'included', (tester) async { + await pumpPhone(tester, destination: AppDestination.runs); + expect(tester.widget(bar()).selectedIndex, 1); + + await pumpPhone(tester, destination: AppDestination.settings); + expect(tester.widget(bar()).selectedIndex, 4); + }); + + testWidgets('a tap shows its destination, and a re-tap of the shown one ' + 'still reports it to the shell', (tester) async { + final selected = []; + await pumpPhone( + tester, + destination: AppDestination.runs, + bodies: { + AppDestination.runs: (_) => const Text('runs body'), + AppDestination.pipelines: (_) => const Text('pipelines body'), + }, + onDestinationSelected: selected.add, + ); + + await tester.tap(find.byKey(const ValueKey('shell.destination.runs'))); + await tester.pumpAndSettle(); + expect(selected, [AppDestination.runs]); + + await tester.tap(find.byKey(const ValueKey('shell.destination.pipelines'))); + await tester.pumpAndSettle(); + expect(selected, [AppDestination.runs, AppDestination.pipelines]); + }); + + testWidgets('without a parent route a tap shows the destination itself', ( + tester, + ) async { + await pumpPhone( + tester, + bodies: { + AppDestination.pipelines: (_) => const Text('pipelines body'), + AppDestination.search: (_) => const Text('search body'), + }, + ); + expect(find.text('pipelines body'), findsOneWidget); + + await tester.tap(find.byKey(const ValueKey('shell.destination.search'))); + await tester.pumpAndSettle(); + expect(find.text('search body'), findsOneWidget); + expect(tester.widget(bar()).selectedIndex, 3); + }); + + testWidgets('the running count sits on Runs and the unread count on Chat in ' + 'the bar', (tester) async { + await pumpPhone( + tester, + destination: AppDestination.chat, + runningRunCount: 3, + bodies: { + AppDestination.chat: (_) => const ShellBadge( + kind: ShellBadgeKind.unread, + count: 2, + child: Text('chat body'), + ), + }, + ); + + final running = find.byKey(const ValueKey('shell.badge.runs.running')); + expect( + find.descendant(of: running, matching: find.text('3')), + findsOneWidget, + ); + expect( + find.descendant( + of: find.byKey(const ValueKey('shell.destination.runs')), + matching: running, + ), + findsOneWidget, + ); + final unread = find.byKey(const ValueKey('shell.badge.chat.unread')); + expect( + find.descendant(of: unread, matching: find.text('2')), + findsOneWidget, + ); + expect( + find.descendant( + of: find.byKey(const ValueKey('shell.destination.chat')), + matching: unread, + ), + findsOneWidget, + ); + }); + + testWidgets('the bar leaves while the keyboard is open and returns after it', ( + tester, + ) async { + await pumpPhone(tester); + expect(bar(), findsOneWidget); + + tester.view.viewInsets = const FakeViewPadding(bottom: 300); + await tester.pump(); + expect(bar(), findsNothing); + + tester.view.resetViewInsets(); + await tester.pumpAndSettle(); + expect(bar(), findsOneWidget); + }); + + testWidgets('a screen that hides navigation takes the bar away and gives it ' + 'back when it closes', (tester) async { + var open = true; + late StateSetter setOuter; + await pumpPhone( + tester, + destination: AppDestination.runs, + bodies: { + AppDestination.runs: (_) => StatefulBuilder( + builder: (context, setState) { + setOuter = setState; + return open + ? const ShellBar( + hideNavigation: true, + child: Text('workspace'), + ) + : const Text('list'); + }, + ), + }, + ); + expect(bar(), findsNothing); + + setOuter(() => open = false); + await tester.pumpAndSettle(); + expect(bar(), findsOneWidget); + }); +} diff --git a/app/test/shell/split_destination_bar_test.dart b/app/test/shell/split_destination_bar_test.dart index c0e7c2e9..6b68d3db 100644 --- a/app/test/shell/split_destination_bar_test.dart +++ b/app/test/shell/split_destination_bar_test.dart @@ -258,24 +258,26 @@ void main() { expect(pill.width, lessThan(640 * 0.6)); }); - testWidgets('390: the bar hugs its tabs at the phone\'s bottom ' - 'right', (tester) async { + testWidgets('390: a phone shows the full-width navigation bar at the bottom, ' + 'with no floating pill', (tester) async { await setSize(tester, const Size(390, 844)); await tester.pumpWidget(shell(split: false)); await tester.pump(); - final pill = destinationPill(tester); - expect(pill.width, lessThanOrEqualTo(390 - 2 * kFloatingBarMargin)); + final bar = find.byType(NavigationBar); + final rect = tester.getRect(bar); + expect(rect.left, 0); + expect(rect.right, 390); + expect(rect.bottom, 844); + expect(find.byType(FloatingDestinationBar), findsNothing); for (final destination in shellTabDestinations) { expect( - find.byKey( - ValueKey( - 'destination-label-${destinationDetails(destination).label}', - ), + find.descendant( + of: bar, + matching: find.text(destinationDetails(destination).label), ), findsOneWidget, ); } - expect(pill.right, closeTo(390 - kFloatingBarMargin, 0.5)); }); for (final width in [600.0, 640.0]) { diff --git a/app/test/widget_test.dart b/app/test/widget_test.dart index dcca1120..a4a508ef 100644 --- a/app/test/widget_test.dart +++ b/app/test/widget_test.dart @@ -24,8 +24,10 @@ void main() { ); expect(find.text('Pipelines'), findsWidgets); expect(find.text('Pipelines — Not implemented'), findsOneWidget); - // One floating tab bar at every width; no rail. - expect(find.byType(FloatingDestinationBar), findsOneWidget); + // This shell reads its width from a MediaQuery of zero size, so it lays + // out as a phone at every test width: the navigation bar, no rail. + expect(find.byType(NavigationBar), findsOneWidget); + expect(find.byType(FloatingDestinationBar), findsNothing); expect(find.byType(NavigationRail), findsNothing); expect(tester.takeException(), isNull); await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));