diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index 716a6a1583..836be534b3 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -435,7 +435,6 @@ final Set _knownMissingTests = { 'examples/api/test/widgets/shortcuts/shortcuts.0_test.dart', 'examples/api/test/widgets/shortcuts/single_activator.single_activator.0_test.dart', 'examples/api/test/widgets/shortcuts/shortcuts.1_test.dart', - 'examples/api/test/widgets/shortcuts/character_activator.0_test.dart', 'examples/api/test/widgets/shortcuts/callback_shortcuts.0_test.dart', 'examples/api/test/widgets/page_storage/page_storage.0_test.dart', 'examples/api/test/widgets/scrollbar/raw_scrollbar.1_test.dart', diff --git a/examples/api/test/widgets/shortcuts/character_activator.0_test.dart b/examples/api/test/widgets/shortcuts/character_activator.0_test.dart new file mode 100644 index 0000000000..fda1dccc21 --- /dev/null +++ b/examples/api/test/widgets/shortcuts/character_activator.0_test.dart @@ -0,0 +1,53 @@ +// 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/shortcuts/character_activator.0.dart' + as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('CharacterActivatorExampleApp', () { + testWidgets('displays correct labels', (WidgetTester tester) async { + await tester.pumpWidget( + const example.CharacterActivatorExampleApp(), + ); + + expect(find.text('CharacterActivator Sample'), findsOneWidget); + expect(find.text('Press question mark for help'), findsOneWidget); + }); + + testWidgets( + 'shows snack bar on question key pressed', + (WidgetTester tester) async { + await tester.pumpWidget( + const example.CharacterActivatorExampleApp(), + ); + + final Finder snackBarFinder = find.ancestor( + of: find.text('Keep calm and carry on!'), + matching: find.byType(SnackBar), + ); + + expect(snackBarFinder, findsNothing); + + await tester.sendKeyEvent(LogicalKeyboardKey.slash, character: '?'); + + // Advance the SnackBar entrance animation to the end. + await tester.pumpAndSettle(); + + expect(snackBarFinder, findsOneWidget); + + // Advance time by default SnackBar display duration. + await tester.pump(const Duration(milliseconds: 4000)); + + // Advance the SnackBar exit animation to the end. + await tester.pumpAndSettle(); + + expect(snackBarFinder, findsNothing); + }, + ); + }); +} diff --git a/packages/flutter/lib/src/widgets/shortcuts.dart b/packages/flutter/lib/src/widgets/shortcuts.dart index 3ee9541056..fa344fbfc1 100644 --- a/packages/flutter/lib/src/widgets/shortcuts.dart +++ b/packages/flutter/lib/src/widgets/shortcuts.dart @@ -622,7 +622,7 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S /// /// {@tool dartpad} /// In the following example, when a key combination results in a question mark, -/// the counter is increased: +/// the [SnackBar] gets shown: /// /// ** See code in examples/api/lib/widgets/shortcuts/character_activator.0.dart ** /// {@end-tool}