forked from flutter/packages
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for restorable_value.0.dart API example. (#148676)
This PR contributes to flutter/flutter#130459 ### Description - Updates `examples/api/lib/widgets/restoration_properties/restorable_value.0.dart` to meet the latest API examples structure - Adds tests for `examples/api/lib/widgets/restoration_properties/restorable_value.0.dart`
- Loading branch information
1 parent
fe0932f
commit 3beeed4
Showing
4 changed files
with
69 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
examples/api/test/widgets/restoration_properties/restorable_value.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// 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/restoration_properties/restorable_value.0.dart' | ||
as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Increments answer on OutlinedButton tap', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.RestorableValueExampleApp(), | ||
); | ||
|
||
// Verify that the initial answer value in the example equals 42. | ||
expect(find.text('42'), findsOneWidget); | ||
|
||
// Tap the button to increment the answer value by 1. | ||
await tester.tap(find.byType(OutlinedButton)); | ||
await tester.pump(); | ||
|
||
// Verify that the answer value increased by 1. | ||
expect(find.text('43'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('Restores answer value after restart', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const MaterialApp( | ||
home: RootRestorationScope( | ||
restorationId: 'root', | ||
child: example.RestorableValueExample(restorationId: 'child'), | ||
), | ||
), | ||
); | ||
|
||
// The initial answer value in the example equals 42. | ||
expect(find.text('42'), findsOneWidget); | ||
|
||
// Tap the button 10 times to change the answer value. | ||
for (int i = 0; i < 10; i++) { | ||
await tester.tap(find.byType(OutlinedButton)); | ||
await tester.pump(); | ||
} | ||
|
||
// Verify that the answer value increased by 10. | ||
expect(find.text('52'), findsOneWidget); | ||
|
||
// Simulate restoring the state of the widget tree after the application | ||
// is restarted. | ||
await tester.restartAndRestore(); | ||
|
||
// Verify that the answer value is restored correctly. | ||
expect(find.text('52'), findsOneWidget); | ||
}); | ||
} |