Add tests for character_activator.0.dart API example. (#147384)
This PR contributes to https://github.com/flutter/flutter/issues/130459 ### Description - Adds `examples/api/lib/widgets/shortcuts/character_activator.0.dart` test - Fixes the description of the `examples/api/lib/widgets/shortcuts/character_activator.0.dart` example
This commit is contained in:
committed by
GitHub
parent
3488d9af80
commit
9230b0e820
@@ -435,7 +435,6 @@ final Set<String> _knownMissingTests = <String>{
|
||||
'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',
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user