diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index 847877abf3..708e8d1f8e 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -336,6 +336,5 @@ final Set _knownMissingTests = { 'examples/api/test/widgets/overscroll_indicator/glowing_overscroll_indicator.1_test.dart', 'examples/api/test/widgets/overscroll_indicator/glowing_overscroll_indicator.0_test.dart', 'examples/api/test/widgets/restoration/restoration_mixin.0_test.dart', - 'examples/api/test/widgets/actions/focusable_action_detector.0_test.dart', 'examples/api/test/widgets/focus_scope/focus_scope.0_test.dart', }; diff --git a/examples/api/test/widgets/actions/focusable_action_detector.0_test.dart b/examples/api/test/widgets/actions/focusable_action_detector.0_test.dart new file mode 100644 index 0000000000..df4f7494f5 --- /dev/null +++ b/examples/api/test/widgets/actions/focusable_action_detector.0_test.dart @@ -0,0 +1,69 @@ +// 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/services.dart'; +import 'package:flutter_api_samples/widgets/actions/focusable_action_detector.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + final Finder redContainerFinder = find.byWidgetPredicate( + (Widget widget) => widget is Container && widget.color == Colors.red, + ); + + testWidgets('Taps on the "And me" button toggle the red box', (WidgetTester tester) async { + await tester.pumpWidget( + const example.FocusableActionDetectorExampleApp(), + ); + + expect(find.widgetWithText(AppBar, 'FocusableActionDetector Example'), findsOne); + + expect(redContainerFinder, findsNothing); + + await tester.tap(find.text('And Me')); + await tester.pump(); + + expect(redContainerFinder, findsOne); + + await tester.tap(find.text('And Me')); + await tester.pump(); + + expect(redContainerFinder, findsNothing); + }); + + testWidgets('Hits on the X key when "And me" is focused toggle the red box', (WidgetTester tester) async { + await tester.pumpWidget( + const example.FocusableActionDetectorExampleApp(), + ); + + expect(find.widgetWithText(AppBar, 'FocusableActionDetector Example'), findsOne); + + expect(redContainerFinder, findsNothing); + + await tester.sendKeyEvent(LogicalKeyboardKey.tab); // Focuses the "Press Me" button. + await tester.pump(); + + expect(redContainerFinder, findsNothing); + + await tester.sendKeyEvent(LogicalKeyboardKey.keyX); + await tester.pump(); + + expect(redContainerFinder, findsNothing); + + await tester.sendKeyEvent(LogicalKeyboardKey.tab); // Focuses the "And Me" button. + await tester.pump(); + + expect(redContainerFinder, findsNothing); + + await tester.sendKeyEvent(LogicalKeyboardKey.keyX); + await tester.pump(); + + expect(redContainerFinder, findsOne); + + await tester.sendKeyEvent(LogicalKeyboardKey.keyX); + await tester.pump(); + + expect(redContainerFinder, findsNothing); + }); +}