From ab256e5caff0f3ba5c8d0b3375697344e7a1b79f Mon Sep 17 00:00:00 2001 From: Valentin Vignal <32538273+ValentinVignal@users.noreply.github.com> Date: Tue, 29 Oct 2024 01:02:07 +0800 Subject: [PATCH] Add test for `restorable_route_future.0.dart` (#157708) Contributes to https://github.com/flutter/flutter/issues/130459 It adds a test for - `examples/api/lib/widgets/navigator/restorable_route_future.0.dart` --- dev/bots/check_code_samples.dart | 1 - .../restorable_route_future.0_test.dart | 80 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 examples/api/test/widgets/navigator/restorable_route_future.0_test.dart diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index 3d7cb976ab5..4cb6c92ed35 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -310,7 +310,6 @@ class SampleChecker { // See https://github.com/flutter/flutter/issues/130459 final Set _knownMissingTests = { 'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart', - 'examples/api/test/widgets/navigator/restorable_route_future.0_test.dart', 'examples/api/test/widgets/nested_scroll_view/nested_scroll_view_state.0_test.dart', 'examples/api/test/widgets/scroll_position/scroll_metrics_notification.0_test.dart', 'examples/api/test/widgets/media_query/media_query_data.system_gesture_insets.0_test.dart', diff --git a/examples/api/test/widgets/navigator/restorable_route_future.0_test.dart b/examples/api/test/widgets/navigator/restorable_route_future.0_test.dart new file mode 100644 index 00000000000..904d159ee26 --- /dev/null +++ b/examples/api/test/widgets/navigator/restorable_route_future.0_test.dart @@ -0,0 +1,80 @@ +// 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/restorable_route_future.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.RestorableRouteFutureExampleApp(), + ); + + expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne); + expect(find.byType(BackButton), findsNothing); + + expect(find.text('Last count: 0'), findsOne); + + await tester.tap(find.widgetWithText(ElevatedButton, 'Open Counter')); + await tester.pumpAndSettle(); + + expect(find.widgetWithText(AppBar, 'Awesome Counter'), findsOne); + expect(find.text('Count: 0'), findsOne); + + await tester.tap(find.widgetWithIcon(FloatingActionButton, Icons.add)); + await tester.pump(); + + expect(find.text('Count: 1'), findsOne); + + await tester.tap(find.byType(BackButton)); + await tester.pumpAndSettle(); + + expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne); + expect(find.text('Last count: 1'), findsOne); + }); + + testWidgets('It pushes a restorable route and restores it', (WidgetTester tester) async { + await tester.pumpWidget( + const example.RestorableRouteFutureExampleApp(), + ); + + expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne); + expect(find.byType(BackButton), findsNothing); + + expect(find.text('Last count: 0'), findsOne); + + await tester.tap(find.widgetWithText(ElevatedButton, 'Open Counter')); + await tester.pumpAndSettle(); + + expect(find.widgetWithText(AppBar, 'Awesome Counter'), findsOne); + expect(find.text('Count: 0'), findsOne); + + await tester.tap(find.widgetWithIcon(FloatingActionButton, Icons.add)); + await tester.pump(); + + expect(find.text('Count: 1'), findsOne); + + await tester.restartAndRestore(); + expect(find.byType(BackButton), findsOne); + + expect(find.text('Count: 1'), findsOne); + + final TestRestorationData data = await tester.getRestorationData(); + + await tester.tap(find.byType(BackButton)); + await tester.pumpAndSettle(); + + expect(find.byType(BackButton), findsNothing); + + expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne); + expect(find.text('Last count: 1'), findsOne); + + await tester.restoreFrom(data); + + expect(find.widgetWithText(AppBar, 'Awesome Counter'), findsOne); + expect(find.byType(BackButton), findsOne); + expect(find.text('Count: 1'), findsOne); + }); +}