Unverified Commit 0ef46388 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Update `ToggleButtons`, `ExpansionPanel`, and `ExpandIcon` tests for Material 3 (#141868)

Updated unit tests for `ToggleButtons`, `ExpansionPanel`, and `ExpandIcon` to have M2 and M3 versions.

More info in #139076
parent 5caa8b89
...@@ -73,9 +73,9 @@ void main() { ...@@ -73,9 +73,9 @@ void main() {
expect(iconTheme.data.color, equals(Colors.white60)); expect(iconTheme.data.color, equals(Colors.white60));
}); });
testWidgets('ExpandIcon disabled', (WidgetTester tester) async { testWidgets('Material2 - ExpandIcon disabled', (WidgetTester tester) async {
IconTheme iconTheme; IconTheme iconTheme;
// Light mode test // Test light mode.
await tester.pumpWidget(wrap( await tester.pumpWidget(wrap(
theme: ThemeData(useMaterial3: false), theme: ThemeData(useMaterial3: false),
child: const ExpandIcon(onPressed: null), child: const ExpandIcon(onPressed: null),
...@@ -85,7 +85,7 @@ void main() { ...@@ -85,7 +85,7 @@ void main() {
iconTheme = tester.firstWidget(find.byType(IconTheme).last); iconTheme = tester.firstWidget(find.byType(IconTheme).last);
expect(iconTheme.data.color, equals(Colors.black38)); expect(iconTheme.data.color, equals(Colors.black38));
// Dark mode test // Test dark mode.
await tester.pumpWidget(wrap( await tester.pumpWidget(wrap(
child: const ExpandIcon(onPressed: null), child: const ExpandIcon(onPressed: null),
theme: ThemeData(useMaterial3: false, brightness: Brightness.dark), theme: ThemeData(useMaterial3: false, brightness: Brightness.dark),
...@@ -96,6 +96,37 @@ void main() { ...@@ -96,6 +96,37 @@ void main() {
expect(iconTheme.data.color, equals(Colors.white38)); expect(iconTheme.data.color, equals(Colors.white38));
}); });
testWidgets('Material3 - ExpandIcon disabled', (WidgetTester tester) async {
ThemeData theme = ThemeData();
IconTheme iconTheme;
// Test light mode.
await tester.pumpWidget(wrap(
theme: theme,
child: const ExpandIcon(onPressed: null),
));
await tester.pumpAndSettle();
iconTheme = tester.firstWidget(find.byType(IconTheme).last);
expect(
iconTheme.data.color,
equals(theme.colorScheme.onSurface.withOpacity(0.38)),
);
theme = ThemeData(brightness: Brightness.dark);
// Test dark mode.
await tester.pumpWidget(wrap(
theme: theme,
child: const ExpandIcon(onPressed: null),
));
await tester.pumpAndSettle();
iconTheme = tester.firstWidget(find.byType(IconTheme).last);
expect(
iconTheme.data.color,
equals(theme.colorScheme.onSurface.withOpacity(0.38)),
);
});
testWidgets('ExpandIcon test isExpanded does not trigger callback', (WidgetTester tester) async { testWidgets('ExpandIcon test isExpanded does not trigger callback', (WidgetTester tester) async {
bool expanded = false; bool expanded = false;
...@@ -173,7 +204,7 @@ void main() { ...@@ -173,7 +204,7 @@ void main() {
expect(icon.size, 48); expect(icon.size, 48);
}); });
testWidgets('ExpandIcon has correct semantic hints', (WidgetTester tester) async { testWidgets('Material2 - ExpandIcon has correct semantic hints', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics(); final SemanticsHandle handle = tester.ensureSemantics();
const DefaultMaterialLocalizations localizations = DefaultMaterialLocalizations(); const DefaultMaterialLocalizations localizations = DefaultMaterialLocalizations();
await tester.pumpWidget(wrap( await tester.pumpWidget(wrap(
...@@ -194,6 +225,7 @@ void main() { ...@@ -194,6 +225,7 @@ void main() {
)); ));
await tester.pumpWidget(wrap( await tester.pumpWidget(wrap(
theme: ThemeData(useMaterial3: false),
child: ExpandIcon( child: ExpandIcon(
onPressed: (bool _) { }, onPressed: (bool _) { },
), ),
...@@ -210,6 +242,52 @@ void main() { ...@@ -210,6 +242,52 @@ void main() {
handle.dispose(); handle.dispose();
}); });
testWidgets('Material3 - ExpandIcon has correct semantic hints', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
const DefaultMaterialLocalizations localizations = DefaultMaterialLocalizations();
await tester.pumpWidget(wrap(
child: ExpandIcon(
isExpanded: true,
onPressed: (bool _) { },
),
));
expect(tester.getSemantics(find.byType(ExpandIcon)), matchesSemantics(
onTapHint: localizations.expandedIconTapHint,
children: <Matcher>[
matchesSemantics(
hasTapAction: true,
hasEnabledState: true,
isEnabled: true,
isFocusable: true,
isButton: true,
),
],
));
await tester.pumpWidget(wrap(
child: ExpandIcon(
onPressed: (bool _) { },
),
));
expect(tester.getSemantics(find.byType(ExpandIcon)), matchesSemantics(
onTapHint: localizations.collapsedIconTapHint,
children: <Matcher>[
matchesSemantics(
hasTapAction: true,
hasEnabledState: true,
isEnabled: true,
isFocusable: true,
isButton: true,
),
],
));
handle.dispose();
});
testWidgets('ExpandIcon uses custom icon color and expanded icon color', (WidgetTester tester) async { testWidgets('ExpandIcon uses custom icon color and expanded icon color', (WidgetTester tester) async {
bool expanded = false; bool expanded = false;
IconTheme iconTheme; IconTheme iconTheme;
......
...@@ -178,7 +178,7 @@ void main() { ...@@ -178,7 +178,7 @@ void main() {
expect(box.size.height - oldHeight, greaterThanOrEqualTo(100.0)); // 100 + some margin expect(box.size.height - oldHeight, greaterThanOrEqualTo(100.0)); // 100 + some margin
}); });
testWidgets('ExpansionPanelList does not merge header when canTapOnHeader is false', (WidgetTester tester) async { testWidgets('Material2 - ExpansionPanelList does not merge header when canTapOnHeader is false', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics(); final SemanticsHandle handle = tester.ensureSemantics();
final Key headerKey = UniqueKey(); final Key headerKey = UniqueKey();
await tester.pumpWidget( await tester.pumpWidget(
...@@ -226,6 +226,58 @@ void main() { ...@@ -226,6 +226,58 @@ void main() {
handle.dispose(); handle.dispose();
}); });
testWidgets('Material3 - ExpansionPanelList does not merge header when canTapOnHeader is false', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
final Key headerKey = UniqueKey();
await tester.pumpWidget(
MaterialApp(
home: ExpansionPanelListSemanticsTest(headerKey: headerKey),
),
);
// Make sure custom gesture detector widget is clickable.
await tester.tap(find.text('head1'));
await tester.pump();
final ExpansionPanelListSemanticsTestState state =
tester.state(find.byType(ExpansionPanelListSemanticsTest));
expect(state.headerTapped, true);
// Check the expansion icon semantics does not merged with header widget.
final Finder expansionIcon = find.descendant(
of: find.ancestor(
of: find.byKey(headerKey),
matching: find.byType(Row),
),
matching: find.byType(ExpandIcon),
);
expect(tester.getSemantics(expansionIcon), matchesSemantics(
label: 'Expand',
children: <Matcher>[
matchesSemantics(
isButton: true,
hasEnabledState: true,
isEnabled: true,
isFocusable: true,
hasTapAction: true,
),
],
));
// Check custom header widget semantics is preserved.
final Finder headerWidget = find.descendant(
of: find.byKey(headerKey),
matching: find.byType(RichText),
);
expect(tester.getSemantics(headerWidget), matchesSemantics(
label: 'head1',
hasTapAction: true,
));
handle.dispose();
});
testWidgets('Multiple Panel List test', (WidgetTester tester) async { testWidgets('Multiple Panel List test', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
...@@ -998,7 +1050,7 @@ void main() { ...@@ -998,7 +1050,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
}); });
testWidgets('Panel header has semantics, canTapOnHeader = false ', (WidgetTester tester) async { testWidgets('Material2 - Panel header has semantics, canTapOnHeader = false', (WidgetTester tester) async {
const Key expandedKey = Key('expanded'); const Key expandedKey = Key('expanded');
const Key collapsedKey = Key('collapsed'); const Key collapsedKey = Key('collapsed');
const DefaultMaterialLocalizations localizations = DefaultMaterialLocalizations(); const DefaultMaterialLocalizations localizations = DefaultMaterialLocalizations();
...@@ -1083,6 +1135,99 @@ void main() { ...@@ -1083,6 +1135,99 @@ void main() {
handle.dispose(); handle.dispose();
}); });
testWidgets('Material3 - Panel header has semantics, canTapOnHeader = false', (WidgetTester tester) async {
const Key expandedKey = Key('expanded');
const Key collapsedKey = Key('collapsed');
const DefaultMaterialLocalizations localizations = DefaultMaterialLocalizations();
final SemanticsHandle handle = tester.ensureSemantics();
final List<ExpansionPanel> demoItems = <ExpansionPanel>[
ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return const Text('Expanded', key: expandedKey);
},
body: const SizedBox(height: 100.0),
isExpanded: true,
),
ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return const Text('Collapsed', key: collapsedKey);
},
body: const SizedBox(height: 100.0),
),
];
final ExpansionPanelList expansionList = ExpansionPanelList(
children: demoItems,
);
await tester.pumpWidget(
MaterialApp(
home: SingleChildScrollView(
child: expansionList,
),
),
);
// Check the semantics of [ExpandIcon] for expanded panel.
final Finder expandedIcon = find.descendant(
of: find.ancestor(
of: find.byKey(expandedKey),
matching: find.byType(Row),
),
matching: find.byType(ExpandIcon),
);
expect(tester.getSemantics(expandedIcon), matchesSemantics(
label: 'Collapse',
onTapHint: localizations.expandedIconTapHint,
children: <Matcher>[
matchesSemantics(
isButton: true,
hasEnabledState: true,
isEnabled: true,
isFocusable: true,
hasTapAction: true,
),
],
));
// Check the semantics of the header widget for expanded panel.
final Finder expandedHeader = find.byKey(expandedKey);
expect(tester.getSemantics(expandedHeader), matchesSemantics(
label: 'Expanded',
));
// Check the semantics of [ExpandIcon] for collapsed panel.
final Finder collapsedIcon = find.descendant(
of: find.ancestor(
of: find.byKey(collapsedKey),
matching: find.byType(Row),
),
matching: find.byType(ExpandIcon),
);
expect(tester.getSemantics(collapsedIcon), matchesSemantics(
label: 'Expand',
onTapHint: localizations.collapsedIconTapHint,
children: <Matcher>[
matchesSemantics(
isButton: true,
hasEnabledState: true,
isEnabled: true,
isFocusable: true,
hasTapAction: true,
),
],
));
// Check the semantics of the header widget for expanded panel.
final Finder collapsedHeader = find.byKey(collapsedKey);
expect(tester.getSemantics(collapsedHeader), matchesSemantics(
label: 'Collapsed',
));
handle.dispose();
});
testWidgets('Panel header has semantics, canTapOnHeader = true', (WidgetTester tester) async { testWidgets('Panel header has semantics, canTapOnHeader = true', (WidgetTester tester) async {
const Key expandedKey = Key('expanded'); const Key expandedKey = Key('expanded');
const Key collapsedKey = Key('collapsed'); const Key collapsedKey = Key('collapsed');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment