|
| 1 | +// Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:flutter/material.dart'; |
| 6 | +import 'package:flutter_api_samples/widgets/navigator/restorable_route_future.0.dart' as example; |
| 7 | +import 'package:flutter_test/flutter_test.dart'; |
| 8 | + |
| 9 | +void main() { |
| 10 | + testWidgets('It pushes a restorable route and pops it', (WidgetTester tester) async { |
| 11 | + await tester.pumpWidget( |
| 12 | + const example.RestorableRouteFutureExampleApp(), |
| 13 | + ); |
| 14 | + |
| 15 | + expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne); |
| 16 | + expect(find.byType(BackButton), findsNothing); |
| 17 | + |
| 18 | + expect(find.text('Last count: 0'), findsOne); |
| 19 | + |
| 20 | + await tester.tap(find.widgetWithText(ElevatedButton, 'Open Counter')); |
| 21 | + await tester.pumpAndSettle(); |
| 22 | + |
| 23 | + expect(find.widgetWithText(AppBar, 'Awesome Counter'), findsOne); |
| 24 | + expect(find.text('Count: 0'), findsOne); |
| 25 | + |
| 26 | + await tester.tap(find.widgetWithIcon(FloatingActionButton, Icons.add)); |
| 27 | + await tester.pump(); |
| 28 | + |
| 29 | + expect(find.text('Count: 1'), findsOne); |
| 30 | + |
| 31 | + await tester.tap(find.byType(BackButton)); |
| 32 | + await tester.pumpAndSettle(); |
| 33 | + |
| 34 | + expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne); |
| 35 | + expect(find.text('Last count: 1'), findsOne); |
| 36 | + }); |
| 37 | + |
| 38 | + testWidgets('It pushes a restorable route and restores it', (WidgetTester tester) async { |
| 39 | + await tester.pumpWidget( |
| 40 | + const example.RestorableRouteFutureExampleApp(), |
| 41 | + ); |
| 42 | + |
| 43 | + expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne); |
| 44 | + expect(find.byType(BackButton), findsNothing); |
| 45 | + |
| 46 | + expect(find.text('Last count: 0'), findsOne); |
| 47 | + |
| 48 | + await tester.tap(find.widgetWithText(ElevatedButton, 'Open Counter')); |
| 49 | + await tester.pumpAndSettle(); |
| 50 | + |
| 51 | + expect(find.widgetWithText(AppBar, 'Awesome Counter'), findsOne); |
| 52 | + expect(find.text('Count: 0'), findsOne); |
| 53 | + |
| 54 | + await tester.tap(find.widgetWithIcon(FloatingActionButton, Icons.add)); |
| 55 | + await tester.pump(); |
| 56 | + |
| 57 | + expect(find.text('Count: 1'), findsOne); |
| 58 | + |
| 59 | + await tester.restartAndRestore(); |
| 60 | + expect(find.byType(BackButton), findsOne); |
| 61 | + |
| 62 | + expect(find.text('Count: 1'), findsOne); |
| 63 | + |
| 64 | + final TestRestorationData data = await tester.getRestorationData(); |
| 65 | + |
| 66 | + await tester.tap(find.byType(BackButton)); |
| 67 | + await tester.pumpAndSettle(); |
| 68 | + |
| 69 | + expect(find.byType(BackButton), findsNothing); |
| 70 | + |
| 71 | + expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne); |
| 72 | + expect(find.text('Last count: 1'), findsOne); |
| 73 | + |
| 74 | + await tester.restoreFrom(data); |
| 75 | + |
| 76 | + expect(find.widgetWithText(AppBar, 'Awesome Counter'), findsOne); |
| 77 | + expect(find.byType(BackButton), findsOne); |
| 78 | + expect(find.text('Count: 1'), findsOne); |
| 79 | + }); |
| 80 | +} |
0 commit comments