Skip to content

Commit 14cb420

Browse files
committed
add test
1 parent 4b2a175 commit 14cb420

File tree

2 files changed

+112
-61
lines changed

2 files changed

+112
-61
lines changed

lib/widgets/dialog.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,7 @@ class UpgradeWelcomeDialog extends StatelessWidget {
217217

218218
await future; // Wait for the dialog to be dismissed.
219219

220-
await globalSettings.setBool(
221-
BoolGlobalSetting.upgradeWelcomeDialogShown,
222-
true,
223-
);
220+
await globalSettings.setBool(BoolGlobalSetting.upgradeWelcomeDialogShown, true);
224221
}
225222

226223
static const String _announcementUrl =

test/widgets/dialog_test.dart

Lines changed: 111 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:url_launcher/url_launcher.dart';
77
import 'package:zulip/model/settings.dart';
88
import 'package:zulip/widgets/app.dart';
99
import 'package:zulip/widgets/dialog.dart';
10-
10+
import '../example_data.dart' as eg;
1111
import '../model/binding.dart';
1212
import 'dialog_checks.dart';
1313
import 'test_app.dart';
@@ -31,48 +31,48 @@ void main() {
3131

3232
group('showErrorDialog', () {
3333
testWidgets('show error dialog', (tester) async {
34-
await prepare(tester);
34+
await prepare(tester);
3535

36-
showErrorDialog(context: context, title: title, message: message);
37-
await tester.pump();
36+
showErrorDialog(context: context, title: title, message: message);
37+
await tester.pump();
3838
checkErrorDialog(tester, expectedTitle: title, expectedMessage: message);
3939
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
4040

4141
testWidgets('user closes error dialog', (tester) async {
42-
await prepare(tester);
42+
await prepare(tester);
4343

44-
showErrorDialog(context: context, title: title, message: message);
45-
await tester.pump();
44+
showErrorDialog(context: context, title: title, message: message);
45+
await tester.pump();
4646

47-
final button = checkErrorDialog(tester, expectedTitle: title);
48-
await tester.tap(find.byWidget(button));
49-
await tester.pump();
50-
checkNoDialog(tester);
47+
final button = checkErrorDialog(tester, expectedTitle: title);
48+
await tester.tap(find.byWidget(button));
49+
await tester.pump();
50+
checkNoDialog(tester);
5151
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
5252

5353
testWidgets('tap "Learn more" button', (tester) async {
54-
await prepare(tester);
54+
await prepare(tester);
5555

56-
final learnMoreButtonUrl = Uri.parse('https://foo.example');
56+
final learnMoreButtonUrl = Uri.parse('https://foo.example');
5757
showErrorDialog(context: context, title: title, learnMoreButtonUrl: learnMoreButtonUrl);
58-
await tester.pump();
59-
checkErrorDialog(tester, expectedTitle: title);
58+
await tester.pump();
59+
checkErrorDialog(tester, expectedTitle: title);
6060

61-
await tester.tap(find.text('Learn more'));
62-
final expectedMode = switch (defaultTargetPlatform) {
63-
TargetPlatform.android => LaunchMode.inAppBrowserView,
61+
await tester.tap(find.text('Learn more'));
62+
final expectedMode = switch (defaultTargetPlatform) {
63+
TargetPlatform.android => LaunchMode.inAppBrowserView,
6464
TargetPlatform.iOS => LaunchMode.externalApplication,
6565
_ => throw StateError('attempted to test with $defaultTargetPlatform'),
66-
};
66+
};
6767
check(testBinding.takeLaunchUrlCalls()).single
6868
.equals((url: learnMoreButtonUrl, mode: expectedMode));
6969
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
7070

7171
testWidgets('only one SingleChildScrollView created', (tester) async {
72-
await prepare(tester);
72+
await prepare(tester);
7373

74-
showErrorDialog(context: context, title: title, message: message);
75-
await tester.pump();
74+
showErrorDialog(context: context, title: title, message: message);
75+
await tester.pump();
7676
checkErrorDialog(tester, expectedTitle: title, expectedMessage: message);
7777

7878
check(find.ancestor(of: find.text(message),
@@ -82,48 +82,48 @@ void main() {
8282

8383
group('showSuggestedActionDialog', () {
8484
testWidgets('tap action button', (tester) async {
85-
addTearDown(testBinding.reset);
86-
await tester.pumpWidget(TestZulipApp());
87-
await tester.pump();
88-
final element = tester.element(find.byType(Placeholder));
85+
addTearDown(testBinding.reset);
86+
await tester.pumpWidget(TestZulipApp());
87+
await tester.pump();
88+
final element = tester.element(find.byType(Placeholder));
8989

9090
final dialog = showSuggestedActionDialog(context: element,
91-
title: 'Continue?',
92-
message: 'Do the thing?',
91+
title: 'Continue?',
92+
message: 'Do the thing?',
9393
actionButtonText: 'Sure');
94-
await tester.pump();
95-
await tester.tap(find.text('Sure'));
96-
await check(dialog.result).completes((it) => it.equals(true));
94+
await tester.pump();
95+
await tester.tap(find.text('Sure'));
96+
await check(dialog.result).completes((it) => it.equals(true));
9797
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
9898

9999
testWidgets('tap cancel', (tester) async {
100-
addTearDown(testBinding.reset);
101-
await tester.pumpWidget(TestZulipApp());
102-
await tester.pump();
103-
final element = tester.element(find.byType(Placeholder));
100+
addTearDown(testBinding.reset);
101+
await tester.pumpWidget(TestZulipApp());
102+
await tester.pump();
103+
final element = tester.element(find.byType(Placeholder));
104104

105105
final dialog = showSuggestedActionDialog(context: element,
106-
title: 'Continue?',
107-
message: 'Do the thing?',
106+
title: 'Continue?',
107+
message: 'Do the thing?',
108108
actionButtonText: 'Sure');
109-
await tester.pump();
110-
await tester.tap(find.text('Cancel'));
111-
await check(dialog.result).completes((it) => it.equals(null));
109+
await tester.pump();
110+
await tester.tap(find.text('Cancel'));
111+
await check(dialog.result).completes((it) => it.equals(null));
112112
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
113113

114114
testWidgets('tap outside dialog area', (tester) async {
115-
addTearDown(testBinding.reset);
116-
await tester.pumpWidget(TestZulipApp());
117-
await tester.pump();
118-
final element = tester.element(find.byType(Placeholder));
115+
addTearDown(testBinding.reset);
116+
await tester.pumpWidget(TestZulipApp());
117+
await tester.pump();
118+
final element = tester.element(find.byType(Placeholder));
119119

120120
final dialog = showSuggestedActionDialog(context: element,
121-
title: 'Continue?',
122-
message: 'Do the thing?',
121+
title: 'Continue?',
122+
message: 'Do the thing?',
123123
actionButtonText: 'Sure');
124-
await tester.pump();
125-
await tester.tapAt(tester.getTopLeft(find.byType(TestZulipApp)));
126-
await check(dialog.result).completes((it) => it.equals(null));
124+
await tester.pump();
125+
await tester.tapAt(tester.getTopLeft(find.byType(TestZulipApp)));
126+
await check(dialog.result).completes((it) => it.equals(null));
127127
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
128128
});
129129

@@ -147,23 +147,77 @@ void main() {
147147
// TODO(#1594): test LegacyUpgradeState and BoolGlobalSetting.upgradeWelcomeDialogShown
148148

149149
testWidgets('only one SingleChildScrollView created', (tester) async {
150-
final transitionDurationObserver = TransitionDurationObserver();
151-
addTearDown(testBinding.reset);
150+
final transitionDurationObserver = TransitionDurationObserver();
151+
addTearDown(testBinding.reset);
152152

153-
// Real ZulipApp needed because the show-dialog function calls
154-
// `await ZulipApp.navigator`.
153+
// Real ZulipApp needed because the show-dialog function calls
154+
// `await ZulipApp.navigator`.
155155
await tester.pumpWidget(ZulipApp(navigatorObservers: [transitionDurationObserver]));
156-
await tester.pump();
156+
await tester.pump();
157157

158158
await testBinding.globalStore.settings
159159
.debugSetLegacyUpgradeState(LegacyUpgradeState.found);
160160

161-
UpgradeWelcomeDialog.maybeShow();
162-
await transitionDurationObserver.pumpPastTransition(tester);
161+
UpgradeWelcomeDialog.maybeShow();
162+
await transitionDurationObserver.pumpPastTransition(tester);
163163

164164
final expectedMessage = 'You’ll find a familiar experience in a faster, sleeker package.';
165165
check(find.ancestor(of: find.text(expectedMessage),
166166
matching: find.byType(SingleChildScrollView))).findsOne();
167167
}, variant: TargetPlatformVariant.all());
168168
});
169-
}
169+
170+
group('IntroModal', () {
171+
testWidgets('IntroModal widget displays correctly', (tester) async {
172+
addTearDown(testBinding.reset);
173+
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
174+
175+
const modal = IntroModal(title: 'Test Title', message: 'Test Message');
176+
177+
await tester.pumpWidget(TestZulipApp(child: modal));
178+
await tester.pumpAndSettle();
179+
180+
check(find.text('Test Title')).findsOne();
181+
check(find.text('Test Message')).findsOne();
182+
check(find.text('Got it')).findsOne();
183+
});
184+
185+
testWidgets('settings track inbox modal shown state', (tester) async {
186+
addTearDown(testBinding.reset);
187+
check(
188+
testBinding.globalStore.settings.getBool(
189+
BoolGlobalSetting.inboxIntroModalShown,
190+
),
191+
).isFalse();
192+
await testBinding.globalStore.settings.setBool(
193+
BoolGlobalSetting.inboxIntroModalShown,
194+
true,
195+
);
196+
check(
197+
testBinding.globalStore.settings.getBool(
198+
BoolGlobalSetting.inboxIntroModalShown,
199+
),
200+
).isTrue();
201+
});
202+
203+
testWidgets('settings track combined feed modal shown state', (
204+
tester,
205+
) async {
206+
addTearDown(testBinding.reset);
207+
check(
208+
testBinding.globalStore.settings.getBool(
209+
BoolGlobalSetting.combinedFeedIntroModalShown,
210+
),
211+
).isFalse();
212+
await testBinding.globalStore.settings.setBool(
213+
BoolGlobalSetting.combinedFeedIntroModalShown,
214+
true,
215+
);
216+
check(
217+
testBinding.globalStore.settings.getBool(
218+
BoolGlobalSetting.combinedFeedIntroModalShown,
219+
),
220+
).isTrue();
221+
});
222+
});
223+
}

0 commit comments

Comments
 (0)