Skip to content

Commit af8d513

Browse files
committed
tests updated for adaptive alert dialogs
1 parent a210120 commit af8d513

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

lib/widgets/dialog.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import 'package:flutter/cupertino.dart';
12
import 'package:flutter/material.dart';
23
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';
3-
import 'package:flutter/cupertino.dart';
44

55
Widget _dialogActionText(String text) {
66
return Text(
@@ -16,9 +16,9 @@ Widget _dialogActionText(String text) {
1616
);
1717
}
1818

19-
// Sets the dialog action to be platform appropriate
20-
// by displaying a [CupertinoDialogAction] for IOS platforms
21-
// and a regular [TextButton] otherwise.
19+
/// Sets the dialog action to be platform appropriate
20+
/// by displaying a [CupertinoDialogAction] for IOS platforms
21+
/// and a regular [TextButton] otherwise.
2222
Widget _adaptiveAction(
2323
{required BuildContext context,
2424
required VoidCallback onPressed,

pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,10 @@ packages:
315315
dependency: transitive
316316
description:
317317
name: file
318-
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
318+
sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4
319319
url: "https://pub.dev"
320320
source: hosted
321-
version: "7.0.0"
321+
version: "7.0.1"
322322
file_picker:
323323
dependency: "direct main"
324324
description:

test/widgets/dialog_checks.dart

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/foundation.dart';
13
import 'package:flutter/material.dart';
24
import 'package:flutter_test/flutter_test.dart';
35

@@ -6,21 +8,41 @@ import 'package:flutter_test/flutter_test.dart';
68
/// Checks for an error dialog matching an expected title
79
/// and, optionally, matching an expected message. Fails if none is found.
810
///
9-
/// On success, returns the widget's "OK" button.
11+
/// On success, returns the widget's "OK" button
12+
/// (which is a [CupertinoDialogAction] for OS platforms).
13+
///
1014
/// Dismiss the dialog by calling `tester.tap(find.byWidget(okButton))`.
1115
Widget checkErrorDialog(WidgetTester tester, {
1216
required String expectedTitle,
1317
String? expectedMessage,
1418
}) {
15-
final dialog = tester.widget<AlertDialog>(find.byType(AlertDialog));
16-
tester.widget(find.descendant(matchRoot: true,
17-
of: find.byWidget(dialog.title!), matching: find.text(expectedTitle)));
18-
if (expectedMessage != null) {
19+
if (defaultTargetPlatform == TargetPlatform.iOS
20+
|| defaultTargetPlatform == TargetPlatform.macOS) {
21+
22+
final dialog = tester.widget<CupertinoAlertDialog>(find.byType(CupertinoAlertDialog));
23+
1924
tester.widget(find.descendant(matchRoot: true,
20-
of: find.byWidget(dialog.content!), matching: find.text(expectedMessage)));
21-
}
25+
of: find.byWidget(dialog.title!), matching: find.text(expectedTitle)));
2226

23-
return tester.widget(
24-
find.descendant(of: find.byWidget(dialog),
25-
matching: find.widgetWithText(TextButton, 'OK')));
27+
if (expectedMessage != null) {
28+
tester.widget(find.descendant(matchRoot: true,
29+
of: find.byWidget(dialog.content!), matching: find.text(expectedMessage)));
30+
}
31+
32+
return tester.widget(
33+
find.descendant(of: find.byWidget(dialog),
34+
matching: find.widgetWithText(CupertinoDialogAction, 'OK')));
35+
36+
}
37+
else {
38+
final dialog = tester.widget<Dialog>(find.byType(Dialog));
39+
tester.widget(find.widgetWithText(Dialog, expectedTitle));
40+
if (expectedMessage != null) {
41+
tester.widget(find.widgetWithText(Dialog, expectedMessage));
42+
}
43+
return tester.widget(
44+
find.descendant(of: find.byWidget(dialog),
45+
matching: find.widgetWithText(TextButton, 'OK')));
46+
}
47+
2648
}

0 commit comments

Comments
 (0)