import 'package:flutter_test/flutter_test.dart'; import 'package:halkyon_learn_flutter/src/app/person_app.dart'; import 'package:halkyon_learn_flutter/src/core/dependencies/dependencies.dart'; import 'package:halkyon_learn_flutter/src/core/dependencies/dependencies_scope.dart'; import 'package:halkyon_learn_flutter/src/core/router/route_paths.dart'; import 'package:halkyon_learn_flutter/src/feature/auth/widget/session_gate.dart'; import 'package:halkyon_learn_flutter/src/feature/studyset/bloc/content_tab_cubit.dart'; import 'package:halkyon_learn_flutter/src/feature/studyset/widget/studyset_parts.dart'; import 'package:material_ui/material_ui.dart'; /// Pumps the whole app as a person starts it, on [dependencies] (usually /// `testDependencies(...)`): signed in, anonymously unless the auth fake says /// otherwise, and opened at [location]. Settles, so that the person's data is /// open and the first screen shows; the app's spinner animates without end, /// so settling needs the fakes to have answered. /// /// Every person's app opens at [location], also after a change of person. Future pumpApp( WidgetTester tester, Dependencies dependencies, { String location = RoutePaths.home, }) async { await tester.pumpWidget( DependenciesScope( dependencies: dependencies, child: SessionGate( app: (person) => PersonApp(person: person, initialLocation: location), ), ), ); await tester.pumpAndSettle(); } /// The tab labelled [label] in the app's navigation, rail or bar. Its label /// alone could also be a screen's title. Finder tab(String label) => find.descendant( of: find.byWidgetPredicate( (widget) => widget is NavigationRail || widget is NavigationBar, ), matching: find.text(label), ); /// Chooses the tab labelled [label] and settles. Future openTab(WidgetTester tester, String label) async { await tester.tap(tab(label)); await tester.pumpAndSettle(); } /// The part of the studyset screen shown. StudysetPart shownPart(WidgetTester tester) => tester.widget(find.byType(StudysetPartSwitch)).current; /// Shows the studyset screen's part [label] ("Material", "Study plan") and /// settles. Future openPart(WidgetTester tester, String label) async { await tester.tap( find.descendant( of: find.byType(StudysetPartSwitch), matching: find.text(label), ), ); await tester.pumpAndSettle(); }