Skip to content

Commit dcc5361

Browse files
Add test for dropdown_menu.1.dart (#149547)
Contributes to flutter/flutter#130459 It adds a test for - `examples/api/lib/material/dropdown_menu/dropdown_menu.1.dart`
1 parent ad56b54 commit dcc5361

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

dev/bots/check_code_samples.dart

-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ final Set<String> _knownMissingTests = <String>{
337337
'examples/api/test/material/input_decorator/input_decoration.material_state.1_test.dart',
338338
'examples/api/test/material/text_form_field/text_form_field.1_test.dart',
339339
'examples/api/test/material/scrollbar/scrollbar.1_test.dart',
340-
'examples/api/test/material/dropdown_menu/dropdown_menu.1_test.dart',
341340
'examples/api/test/material/search_anchor/search_anchor.0_test.dart',
342341
'examples/api/test/material/search_anchor/search_anchor.1_test.dart',
343342
'examples/api/test/material/search_anchor/search_anchor.2_test.dart',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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/material.dart';
6+
import 'package:flutter_api_samples/material/dropdown_menu/dropdown_menu.1.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('The DropdownMenu should display a menu with the list of entries the user can select', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.DropdownMenuApp(),
13+
);
14+
15+
expect(find.widgetWithText(TextField, 'One'), findsOne);
16+
final Finder menu = find.byType(DropdownMenu<String>);
17+
expect(menu, findsOne);
18+
19+
Finder findMenuItem(String label) {
20+
return find.widgetWithText(MenuItemButton, label).last;
21+
}
22+
23+
await tester.tap(menu);
24+
await tester.pumpAndSettle();
25+
expect(findMenuItem('One'), findsOne);
26+
expect(findMenuItem('Two'), findsOne);
27+
expect(findMenuItem('Three'), findsOne);
28+
expect(findMenuItem('Four'), findsOne);
29+
30+
await tester.tap(findMenuItem('Two'));
31+
32+
// The DropdownMenu's onSelected callback is delayed
33+
// with SchedulerBinding.instance.addPostFrameCallback
34+
// to give the focus a chance to return to where it was
35+
// before the menu appeared. The pumpAndSettle()
36+
// give the callback a chance to run.
37+
await tester.pumpAndSettle();
38+
39+
expect(find.widgetWithText(TextField, 'Two'), findsOne);
40+
});
41+
42+
testWidgets('DropdownMenu has focus when tapping on the text field', (WidgetTester tester) async {
43+
await tester.pumpWidget(
44+
const example.DropdownMenuApp(),
45+
);
46+
47+
// Make sure the dropdown menus are there.
48+
final Finder menu = find.byType(DropdownMenu<String>);
49+
expect(menu, findsOne);
50+
51+
// Tap on the menu and make sure it is focused.
52+
await tester.tap(menu);
53+
await tester.pumpAndSettle();
54+
expect(FocusScope.of(tester.element(menu)).hasFocus, isTrue);
55+
});
56+
}

0 commit comments

Comments
 (0)