Skip to content

Commit 047c0bd

Browse files
authored
test: Improve DropdownMenuFormField tests (flutter#181369)
Resolves flutter#181367 (comment) The test was still valid as `DropdownMenuFormField` includes `DropdownMenu` and therefore could select the desired MenuItemButton. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent e435edf commit 047c0bd

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

packages/flutter/test/material/dropdown_menu_form_field_test.dart

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ void main() {
2424
menuEntries.add(entry);
2525
}
2626

27-
Finder findMenuItem(MenuItem menuItem) {
28-
// For each menu item there are two MenuItemButton widgets.
29-
// The last one is the real button item in the menu.
30-
// The first one is not visible, it is part of _DropdownMenuBody
31-
// which is used to compute the dropdown width.
32-
return find.widgetWithText(MenuItemButton, menuItem.label).last;
33-
}
34-
3527
Finder findMenuItemButton(String label) {
3628
// For each menu items there are two MenuItemButton widgets.
3729
// The last one is the real button item in the menu.
@@ -40,6 +32,10 @@ void main() {
4032
return find.widgetWithText(MenuItemButton, label).last;
4133
}
4234

35+
Finder findMenuItem(MenuItem menuItem) {
36+
return findMenuItemButton(menuItem.label);
37+
}
38+
4339
testWidgets('Creates an underlying DropdownMenu', (WidgetTester tester) async {
4440
await tester.pumpWidget(
4541
MaterialApp(
@@ -884,7 +880,7 @@ void main() {
884880
expect(dropdownMenu.restorationId, restorationId);
885881
});
886882

887-
testWidgets('Field state is correcly updated', (WidgetTester tester) async {
883+
testWidgets('Field state is correctly updated', (WidgetTester tester) async {
888884
final fieldKey = GlobalKey<FormFieldState<MenuItem>>();
889885

890886
await tester.pumpWidget(
@@ -1366,7 +1362,7 @@ void main() {
13661362
expect(onSelectedCallCount, 1);
13671363
});
13681364

1369-
testWidgets('onSelect is called exactly once when reseted', (WidgetTester tester) async {
1365+
testWidgets('onSelect is called exactly once when reset', (WidgetTester tester) async {
13701366
var onSelectedCallCount = 0;
13711367
final fieldKey = GlobalKey<FormFieldState<MenuItem>>();
13721368
await tester.pumpWidget(
@@ -1436,7 +1432,7 @@ void main() {
14361432
);
14371433

14381434
// Open the menu.
1439-
await tester.tap(find.byType(DropdownMenu<String?>));
1435+
await tester.tap(find.byType(DropdownMenuFormField<String?>));
14401436
await tester.pump();
14411437

14421438
// Select the 'None' item.

0 commit comments

Comments
 (0)