Skip to content

Commit 357bd65

Browse files
Add test for undo_history_controller.0.dart (flutter#148205)
Contributes to flutter#130459 It adds test for `examples/api/test/widgets/undo_history/undo_history_controller.0_test.dart`.
1 parent 185a4c6 commit 357bd65

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ final Set<String> _knownMissingTests = <String>{
420420
'examples/api/test/widgets/notification_listener/notification.0_test.dart',
421421
'examples/api/test/widgets/editable_text/text_editing_controller.0_test.dart',
422422
'examples/api/test/widgets/editable_text/editable_text.on_changed.0_test.dart',
423-
'examples/api/test/widgets/undo_history/undo_history_controller.0_test.dart',
424423
'examples/api/test/widgets/overscroll_indicator/glowing_overscroll_indicator.1_test.dart',
425424
'examples/api/test/widgets/overscroll_indicator/glowing_overscroll_indicator.0_test.dart',
426425
'examples/api/test/widgets/tween_animation_builder/tween_animation_builder.0_test.dart',
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)