Skip to content

Commit af522e2

Browse files
Add tests for action_listener.0.dart (flutter#150606)
Contributes to flutter#130459 It adds a test for - `examples/api/lib/widgets/actions/action_listener.0.dart`
1 parent ad6166a commit af522e2

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
@@ -378,7 +378,6 @@ final Set<String> _knownMissingTests = <String>{
378378
'examples/api/test/widgets/single_child_scroll_view/single_child_scroll_view.1_test.dart',
379379
'examples/api/test/widgets/single_child_scroll_view/single_child_scroll_view.0_test.dart',
380380
'examples/api/test/widgets/restoration/restoration_mixin.0_test.dart',
381-
'examples/api/test/widgets/actions/action_listener.0_test.dart',
382381
'examples/api/test/widgets/actions/focusable_action_detector.0_test.dart',
383382
'examples/api/test/widgets/focus_scope/focus_scope.0_test.dart',
384383
'examples/api/test/widgets/scroll_view/custom_scroll_view.1_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/foundation.dart';
6+
import 'package:flutter/material.dart';
7+
import 'package:flutter_api_samples/widgets/actions/action_listener.0.dart' as example;
8+
import 'package:flutter_test/flutter_test.dart';
9+
10+
void main() {
11+
testWidgets('ActionListener can be enabled, triggered, and disabled', (WidgetTester tester) async {
12+
final List<String?> log = <String?>[];
13+
14+
final DebugPrintCallback originalDebugPrint = debugPrint;
15+
debugPrint = (String? message, {int? wrapWidth}) {
16+
log.add(message);
17+
};
18+
try {
19+
await tester.pumpWidget(
20+
const example.ActionListenerExampleApp(),
21+
);
22+
23+
expect(find.widgetWithText(AppBar, 'ActionListener Sample'), findsOne);
24+
expect(find.widgetWithText(OutlinedButton, 'Enable'), findsOne);
25+
26+
await tester.tap(find.byType(OutlinedButton));
27+
await tester.pump();
28+
29+
expect(find.widgetWithText(OutlinedButton, 'Disable'), findsOne);
30+
expect(find.widgetWithText(ElevatedButton, 'Call Action Listener'), findsOne);
31+
expect(log, const <String?>['Action Listener was added']);
32+
33+
await tester.tap(find.text('Call Action Listener'));
34+
await tester.pumpAndSettle();
35+
36+
expect(find.widgetWithText(SnackBar, 'Action Listener Called'), findsOne);
37+
38+
await tester.tap(find.text('Disable'));
39+
await tester.pump();
40+
41+
expect(find.widgetWithText(OutlinedButton, 'Enable'), findsOne);
42+
expect(
43+
log,
44+
const <String?>['Action Listener was added', 'Action Listener was removed'],
45+
);
46+
} finally {
47+
debugPrint = originalDebugPrint;
48+
}
49+
});
50+
}

0 commit comments

Comments
 (0)