Skip to content

Commit af76dc8

Browse files
committed
login test [nfc]: Extract login helper
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 13c2044 commit af76dc8

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

test/widgets/login_test.dart

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:zulip/api/model/web_auth.dart';
99
import 'package:zulip/api/route/account.dart';
1010
import 'package:zulip/api/route/realm.dart';
1111
import 'package:zulip/model/binding.dart';
12+
import 'package:zulip/model/database.dart';
1213
import 'package:zulip/model/localizations.dart';
1314
import 'package:zulip/widgets/app.dart';
1415
import 'package:zulip/widgets/home.dart';
@@ -118,22 +119,26 @@ void main() {
118119
});
119120
}
120121

121-
testWidgets('basic happy case', (tester) async {
122-
final serverSettings = eg.serverSettings();
123-
await prepare(tester, serverSettings);
124-
check(testBinding.globalStore.accounts).isEmpty();
125-
126-
await tester.enterText(findUsernameInput, eg.selfAccount.email);
122+
Future<void> login(WidgetTester tester, Account account) async {
123+
await tester.enterText(findUsernameInput, account.email);
127124
await tester.enterText(findPasswordInput, 'p455w0rd');
128125
testBinding.globalStore.useCachedApiConnections = true;
129126
connection.prepare(json: FetchApiKeyResult(
130-
apiKey: eg.selfAccount.apiKey,
131-
email: eg.selfAccount.email,
132-
userId: eg.selfAccount.userId,
127+
apiKey: account.apiKey,
128+
email: account.email,
129+
userId: account.userId,
133130
).toJson());
134131
await tester.tap(findSubmitButton);
135-
checkFetchApiKey(username: eg.selfAccount.email, password: 'p455w0rd');
132+
checkFetchApiKey(username: account.email, password: 'p455w0rd');
136133
await tester.idle();
134+
}
135+
136+
testWidgets('basic happy case', (tester) async {
137+
final serverSettings = eg.serverSettings();
138+
await prepare(tester, serverSettings);
139+
check(testBinding.globalStore.accounts).isEmpty();
140+
141+
await login(tester, eg.selfAccount);
137142
check(testBinding.globalStore.accounts).single
138143
.equals(eg.selfAccount.copyWith(
139144
id: testBinding.globalStore.accounts.single.id));

0 commit comments

Comments
 (0)