Skip to content

Commit 28c179a

Browse files
committed
login [nfc]: Pass GlobalStore to logOutAccount
This allows us to call it from model code when GlobalStore is available. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 731b44f commit 28c179a

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

lib/widgets/actions.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import '../notifications/receive.dart';
2020
import 'dialog.dart';
2121
import 'store.dart';
2222

23-
Future<void> logOutAccount(BuildContext context, int accountId) async {
24-
final globalStore = GlobalStoreWidget.of(context);
25-
23+
Future<void> logOutAccount(GlobalStore globalStore, int accountId) async {
2624
final account = globalStore.getAccount(accountId);
2725
if (account == null) return; // TODO(log)
2826

lib/widgets/app.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class ChooseAccountPage extends StatelessWidget {
249249
actionButtonText: zulipLocalizations.logOutConfirmationDialogConfirmButton,
250250
onActionButtonPress: () {
251251
// TODO error handling if db write fails?
252-
logOutAccount(context, accountId);
252+
logOutAccount(GlobalStoreWidget.of(context), accountId);
253253
});
254254
},
255255
child: Text(zulipLocalizations.chooseAccountPageLogOutButton)),

test/widgets/actions_test.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'package:zulip/widgets/actions.dart';
2020
import 'package:zulip/widgets/app.dart';
2121
import 'package:zulip/widgets/inbox.dart';
2222
import 'package:zulip/widgets/page.dart';
23+
import 'package:zulip/widgets/store.dart';
2324

2425
import '../api/fake_api.dart';
2526
import '../example_data.dart' as eg;
@@ -109,7 +110,7 @@ void main() {
109110
final newConnection = separateConnection()
110111
..prepare(delay: unregisterDelay, json: {'msg': '', 'result': 'success'});
111112

112-
final future = logOutAccount(context, eg.selfAccount.id);
113+
final future = logOutAccount(GlobalStoreWidget.of(context), eg.selfAccount.id);
113114
// Unregister-token request and account removal dispatched together
114115
checkSingleUnregisterRequest(newConnection);
115116
check(testBinding.globalStore.takeDoRemoveAccountCalls())
@@ -141,7 +142,7 @@ void main() {
141142
final newConnection = separateConnection()
142143
..prepare(delay: unregisterDelay, exception: exception);
143144

144-
final future = logOutAccount(context, eg.selfAccount.id);
145+
final future = logOutAccount(GlobalStoreWidget.of(context), eg.selfAccount.id);
145146
// Unregister-token request and account removal dispatched together
146147
checkSingleUnregisterRequest(newConnection);
147148
check(testBinding.globalStore.takeDoRemoveAccountCalls())
@@ -211,7 +212,7 @@ void main() {
211212
testNavObserver.onRemoved = (route, prevRoute) => removedRoutes.add(route);
212213

213214
final context = tester.element(find.byType(MaterialApp));
214-
final future = logOutAccount(context, account1.id);
215+
final future = logOutAccount(GlobalStoreWidget.of(context), account1.id);
215216
await tester.pump(TestGlobalStore.removeAccountDuration);
216217
await future;
217218
check(removedRoutes).single.identicalTo(account1Route);

test/widgets/home_test.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:zulip/widgets/inbox.dart';
1515
import 'package:zulip/widgets/message_list.dart';
1616
import 'package:zulip/widgets/page.dart';
1717
import 'package:zulip/widgets/profile.dart';
18+
import 'package:zulip/widgets/store.dart';
1819
import 'package:zulip/widgets/subscription_list.dart';
1920
import 'package:zulip/widgets/theme.dart';
2021

@@ -454,7 +455,7 @@ void main () {
454455
checkOnLoadingPage();
455456

456457
final element = tester.element(find.byType(MaterialApp));
457-
final future = logOutAccount(element, eg.selfAccount.id);
458+
final future = logOutAccount(GlobalStoreWidget.of(element), eg.selfAccount.id);
458459
await tester.pump(TestGlobalStore.removeAccountDuration);
459460
await future;
460461
// No error expected from briefly not having
@@ -472,7 +473,7 @@ void main () {
472473
checkOnHomePage(tester, expectedAccount: eg.selfAccount);
473474

474475
final element = tester.element(find.byType(HomePage));
475-
final future = logOutAccount(element, eg.selfAccount.id);
476+
final future = logOutAccount(GlobalStoreWidget.of(element), eg.selfAccount.id);
476477
await tester.pump(TestGlobalStore.removeAccountDuration);
477478
await future;
478479
// No error expected from briefly not having

0 commit comments

Comments
 (0)