Add tests for navigator_state.restorable_push.0.dart (#157667)

Contributes to https://github.com/flutter/flutter/issues/130459

It adds a test for
- `examples/api/lib/widgets/navigator/navigator_state.restorable_push.0.dart`
This commit is contained in:
Valentin Vignal
2024-10-28 16:10:19 +08:00
committed by GitHub
parent 3abd2f3131
commit 8f5d032d78
3 changed files with 58 additions and 3 deletions

View File

@@ -13,8 +13,12 @@ class RestorablePushExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: RestorablePushExample(),
return const RootRestorationScope(
restorationId: 'app',
child: MaterialApp(
restorationScopeId: 'app',
home: RestorablePushExample(),
),
);
}
}

View File

@@ -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.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.RestorablePushExampleApp(),
);
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.RestorablePushExampleApp(),
);
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);
});
}