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