Skip to content

Commit e3350be

Browse files
ksokolovskyipull[bot]
authored andcommitted
Add tests for shortcuts.dart API examples. (flutter#147433)
This PR contributes to flutter#130459 ### Description - Adds tests for `examples/api/lib/widgets/shortcuts/shortcuts.0.dart` - Adds tests for `examples/api/lib/widgets/shortcuts/shortcuts.1.dart`
1 parent 1d75b1c commit e3350be

File tree

3 files changed

+110
-2
lines changed

3 files changed

+110
-2
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +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/shortcuts.0_test.dart',
435-
'examples/api/test/widgets/shortcuts/shortcuts.1_test.dart',
436434
'examples/api/test/widgets/shortcuts/callback_shortcuts.0_test.dart',
437435
'examples/api/test/widgets/page_storage/page_storage.0_test.dart',
438436
'examples/api/test/widgets/scrollbar/raw_scrollbar.1_test.dart',
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/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.ShortcutsExampleApp(),
14+
);
15+
16+
expect(find.text('Shortcuts Sample'), findsOneWidget);
17+
expect(
18+
find.text('Add to the counter by pressing the up arrow key'),
19+
findsOneWidget,
20+
);
21+
expect(
22+
find.text('Subtract from the counter by pressing the down arrow key'),
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.ShortcutsExampleApp(),
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+
}
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/shortcuts.1.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.ShortcutsExampleApp(),
14+
);
15+
16+
expect(find.text('Shortcuts Sample'), findsOneWidget);
17+
expect(
18+
find.text('Add to the counter by pressing the up arrow key'),
19+
findsOneWidget,
20+
);
21+
expect(
22+
find.text('Subtract from the counter by pressing the down arrow key'),
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.ShortcutsExampleApp(),
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 += 2;
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 -= 2;
53+
}
54+
});
55+
}

0 commit comments

Comments
 (0)