Skip to content

Commit

Permalink
add more onboarding test and routing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed May 30, 2024
1 parent 34fdfd8 commit 062a2a6
Show file tree
Hide file tree
Showing 12 changed files with 1,101 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class KeyVerifiedPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
return const WalletReadyView();
return const KeyVerifiedView();
}
}

class WalletReadyView extends StatelessWidget {
const WalletReadyView({super.key});
class KeyVerifiedView extends StatelessWidget {
const KeyVerifiedView({super.key});

@override
Widget build(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:key_generator/key_generator.dart';

import 'package:secure_storage/secure_storage.dart';

part 'onboarding_verify_phrase_cubit.g.dart';

part 'onboarding_verify_phrase_state.dart';

class OnBoardingVerifyPhraseCubit extends Cubit<OnBoardingVerifyPhraseState> {
OnBoardingVerifyPhraseCubit({
required this.secureStorageProvider,
required this.keyGenerator,
required this.didKitProvider,
required this.homeCubit,
Expand All @@ -29,7 +26,6 @@ class OnBoardingVerifyPhraseCubit extends Cubit<OnBoardingVerifyPhraseState> {
required this.profileCubit,
}) : super(OnBoardingVerifyPhraseState());

final SecureStorageProvider secureStorageProvider;
final KeyGenerator keyGenerator;
final DIDKitProvider didKitProvider;

Expand Down Expand Up @@ -125,7 +121,7 @@ class OnBoardingVerifyPhraseCubit extends Cubit<OnBoardingVerifyPhraseState> {
profileCubit: profileCubit,
);
}
await secureStorageProvider.set(
await profileCubit.secureStorageProvider.set(
SecureStorageKeys.hasVerifiedMnemonics,
'yes',
);
Expand Down
57 changes: 28 additions & 29 deletions lib/onboarding/verify_phrase/view/onboarding_verify_phrase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:did_kit/did_kit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:key_generator/key_generator.dart';
import 'package:secure_storage/secure_storage.dart';

class OnBoardingVerifyPhrasePage extends StatelessWidget {
const OnBoardingVerifyPhrasePage({
Expand Down Expand Up @@ -39,7 +38,6 @@ class OnBoardingVerifyPhrasePage extends StatelessWidget {
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => OnBoardingVerifyPhraseCubit(
secureStorageProvider: getSecureStorage,
didKitProvider: DIDKitProvider(),
keyGenerator: KeyGenerator(),
homeCubit: context.read<HomeCubit>(),
Expand All @@ -52,6 +50,9 @@ class OnBoardingVerifyPhrasePage extends StatelessWidget {
child: OnBoardingVerifyPhraseView(
mnemonic: mnemonic,
isFromOnboarding: isFromOnboarding,
onBoardingVerifyPhraseCubit:
context.read<OnBoardingVerifyPhraseCubit>(),
onboardingCubit: context.read<OnboardingCubit>(),
),
);
}
Expand All @@ -61,11 +62,15 @@ class OnBoardingVerifyPhraseView extends StatefulWidget {
const OnBoardingVerifyPhraseView({
required this.mnemonic,
required this.isFromOnboarding,
required this.onBoardingVerifyPhraseCubit,
required this.onboardingCubit,
super.key,
});

final List<String> mnemonic;
final bool isFromOnboarding;
final OnBoardingVerifyPhraseCubit onBoardingVerifyPhraseCubit;
final OnboardingCubit onboardingCubit;

@override
State<OnBoardingVerifyPhraseView> createState() =>
Expand All @@ -77,7 +82,7 @@ class _OnBoardingVerifyPhraseViewState
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) {
context.read<OnBoardingVerifyPhraseCubit>().orderMnemonics();
widget.onBoardingVerifyPhraseCubit.orderMnemonics();
});
super.initState();
}
Expand Down Expand Up @@ -169,57 +174,54 @@ class _OnBoardingVerifyPhraseViewState
children: <Widget>[
Expanded(
child: PhraseWord(
key: Key(col1Mnemonics.order.toString()),
order: col1Mnemonics.order,
word:
widget.mnemonic[col1Mnemonics.order - 1],
showOrder:
col1Mnemonics.mnemonicStatus.showOrder,
color: col1Mnemonics.mnemonicStatus.color,
onTap: () {
context
.read<OnBoardingVerifyPhraseCubit>()
.verify(
mnemonic: widget.mnemonic,
index: j,
);
widget.onBoardingVerifyPhraseCubit.verify(
mnemonic: widget.mnemonic,
index: j,
);
},
),
),
const SizedBox(width: 12),
Expanded(
child: PhraseWord(
key: Key(col2Mnemonics.order.toString()),
order: col2Mnemonics.order,
word:
widget.mnemonic[col2Mnemonics.order - 1],
showOrder:
col2Mnemonics.mnemonicStatus.showOrder,
color: col2Mnemonics.mnemonicStatus.color,
onTap: () {
context
.read<OnBoardingVerifyPhraseCubit>()
.verify(
mnemonic: widget.mnemonic,
index: j + 1,
);
widget.onBoardingVerifyPhraseCubit.verify(
mnemonic: widget.mnemonic,
index: j + 1,
);
},
),
),
const SizedBox(width: 12),
Expanded(
child: PhraseWord(
key: Key(col3Mnemonics.order.toString()),
order: col3Mnemonics.order,
word:
widget.mnemonic[col3Mnemonics.order - 1],
showOrder:
col3Mnemonics.mnemonicStatus.showOrder,
color: col3Mnemonics.mnemonicStatus.color,
onTap: () {
context
.read<OnBoardingVerifyPhraseCubit>()
.verify(
mnemonic: widget.mnemonic,
index: j + 2,
);
widget.onBoardingVerifyPhraseCubit.verify(
mnemonic: widget.mnemonic,
index: j + 2,
);
},
),
),
Expand All @@ -241,15 +243,12 @@ class _OnBoardingVerifyPhraseViewState
verticalSpacing: 18,
onPressed: state.isVerified
? () async {
await context
.read<OnboardingCubit>()
.emitOnboardingProcessing();
await context
.read<OnBoardingVerifyPhraseCubit>()
await widget.onboardingCubit.emitOnboardingProcessing();
await widget.onBoardingVerifyPhraseCubit
.generateSSIAndCryptoAccount(
mnemonic: widget.mnemonic,
isFromOnboarding: widget.isFromOnboarding,
);
mnemonic: widget.mnemonic,
isFromOnboarding: widget.isFromOnboarding,
);
}
: null,
),
Expand Down
43 changes: 25 additions & 18 deletions lib/onboarding/wallet_ready/view/wallet_ready_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,46 @@ class WalletReadyPage extends StatelessWidget {
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => WalletReadyCubit(),
child: const WalletReadyView(),
child: WalletReadyView(
profileCubit: context.read<ProfileCubit>(),
walletReadyCubit: context.read<WalletReadyCubit>(),
confettiController: ConfettiController(),
),
);
}
}

class WalletReadyView extends StatefulWidget {
const WalletReadyView({super.key});
const WalletReadyView({
super.key,
required this.walletReadyCubit,
required this.profileCubit,
required this.confettiController,
});

final WalletReadyCubit walletReadyCubit;
final ProfileCubit profileCubit;
final ConfettiController confettiController;

@override
State<WalletReadyView> createState() => _WalletReadyViewState();
}

class _WalletReadyViewState extends State<WalletReadyView> {
late final ConfettiController confettiController;

@override
void initState() {
confettiController = ConfettiController();
Future<void>.delayed(Duration.zero).then((value) {
WidgetsBinding.instance.addPostFrameCallback((_) {
context.read<OnboardingCubit>().emitOnboardingDone();

confettiController.play();
widget.confettiController.play();
});

super.initState();
}

@override
void dispose() {
confettiController.stop();
confettiController.dispose();
widget.confettiController.stop();
widget.confettiController.dispose();
super.dispose();
}

Expand All @@ -75,7 +85,7 @@ class _WalletReadyViewState extends State<WalletReadyView> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
WalletLogo(
profileModel: context.read<ProfileCubit>().state.model,
profileModel: widget.profileCubit.state.model,
height: 90,
width: MediaQuery.of(context).size.shortestSide * 0.5,
showPoweredBy: true,
Expand Down Expand Up @@ -134,9 +144,8 @@ class _WalletReadyViewState extends State<WalletReadyView> {
Radius.circular(6),
),
),
onChanged: (newValue) => context
.read<WalletReadyCubit>()
.toggleAgreement(),
onChanged: (newValue) =>
widget.walletReadyCubit.toggleAgreement(),
),
),
Expanded(
Expand All @@ -145,9 +154,7 @@ class _WalletReadyViewState extends State<WalletReadyView> {
children: [
InkWell(
onTap: () {
context
.read<WalletReadyCubit>()
.toggleAgreement();
widget.walletReadyCubit.toggleAgreement();
},
child: MyText(
l10n.iAgreeToThe,
Expand Down Expand Up @@ -210,7 +217,7 @@ class _WalletReadyViewState extends State<WalletReadyView> {
),
),
ConfettiWidget(
confettiController: confettiController,
confettiController: widget.confettiController,
canvas: Size.infinite,
shouldLoop: true,
blastDirectionality: BlastDirectionality.explosive,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:altme/app/app.dart';
import 'package:altme/onboarding/onboarding.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('OnBoardingVerifyPhraseState', () {
test('success method returns a new state with updated status and message',
() {
final state = OnBoardingVerifyPhraseState();
final newState = state.success(messageHandler: ResponseMessage());

expect(newState.status, AppStatus.success);
expect(newState.message, isNotNull);
expect(newState.isVerified, state.isVerified);
expect(newState.mnemonicStates, state.mnemonicStates);
});

test('toJson and fromJson work correctly', () {
final state = OnBoardingVerifyPhraseState(
status: AppStatus.success,
isVerified: true,
);

final json = state.toJson();
final newState = OnBoardingVerifyPhraseState.fromJson(json);

expect(state, newState);
});
});

group('MnemonicState', () {
test('toJson and fromJson work correctly', () {
const mnemonicState = MnemonicState(
mnemonicStatus: MnemonicStatus.selected,
order: 1,
);

final json = mnemonicState.toJson();
final newState = MnemonicState.fromJson(json);

expect(newState, mnemonicState);
});
});
}
Loading

0 comments on commit 062a2a6

Please sign in to comment.