From 1f0496fa00bd0a557e4cf4d8e2a5734aec758b6e Mon Sep 17 00:00:00 2001 From: Eldar2021 Date: Sun, 3 Mar 2024 00:03:25 +0600 Subject: [PATCH] fixed tests --- .../home/domain/usecase/get_data_usecase.dart | 2 +- app/test/helpers/pump_app.dart | 4 ++-- app/test/widget_test.dart | 14 +++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/lib/modules/home/domain/usecase/get_data_usecase.dart b/app/lib/modules/home/domain/usecase/get_data_usecase.dart index d22ca2b2..d0ce703f 100644 --- a/app/lib/modules/home/domain/usecase/get_data_usecase.dart +++ b/app/lib/modules/home/domain/usecase/get_data_usecase.dart @@ -3,7 +3,7 @@ import 'package:my_quran/modules/modules.dart'; class GetHomeDataUseCase { const GetHomeDataUseCase(this.repository); - final HomeRepositoryImpl repository; + final HomeRepository repository; Future execute(String token) { return repository.getData(token); diff --git a/app/test/helpers/pump_app.dart b/app/test/helpers/pump_app.dart index c4bd8b25..578ef63c 100644 --- a/app/test/helpers/pump_app.dart +++ b/app/test/helpers/pump_app.dart @@ -10,7 +10,7 @@ extension PumpApp on WidgetTester { AppService appService, ThemeService themeService, AuthService authStorage, - HomeRepositoryImpl homeService, + HomeRepository homeRepo, ) { return pumpWidget( RepositoryProvider( @@ -19,7 +19,7 @@ extension PumpApp on WidgetTester { providers: [ BlocProvider(create: (context) => AppCubit(appService, themeService)), BlocProvider(create: (context) => AuthCubit(authStorage)), - BlocProvider(create: (context) => HomeCubit(GetHomeDataUseCase(homeService))), + BlocProvider(create: (context) => HomeCubit(GetHomeDataUseCase(homeRepo))), ], child: const QuranApp(), ), diff --git a/app/test/widget_test.dart b/app/test/widget_test.dart index 3b0d86ef..49a7b73e 100644 --- a/app/test/widget_test.dart +++ b/app/test/widget_test.dart @@ -14,17 +14,22 @@ final class MockPreferencesStorage extends Mock implements PreferencesStorage {} final class MockRemoteClient extends Mock implements RemoteClient {} +final class MockHomeRepositoryImpl implements HomeRepository { + @override + Future getData(String token) async { + return const HomeModel(allDoneHatims: 8, allDonePages: 5325, donePages: 634); + } +} + // flutter test void main() { testWidgets('Punmp app', (WidgetTester tester) async { final storage = MockPreferencesStorage(); final remoteClient = MockRemoteClient(); - final localDataSource = HomeLocalDataSource(storage); - final remoteDataSource = HomeRemoteDataSource(remoteClient); final appService = AppService(storage); final authStorage = AuthService(storage, remoteClient); - final homeService = HomeRepositoryImpl(localDataSource, remoteDataSource); + final homeRepo = MockHomeRepositoryImpl(); final themeService = ThemeService(storage); when(() => storage.readString(key: AppConst.tokenKey)).thenReturn(null); @@ -33,8 +38,7 @@ void main() { when(() => storage.readString(key: AppConst.modeKey)).thenReturn(null); when(() => storage.readString(key: AppConst.colorKey)).thenReturn(null); - // // Build our app and trigger a frame. - await tester.pumpApp(appService, themeService, authStorage, homeService); + await tester.pumpApp(appService, themeService, authStorage, homeRepo); await tester.pumpAndSettle(); expect(find.byType(MaterialApp), findsOneWidget); });