|
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';
|
@@ -61,7 +64,48 @@ void main() {
|
61 | 64 | expectErrorFromText( '[email protected]', ServerUrlValidationError.noUseEmail);
|
62 | 65 | });
|
63 | 66 |
|
64 |
| - // TODO test AddAccountPage |
| 67 | + group('AddAccountPage Server URL Helper Text', () { |
| 68 | + Future<void> prepareAddAccountPage(WidgetTester tester) async { |
| 69 | + await tester.pumpWidget(const MaterialApp( |
| 70 | + localizationsDelegates: ZulipLocalizations.localizationsDelegates, |
| 71 | + supportedLocales: ZulipLocalizations.supportedLocales, |
| 72 | + home: AddAccountPage(), |
| 73 | + )); |
| 74 | + } |
| 75 | + |
| 76 | + final zulipLocalizations = GlobalLocalizations.zulipLocalizations; |
| 77 | + |
| 78 | + Future<Finder> findHelperText(WidgetTester tester) async { |
| 79 | + return find.text(zulipLocalizations.serverUrlDocLinkLabel); |
| 80 | + } |
| 81 | + |
| 82 | + testWidgets('launches URL when helper text is tapped', (tester) async { |
| 83 | + await prepareAddAccountPage(tester); |
| 84 | + final helper = await findHelperText(tester); |
| 85 | + await tester.tap(helper); |
| 86 | + |
| 87 | + check(testBinding.takeLaunchUrlCalls()).single.equals(( |
| 88 | + url: AddAccountPage.serverUrlHelpUrl, |
| 89 | + mode: LaunchMode.platformDefault, |
| 90 | + )); |
| 91 | + }); |
| 92 | + |
| 93 | + testWidgets('shows error dialog when URL fails to open', (tester) async { |
| 94 | + await prepareAddAccountPage(tester); |
| 95 | + testBinding.launchUrlResult = false; |
| 96 | + final helper = await findHelperText(tester); |
| 97 | + await tester.tap(helper); |
| 98 | + await tester.pump(); |
| 99 | + |
| 100 | + await tester.tap(find.byWidget(checkErrorDialog( |
| 101 | + tester, |
| 102 | + expectedTitle: zulipLocalizations.errorUnableToOpenLinkTitle, |
| 103 | + expectedMessage: zulipLocalizations.errorUnableToOpenLinkMessage( |
| 104 | + AddAccountPage.serverUrlHelpUrl.toString(), |
| 105 | + ), |
| 106 | + ))); |
| 107 | + }); |
| 108 | + }); |
65 | 109 |
|
66 | 110 | group('LoginPage', () {
|
67 | 111 | late FakeApiConnection connection;
|
|
0 commit comments