|
1 | 1 | import 'package:checks/checks.dart'; |
2 | | -import 'package:flutter/widgets.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:flutter_gen/gen_l10n/zulip_localizations.dart'; |
3 | 4 | import 'package:flutter_test/flutter_test.dart'; |
| 5 | +import 'package:zulip/model/database.dart'; |
4 | 6 | import 'package:zulip/widgets/app.dart'; |
5 | 7 | import 'package:zulip/widgets/inbox.dart'; |
6 | 8 | import 'package:zulip/widgets/page.dart'; |
| 9 | +import 'package:zulip/widgets/store.dart'; |
7 | 10 |
|
8 | 11 | import '../example_data.dart' as eg; |
9 | 12 | import '../model/binding.dart'; |
@@ -51,4 +54,56 @@ void main() { |
51 | 54 | ]); |
52 | 55 | }); |
53 | 56 | }); |
| 57 | + |
| 58 | + group('choose account page', () { |
| 59 | + Future<void> setupChooseAccountPage(WidgetTester tester, { |
| 60 | + List<Account>? accounts, |
| 61 | + }) async { |
| 62 | + addTearDown(testBinding.reset); |
| 63 | + |
| 64 | + for (final account in accounts ?? []) { |
| 65 | + await testBinding.globalStore |
| 66 | + .insertAccount(account.toCompanion(false)); |
| 67 | + } |
| 68 | + |
| 69 | + await tester.pumpWidget( |
| 70 | + const MaterialApp( |
| 71 | + localizationsDelegates: ZulipLocalizations.localizationsDelegates, |
| 72 | + supportedLocales: ZulipLocalizations.supportedLocales, |
| 73 | + home: GlobalStoreWidget( |
| 74 | + child: ChooseAccountPage()))); |
| 75 | + |
| 76 | + // global store gets loaded |
| 77 | + await tester.pumpAndSettle(); |
| 78 | + } |
| 79 | + |
| 80 | + List<Account> dummyAccounts(int count) { |
| 81 | + return List.generate(count, (i) => eg.account( |
| 82 | + id: i, |
| 83 | + user: eg.user(fullName: 'User $i', email: 'user$i@example'), |
| 84 | + apiKey: 'user${i}apikey', |
| 85 | + )); |
| 86 | + } |
| 87 | + |
| 88 | + Finder findAccount(Account account) => find.text(account.email).hitTestable(); |
| 89 | + |
| 90 | + void checkAccountShown(Account account, {required bool expected}) { |
| 91 | + check(findAccount(account).evaluate().length).equals(expected ? 1 : 0); |
| 92 | + } |
| 93 | + |
| 94 | + testWidgets('accounts list is scrollable when more than a screenful', (tester) async { |
| 95 | + final accounts = dummyAccounts(15); |
| 96 | + await setupChooseAccountPage(tester, accounts: accounts); |
| 97 | + |
| 98 | + // Accounts list is more than a screenful |
| 99 | + // * First account is shown |
| 100 | + // * Last account is out of view |
| 101 | + checkAccountShown(accounts.first, expected: true); |
| 102 | + checkAccountShown(accounts.last, expected: false); |
| 103 | + |
| 104 | + // Accounts list is scrollable to the bottom |
| 105 | + await tester.scrollUntilVisible(findAccount(accounts.last), 50); |
| 106 | + checkAccountShown(accounts.last, expected: true); |
| 107 | + }); |
| 108 | + }); |
54 | 109 | } |
0 commit comments