Skip to content

Commit 8a52974

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 56ff4cc commit 8a52974

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

lib/widgets/actions.dart

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class ChooseAccountPage extends StatelessWidget {
261261
actionButtonText: zulipLocalizations.logOutConfirmationDialogConfirmButton,
262262
onActionButtonPress: () {
263263
// TODO error handling if db write fails?
264-
logOutAccount(context, accountId);
264+
logOutAccount(GlobalStoreWidget.of(context), accountId);
265265
});
266266
},
267267
child: Text(zulipLocalizations.chooseAccountPageLogOutButton)),

test/widgets/actions_test.dart

Lines changed: 4 additions & 3 deletions
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;
@@ -106,7 +107,7 @@ void main() {
106107
final newConnection = separateConnection()
107108
..prepare(delay: unregisterDelay, json: {'msg': '', 'result': 'success'});
108109

109-
final future = logOutAccount(context, eg.selfAccount.id);
110+
final future = logOutAccount(GlobalStoreWidget.of(context), eg.selfAccount.id);
110111
// Unregister-token request and account removal dispatched together
111112
checkSingleUnregisterRequest(newConnection);
112113
check(testBinding.globalStore.takeDoRemoveAccountCalls())
@@ -138,7 +139,7 @@ void main() {
138139
final newConnection = separateConnection()
139140
..prepare(delay: unregisterDelay, exception: exception);
140141

141-
final future = logOutAccount(context, eg.selfAccount.id);
142+
final future = logOutAccount(GlobalStoreWidget.of(context), eg.selfAccount.id);
142143
// Unregister-token request and account removal dispatched together
143144
checkSingleUnregisterRequest(newConnection);
144145
check(testBinding.globalStore.takeDoRemoveAccountCalls())
@@ -208,7 +209,7 @@ void main() {
208209
testNavObserver.onRemoved = (route, prevRoute) => removedRoutes.add(route);
209210

210211
final context = tester.element(find.byType(MaterialApp));
211-
final future = logOutAccount(context, account1.id);
212+
final future = logOutAccount(GlobalStoreWidget.of(context), account1.id);
212213
await tester.pump(TestGlobalStore.removeAccountDuration);
213214
await future;
214215
check(removedRoutes).single.identicalTo(account1Route);

test/widgets/home_test.dart

Lines changed: 2 additions & 1 deletion
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

@@ -453,7 +454,7 @@ void main () {
453454
await tester.pump(); // wait for store
454455

455456
final element = tester.element(find.byType(HomePage));
456-
final future = logOutAccount(element, eg.selfAccount.id);
457+
final future = logOutAccount(GlobalStoreWidget.of(element), eg.selfAccount.id);
457458
await tester.pump(TestGlobalStore.removeAccountDuration);
458459
await future;
459460
// No error expected from [_LoadingPlaceholderPage] briefly not having

0 commit comments

Comments
 (0)