Skip to content

Commit f6655b8

Browse files
PIG208gnprice
authored andcommitted
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 1e8397b commit f6655b8

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
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
@@ -265,7 +265,7 @@ class ChooseAccountPage extends StatelessWidget {
265265
actionButtonText: zulipLocalizations.logOutConfirmationDialogConfirmButton,
266266
onActionButtonPress: () {
267267
// TODO error handling if db write fails?
268-
logOutAccount(context, accountId);
268+
logOutAccount(GlobalStoreWidget.of(context), accountId);
269269
});
270270
},
271271
child: Text(zulipLocalizations.chooseAccountPageLogOutButton)),

test/widgets/actions_test.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void main() {
109109
final newConnection = separateConnection()
110110
..prepare(delay: unregisterDelay, json: {'msg': '', 'result': 'success'});
111111

112-
final future = logOutAccount(context, eg.selfAccount.id);
112+
final future = logOutAccount(testBinding.globalStore, eg.selfAccount.id);
113113
// Unregister-token request and account removal dispatched together
114114
checkSingleUnregisterRequest(newConnection);
115115
check(testBinding.globalStore.takeDoRemoveAccountCalls())
@@ -141,7 +141,7 @@ void main() {
141141
final newConnection = separateConnection()
142142
..prepare(delay: unregisterDelay, exception: exception);
143143

144-
final future = logOutAccount(context, eg.selfAccount.id);
144+
final future = logOutAccount(testBinding.globalStore, eg.selfAccount.id);
145145
// Unregister-token request and account removal dispatched together
146146
checkSingleUnregisterRequest(newConnection);
147147
check(testBinding.globalStore.takeDoRemoveAccountCalls())
@@ -210,8 +210,7 @@ void main() {
210210
final removedRoutes = <Route<dynamic>>[];
211211
testNavObserver.onRemoved = (route, prevRoute) => removedRoutes.add(route);
212212

213-
final context = tester.element(find.byType(MaterialApp));
214-
final future = logOutAccount(context, account1.id);
213+
final future = logOutAccount(testBinding.globalStore, account1.id);
215214
await tester.pump(TestGlobalStore.removeAccountDuration);
216215
await future;
217216
check(removedRoutes).single.identicalTo(account1Route);

test/widgets/home_test.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,7 @@ void main () {
453453
await tester.pump(); // wait for the loading page
454454
checkOnLoadingPage();
455455

456-
final element = tester.element(find.byType(MaterialApp));
457-
final future = logOutAccount(element, eg.selfAccount.id);
456+
final future = logOutAccount(testBinding.globalStore, eg.selfAccount.id);
458457
await tester.pump(TestGlobalStore.removeAccountDuration);
459458
await future;
460459
// No error expected from briefly not having
@@ -471,8 +470,7 @@ void main () {
471470
await tester.pump(); // wait for store
472471
checkOnHomePage(tester, expectedAccount: eg.selfAccount);
473472

474-
final element = tester.element(find.byType(HomePage));
475-
final future = logOutAccount(element, eg.selfAccount.id);
473+
final future = logOutAccount(testBinding.globalStore, eg.selfAccount.id);
476474
await tester.pump(TestGlobalStore.removeAccountDuration);
477475
await future;
478476
// No error expected from briefly not having

0 commit comments

Comments
 (0)