|
| 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/undo_history/undo_history_controller.0.dart' as example; |
| 7 | +import 'package:flutter_test/flutter_test.dart'; |
| 8 | + |
| 9 | +void main() { |
| 10 | + testWidgets('The undo history controller should undo and redo the history changes', (WidgetTester tester) async { |
| 11 | + await tester.pumpWidget( |
| 12 | + const example.UndoHistoryControllerExampleApp(), |
| 13 | + ); |
| 14 | + |
| 15 | + // Equals to UndoHistoryState._kThrottleDuration. |
| 16 | + const Duration kThrottleDuration = Duration(milliseconds: 500); |
| 17 | + |
| 18 | + expect(find.byType(TextField), findsOne); |
| 19 | + expect(find.widgetWithText(TextButton, 'Undo'), findsOne); |
| 20 | + expect(find.widgetWithText(TextButton, 'Redo'), findsOne); |
| 21 | + |
| 22 | + await tester.enterText(find.byType(TextField), '1st change'); |
| 23 | + await tester.pump(kThrottleDuration); |
| 24 | + expect(find.text('1st change'), findsOne); |
| 25 | + |
| 26 | + await tester.enterText(find.byType(TextField), '2nd change'); |
| 27 | + await tester.pump(kThrottleDuration); |
| 28 | + expect(find.text('2nd change'), findsOne); |
| 29 | + |
| 30 | + await tester.enterText(find.byType(TextField), '3rd change'); |
| 31 | + await tester.pump(kThrottleDuration); |
| 32 | + expect(find.text('3rd change'), findsOne); |
| 33 | + |
| 34 | + await tester.tap(find.text('Undo')); |
| 35 | + await tester.pump(); |
| 36 | + expect(find.text('2nd change'), findsOne); |
| 37 | + |
| 38 | + await tester.tap(find.text('Undo')); |
| 39 | + await tester.pump(); |
| 40 | + expect(find.text('1st change'), findsOne); |
| 41 | + |
| 42 | + await tester.tap(find.text('Redo')); |
| 43 | + await tester.pump(); |
| 44 | + expect(find.text('2nd change'), findsOne); |
| 45 | + |
| 46 | + await tester.tap(find.text('Redo')); |
| 47 | + await tester.pump(); |
| 48 | + expect(find.text('3rd change'), findsOne); |
| 49 | + }); |
| 50 | +} |
0 commit comments