Skip to content

Commit

Permalink
login: Link to doc for what "server URL" is and how to find it
Browse files Browse the repository at this point in the history
- Add informative helper text below the "server URL" field in the login screen.
- When tapped, the helper text opens Zulip documentation explaining server URLs and how to find them.
- Improves user experience during login by providing clear guidance.
- Add i18n for "What's this?" helper text.
- Fixes: #109
  • Loading branch information
VatsalBhesaniya committed Apr 2, 2024
1 parent b715ce3 commit fbbcc13
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
4 changes: 4 additions & 0 deletions assets/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@
"@loginServerUrlInputLabel": {
"description": "Input label in login page for Zulip server URL entry."
},
"serverUrlDocLinkLabel": "What's this?",
"@serverUrlDocLinkLabel": {
"description": "Link to doc to help users understand what a server URL is and how to find theirs."
},
"errorUnableToOpenLinkTitle": "Unable to open link",
"@errorUnableToOpenLinkTitle": {
"description": "Error title when a link fails to open."
Expand Down
13 changes: 11 additions & 2 deletions lib/widgets/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import '../model/store.dart';
import 'app.dart';
import 'dialog.dart';
import 'input.dart';
import 'launch_url.dart';
import 'page.dart';
import 'store.dart';

Expand Down Expand Up @@ -101,6 +102,8 @@ class ServerUrlTextEditingController extends TextEditingController {
class AddAccountPage extends StatefulWidget {
const AddAccountPage({super.key});

static const String serverUrlHelpUrl = 'https://zulip.com/help/logging-in#find-the-zulip-log-in-url';

static Route<void> buildRoute() {
return _LoginSequenceRoute(page: const AddAccountPage());
}
Expand Down Expand Up @@ -207,7 +210,6 @@ class _AddAccountPageState extends State<AddAccountPage> {
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 400),
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
// TODO(#109) Link to doc about what a "server URL" is and how to find it
// TODO(#111) Perhaps give tappable realm URL suggestions based on text typed so far
TextField(
controller: _controller,
Expand All @@ -223,7 +225,14 @@ class _AddAccountPageState extends State<AddAccountPage> {
decoration: InputDecoration(
labelText: zulipLocalizations.loginServerUrlInputLabel,
errorText: errorText,
helperText: kLayoutPinningHelperText,
helper: GestureDetector(
onTap: () {
launchUrlWithoutRealm(context, Uri.parse(AddAccountPage.serverUrlHelpUrl));
},
child: Text(
zulipLocalizations.serverUrlDocLinkLabel,
style: Theme.of(context).textTheme.bodySmall!
.apply(color: const HSLColor.fromAHSL(1, 200, 1, 0.4).toColor()))),
hintText: 'your-org.zulipchat.com')),
const SizedBox(height: 8),
ElevatedButton(
Expand Down
39 changes: 39 additions & 0 deletions test/widgets/login_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart' as http;
import 'package:url_launcher/url_launcher.dart';
import 'package:zulip/api/route/account.dart';
import 'package:zulip/api/route/realm.dart';
import 'package:zulip/model/localizations.dart';
Expand All @@ -13,6 +14,7 @@ import '../api/fake_api.dart';
import '../example_data.dart' as eg;
import '../model/binding.dart';
import '../stdlib_checks.dart';
import 'dialog_checks.dart';

void main() {
TestZulipBinding.ensureInitialized();
Expand Down Expand Up @@ -142,4 +144,41 @@ void main() {
// TODO test handling failure in fetchApiKey request
// TODO test _inProgress logic
});

group('Server URL Helper Text', () {
Future<void> prepareAddAccountPage(WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(
localizationsDelegates: ZulipLocalizations.localizationsDelegates,
supportedLocales: ZulipLocalizations.supportedLocales,
home: AddAccountPage(),
));
}

final zulipLocalizations = GlobalLocalizations.zulipLocalizations;

Future<Finder> findHelperText(WidgetTester tester) async {
return find.text(zulipLocalizations.serverUrlDocLinkLabel);
}

testWidgets('launches URL when helper text is tapped', (tester) async {
await prepareAddAccountPage(tester);
final helper = await findHelperText(tester);
await tester.tap(helper);

check(testBinding.takeLaunchUrlCalls())
.single.equals((url: Uri.parse(AddAccountPage.serverUrlHelpUrl), mode: LaunchMode.platformDefault));
});

testWidgets('shows error dialog when URL fails to open', (tester) async {
await prepareAddAccountPage(tester);
testBinding.launchUrlResult = false;
final helper = await findHelperText(tester);
await tester.tap(helper);
await tester.pump();

checkErrorDialog(tester,
expectedTitle: zulipLocalizations.errorUnableToOpenLinkTitle,
expectedMessage: zulipLocalizations.errorLinkCouldNotBeOpened(AddAccountPage.serverUrlHelpUrl));
});
});
}

0 comments on commit fbbcc13

Please sign in to comment.