Skip to content

Commit

Permalink
Add tests for single_activator.0.dart API example. (#147426)
Browse files Browse the repository at this point in the history
This PR contributes to #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`
  • Loading branch information
ksokolovskyi committed May 1, 2024
1 parent 2867ac7 commit d33bb8f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
1 change: 0 additions & 1 deletion dev/bots/check_code_samples.dart
Expand Up @@ -433,7 +433,6 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/widgets/image/image.loading_builder.0_test.dart',
'examples/api/test/widgets/shortcuts/logical_key_set.0_test.dart',
'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/callback_shortcuts.0_test.dart',
'examples/api/test/widgets/page_storage/page_storage.0_test.dart',
Expand Down
Expand Up @@ -5,7 +5,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

/// Flutter code sample for [SingleActivator.SingleActivator].
/// Flutter code sample for [SingleActivator].
void main() => runApp(const SingleActivatorExampleApp());

Expand Down
47 changes: 47 additions & 0 deletions examples/api/test/widgets/shortcuts/single_activator.0_test.dart
@@ -0,0 +1,47 @@
// 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/services.dart';
import 'package:flutter_api_samples/widgets/shortcuts/single_activator.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';

void main() {
Future<void> pressControlC(WidgetTester tester) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.control);
await tester.sendKeyDownEvent(LogicalKeyboardKey.keyC);
await tester.sendKeyUpEvent(LogicalKeyboardKey.keyC);
await tester.sendKeyUpEvent(LogicalKeyboardKey.control);
}

group('SingleActivatorExampleApp', () {
testWidgets('displays correct labels', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SingleActivatorExampleApp(),
);

expect(
find.text('Add to the counter by pressing Ctrl+C'),
findsOneWidget,
);
expect(find.text('count: 0'), findsOneWidget);
});

testWidgets(
'updates counter when Ctrl-C combination pressed',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.SingleActivatorExampleApp(),
);

for (int counter = 0; counter < 10; counter++) {
expect(find.text('count: $counter'), findsOneWidget);

await pressControlC(tester);
await tester.pump();
}
},
);
});
}
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/widgets/shortcuts.dart
Expand Up @@ -432,7 +432,7 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S
/// In the following example, the shortcut `Control + C` increases the
/// counter:
///
/// ** See code in examples/api/lib/widgets/shortcuts/single_activator.single_activator.0.dart **
/// ** See code in examples/api/lib/widgets/shortcuts/single_activator.0.dart **
/// {@end-tool}
const SingleActivator(
this.trigger, {
Expand Down

0 comments on commit d33bb8f

Please sign in to comment.