Skip to content

Commit

Permalink
test: SessionCubit can create account test group
Browse files Browse the repository at this point in the history
  • Loading branch information
damian-molinski committed Jan 17, 2025
1 parent 48afb3c commit 78d2492
Showing 1 changed file with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -77,6 +82,8 @@ void main() {
await const FlutterSecureStorage().deleteAll();
await SharedPreferencesAsync().clear();

notifier.value = const RegistrationProgress();

reset(registrationService);
});

Expand Down Expand Up @@ -213,6 +220,68 @@ void main() {

expect(sessionCubit.state, isA<ActiveAccountSessionState>());
});

group('can create account', () {
test('is disabled when no cardano wallets are found', () async {
// Given
const cardanoWallets = <CardanoWallet>[];
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<void>.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 = <CardanoWallet>[
_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<void>.delayed(const Duration(milliseconds: 100));

// Then
expect(sessionCubit.state, expectedState);
});
});
});
}

Expand Down

0 comments on commit 78d2492

Please sign in to comment.