flutter/examples/api/test/widgets/page/page_can_pop.0_test.dart
chunhtai a36ff80cf6
Refactors page API (#137792)
fixes https://github.com/flutter/flutter/issues/137458

Chagnes:
1. Navigator.pop will always pop page based route
2. add a onDidRemovePage callback to replace onPopPage
3. Page.canPop and Page.onPopInvoked mirrors the PopScope, but in Page class.

migration guide https://github.com/flutter/website/pull/10523
2024-05-13 22:45:51 +00:00

55 lines
1.7 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_api_samples/widgets/page/page_can_pop.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
import '../navigator_utils.dart';
void main() {
testWidgets('Can choose to stay on page', (WidgetTester tester) async {
await tester.pumpWidget(
const example.PageApiExampleApp(),
);
expect(find.text('Home'), findsOneWidget);
await tester.tap(find.text('Go to details'));
await tester.pumpAndSettle();
expect(find.text('Home'), findsNothing);
expect(find.text('Details'), findsOneWidget);
await simulateSystemBack();
await tester.pumpAndSettle();
expect(find.text('Are you sure?'), findsOneWidget);
await tester.tap(find.text('Cancel'));
await tester.pumpAndSettle();
expect(find.text('Home'), findsNothing);
expect(find.text('Details'), findsOneWidget);
});
testWidgets('Can choose to go back', (WidgetTester tester) async {
await tester.pumpWidget(
const example.PageApiExampleApp(),
);
expect(find.text('Home'), findsOneWidget);
await tester.tap(find.text('Go to details'));
await tester.pumpAndSettle();
expect(find.text('Home'), findsNothing);
expect(find.text('Details'), findsOneWidget);
await simulateSystemBack();
await tester.pumpAndSettle();
expect(find.text('Are you sure?'), findsOneWidget);
await tester.tap(find.text('Confirm'));
await tester.pumpAndSettle();
expect(find.text('Details'), findsNothing);
expect(find.text('Home'), findsOneWidget);
});
}