Unverified Commit abfc560b authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

ToggleButtons test improvement (#38898)

* Improve finders throughout toggle_buttons_test.dart

* Improve Material finders

* Update toggle_buttons_theme_test.dart finders to be more precise

* Refactor out textStyle and iconTheme finders

* Refactor iconTheme and buttonTextTheme logic
parent a415c76b
...@@ -157,6 +157,18 @@ void main() { ...@@ -157,6 +157,18 @@ void main() {
testWidgets( testWidgets(
'Theme text/icon colors for enabled, selected and disabled states', 'Theme text/icon colors for enabled, selected and disabled states',
(WidgetTester tester) async { (WidgetTester tester) async {
TextStyle buttonTextStyle(String text) {
return tester.widget<DefaultTextStyle>(find.descendant(
of: find.widgetWithText(RawMaterialButton, text),
matching: find.byType(DefaultTextStyle),
)).style;
}
IconTheme iconTheme(IconData icon) {
return tester.widget(find.descendant(
of: find.widgetWithIcon(RawMaterialButton, icon),
matching: find.byType(IconTheme),
));
}
final ThemeData theme = ThemeData(); final ThemeData theme = ThemeData();
const Color enabledColor = Colors.lime; const Color enabledColor = Colors.lime;
const Color selectedColor = Colors.green; const Color selectedColor = Colors.green;
...@@ -184,20 +196,10 @@ void main() { ...@@ -184,20 +196,10 @@ void main() {
), ),
), ),
); );
// Custom theme enabled color
DefaultTextStyle textStyle;
IconTheme iconTheme;
// custom theme enabled color
expect(theme.colorScheme.onSurface, isNot(enabledColor)); expect(theme.colorScheme.onSurface, isNot(enabledColor));
textStyle = tester.firstWidget<DefaultTextStyle>( expect(buttonTextStyle('First child').color, enabledColor);
find.widgetWithText(DefaultTextStyle, 'First child'), expect(iconTheme(Icons.check).data.color, enabledColor);
);
expect(textStyle.style.color, enabledColor);
iconTheme = tester.firstWidget<IconTheme>(
find.widgetWithIcon(IconTheme, Icons.check),
);
expect(iconTheme.data.color, enabledColor);
await tester.pumpWidget( await tester.pumpWidget(
Material( Material(
...@@ -222,16 +224,10 @@ void main() { ...@@ -222,16 +224,10 @@ void main() {
), ),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// custom theme selected color // Custom theme selected color
expect(theme.colorScheme.primary, isNot(selectedColor)); expect(theme.colorScheme.primary, isNot(selectedColor));
textStyle = tester.firstWidget<DefaultTextStyle>( expect(buttonTextStyle('First child').color, selectedColor);
find.widgetWithText(DefaultTextStyle, 'First child'), expect(iconTheme(Icons.check).data.color, selectedColor);
);
expect(textStyle.style.color, selectedColor);
iconTheme = tester.firstWidget<IconTheme>(
find.widgetWithIcon(IconTheme, Icons.check),
);
expect(iconTheme.data.color, selectedColor);
await tester.pumpWidget( await tester.pumpWidget(
Material( Material(
...@@ -255,16 +251,10 @@ void main() { ...@@ -255,16 +251,10 @@ void main() {
), ),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// custom theme disabled color // Custom theme disabled color
expect(theme.disabledColor, isNot(disabledColor)); expect(theme.disabledColor, isNot(disabledColor));
textStyle = tester.firstWidget<DefaultTextStyle>( expect(buttonTextStyle('First child').color, disabledColor);
find.widgetWithText(DefaultTextStyle, 'First child'), expect(iconTheme(Icons.check).data.color, disabledColor);
);
expect(textStyle.style.color, disabledColor);
iconTheme = tester.firstWidget<IconTheme>(
find.widgetWithIcon(IconTheme, Icons.check),
);
expect(iconTheme.data.color, disabledColor);
}, },
); );
...@@ -289,12 +279,10 @@ void main() { ...@@ -289,12 +279,10 @@ void main() {
), ),
); );
final Material material = tester.firstWidget<Material>( final Material material = tester.widget<Material>(find.descendant(
find.descendant( of: find.byType(RawMaterialButton),
of: find.byType(RawMaterialButton), matching: find.byType(Material),
matching: find.byType(Material), ));
),
);
expect(material.color, customFillColor); expect(material.color, customFillColor);
expect(material.type, MaterialType.button); expect(material.type, MaterialType.button);
}); });
......
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