From 2d09837ed0cccd3fbaafc3110dc12c02c717e6d0 Mon Sep 17 00:00:00 2001 From: Valentin Vignal <32538273+ValentinVignal@users.noreply.github.com> Date: Sat, 26 Oct 2024 18:21:26 +0800 Subject: [PATCH] Add test for `navigator_state.restorable_push_and_remove_until.0.dart` (#157595) Contributes to https://github.com/flutter/flutter/issues/130459 It adds a test for - `examples/api/lib/widgets/navigator/navigator_state.restorable_push_and_remove_until.0.dart` --- dev/bots/check_code_samples.dart | 1 - ...te.restorable_push_and_remove_until.0.dart | 8 ++- ...storable_push_and_remove_until.0_test.dart | 52 +++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 examples/api/test/widgets/navigator/navigator_state.restorable_push_and_remove_until.0_test.dart diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index 48beb1e90c5..ce181f68584 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -311,7 +311,6 @@ class SampleChecker { final Set _knownMissingTests = { 'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart', 'examples/api/test/widgets/navigator/navigator_state.restorable_push_replacement.0_test.dart', - 'examples/api/test/widgets/navigator/navigator_state.restorable_push_and_remove_until.0_test.dart', 'examples/api/test/widgets/navigator/navigator.restorable_push_replacement.0_test.dart', 'examples/api/test/widgets/navigator/restorable_route_future.0_test.dart', 'examples/api/test/widgets/navigator/navigator_state.restorable_push.0_test.dart', diff --git a/examples/api/lib/widgets/navigator/navigator_state.restorable_push_and_remove_until.0.dart b/examples/api/lib/widgets/navigator/navigator_state.restorable_push_and_remove_until.0.dart index 0567ad4ac21..b20acd93ff7 100644 --- a/examples/api/lib/widgets/navigator/navigator_state.restorable_push_and_remove_until.0.dart +++ b/examples/api/lib/widgets/navigator/navigator_state.restorable_push_and_remove_until.0.dart @@ -13,8 +13,12 @@ class RestorablePushAndRemoveUntilExampleApp extends StatelessWidget { @override Widget build(BuildContext context) { - return const MaterialApp( - home: RestorablePushAndRemoveUntilExample(), + return const RootRestorationScope( + restorationId: 'app', + child: MaterialApp( + restorationScopeId: 'app', + home: RestorablePushAndRemoveUntilExample(), + ), ); } } diff --git a/examples/api/test/widgets/navigator/navigator_state.restorable_push_and_remove_until.0_test.dart b/examples/api/test/widgets/navigator/navigator_state.restorable_push_and_remove_until.0_test.dart new file mode 100644 index 00000000000..8d91b0a4cca --- /dev/null +++ b/examples/api/test/widgets/navigator/navigator_state.restorable_push_and_remove_until.0_test.dart @@ -0,0 +1,52 @@ +// 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/material.dart'; +import 'package:flutter_api_samples/widgets/navigator/navigator_state.restorable_push_and_remove_until.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('It pushes a restorable route and pops it', (WidgetTester tester) async { + await tester.pumpWidget( + const example.RestorablePushAndRemoveUntilExampleApp(), + ); + + expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne); + expect(find.byType(BackButton), findsNothing); + + await tester.tap(find.widgetWithIcon(FloatingActionButton, Icons.add)); + await tester.pumpAndSettle(); + + await tester.tap(find.byType(BackButton)); + await tester.pumpAndSettle(); + + expect(find.byType(BackButton), findsNothing); + }); + + testWidgets('It pushes a restorable route and restores it', (WidgetTester tester) async { + await tester.pumpWidget( + const example.RestorablePushAndRemoveUntilExampleApp(), + ); + + expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne); + expect(find.byType(BackButton), findsNothing); + + await tester.tap(find.widgetWithIcon(FloatingActionButton, Icons.add)); + await tester.pumpAndSettle(); + + await tester.restartAndRestore(); + + expect(find.byType(BackButton), findsOne); + + final TestRestorationData data = await tester.getRestorationData(); + + await tester.tap(find.byType(BackButton)); + await tester.pumpAndSettle(); + + expect(find.byType(BackButton), findsNothing); + + await tester.restoreFrom(data); + expect(find.byType(BackButton), findsOne); + }); +}