fix(app): remove every app-level system Back override
This commit is contained in:
@@ -1,126 +1,71 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app_route.dart';
|
||||
import 'package:pipelines_app/application/app_router.dart';
|
||||
|
||||
AppRouterDelegate delegate(AppRoute initial, {void Function()? onChat}) =>
|
||||
AppRouterDelegate(
|
||||
builder: (context, route) => const SizedBox.shrink(),
|
||||
onPopToRuns: () {},
|
||||
onPopToChat: onChat ?? () {},
|
||||
cupertino: false,
|
||||
initial: initial,
|
||||
);
|
||||
AppRouterDelegate delegate(AppRoute initial) => AppRouterDelegate(
|
||||
builder: (context, route) => const SizedBox.shrink(),
|
||||
cupertino: false,
|
||||
initial: initial,
|
||||
);
|
||||
|
||||
Future<AppRouterDelegate> pumpRouter(
|
||||
WidgetTester tester,
|
||||
AppRoute initial,
|
||||
) async {
|
||||
final router = AppRouterDelegate(
|
||||
builder: (_, route) => Scaffold(body: Text(route.path)),
|
||||
templatesBuilder: (_) => const Scaffold(body: Text('Templates page')),
|
||||
cupertino: false,
|
||||
initial: initial,
|
||||
);
|
||||
addTearDown(router.dispose);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse(initial.path)),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp.router(
|
||||
routerDelegate: router,
|
||||
routeInformationParser: const AppRouteParser(),
|
||||
routeInformationProvider: provider,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return router;
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
test(
|
||||
'router does not intercept chat Back or invoke the legacy override',
|
||||
() async {
|
||||
var left = 0;
|
||||
final router = delegate(AppRoute.chatSession('s1'), onChat: () => left++);
|
||||
addTearDown(router.dispose);
|
||||
|
||||
// With no Navigator mounted there is nothing to pop. The router must not
|
||||
// substitute a chat-specific callback or arm main-screen double-back.
|
||||
expect(await router.popRoute(), isFalse);
|
||||
expect(await router.popRoute(), isFalse);
|
||||
expect(left, 0);
|
||||
expect(router.route, AppRoute.chatSession('s1'));
|
||||
},
|
||||
);
|
||||
|
||||
test('system Back steps up one level at a time', () async {
|
||||
var runs = 0;
|
||||
final router = AppRouterDelegate(
|
||||
builder: (context, route) => const SizedBox.shrink(),
|
||||
onPopToRuns: () => runs++,
|
||||
onPopToChat: () {},
|
||||
cupertino: false,
|
||||
initial: AppRoute.run.stage(77, 'plan', visit: 0),
|
||||
);
|
||||
addTearDown(router.dispose);
|
||||
|
||||
// A stage returns to its run, then the run to the Runs list.
|
||||
expect(await router.popRoute(), isTrue);
|
||||
expect(router.route, AppRoute.run(77));
|
||||
expect(await router.popRoute(), isTrue);
|
||||
expect(runs, 1);
|
||||
|
||||
// A pipeline stage returns to its pipeline, then to the list, and the
|
||||
// list arms exit, then leaves Back to the platform.
|
||||
router.goTo(AppRoute.pipelineStage(4, 'plan', version: 2));
|
||||
expect(await router.popRoute(), isTrue);
|
||||
expect(router.route, AppRoute.pipeline(4, version: 2));
|
||||
expect(await router.popRoute(), isTrue);
|
||||
expect(router.route, AppRoute.pipelines);
|
||||
expect(await router.popRoute(), isTrue);
|
||||
expect(await router.popRoute(), isFalse);
|
||||
test('with nothing pushed the router leaves Back to the platform', () async {
|
||||
for (final route in [
|
||||
AppRoute.pipelines,
|
||||
AppRoute.chat,
|
||||
AppRoute.chatSession('s1'),
|
||||
AppRoute.run.stage(77, 'plan', visit: 0),
|
||||
AppRoute.pipelineStage(4, 'plan', version: 2),
|
||||
]) {
|
||||
final router = delegate(route);
|
||||
expect(await router.popRoute(), isFalse, reason: route.path);
|
||||
expect(router.route, route, reason: route.path);
|
||||
router.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
test(
|
||||
'Android list Back arms exit before handing it to the platform',
|
||||
() async {
|
||||
final router = delegate(AppRoute.chat);
|
||||
addTearDown(router.dispose);
|
||||
|
||||
expect(await router.popRoute(), isTrue);
|
||||
expect(await router.popRoute(), isFalse);
|
||||
},
|
||||
);
|
||||
|
||||
for (final root in [
|
||||
AppRoute.pipelines,
|
||||
AppRoute.runs,
|
||||
AppRoute.runsForPipeline(3),
|
||||
AppRoute.run(7),
|
||||
AppRoute.chat,
|
||||
AppRoute.settings,
|
||||
AppRoute.search,
|
||||
]) {
|
||||
testWidgets('${root.path} root exit expires and navigation clears it', (
|
||||
tester,
|
||||
) async {
|
||||
final router = AppRouterDelegate(
|
||||
builder: (_, route) => Scaffold(body: Text(route.path)),
|
||||
onPopToRuns: () {},
|
||||
onPopToChat: () {},
|
||||
cupertino: false,
|
||||
initial: root,
|
||||
);
|
||||
addTearDown(router.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp.router(
|
||||
routerDelegate: router,
|
||||
routeInformationParser: const AppRouteParser(),
|
||||
routeInformationProvider: PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(
|
||||
uri: Uri.parse(root.path),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(await router.popRoute(), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Press back again to close'), findsOneWidget);
|
||||
expect(await router.popRoute(), isFalse);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
await tester.pumpAndSettle();
|
||||
expect(await router.popRoute(), isTrue);
|
||||
await tester.pump();
|
||||
|
||||
router.goTo(AppRoute.pipeline(7));
|
||||
await tester.pumpAndSettle();
|
||||
expect(await router.popRoute(), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(router.route, AppRoute.pipelines);
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
expect(await router.popRoute(), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Press back again to close'), findsOneWidget);
|
||||
// Imperative dialogs also clear an already armed root exit.
|
||||
testWidgets('${root.path}: Back pops a dialog, then belongs to the '
|
||||
'platform with no exit prompt or step-up', (tester) async {
|
||||
final router = await pumpRouter(tester, root);
|
||||
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
|
||||
expect(
|
||||
find.byWidgetPredicate((widget) => widget is PopScope),
|
||||
findsNothing,
|
||||
);
|
||||
showDialog<void>(
|
||||
context: navigator.overlay!.context,
|
||||
builder: (_) => const AlertDialog(title: Text('Root dialog')),
|
||||
@@ -129,42 +74,28 @@ void main() {
|
||||
expect(await router.popRoute(), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Root dialog'), findsNothing);
|
||||
expect(await router.popRoute(), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(await router.popRoute(), isFalse);
|
||||
// Switching tabs or applying a platform/browser route re-arms exit too.
|
||||
router.goTo(AppRoute.settings);
|
||||
await tester.pumpAndSettle();
|
||||
expect(await router.popRoute(), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
await router.setNewRoutePath(AppRoute.chat);
|
||||
await tester.pumpAndSettle();
|
||||
expect(await router.popRoute(), isTrue);
|
||||
await tester.pump(const Duration(seconds: 3));
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
expect(router.route, root);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
}
|
||||
|
||||
test('iOS root Back is not intercepted', () async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
||||
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
||||
final router = delegate(AppRoute.pipelines);
|
||||
addTearDown(router.dispose);
|
||||
expect(await router.popRoute(), isFalse);
|
||||
expect(await router.popRoute(), isFalse);
|
||||
});
|
||||
|
||||
test('Templates opens above Settings and Back restores the route', () async {
|
||||
final router = delegate(AppRoute.settings);
|
||||
addTearDown(router.dispose);
|
||||
|
||||
testWidgets('Templates is a page above Settings and Back pops it', (
|
||||
tester,
|
||||
) async {
|
||||
final router = await pumpRouter(tester, AppRoute.settings);
|
||||
router.openTemplates();
|
||||
expect(router.route, AppRoute.templates);
|
||||
expect(router.templatesOpen, isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Templates page'), findsOneWidget);
|
||||
|
||||
expect(await router.popRoute(), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(router.route, AppRoute.settings);
|
||||
expect(router.templatesOpen, isFalse);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
test('a /templates boot link still closes back to Settings', () async {
|
||||
|
||||
@@ -73,8 +73,6 @@ void main() {
|
||||
router = AppRouterDelegate(
|
||||
initial: AppRoute.chat,
|
||||
cupertino: false,
|
||||
onPopToChat: () => fail('Chat Back must not use the router override'),
|
||||
onPopToRuns: () {},
|
||||
builder: (_, route) => AdaptiveShell(
|
||||
destination: AppDestination.chat,
|
||||
destinationBodies: {
|
||||
@@ -155,14 +153,11 @@ void main() {
|
||||
expect(router.route, AppRoute.chat);
|
||||
expect(find.text('Scroll and return'), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('chat-thread-s')), findsNothing);
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
expect(exits, isEmpty);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Press back again to close'), findsOneWidget);
|
||||
expect(exits, isEmpty);
|
||||
// At the main screen Back is the platform's: no exit prompt.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pump();
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
expect(exits, ['SystemNavigator.pop']);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
disposeRouter();
|
||||
|
||||
@@ -28,7 +28,7 @@ class _Gateway extends FakeChatGateway {
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('an open chat beside the list takes the root double-back', (
|
||||
testWidgets('an open chat beside the list leaves Back to the platform', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
@@ -55,8 +55,6 @@ void main() {
|
||||
router = AppRouterDelegate(
|
||||
initial: AppRoute.chat,
|
||||
cupertino: false,
|
||||
onPopToChat: () => fail('Chat Back must not use the router override'),
|
||||
onPopToRuns: () {},
|
||||
builder: (_, route) => AdaptiveShell(
|
||||
destination: AppDestination.chat,
|
||||
destinationBodies: {
|
||||
@@ -87,15 +85,11 @@ void main() {
|
||||
expect(router.route, AppRoute.chatSession('s'));
|
||||
expect(find.byKey(const ValueKey('chat-thread-s')), findsOneWidget);
|
||||
|
||||
// First Back arms the exit instead of closing the app at once.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Press back again to close'), findsOneWidget);
|
||||
expect(exits, isEmpty);
|
||||
expect(find.byKey(const ValueKey('chat-thread-s')), findsOneWidget);
|
||||
|
||||
// No page covers the shell and the app adds no Back behavior: the
|
||||
// platform's own Back applies at once, with no exit prompt.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pump();
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
expect(exits, ['SystemNavigator.pop']);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
router.dispose();
|
||||
|
||||
@@ -35,7 +35,7 @@ void main() {
|
||||
for (final predictive in [false, true]) {
|
||||
for (final destination in ['pipelines', 'runs', 'chat']) {
|
||||
testWidgets(
|
||||
'$destination: ${predictive ? 'gesture' : 'button'} Back pops dialog, detail, then double-back exits',
|
||||
'$destination: ${predictive ? 'gesture' : 'button'} Back pops dialog, detail, then leaves to the platform',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
@@ -137,22 +137,11 @@ void main() {
|
||||
expect(navigator.canPop(), isFalse);
|
||||
expect(exits, isEmpty);
|
||||
|
||||
// A detail pop never arms root exit. The first root Back only hints.
|
||||
if (predictive) {
|
||||
await backGesture(tester, 'startBackGesture');
|
||||
await backGesture(tester, 'cancelBackGesture');
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
await backGesture(tester, 'startBackGesture');
|
||||
await backGesture(tester, 'commitBackGesture');
|
||||
} else {
|
||||
await tester.binding.handlePopRoute();
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
expect(exits, isEmpty);
|
||||
expect(find.text('Press back again to close'), findsOneWidget);
|
||||
// At the main screen Back is the platform's own: one press leaves,
|
||||
// with no exit prompt.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
expect(exits, ['SystemNavigator.pop']);
|
||||
expect(find.text('Close Pipelines?'), findsNothing);
|
||||
final router =
|
||||
|
||||
@@ -171,7 +171,7 @@ void main() {
|
||||
expect(find.text('Deep-linked run'), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('Android Back on a wide screen steps out of a run, not the app', (
|
||||
testWidgets('Android Back on a wide screen run is left to the platform', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1000, 800);
|
||||
@@ -208,22 +208,13 @@ void main() {
|
||||
await replyDetail(tester, channel, 1);
|
||||
expect(provider.value.uri.path, '/runs/1');
|
||||
|
||||
// The system Back button or gesture.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/runs');
|
||||
expect(exits, isEmpty);
|
||||
|
||||
// From the list, the first Back hints; the second is left to Android.
|
||||
// A wide run sits in its tab, not on a pushed page, and the app adds no
|
||||
// Back behavior: the system Back is the platform's at once.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(exits, isEmpty);
|
||||
expect(find.text('Press back again to close'), findsOneWidget);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Close Pipelines?'), findsNothing);
|
||||
expect(find.text('Press back again to close'), findsNothing);
|
||||
expect(exits, ['SystemNavigator.pop']);
|
||||
expect(provider.value.uri.path, '/runs');
|
||||
expect(provider.value.uri.path, '/runs/1');
|
||||
});
|
||||
|
||||
testWidgets('tabs and run selection update the route; browser Back pops it', (
|
||||
|
||||
@@ -829,29 +829,24 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'openSearch keeps the previous route and system Back restores it',
|
||||
() async {
|
||||
final router = AppRouterDelegate(
|
||||
builder: (context, route) => const SizedBox.shrink(),
|
||||
onPopToRuns: () {},
|
||||
onPopToChat: () {},
|
||||
cupertino: false,
|
||||
initial: AppRoute.run(3),
|
||||
);
|
||||
addTearDown(router.dispose);
|
||||
test('openSearch keeps the previous route and closing restores it', () async {
|
||||
final router = AppRouterDelegate(
|
||||
builder: (context, route) => const SizedBox.shrink(),
|
||||
cupertino: false,
|
||||
initial: AppRoute.run(3),
|
||||
);
|
||||
addTearDown(router.dispose);
|
||||
|
||||
router.openSearch();
|
||||
expect(router.route, AppRoute.search);
|
||||
expect(router.searchOpen, isTrue);
|
||||
// Without a page builder Search is the shell's own tab.
|
||||
expect(router.shellRoute, AppRoute.search);
|
||||
router.openSearch();
|
||||
expect(router.route, AppRoute.search);
|
||||
expect(router.searchOpen, isTrue);
|
||||
// Without a page builder Search is the shell's own tab.
|
||||
expect(router.shellRoute, AppRoute.search);
|
||||
|
||||
expect(await router.popRoute(), isTrue);
|
||||
expect(router.route, AppRoute.run(3));
|
||||
expect(router.searchOpen, isFalse);
|
||||
},
|
||||
);
|
||||
router.closeSearch();
|
||||
expect(router.route, AppRoute.run(3));
|
||||
expect(router.searchOpen, isFalse);
|
||||
});
|
||||
|
||||
test('the /search route is total and survives the parser', () {
|
||||
expect(AppRoute.parse('/search'), AppRoute.search);
|
||||
|
||||
Reference in New Issue
Block a user