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`
This commit is contained in:
Valentin Vignal 2024-10-29 01:02:07 +08:00 committed by GitHub
parent bac39a3899
commit ab256e5caf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 80 additions and 1 deletions

View File

@ -310,7 +310,6 @@ class SampleChecker {
// See https://github.com/flutter/flutter/issues/130459
final Set<String> _knownMissingTests = <String>{
'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',

View File

@ -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);
});
}