From 9c1cb0e187cb026f357f04065c3e78c1f51e63ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Moli=C5=84ski?= <47773413+damian-molinski@users.noreply.github.com> Date: Tue, 17 Dec 2024 08:23:03 +0100 Subject: [PATCH] feat: bootstrap router parameter (#1401) --- .../voices/integration_test/app_test.dart | 12 +++++++--- .../apps/voices/lib/configs/bootstrap.dart | 22 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/catalyst_voices/apps/voices/integration_test/app_test.dart b/catalyst_voices/apps/voices/integration_test/app_test.dart index 4bf9d3f79eb..fc40b749252 100644 --- a/catalyst_voices/apps/voices/integration_test/app_test.dart +++ b/catalyst_voices/apps/voices/integration_test/app_test.dart @@ -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'; @@ -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.delayed(const Duration(seconds: 5)); diff --git a/catalyst_voices/apps/voices/lib/configs/bootstrap.dart b/catalyst_voices/apps/voices/lib/configs/bootstrap.dart index 7595b62ce39..d75d7fda766 100644 --- a/catalyst_voices/apps/voices/lib/configs/bootstrap.dart +++ b/catalyst_voices/apps/voices/lib/configs/bootstrap.dart @@ -74,6 +74,17 @@ Future _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 @@ -81,7 +92,9 @@ Future _doBootstrapAndRun(BootstrapWidgetBuilder builder) async { /// /// Initialization logic that is relevant for [runApp] scenario /// only should be added to [_doBootstrapAndRun], not here. -Future bootstrap({String? initialLocation}) async { +Future bootstrap({ + GoRouter? router, +}) async { _loggingService ..level = kDebugMode ? Level.FINER : Level.OFF ..printLogs = kDebugMode; @@ -94,12 +107,7 @@ Future 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();