Skip to content

Commit ee1993f

Browse files
login: Store realmName and realmIcon while creating account
1 parent afbb80f commit ee1993f

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

lib/widgets/login.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ class _LoginPageState extends State<LoginPage> {
406406
try {
407407
accountId = await globalStore.insertAccount(AccountsCompanion.insert(
408408
realmUrl: realmUrl,
409+
// TODO store the updated value from /register
410+
realmName: Value(widget.serverSettings.realmName),
411+
// TODO store the updated value from /register
412+
realmIcon: Value(widget.serverSettings.realmIcon),
409413
email: email,
410414
apiKey: apiKey,
411415
userId: userId,

test/widgets/login_test.dart

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'dart:async';
22

33
import 'package:checks/checks.dart';
4-
import 'package:drift/drift.dart';
54
import 'package:flutter/material.dart';
65
import 'package:flutter/services.dart';
76
import 'package:flutter_test/flutter_test.dart';
@@ -11,8 +10,8 @@ import 'package:zulip/api/model/web_auth.dart';
1110
import 'package:zulip/api/route/account.dart';
1211
import 'package:zulip/api/route/realm.dart';
1312
import 'package:zulip/model/binding.dart';
14-
import 'package:zulip/model/database.dart';
1513
import 'package:zulip/model/localizations.dart';
14+
import 'package:zulip/model/store.dart';
1615
import 'package:zulip/widgets/app.dart';
1716
import 'package:zulip/widgets/home.dart';
1817
import 'package:zulip/widgets/login.dart';
@@ -258,11 +257,7 @@ void main() {
258257
await login(tester, eg.selfAccount);
259258
check(testBinding.globalStore.accounts).single
260259
.equals(eg.selfAccount.copyWith(
261-
id: testBinding.globalStore.accounts.single.id,
262-
// TODO store value from server settings during login flow
263-
realmName: Value(null),
264-
// TODO store value from server settings during login flow
265-
realmIcon: Value(null)));
260+
id: testBinding.globalStore.accounts.single.id));
266261
});
267262

268263
testWidgets('logging into a second account', (tester) async {
@@ -279,12 +274,7 @@ void main() {
279274
await login(tester, eg.otherAccount);
280275
final newAccount = testBinding.globalStore.accounts.singleWhere(
281276
(account) => account != eg.selfAccount);
282-
check(newAccount).equals(eg.otherAccount.copyWith(
283-
id: newAccount.id,
284-
// TODO store value from server settings during login flow
285-
realmName: Value(null),
286-
// TODO store value from server settings during login flow
287-
realmIcon: Value(null)));
277+
check(newAccount).equals(eg.otherAccount.copyWith(id: newAccount.id));
288278
check(poppedRoutes).length.equals(2);
289279
check(pushedRoutes).single.isA<WidgetRoute>().page.isA<HomePage>();
290280
});
@@ -309,11 +299,7 @@ void main() {
309299
await tester.idle();
310300
check(testBinding.globalStore.accounts).single
311301
.equals(eg.selfAccount.copyWith(
312-
id: testBinding.globalStore.accounts.single.id,
313-
// TODO store value from server settings during login flow
314-
realmName: Value(null),
315-
// TODO store value from server settings during login flow
316-
realmIcon: Value(null)));
302+
id: testBinding.globalStore.accounts.single.id));
317303
});
318304

319305
testWidgets('account already exists', (tester) async {
@@ -340,6 +326,30 @@ void main() {
340326
expectedTitle: zulipLocalizations.errorAccountLoggedInTitle)));
341327
});
342328

329+
testWidgets('creates account with data from server settings', (tester) async {
330+
final serverSettings = eg.serverSettings(
331+
realmName: 'Some organization',
332+
realmIcon: Uri.parse('/some-image.png'),
333+
zulipFeatureLevel: 427,
334+
zulipVersion: '12.0-dev-524-ga557b1e721',
335+
zulipMergeBase: '12.0-dev-523-g72e3b94855',
336+
);
337+
await prepare(tester, serverSettings);
338+
takeStartingRoutes();
339+
check(pushedRoutes).isEmpty();
340+
check(testBinding.globalStore.accounts).isEmpty();
341+
342+
await login(tester, eg.selfAccount);
343+
check(testBinding.globalStore.accounts).single
344+
.equals(eg.selfAccount.copyWith(
345+
id: testBinding.globalStore.accounts.single.id,
346+
realmName: Value('Some organization'),
347+
realmIcon: Value(Uri.parse('/some-image.png')),
348+
zulipFeatureLevel: 427,
349+
zulipVersion: '12.0-dev-524-ga557b1e721',
350+
zulipMergeBase: Value('12.0-dev-523-g72e3b94855')));
351+
});
352+
343353
// TODO test validators on the TextFormField widgets
344354
// TODO test _getUserId case
345355
// TODO test handling failure in fetchApiKey request
@@ -390,12 +400,7 @@ void main() {
390400
check(testBinding.takeCloseInAppWebViewCallCount()).equals(1);
391401

392402
final account = testBinding.globalStore.accounts.single;
393-
check(account).equals(eg.selfAccount.copyWith(
394-
id: account.id,
395-
// TODO store value from server settings during login flow
396-
realmName: Value(null),
397-
// TODO store value from server settings during login flow
398-
realmIcon: Value(null)));
403+
check(account).equals(eg.selfAccount.copyWith(id: account.id));
399404
check(pushedRoutes).single.isA<MaterialAccountWidgetRoute>()
400405
..accountId.equals(account.id)
401406
..page.isA<HomePage>();

0 commit comments

Comments
 (0)