Skip to content

Commit ffb1239

Browse files
Add tests for focusable_action_detector.0.dart (#157575)
Contributes to flutter/flutter#130459 It adds a test for - `examples/api/lib/widgets/actions/focusable_action_detector.0.dart`
1 parent 29eee6a commit ffb1239

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,5 @@ final Set<String> _knownMissingTests = <String>{
336336
'examples/api/test/widgets/overscroll_indicator/glowing_overscroll_indicator.1_test.dart',
337337
'examples/api/test/widgets/overscroll_indicator/glowing_overscroll_indicator.0_test.dart',
338338
'examples/api/test/widgets/restoration/restoration_mixin.0_test.dart',
339-
'examples/api/test/widgets/actions/focusable_action_detector.0_test.dart',
340339
'examples/api/test/widgets/focus_scope/focus_scope.0_test.dart',
341340
};
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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/services.dart';
7+
import 'package:flutter_api_samples/widgets/actions/focusable_action_detector.0.dart' as example;
8+
import 'package:flutter_test/flutter_test.dart';
9+
10+
void main() {
11+
final Finder redContainerFinder = find.byWidgetPredicate(
12+
(Widget widget) => widget is Container && widget.color == Colors.red,
13+
);
14+
15+
testWidgets('Taps on the "And me" button toggle the red box', (WidgetTester tester) async {
16+
await tester.pumpWidget(
17+
const example.FocusableActionDetectorExampleApp(),
18+
);
19+
20+
expect(find.widgetWithText(AppBar, 'FocusableActionDetector Example'), findsOne);
21+
22+
expect(redContainerFinder, findsNothing);
23+
24+
await tester.tap(find.text('And Me'));
25+
await tester.pump();
26+
27+
expect(redContainerFinder, findsOne);
28+
29+
await tester.tap(find.text('And Me'));
30+
await tester.pump();
31+
32+
expect(redContainerFinder, findsNothing);
33+
});
34+
35+
testWidgets('Hits on the X key when "And me" is focused toggle the red box', (WidgetTester tester) async {
36+
await tester.pumpWidget(
37+
const example.FocusableActionDetectorExampleApp(),
38+
);
39+
40+
expect(find.widgetWithText(AppBar, 'FocusableActionDetector Example'), findsOne);
41+
42+
expect(redContainerFinder, findsNothing);
43+
44+
await tester.sendKeyEvent(LogicalKeyboardKey.tab); // Focuses the "Press Me" button.
45+
await tester.pump();
46+
47+
expect(redContainerFinder, findsNothing);
48+
49+
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
50+
await tester.pump();
51+
52+
expect(redContainerFinder, findsNothing);
53+
54+
await tester.sendKeyEvent(LogicalKeyboardKey.tab); // Focuses the "And Me" button.
55+
await tester.pump();
56+
57+
expect(redContainerFinder, findsNothing);
58+
59+
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
60+
await tester.pump();
61+
62+
expect(redContainerFinder, findsOne);
63+
64+
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
65+
await tester.pump();
66+
67+
expect(redContainerFinder, findsNothing);
68+
});
69+
}

0 commit comments

Comments
 (0)