[Reland] - Update DialogTheme tests for M2/M3 (#130711)

This relands https://github.com/flutter/flutter/pull/130414 (which was reverted in https://github.com/flutter/flutter/pull/130578)
This commit is contained in:
Taha Tesser 2023-07-17 18:16:58 +03:00 committed by GitHub
parent 8b2d4e705c
commit 526522d9e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -165,7 +165,31 @@ void main() {
expect(bottomLeft.dy, 576.0);
});
testWidgets('Dialog alignment takes priority over theme', (WidgetTester tester) async {
testWidgets('Material3 - Dialog alignment takes priority over theme', (WidgetTester tester) async {
const AlertDialog dialog = AlertDialog(
title: Text('Title'),
actions: <Widget>[ ],
alignment: Alignment.topRight,
);
final ThemeData theme = ThemeData(
useMaterial3: true,
dialogTheme: const DialogTheme(alignment: Alignment.bottomLeft),
);
await tester.pumpWidget(
_appWithDialog(tester, dialog, theme: theme),
);
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
final Offset bottomLeft = tester.getBottomLeft(
find.descendant(of: find.byType(Dialog), matching: find.byType(Material)),
);
expect(bottomLeft.dx, 480.0);
expect(bottomLeft.dy, 124.0);
});
testWidgets('Material2 - Dialog alignment takes priority over theme', (WidgetTester tester) async {
const AlertDialog dialog = AlertDialog(
title: Text('Title'),
actions: <Widget>[ ],
@ -186,7 +210,29 @@ void main() {
expect(bottomLeft.dy, 104.0);
});
testWidgets('Custom dialog shape matches golden', (WidgetTester tester) async {
testWidgets('Material3 - Custom dialog shape matches golden', (WidgetTester tester) async {
const RoundedRectangleBorder customBorder =
RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0)));
const AlertDialog dialog = AlertDialog(
title: Text('Title'),
actions: <Widget>[ ],
);
final ThemeData theme = ThemeData(
useMaterial3: true,
dialogTheme: const DialogTheme(shape: customBorder),
);
await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
await expectLater(
find.byKey(_painterKey),
matchesGoldenFile('m3_dialog_theme.dialog_with_custom_border.png'),
);
});
testWidgets('Material2 - Custom dialog shape matches golden', (WidgetTester tester) async {
const RoundedRectangleBorder customBorder =
RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0)));
const AlertDialog dialog = AlertDialog(
@ -201,7 +247,7 @@ void main() {
await expectLater(
find.byKey(_painterKey),
matchesGoldenFile('dialog_theme.dialog_with_custom_border.png'),
matchesGoldenFile('m2_dialog_theme.dialog_with_custom_border.png'),
);
});
@ -246,7 +292,23 @@ void main() {
expect(text.text.style!.color, dialogThemeColor);
});
testWidgets('Custom Icon Color - Theme - lowest preference', (WidgetTester tester) async {
testWidgets('Material3 - Custom Icon Color - Theme - lowest preference', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
const AlertDialog dialog = AlertDialog(
icon: Icon(Icons.ac_unit),
actions: <Widget>[ ],
);
await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
// first is Text('X')
final RichText text = tester.widget(find.byType(RichText).last);
expect(text.text.style!.color, theme.colorScheme.secondary);
});
testWidgets('Material2 - Custom Icon Color - Theme - lowest preference', (WidgetTester tester) async {
const Color iconThemeColor = Colors.yellow;
final ThemeData theme = ThemeData(useMaterial3: false, iconTheme: const IconThemeData(color: iconThemeColor));
const AlertDialog dialog = AlertDialog(
@ -263,22 +325,6 @@ void main() {
expect(text.text.style!.color, iconThemeColor);
});
testWidgets('Custom Icon Color - Theme - lowest preference for M3', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
const AlertDialog dialog = AlertDialog(
icon: Icon(Icons.ac_unit),
actions: <Widget>[ ],
);
await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
// first is Text('X')
final RichText text = tester.widget(find.byType(RichText).last);
expect(text.text.style!.color, theme.colorScheme.secondary);
});
testWidgets('Custom Title Text Style - Constructor Param', (WidgetTester tester) async {
const String titleText = 'Title';
const TextStyle titleTextStyle = TextStyle(color: Colors.pink);
@ -313,13 +359,24 @@ void main() {
expect(title.text.style, titleTextStyle);
});
testWidgets('Custom Title Text Style - Theme', (WidgetTester tester) async {
testWidgets('Material3 - Custom Title Text Style - Theme', (WidgetTester tester) async {
const String titleText = 'Title';
const TextStyle titleTextStyle = TextStyle(color: Colors.pink);
const AlertDialog dialog = AlertDialog(
title: Text(titleText),
actions: <Widget>[ ],
);
const AlertDialog dialog = AlertDialog(title: Text(titleText));
final ThemeData theme = ThemeData(useMaterial3: true, textTheme: const TextTheme(headlineSmall: titleTextStyle));
await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
final RenderParagraph title = _getTextRenderObject(tester, titleText);
expect(title.text.style!.color, titleTextStyle.color);
});
testWidgets('Material2 - Custom Title Text Style - Theme', (WidgetTester tester) async {
const String titleText = 'Title';
const TextStyle titleTextStyle = TextStyle(color: Colors.pink);
const AlertDialog dialog = AlertDialog(title: Text(titleText));
final ThemeData theme = ThemeData(useMaterial3: false, textTheme: const TextTheme(titleLarge: titleTextStyle));
await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
@ -412,13 +469,24 @@ void main() {
expect(content.text.style, contentTextStyle);
});
testWidgets('Custom Content Text Style - Theme', (WidgetTester tester) async {
testWidgets('Material3 - Custom Content Text Style - Theme', (WidgetTester tester) async {
const String contentText = 'Content';
const TextStyle contentTextStyle = TextStyle(color: Colors.pink);
const AlertDialog dialog = AlertDialog(
content: Text(contentText),
actions: <Widget>[ ],
);
const AlertDialog dialog = AlertDialog(content: Text(contentText),);
final ThemeData theme = ThemeData(useMaterial3: true, textTheme: const TextTheme(bodyMedium: contentTextStyle));
await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
final RenderParagraph content = _getTextRenderObject(tester, contentText);
expect(content.text.style!.color, contentTextStyle.color);
});
testWidgets('Material2 - Custom Content Text Style - Theme', (WidgetTester tester) async {
const String contentText = 'Content';
const TextStyle contentTextStyle = TextStyle(color: Colors.pink);
const AlertDialog dialog = AlertDialog(content: Text(contentText));
final ThemeData theme = ThemeData(useMaterial3: false, textTheme: const TextTheme(titleMedium: contentTextStyle));
await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));