From 78d24929aa3802fdfee413cf98a379b6c1678f08 Mon Sep 17 00:00:00 2001 From: Damian Molinski Date: Fri, 17 Jan 2025 10:30:35 +0100 Subject: [PATCH] test: SessionCubit can create account test group --- .../test/session/session_cubit_test.dart | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/catalyst_voices/packages/internal/catalyst_voices_blocs/test/session/session_cubit_test.dart b/catalyst_voices/packages/internal/catalyst_voices_blocs/test/session/session_cubit_test.dart index 61d7c824fd5..c7d1d1f15af 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_blocs/test/session/session_cubit_test.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_blocs/test/session/session_cubit_test.dart @@ -57,6 +57,11 @@ void main() { // each test might emit using this cubit, therefore we reset it here adminToolsCubit = AdminToolsCubit(); + // restart list of wallets to default one found. + (registrationService as _MockRegistrationService).cardanoWallets = [ + _MockCardanoWallet(), + ]; + sessionCubit = SessionCubit( userService, registrationService, @@ -77,6 +82,8 @@ void main() { await const FlutterSecureStorage().deleteAll(); await SharedPreferencesAsync().clear(); + notifier.value = const RegistrationProgress(); + reset(registrationService); }); @@ -213,6 +220,68 @@ void main() { expect(sessionCubit.state, isA()); }); + + group('can create account', () { + test('is disabled when no cardano wallets are found', () async { + // Given + const cardanoWallets = []; + const expectedState = VisitorSessionState( + isRegistrationInProgress: false, + canCreateAccount: false, + ); + final mockedService = (registrationService as _MockRegistrationService); + + // When + + // ignore: cascade_invocations + mockedService.cardanoWallets = cardanoWallets; + + sessionCubit = SessionCubit( + userService, + registrationService, + notifier, + accessControl, + adminToolsCubit, + ); + + // Gives time for stream to emit. + await Future.delayed(const Duration(milliseconds: 100)); + + // Then + expect(sessionCubit.state, expectedState); + }); + + test('is enabled when at least one cardano wallets is found', () async { + // Given + final cardanoWallets = [ + _MockCardanoWallet(), + ]; + const expectedState = VisitorSessionState( + isRegistrationInProgress: false, + canCreateAccount: true, + ); + final mockedService = (registrationService as _MockRegistrationService); + + // When + + // ignore: cascade_invocations + mockedService.cardanoWallets = cardanoWallets; + + sessionCubit = SessionCubit( + userService, + registrationService, + notifier, + accessControl, + adminToolsCubit, + ); + + // Gives time for stream to emit. + await Future.delayed(const Duration(milliseconds: 100)); + + // Then + expect(sessionCubit.state, expectedState); + }); + }); }); }