|
1 | 1 | import 'package:checks/checks.dart';
|
2 | 2 | import 'package:flutter/material.dart';
|
3 | 3 | import 'package:flutter/services.dart';
|
| 4 | +import 'package:flutter_gen/gen_l10n/zulip_localizations.dart'; |
4 | 5 | import 'package:flutter_test/flutter_test.dart';
|
5 | 6 | import 'package:http/http.dart' as http;
|
| 7 | +import 'package:url_launcher/url_launcher.dart'; |
| 8 | + |
6 | 9 | import 'package:zulip/api/model/web_auth.dart';
|
7 | 10 | import 'package:zulip/api/route/account.dart';
|
8 | 11 | import 'package:zulip/api/route/realm.dart';
|
@@ -218,4 +221,41 @@ void main() {
|
218 | 221 | // WebAuthPayload.realm doesn't match the realm the UI is about
|
219 | 222 | });
|
220 | 223 | });
|
| 224 | + |
| 225 | + group('Server URL Helper Text', () { |
| 226 | + Future<void> prepareAddAccountPage(WidgetTester tester) async { |
| 227 | + await tester.pumpWidget(const MaterialApp( |
| 228 | + localizationsDelegates: ZulipLocalizations.localizationsDelegates, |
| 229 | + supportedLocales: ZulipLocalizations.supportedLocales, |
| 230 | + home: AddAccountPage(), |
| 231 | + )); |
| 232 | + } |
| 233 | + |
| 234 | + final zulipLocalizations = GlobalLocalizations.zulipLocalizations; |
| 235 | + |
| 236 | + Future<Finder> findHelperText(WidgetTester tester) async { |
| 237 | + return find.text(zulipLocalizations.serverUrlDocLinkLabel); |
| 238 | + } |
| 239 | + |
| 240 | + testWidgets('launches URL when helper text is tapped', (tester) async { |
| 241 | + await prepareAddAccountPage(tester); |
| 242 | + final helper = await findHelperText(tester); |
| 243 | + await tester.tap(helper); |
| 244 | + |
| 245 | + check(testBinding.takeLaunchUrlCalls()) |
| 246 | + .single.equals((url: Uri.parse(AddAccountPage.serverUrlHelpUrl), mode: LaunchMode.platformDefault)); |
| 247 | + }); |
| 248 | + |
| 249 | + testWidgets('shows error dialog when URL fails to open', (tester) async { |
| 250 | + await prepareAddAccountPage(tester); |
| 251 | + testBinding.launchUrlResult = false; |
| 252 | + final helper = await findHelperText(tester); |
| 253 | + await tester.tap(helper); |
| 254 | + await tester.pump(); |
| 255 | + |
| 256 | + checkErrorDialog(tester, |
| 257 | + expectedTitle: zulipLocalizations.errorUnableToOpenLinkTitle, |
| 258 | + expectedMessage: zulipLocalizations.errorLinkCouldNotBeOpened(AddAccountPage.serverUrlHelpUrl)); |
| 259 | + }); |
| 260 | + }); |
221 | 261 | }
|
0 commit comments