Skip to content

Commit 7920a52

Browse files
authored
Add tests for callback_shortcuts.0.dart API example. (#147536)
This PR contributes to flutter/flutter#130459 ### Description - Corrects the name for `examples/api/test/widgets/shortcuts/callback_shortcuts.0_test.dart` test file - Update tests for `examples/api/lib/widgets/shortcuts/callback_shortcuts.0.dart`
1 parent 7cf1969 commit 7920a52

File tree

3 files changed

+55
-30
lines changed

3 files changed

+55
-30
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ final Set<String> _knownMissingTests = <String>{
431431
'examples/api/test/widgets/image/image.frame_builder.0_test.dart',
432432
'examples/api/test/widgets/image/image.loading_builder.0_test.dart',
433433
'examples/api/test/widgets/shortcuts/logical_key_set.0_test.dart',
434-
'examples/api/test/widgets/shortcuts/callback_shortcuts.0_test.dart',
435434
'examples/api/test/widgets/page_storage/page_storage.0_test.dart',
436435
'examples/api/test/widgets/scrollbar/raw_scrollbar.1_test.dart',
437436
'examples/api/test/widgets/scrollbar/raw_scrollbar.2_test.dart',

examples/api/test/widgets/shortcuts/callback_shortcuts.0.dart

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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/callback_shortcuts.0.dart'
7+
as example;
8+
import 'package:flutter_test/flutter_test.dart';
9+
10+
void main() {
11+
testWidgets('Verify correct labels are displayed', (WidgetTester tester) async {
12+
await tester.pumpWidget(
13+
const example.CallbackShortcutsApp(),
14+
);
15+
16+
expect(find.text('CallbackShortcuts Sample'), findsOneWidget);
17+
expect(
18+
find.text('Press the up arrow key to add to the counter'),
19+
findsOneWidget,
20+
);
21+
expect(
22+
find.text('Press the down arrow key to subtract from the counter'),
23+
findsOneWidget,
24+
);
25+
expect(find.text('count: 0'), findsOneWidget);
26+
});
27+
28+
testWidgets('Up and down arrow press updates counter', (WidgetTester tester) async {
29+
await tester.pumpWidget(
30+
const example.CallbackShortcutsApp(),
31+
);
32+
33+
int counter = 0;
34+
35+
while (counter < 10) {
36+
expect(find.text('count: $counter'), findsOneWidget);
37+
38+
// Increment the counter.
39+
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
40+
await tester.pump();
41+
42+
counter++;
43+
}
44+
45+
while (counter >= 0) {
46+
expect(find.text('count: $counter'), findsOneWidget);
47+
48+
// Decrement the counter.
49+
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
50+
await tester.pump();
51+
52+
counter--;
53+
}
54+
});
55+
}

0 commit comments

Comments
 (0)