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'; /// Settings is a top-level destination: it draws no Back arrow however it was /// reached (a shell control, a route change, a deep link or the Pipelines /// gear); the system Back still leaves it for the previous destination. void main() { AdaptiveShell shellAt(AppDestination destination) => AdaptiveShell( destination: destination, destinationBodies: { for (final value in AppDestination.values) value: (_) => Text('${value.name} body'), }, ); Future pumpAt( WidgetTester tester, AppDestination destination, { double width = 1000, }) async { tester.view.physicalSize = Size(width, 800); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); await tester.pumpWidget(MaterialApp(home: shellAt(destination))); await tester.pumpAndSettle(); } testWidgets('Settings selected from a rail item has no Back', (tester) async { await pumpAt(tester, AppDestination.pipelines); expect(find.byKey(const ValueKey('shell.back')), findsNothing); await tester.tap(find.byKey(const ValueKey('shell.destination.settings'))); await tester.pumpAndSettle(); expect(find.text('settings body'), findsOneWidget); expect(find.byKey(const ValueKey('shell.back')), findsNothing); }); testWidgets('Settings selected from a phone bar item has no Back', ( tester, ) async { await pumpAt(tester, AppDestination.pipelines, width: 390); await tester.tap(find.byKey(const ValueKey('shell.destination.settings'))); await tester.pumpAndSettle(); expect(find.text('settings body'), findsOneWidget); expect(find.byKey(const ValueKey('shell.back')), findsNothing); }); testWidgets('Settings reached by a route change has no Back arrow; the ' 'system Back returns to Pipelines', (tester) async { await pumpAt(tester, AppDestination.pipelines); // The route moves to Settings (as a gear or a deep link does). await tester.pumpWidget( MaterialApp(home: shellAt(AppDestination.settings)), ); await tester.pumpAndSettle(); expect(find.text('settings body'), findsOneWidget); expect(find.byKey(const ValueKey('shell.back')), findsNothing); await tester.binding.handlePopRoute(); await tester.pumpAndSettle(); expect(find.text('pipelines body'), findsOneWidget); }); testWidgets('a first load on Settings (a deep link) has no Back arrow', ( tester, ) async { await pumpAt(tester, AppDestination.settings); expect(find.text('settings body'), findsOneWidget); expect(find.byKey(const ValueKey('shell.back')), findsNothing); }); }