77a88d09d3
Show Back only when Settings is reached through a pushed route, and remove duplicate Settings controls where the shell already provides navigation. Update focused widget coverage and document the destination behavior.
91 lines
3.5 KiB
Dart
91 lines
3.5 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';
|
|
|
|
/// Settings' Back: a destination reached from a shell control has none; a page
|
|
/// pushed by a route (a first load or a route change, such as a deep link or
|
|
/// the Pipelines gear) has one that returns to Pipelines.
|
|
void main() {
|
|
AdaptiveShell shellAt(AppDestination destination) => AdaptiveShell(
|
|
destination: destination,
|
|
destinationBodies: {
|
|
for (final value in AppDestination.values)
|
|
value: (_) => Text('${value.name} body'),
|
|
},
|
|
);
|
|
|
|
Future<void> 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 pushed by a route change has Back, which 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')), findsOneWidget);
|
|
|
|
await tester.tap(find.byKey(const ValueKey('shell.back')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('pipelines body'), findsOneWidget);
|
|
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
|
|
});
|
|
|
|
testWidgets('a first load on Settings (a deep link) has Back', (
|
|
tester,
|
|
) async {
|
|
await pumpAt(tester, AppDestination.settings);
|
|
expect(find.text('settings body'), findsOneWidget);
|
|
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('a nav selection after a pushed Settings clears its Back', (
|
|
tester,
|
|
) async {
|
|
await pumpAt(tester, AppDestination.settings);
|
|
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('chat body'), findsOneWidget);
|
|
|
|
// Settings opened again from its rail item is a destination, not a page.
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
|
|
});
|
|
}
|