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

This PR contributes to https://github.com/flutter/flutter/issues/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`
This commit is contained in:
Kostia Sokolovskyi 2024-05-01 16:52:57 +02:00 committed by GitHub
parent 2867ac7885
commit d33bb8fa5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 49 additions and 3 deletions

View File

@ -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',

View File

@ -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());

View File

@ -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();
}
},
);
});
}

View File

@ -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, {