Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for single_activator.0.dart API example. #147426

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion dev/bots/check_code_samples.dart
Expand Up @@ -434,7 +434,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/character_activator.0_test.dart',
'examples/api/test/widgets/shortcuts/callback_shortcuts.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