Files
pipelines/app/test/shell/shell_navigation_bar_test.dart
T
alan aabd22b5ad Add phone bottom navigation bar
Replace the narrow-layout floating destination pill with a full-width Material 3 NavigationBar. Reuse the shell destination model and badge wiring while preserving re-selection callbacks and hiding the bar for keyboard/detail states.
2026-11-12 02:51:01 +00:00

197 lines
6.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';
/// 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<void> pumpPhone(
WidgetTester tester, {
AppDestination destination = AppDestination.pipelines,
Map<AppDestination, WidgetBuilder> bodies = const {},
int runningRunCount = 0,
ValueChanged<AppDestination>? 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<NavigationBar>(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<NavigationBar>(bar()).selectedIndex, 1);
await pumpPhone(tester, destination: AppDestination.settings);
expect(tester.widget<NavigationBar>(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 = <AppDestination>[];
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<NavigationBar>(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);
});
}