Skip to content

Commit 57ed724

Browse files
Update dialog tests for Material3 (flutter#135775)
Separates the tests for the Material dialog into Material3 and Material2 versions. More info in flutter#127064
1 parent a6da9ce commit 57ed724

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

packages/flutter/test/material/dialog_test.dart

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void main() {
111111
expect(materialWidget.color, customColor);
112112
});
113113

114-
testWidgetsWithLeakTracking('Dialog Defaults', (WidgetTester tester) async {
114+
testWidgetsWithLeakTracking('Material2 - Dialog Defaults', (WidgetTester tester) async {
115115
const AlertDialog dialog = AlertDialog(
116116
title: Text('Title'),
117117
content: Text('Y'),
@@ -131,10 +131,14 @@ void main() {
131131
find.descendant(of: find.byType(Dialog), matching: find.byType(Material)),
132132
);
133133
expect(bottomLeft.dy, 360.0);
134+
});
134135

135-
await tester.tapAt(const Offset(10.0, 10.0));
136-
await tester.pumpAndSettle();
137-
136+
testWidgetsWithLeakTracking('Material3 - Dialog Defaults', (WidgetTester tester) async {
137+
const AlertDialog dialog = AlertDialog(
138+
title: Text('Title'),
139+
content: Text('Y'),
140+
actions: <Widget>[ ],
141+
);
138142
await tester.pumpWidget(_buildAppWithDialog(dialog, theme: material3Theme));
139143

140144
await tester.tap(find.text('X'));
@@ -146,9 +150,8 @@ void main() {
146150
expect(material3Widget.elevation, 6.0);
147151
});
148152

149-
testWidgetsWithLeakTracking('Dialog.fullscreen Defaults', (WidgetTester tester) async {
153+
testWidgetsWithLeakTracking('Material2 - Dialog.fullscreen Defaults', (WidgetTester tester) async {
150154
const String dialogTextM2 = 'Fullscreen Dialog - M2';
151-
const String dialogTextM3 = 'Fullscreen Dialog - M3';
152155

153156
await tester.pumpWidget(_buildAppWithDialog(
154157
theme: material2Theme,
@@ -162,14 +165,18 @@ void main() {
162165

163166
expect(find.text(dialogTextM2), findsOneWidget);
164167

165-
Material materialWidget = _getMaterialFromDialog(tester);
168+
final Material materialWidget = _getMaterialFromDialog(tester);
166169
expect(materialWidget.color, Colors.grey[800]);
167170

168171
// Try to dismiss the fullscreen dialog with the escape key.
169172
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
170173
await tester.pumpAndSettle();
171174

172175
expect(find.text(dialogTextM2), findsNothing);
176+
});
177+
178+
testWidgetsWithLeakTracking('Material3 - Dialog.fullscreen Defaults', (WidgetTester tester) async {
179+
const String dialogTextM3 = 'Fullscreen Dialog - M3';
173180

174181
await tester.pumpWidget(_buildAppWithDialog(
175182
theme: material3Theme,
@@ -183,7 +190,7 @@ void main() {
183190

184191
expect(find.text(dialogTextM3), findsOneWidget);
185192

186-
materialWidget = _getMaterialFromDialog(tester);
193+
final Material materialWidget = _getMaterialFromDialog(tester);
187194
expect(materialWidget.color, material3Theme.colorScheme.surface);
188195

189196
// Try to dismiss the fullscreen dialog with the escape key.
@@ -644,7 +651,7 @@ void main() {
644651
expect(actionsSize.width, dialogSize.width - (30.0 * 2));
645652
});
646653

647-
testWidgetsWithLeakTracking('AlertDialog.buttonPadding defaults', (WidgetTester tester) async {
654+
testWidgetsWithLeakTracking('Material2 - AlertDialog.buttonPadding defaults', (WidgetTester tester) async {
648655
final GlobalKey key1 = GlobalKey();
649656
final GlobalKey key2 = GlobalKey();
650657

@@ -700,10 +707,28 @@ void main() {
700707
tester.getBottomRight(find.byKey(key2)).dx,
701708
tester.getBottomRight(_findButtonBar()).dx - 8.0,
702709
); // right
710+
});
703711

704-
// Dismiss it and test material 3 dialog
705-
await tester.tapAt(const Offset(10.0, 10.0));
706-
await tester.pumpAndSettle();
712+
testWidgetsWithLeakTracking('Material3 - AlertDialog.buttonPadding defaults', (WidgetTester tester) async {
713+
final GlobalKey key1 = GlobalKey();
714+
final GlobalKey key2 = GlobalKey();
715+
716+
final AlertDialog dialog = AlertDialog(
717+
title: const Text('title'),
718+
content: const Text('content'),
719+
actions: <Widget>[
720+
ElevatedButton(
721+
key: key1,
722+
onPressed: () {},
723+
child: const Text('button 1'),
724+
),
725+
ElevatedButton(
726+
key: key2,
727+
onPressed: () {},
728+
child: const Text('button 2'),
729+
),
730+
],
731+
);
707732

708733
await tester.pumpWidget(_buildAppWithDialog(dialog, theme: material3Theme));
709734

0 commit comments

Comments
 (0)