Skip to content

Commit

Permalink
[Reland] - Update DialogTheme tests for M2/M3 (#130711)
Browse files Browse the repository at this point in the history
This relands flutter/flutter#130414 (which was reverted in flutter/flutter#130578)
  • Loading branch information
TahaTesser authored Jul 17, 2023
1 parent 8b2d4e7 commit 526522d
Showing 1 changed file with 88 additions and 20 deletions.
108 changes: 88 additions & 20 deletions packages/flutter/test/material/dialog_theme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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>[ ],
Expand All @@ -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(
Expand All @@ -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'),
);
});

Expand Down Expand Up @@ -246,9 +292,8 @@ void main() {
expect(text.text.style!.color, dialogThemeColor);
});

testWidgets('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));
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>[ ],
Expand All @@ -260,11 +305,12 @@ void main() {

// first is Text('X')
final RichText text = tester.widget(find.byType(RichText).last);
expect(text.text.style!.color, iconThemeColor);
expect(text.text.style!.color, theme.colorScheme.secondary);
});

testWidgets('Custom Icon Color - Theme - lowest preference for M3', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
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(
icon: Icon(Icons.ac_unit),
actions: <Widget>[ ],
Expand All @@ -276,7 +322,7 @@ void main() {

// first is Text('X')
final RichText text = tester.widget(find.byType(RichText).last);
expect(text.text.style!.color, theme.colorScheme.secondary);
expect(text.text.style!.color, iconThemeColor);
});

testWidgets('Custom Title Text Style - Constructor Param', (WidgetTester tester) async {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 526522d

Please sign in to comment.