Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Eldar2021 committed Mar 2, 2024
1 parent 568e3c0 commit 1f0496f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/lib/modules/home/domain/usecase/get_data_usecase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:my_quran/modules/modules.dart';
class GetHomeDataUseCase {
const GetHomeDataUseCase(this.repository);

final HomeRepositoryImpl repository;
final HomeRepository repository;

Future<HomeModel> execute(String token) {
return repository.getData(token);
Expand Down
4 changes: 2 additions & 2 deletions app/test/helpers/pump_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension PumpApp on WidgetTester {
AppService appService,
ThemeService themeService,
AuthService authStorage,
HomeRepositoryImpl homeService,
HomeRepository homeRepo,
) {
return pumpWidget(
RepositoryProvider(
Expand All @@ -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(),
),
Expand Down
14 changes: 9 additions & 5 deletions app/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<HomeModel> 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);
Expand All @@ -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);
});
Expand Down

0 comments on commit 1f0496f

Please sign in to comment.