Skip to content

Commit 4e52def

Browse files
Add tests for navigator.restorable_push.0.dart (#157492)
Contributes to flutter/flutter#130459 It adds a test for - `examples/api/lib/widgets/navigator/navigator.restorable_push.0.dart`
1 parent ece457b commit 4e52def

3 files changed

Lines changed: 58 additions & 3 deletions

File tree

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/navigator.restorable_push.0_test.dart',
314313
'examples/api/test/widgets/navigator/navigator_state.restorable_push_replacement.0_test.dart',
315314
'examples/api/test/widgets/navigator/navigator_state.restorable_push_and_remove_until.0_test.dart',
316315
'examples/api/test/widgets/navigator/navigator.restorable_push_replacement.0_test.dart',

examples/api/lib/widgets/navigator/navigator.restorable_push.0.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ class RestorablePushExampleApp extends StatelessWidget {
1313

1414
@override
1515
Widget build(BuildContext context) {
16-
return const MaterialApp(
17-
home: RestorablePushExample(),
16+
return const RootRestorationScope(
17+
restorationId: 'app',
18+
child: MaterialApp(
19+
restorationScopeId: 'app',
20+
home: RestorablePushExample(),
21+
),
1822
);
1923
}
2024
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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/navigator.restorable_push.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.RestorablePushExampleApp(),
13+
);
14+
15+
expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne);
16+
expect(find.byType(BackButton), findsNothing);
17+
18+
await tester.tap(find.widgetWithIcon(FloatingActionButton, Icons.add));
19+
await tester.pumpAndSettle();
20+
21+
await tester.tap(find.byType(BackButton));
22+
await tester.pumpAndSettle();
23+
24+
expect(find.byType(BackButton), findsNothing);
25+
});
26+
27+
testWidgets('It pushes a restorable route and restores it', (WidgetTester tester) async {
28+
await tester.pumpWidget(
29+
const example.RestorablePushExampleApp(),
30+
);
31+
32+
expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne);
33+
expect(find.byType(BackButton), findsNothing);
34+
35+
await tester.tap(find.widgetWithIcon(FloatingActionButton, Icons.add));
36+
await tester.pumpAndSettle();
37+
38+
await tester.restartAndRestore();
39+
40+
expect(find.byType(BackButton), findsOne);
41+
42+
final TestRestorationData data = await tester.getRestorationData();
43+
44+
await tester.tap(find.byType(BackButton));
45+
await tester.pumpAndSettle();
46+
47+
expect(find.byType(BackButton), findsNothing);
48+
49+
await tester.restoreFrom(data);
50+
expect(find.byType(BackButton), findsOne);
51+
});
52+
}

0 commit comments

Comments
 (0)