-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
213 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:altme/app/app.dart'; | ||
import 'package:altme/onboarding/cubit/onboarding_cubit.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('OnboardingState', () { | ||
test('can be instantiated from JSON', () { | ||
final json = {'status': 'init'}; | ||
|
||
final onboardingState = OnboardingState.fromJson(json); | ||
|
||
expect(onboardingState.status, AppStatus.init); | ||
}); | ||
|
||
test('can be converted to JSON', () { | ||
const onboardingState = OnboardingState(status: AppStatus.init); | ||
final json = onboardingState.toJson(); | ||
|
||
expect(json, {'status': 'init'}); | ||
}); | ||
}); | ||
} |
63 changes: 0 additions & 63 deletions
63
test/onboarding/gen_phrase/cubit/onboarding_gen_phrase_cubit_test.dart
This file was deleted.
Oops, something went wrong.
190 changes: 190 additions & 0 deletions
190
test/onboarding/gen_phrase/view/onboarding_gen_phrase_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
import 'package:altme/app/app.dart'; | ||
import 'package:altme/chat_room/chat_room.dart'; | ||
import 'package:altme/dashboard/dashboard.dart'; | ||
import 'package:altme/onboarding/onboarding.dart'; | ||
import 'package:altme/splash/splash.dart'; | ||
import 'package:altme/wallet/wallet.dart'; | ||
import 'package:bloc_test/bloc_test.dart'; | ||
import 'package:did_kit/did_kit.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:key_generator/key_generator.dart'; | ||
import 'package:mockingjay/mockingjay.dart'; | ||
import 'package:secure_storage/secure_storage.dart'; | ||
|
||
import '../../../helpers/helpers.dart'; | ||
|
||
class MockSecureStorage extends Mock implements SecureStorageProvider {} | ||
|
||
class MockDIDKitProvider extends Mock implements DIDKitProvider {} | ||
|
||
class MockKeyGenerator extends Mock implements KeyGenerator {} | ||
|
||
class MockHomeCubit extends MockCubit<HomeState> implements HomeCubit { | ||
@override | ||
Future<void> emitHasWallet() async {} | ||
} | ||
|
||
class MockWalletCubit extends MockCubit<WalletState> implements WalletCubit { | ||
@override | ||
final state = WalletState( | ||
cryptoAccount: CryptoAccount( | ||
data: [ | ||
CryptoAccountData( | ||
name: '', | ||
secretKey: '', | ||
blockchainType: BlockchainType.tezos, | ||
walletAddress: '', | ||
), | ||
], | ||
), | ||
); | ||
|
||
@override | ||
Future<void> createCryptoWallet({ | ||
String? accountName, | ||
required String mnemonicOrKey, | ||
required bool isImported, | ||
required bool isFromOnboarding, | ||
BlockchainType? blockchainType, | ||
bool showStatus = true, | ||
void Function({ | ||
required CryptoAccount cryptoAccount, | ||
required MessageHandler messageHandler, | ||
})? onComplete, | ||
}) async {} | ||
} | ||
|
||
class MockSplashCubit extends MockCubit<SplashState> implements SplashCubit {} | ||
|
||
class MockAltmeChatSupportCubit extends MockCubit<ChatRoomState> | ||
implements AltmeChatSupportCubit {} | ||
|
||
class MockProfileCubit extends MockCubit<ProfileState> implements ProfileCubit { | ||
@override | ||
final state = ProfileState(model: ProfileModel.empty()); | ||
} | ||
|
||
void main() { | ||
late SecureStorageProvider mockSecureStorage; | ||
late DIDKitProvider didKitProvider; | ||
late KeyGenerator keyGenerator; | ||
late HomeCubit homeCubit; | ||
late WalletCubit walletCubit; | ||
late SplashCubit splashCubit; | ||
late AltmeChatSupportCubit altmeChatSupportCubit; | ||
late ProfileCubit profileCubit; | ||
|
||
setUpAll(() { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
mockSecureStorage = MockSecureStorage(); | ||
didKitProvider = MockDIDKitProvider(); | ||
keyGenerator = MockKeyGenerator(); | ||
homeCubit = MockHomeCubit(); | ||
splashCubit = MockSplashCubit(); | ||
walletCubit = MockWalletCubit(); | ||
altmeChatSupportCubit = MockAltmeChatSupportCubit(); | ||
profileCubit = MockProfileCubit(); | ||
|
||
when(() => mockSecureStorage.set(any(), any())).thenAnswer((_) async {}); | ||
when(() => mockSecureStorage.get(any())).thenAnswer((_) async {}); | ||
}); | ||
|
||
group('OnBoarding GenPhrase Page', () { | ||
late OnBoardingGenPhraseCubit onBoardingGenPhraseCubit; | ||
|
||
late MockNavigator navigator; | ||
|
||
setUpAll(() { | ||
onBoardingGenPhraseCubit = OnBoardingGenPhraseCubit( | ||
secureStorageProvider: mockSecureStorage, | ||
didKitProvider: didKitProvider, | ||
keyGenerator: keyGenerator, | ||
homeCubit: homeCubit, | ||
walletCubit: walletCubit, | ||
splashCubit: splashCubit, | ||
altmeChatSupportCubit: altmeChatSupportCubit, | ||
profileCubit: profileCubit, | ||
); | ||
navigator = MockNavigator(); | ||
when(navigator.canPop).thenReturn(true); | ||
|
||
when(() => navigator.push<void>(any())).thenAnswer((_) async {}); | ||
}); | ||
|
||
testWidgets('is routable', (tester) async { | ||
await tester.pumpApp( | ||
MockNavigatorProvider( | ||
navigator: navigator, | ||
child: Builder( | ||
builder: (context) => Scaffold( | ||
floatingActionButton: FloatingActionButton( | ||
onPressed: () { | ||
Navigator.of(context) | ||
.push<void>(OnBoardingVerifyPhrasePage.route( | ||
isFromOnboarding: true, | ||
mnemonic: [], | ||
)); | ||
}, | ||
), | ||
), | ||
), | ||
), | ||
); | ||
await tester.tap(find.byType(FloatingActionButton)); | ||
await tester.pumpAndSettle(); | ||
|
||
verify( | ||
() => navigator.push<void>( | ||
any( | ||
that: isRoute<void>( | ||
whereName: equals('/OnBoardingVerifyPhrasePage'), | ||
), | ||
), | ||
), | ||
).called(1); | ||
}); | ||
|
||
testWidgets('renders UI correctly', (tester) async { | ||
await tester.pumpApp( | ||
BlocProvider.value( | ||
value: onBoardingGenPhraseCubit, | ||
child: const OnBoardingGenPhraseView(), | ||
), | ||
); | ||
|
||
expect(find.byType(BasePage), findsOneWidget); | ||
expect(find.byType(MStepper), findsOneWidget); | ||
expect(find.byType(MnemonicDisplay), findsOneWidget); | ||
expect(find.byType(MyElevatedButton), findsOneWidget); | ||
expect(find.byType(MyGradientButton), findsOneWidget); | ||
}); | ||
|
||
testWidgets( | ||
'navigates to OnBoardingVerifyPhrasePage when Verify Now button' | ||
' is tapped', (tester) async { | ||
await tester.pumpApp( | ||
MockNavigatorProvider( | ||
navigator: navigator, | ||
child: BlocProvider.value( | ||
value: onBoardingGenPhraseCubit, | ||
child: const OnBoardingGenPhraseView(), | ||
), | ||
), | ||
); | ||
|
||
await tester.tap(find.text('Verify Now'.toUpperCase())); | ||
|
||
verify( | ||
() => navigator.push<void>( | ||
any( | ||
that: isRoute<void>( | ||
whereName: equals('/OnBoardingVerifyPhrasePage'), | ||
), | ||
), | ||
), | ||
).called(1); | ||
}); | ||
}); | ||
} |