Skip to content

Commit d33bb8f

Browse files
authored
Add tests for single_activator.0.dart API example. (#147426)
This PR contributes to flutter/flutter#130459 ### Description - Fixes name of the `examples/api/lib/widgets/shortcuts/single_activator.single_activator.0.dart` - Adds tests for `examples/api/lib/widgets/shortcuts/single_activator.0.dart`
1 parent 2867ac7 commit d33bb8f

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ final Set<String> _knownMissingTests = <String>{
433433
'examples/api/test/widgets/image/image.loading_builder.0_test.dart',
434434
'examples/api/test/widgets/shortcuts/logical_key_set.0_test.dart',
435435
'examples/api/test/widgets/shortcuts/shortcuts.0_test.dart',
436-
'examples/api/test/widgets/shortcuts/single_activator.single_activator.0_test.dart',
437436
'examples/api/test/widgets/shortcuts/shortcuts.1_test.dart',
438437
'examples/api/test/widgets/shortcuts/callback_shortcuts.0_test.dart',
439438
'examples/api/test/widgets/page_storage/page_storage.0_test.dart',

examples/api/lib/widgets/shortcuts/single_activator.single_activator.0.dart renamed to examples/api/lib/widgets/shortcuts/single_activator.0.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'package:flutter/material.dart';
66
import 'package:flutter/services.dart';
77

8-
/// Flutter code sample for [SingleActivator.SingleActivator].
8+
/// Flutter code sample for [SingleActivator].
99
1010
void main() => runApp(const SingleActivatorExampleApp());
1111

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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/services.dart';
6+
import 'package:flutter_api_samples/widgets/shortcuts/single_activator.0.dart'
7+
as example;
8+
import 'package:flutter_test/flutter_test.dart';
9+
10+
void main() {
11+
Future<void> pressControlC(WidgetTester tester) async {
12+
await tester.sendKeyDownEvent(LogicalKeyboardKey.control);
13+
await tester.sendKeyDownEvent(LogicalKeyboardKey.keyC);
14+
await tester.sendKeyUpEvent(LogicalKeyboardKey.keyC);
15+
await tester.sendKeyUpEvent(LogicalKeyboardKey.control);
16+
}
17+
18+
group('SingleActivatorExampleApp', () {
19+
testWidgets('displays correct labels', (WidgetTester tester) async {
20+
await tester.pumpWidget(
21+
const example.SingleActivatorExampleApp(),
22+
);
23+
24+
expect(
25+
find.text('Add to the counter by pressing Ctrl+C'),
26+
findsOneWidget,
27+
);
28+
expect(find.text('count: 0'), findsOneWidget);
29+
});
30+
31+
testWidgets(
32+
'updates counter when Ctrl-C combination pressed',
33+
(WidgetTester tester) async {
34+
await tester.pumpWidget(
35+
const example.SingleActivatorExampleApp(),
36+
);
37+
38+
for (int counter = 0; counter < 10; counter++) {
39+
expect(find.text('count: $counter'), findsOneWidget);
40+
41+
await pressControlC(tester);
42+
await tester.pump();
43+
}
44+
},
45+
);
46+
});
47+
}

packages/flutter/lib/src/widgets/shortcuts.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S
432432
/// In the following example, the shortcut `Control + C` increases the
433433
/// counter:
434434
///
435-
/// ** See code in examples/api/lib/widgets/shortcuts/single_activator.single_activator.0.dart **
435+
/// ** See code in examples/api/lib/widgets/shortcuts/single_activator.0.dart **
436436
/// {@end-tool}
437437
const SingleActivator(
438438
this.trigger, {

0 commit comments

Comments
 (0)