Skip to content

Commit

Permalink
solve app version test of splash cubit
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed May 16, 2024
1 parent ffd39e8 commit 77bc505
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/splash/cubit/splash_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class SplashCubit extends Cubit<SplashState> {
required this.altmeChatSupportCubit,
required this.client,
required this.profileCubit,
this.packageInfo,
}) : super(const SplashState()) {
_getAppVersion();
_getAppVersion(packageInfo);
}

final SecureStorageProvider secureStorageProvider;
Expand All @@ -34,6 +35,7 @@ class SplashCubit extends Cubit<SplashState> {
final AltmeChatSupportCubit altmeChatSupportCubit;
final DioClient client;
final ProfileCubit profileCubit;
final PackageInfo? packageInfo;

Future<void> initialiseApp() async {
double counter = 0;
Expand Down Expand Up @@ -71,8 +73,14 @@ class SplashCubit extends Cubit<SplashState> {
});
}

Future<void> _getAppVersion() async {
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
Future<void> _getAppVersion(PackageInfo? packageInformation) async {
late PackageInfo packageInfo;
if (packageInformation == null) {
packageInfo = await PackageInfo.fromPlatform();
} else {
packageInfo = packageInformation;
}

final String? savedVersion = await secureStorageProvider.get(
SecureStorageKeys.version,
);
Expand Down
22 changes: 22 additions & 0 deletions test/splash/cubit/splash_cubit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:fake_async/fake_async.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:secure_storage/secure_storage.dart';

class MockSecureStorage extends Mock implements SecureStorageProvider {}
Expand Down Expand Up @@ -77,6 +78,13 @@ void main() {
late AltmeChatSupportCubit altmeChatSupportCubit;
late ProfileCubit profileCubit;

final packageInfo = PackageInfo(
appName: 'testApp',
packageName: 'com.example.test',
version: '1.0.0',
buildNumber: '1',
);

setUp(() {
WidgetsFlutterBinding.ensureInitialized();
mockSecureStorage = MockSecureStorage();
Expand All @@ -85,6 +93,15 @@ void main() {
walletCubit = MockWalletCubit();
altmeChatSupportCubit = MockAltmeChatSupportCubit();
profileCubit = MockProfileCubit();

when(() => mockSecureStorage.get(SecureStorageKeys.version))
.thenAnswer((_) async => '1.0.0');
when(() => mockSecureStorage.get(SecureStorageKeys.buildNumber))
.thenAnswer((_) async => '1');
when(() => mockSecureStorage.set(SecureStorageKeys.version, '1.0.0'))
.thenAnswer((_) async => {});
when(() => mockSecureStorage.set(SecureStorageKeys.buildNumber, '1'))
.thenAnswer((_) async => {});
});

group('Splash Cubit', () {
Expand All @@ -102,6 +119,7 @@ void main() {
),
altmeChatSupportCubit: altmeChatSupportCubit,
profileCubit: profileCubit,
packageInfo: packageInfo,
).state,
const SplashState(
status: SplashStatus.init,
Expand All @@ -127,6 +145,7 @@ void main() {
),
altmeChatSupportCubit: altmeChatSupportCubit,
profileCubit: profileCubit,
packageInfo: packageInfo,
);
fakeAsync((async) {
splashCubit.initialiseApp();
Expand Down Expand Up @@ -173,6 +192,7 @@ void main() {
),
altmeChatSupportCubit: altmeChatSupportCubit,
profileCubit: profileCubit,
packageInfo: packageInfo,
);
fakeAsync((async) {
splashCubit.initialiseApp();
Expand Down Expand Up @@ -201,6 +221,7 @@ void main() {
),
altmeChatSupportCubit: altmeChatSupportCubit,
profileCubit: profileCubit,
packageInfo: packageInfo,
);
fakeAsync((async) {
splashCubit.initialiseApp();
Expand Down Expand Up @@ -229,6 +250,7 @@ void main() {
),
altmeChatSupportCubit: altmeChatSupportCubit,
profileCubit: profileCubit,
packageInfo: packageInfo,
);
fakeAsync((async) {
splashCubit.initialiseApp();
Expand Down

0 comments on commit 77bc505

Please sign in to comment.