From 526522d9e5c7c7935de1fbc99fcbb771b18a4390 Mon Sep 17 00:00:00 2001 From: Taha Tesser Date: Mon, 17 Jul 2023 18:16:58 +0300 Subject: [PATCH] [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) --- .../test/material/dialog_theme_test.dart | 108 ++++++++++++++---- 1 file changed, 88 insertions(+), 20 deletions(-) diff --git a/packages/flutter/test/material/dialog_theme_test.dart b/packages/flutter/test/material/dialog_theme_test.dart index f215649d4826..22c78e3a817e 100644 --- a/packages/flutter/test/material/dialog_theme_test.dart +++ b/packages/flutter/test/material/dialog_theme_test.dart @@ -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: [ ], + 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: [ ], @@ -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: [ ], + ); + 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,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: [ ], @@ -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: [ ], @@ -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 { @@ -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: [ ], - ); + 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: [ ], - ); + 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));