Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 71 additions & 1 deletion packages/dropdown_button2/test/dropdown_button2_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,10 @@ void main() {
expect(expandedSemantics.properties.expanded, isTrue);

// Close the menu by selecting an item.
await tester.tap(find.text('1'));
await tester.tap(find.text('1').last);
await tester.pumpAndSettle();

// After closing: should have expanded state but not be expanded.
expect(
tester.getSemantics(find.byType(DropdownButton2<int>)),
matchesSemantics(
Expand All @@ -572,6 +573,75 @@ void main() {
},
);

testWidgets(
'button should include hint semantics when no value is selected',
(
WidgetTester tester,
) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: DropdownButton2<int>(
hint: const Text('Select a number'),
items: buildItems(),
onChanged: (_) {},
),
),
),
);

expect(
tester.getSemantics(find.byType(DropdownButton2<int>)),
matchesSemantics(
hasExpandedState: true,
isFocusable: true,
hasTapAction: true,
hasFocusAction: true,
label: 'Select a number',
),
);
},
);

testWidgets(
'semantics tree should only contain the selected item label when the menu is closed',
(
WidgetTester tester,
) async {
final valueListenable = ValueNotifier(menuItems[1]);

await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: DropdownButton2<int>(
valueListenable: valueListenable,
items: buildItems(),
onChanged: (_) {},
),
),
),
);

// Only the selected item (1) should be in the semantics tree.
expect(
find.bySemanticsLabel('${menuItems[0]}'),
findsNothing,
);
expect(
find.bySemanticsLabel('${menuItems[1]}'),
findsOneWidget,
);
expect(
find.bySemanticsLabel('${menuItems[2]}'),
findsNothing,
);
expect(
find.bySemanticsLabel('${menuItems[3]}'),
findsNothing,
);
},
);

testWidgets('menu should include menu and menuItem role semantics', (
WidgetTester tester,
) async {
Expand Down
Loading