Skip to content

Commit

Permalink
feat: bootstrap router parameter (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
damian-molinski authored Dec 17, 2024
1 parent b4bec98 commit 9c1cb0e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
12 changes: 9 additions & 3 deletions catalyst_voices/apps/voices/integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:catalyst_voices/configs/bootstrap.dart';
import 'package:catalyst_voices/routes/routes.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:integration_test/integration_test.dart';
import 'package:patrol_finders/patrol_finders.dart';

Expand All @@ -11,12 +12,17 @@ import 'pageobject/spaces_drawer_page.dart';

void main() async {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
late final GoRouter router;

setUpAll(() async {
router = buildAppRouter(initialLocation: const DiscoveryRoute().location);

await bootstrap(router: router);
});

patrolWidgetTest('Spaces drawer guest menu renders correctly',
(PatrolTester $) async {
final args =
await bootstrap(initialLocation: const DiscoveryRoute().location);
await $.pumpWidgetAndSettle(App(routerConfig: args.routerConfig));
await $.pumpWidgetAndSettle(App(routerConfig: router));
await $(DashboardPage.guestShortcutBtn).tap();
await $.pumpAndSettle();
await Future<void>.delayed(const Duration(seconds: 5));
Expand Down
22 changes: 15 additions & 7 deletions catalyst_voices/apps/voices/lib/configs/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,27 @@ Future<void> _doBootstrapAndRun(BootstrapWidgetBuilder builder) async {
await _runApp(app);
}

GoRouter buildAppRouter({
String? initialLocation,
}) {
return AppRouter.init(
initialLocation: initialLocation,
guards: const [
MilestoneGuard(),
],
);
}

/// Initializes the application before it can be run. Should setup all
/// the things which are necessary before the actual app is run,
/// either via [runApp] or injected into a test environment during
/// integration tests.
///
/// Initialization logic that is relevant for [runApp] scenario
/// only should be added to [_doBootstrapAndRun], not here.
Future<BootstrapArgs> bootstrap({String? initialLocation}) async {
Future<BootstrapArgs> bootstrap({
GoRouter? router,
}) async {
_loggingService
..level = kDebugMode ? Level.FINER : Level.OFF
..printLogs = kDebugMode;
Expand All @@ -94,12 +107,7 @@ Future<BootstrapArgs> bootstrap({String? initialLocation}) async {
// Key derivation needs to be initialized before it can be used
await CatalystKeyDerivation.init();

final router = AppRouter.init(
initialLocation: initialLocation,
guards: const [
MilestoneGuard(),
],
);
router ??= buildAppRouter();

Bloc.observer = AppBlocObserver();

Expand Down

0 comments on commit 9c1cb0e

Please sign in to comment.