Skip to content

Commit 127239b

Browse files
committed
home test [nfc]: Extract helpers to be shared
Signed-off-by: Zixuan James Li <[email protected]>
1 parent ae7939a commit 127239b

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

test/widgets/home_test.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ void main () {
4949
await tester.pump();
5050
}
5151

52+
void checkOnLoadingPage() {
53+
check(find.byType(CircularProgressIndicator).hitTestable()).findsOne();
54+
check(find.byType(ChooseAccountPage)).findsNothing();
55+
check(find.byType(HomePage)).findsNothing();
56+
}
57+
58+
ModalRoute<void>? getRouteOf(WidgetTester tester, Finder finder) =>
59+
ModalRoute.of(tester.element(finder));
60+
61+
void checkOnHomePage(WidgetTester tester, {required Account expectedAccount}) {
62+
check(find.byType(CircularProgressIndicator)).findsNothing();
63+
check(find.byType(ChooseAccountPage)).findsNothing();
64+
check(find.byType(HomePage).hitTestable()).findsOne();
65+
check(getRouteOf(tester, find.byType(HomePage)))
66+
.isA<MaterialAccountWidgetRoute>().accountId.equals(expectedAccount.id);
67+
}
68+
5269
group('bottom nav navigation', () {
5370
testWidgets('preserve states when switching between views', (tester) async {
5471
await prepare(tester);
@@ -255,30 +272,13 @@ void main () {
255272
const loadPerAccountDuration = Duration(seconds: 30);
256273
assert(loadPerAccountDuration > kTryAnotherAccountWaitPeriod);
257274

258-
void checkOnLoadingPage() {
259-
check(find.byType(CircularProgressIndicator).hitTestable()).findsOne();
260-
check(find.byType(ChooseAccountPage)).findsNothing();
261-
check(find.byType(HomePage)).findsNothing();
262-
}
263-
264275
void checkOnChooseAccountPage() {
265276
// Ignore the possible loading page in the background.
266277
check(find.byType(CircularProgressIndicator).hitTestable()).findsNothing();
267278
check(find.byType(ChooseAccountPage)).findsOne();
268279
check(find.byType(HomePage)).findsNothing();
269280
}
270281

271-
ModalRoute<void>? getRouteOf(WidgetTester tester, Finder finder) =>
272-
ModalRoute.of(tester.element(finder));
273-
274-
void checkOnHomePage(WidgetTester tester, {required Account expectedAccount}) {
275-
check(find.byType(CircularProgressIndicator)).findsNothing();
276-
check(find.byType(ChooseAccountPage)).findsNothing();
277-
check(find.byType(HomePage).hitTestable()).findsOne();
278-
check(getRouteOf(tester, find.byType(HomePage)))
279-
.isA<MaterialAccountWidgetRoute>().accountId.equals(expectedAccount.id);
280-
}
281-
282282
Future<void> prepare(WidgetTester tester) async {
283283
addTearDown(testBinding.reset);
284284
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());

0 commit comments

Comments
 (0)