Skip to content

Commit ab256e5

Browse files
Add test for restorable_route_future.0.dart (#157708)
Contributes to flutter/flutter#130459 It adds a test for - `examples/api/lib/widgets/navigator/restorable_route_future.0.dart`
1 parent bac39a3 commit ab256e5

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ class SampleChecker {
310310
// See https://github.com/flutter/flutter/issues/130459
311311
final Set<String> _knownMissingTests = <String>{
312312
'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart',
313-
'examples/api/test/widgets/navigator/restorable_route_future.0_test.dart',
314313
'examples/api/test/widgets/nested_scroll_view/nested_scroll_view_state.0_test.dart',
315314
'examples/api/test/widgets/scroll_position/scroll_metrics_notification.0_test.dart',
316315
'examples/api/test/widgets/media_query/media_query_data.system_gesture_insets.0_test.dart',
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_api_samples/widgets/navigator/restorable_route_future.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('It pushes a restorable route and pops it', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.RestorableRouteFutureExampleApp(),
13+
);
14+
15+
expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne);
16+
expect(find.byType(BackButton), findsNothing);
17+
18+
expect(find.text('Last count: 0'), findsOne);
19+
20+
await tester.tap(find.widgetWithText(ElevatedButton, 'Open Counter'));
21+
await tester.pumpAndSettle();
22+
23+
expect(find.widgetWithText(AppBar, 'Awesome Counter'), findsOne);
24+
expect(find.text('Count: 0'), findsOne);
25+
26+
await tester.tap(find.widgetWithIcon(FloatingActionButton, Icons.add));
27+
await tester.pump();
28+
29+
expect(find.text('Count: 1'), findsOne);
30+
31+
await tester.tap(find.byType(BackButton));
32+
await tester.pumpAndSettle();
33+
34+
expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne);
35+
expect(find.text('Last count: 1'), findsOne);
36+
});
37+
38+
testWidgets('It pushes a restorable route and restores it', (WidgetTester tester) async {
39+
await tester.pumpWidget(
40+
const example.RestorableRouteFutureExampleApp(),
41+
);
42+
43+
expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne);
44+
expect(find.byType(BackButton), findsNothing);
45+
46+
expect(find.text('Last count: 0'), findsOne);
47+
48+
await tester.tap(find.widgetWithText(ElevatedButton, 'Open Counter'));
49+
await tester.pumpAndSettle();
50+
51+
expect(find.widgetWithText(AppBar, 'Awesome Counter'), findsOne);
52+
expect(find.text('Count: 0'), findsOne);
53+
54+
await tester.tap(find.widgetWithIcon(FloatingActionButton, Icons.add));
55+
await tester.pump();
56+
57+
expect(find.text('Count: 1'), findsOne);
58+
59+
await tester.restartAndRestore();
60+
expect(find.byType(BackButton), findsOne);
61+
62+
expect(find.text('Count: 1'), findsOne);
63+
64+
final TestRestorationData data = await tester.getRestorationData();
65+
66+
await tester.tap(find.byType(BackButton));
67+
await tester.pumpAndSettle();
68+
69+
expect(find.byType(BackButton), findsNothing);
70+
71+
expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne);
72+
expect(find.text('Last count: 1'), findsOne);
73+
74+
await tester.restoreFrom(data);
75+
76+
expect(find.widgetWithText(AppBar, 'Awesome Counter'), findsOne);
77+
expect(find.byType(BackButton), findsOne);
78+
expect(find.text('Count: 1'), findsOne);
79+
});
80+
}

0 commit comments

Comments
 (0)