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
2 changed files with 80 additions and 1 deletions

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