Skip to content

Commit

Permalink
refactor:adding mock classes to test_utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
saksham-gt committed Jun 24, 2022
1 parent 0abb746 commit 3b75b91
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 14 deletions.
12 changes: 3 additions & 9 deletions test/application/user/avatar_bloc_fixtures.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import 'dart:io';

import 'package:collaction_app/application/user/avatar/avatar_bloc.dart';
import 'package:collaction_app/infrastructure/user/avatar_repository.dart';
import 'package:mocktail/mocktail.dart';

class MockAvatarRepo extends Mock implements AvatarRepository {}

class MockAvatarFile extends Mock implements File {}
import '../../test_utilities.dart';

final avatarRepo = MockAvatarRepo();
final avatarRepo2 = MockAvatarRepo();
final avatarRepo = MockAvatarRepository();
final avatarRepo2 = MockAvatarRepository();
final tAvatarBloc = AvatarBloc(avatarRepo);
final tAvatarFile = MockAvatarFile();
final tUri = Uri.parse('testAvatarUploadUri');
8 changes: 4 additions & 4 deletions test/application/user/avatar_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:collaction_app/domain/user/upload_failures.dart';
import 'package:dartz/dartz.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

import '../../test_utilities.dart';
import 'avatar_bloc_fixtures.dart';

void main() {
Expand All @@ -19,7 +19,7 @@ void main() {
});

{
final avatarRepo1 = MockAvatarRepo();
final avatarRepo1 = MockAvatarRepository();
when(() => avatarRepo1.getAvatarUploadPath()).thenAnswer(
(_) => Future.value(
left(const UploadPathFailure.unexpected()),
Expand All @@ -39,7 +39,7 @@ void main() {
}

{
final avatarRepo2 = MockAvatarRepo();
final avatarRepo2 = MockAvatarRepository();

when(() => avatarRepo2.getAvatarUploadPath()).thenAnswer(
(_) => Future.value(right(tUri)),
Expand All @@ -62,7 +62,7 @@ void main() {
);
}
{
final avatarRepo3 = MockAvatarRepo();
final avatarRepo3 = MockAvatarRepository();
when(() => avatarRepo3.getAvatarUploadPath()).thenAnswer(
(_) => Future.value(right(tUri)),
);
Expand Down
21 changes: 21 additions & 0 deletions test/application/user/profile/profile_bloc_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:collaction_app/application/user/profile/profile_bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

import 'profile_fixtures.dart';

void main() {
group('Testing Profile BLoC initial state', () {
test('Testing initial state', () {
expect(tProfileBloc.state, ProfileState.initial());
});

{
final tProfileRepository1 = tProfileRepository;
when(() => tProfileRepository1.getUserProfile()).thenAnswer(
(_) => Future.value(right(tUserProfile)),
);
}
});
}
13 changes: 13 additions & 0 deletions test/application/user/profile/profile_fixtures.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:collaction_app/application/user/profile/profile_bloc.dart';
import 'package:collaction_app/domain/profile/profile.dart';
import 'package:collaction_app/domain/profile/user_profile.dart';
import 'package:collaction_app/domain/user/user.dart';

import '../../../test_utilities.dart';

final tProfileRepository = MockProfileRepository();
final tAvatarRepository = MockAvatarRepository();
const tUser = User(id: 'tId', getIdToken: getAnonymousIdToken);
const tProfile = Profile(bio: 'tBio');
const tUserProfile = UserProfile(user: tUser, profile: tProfile);
final tProfileBloc = ProfileBloc(tProfileRepository, tAvatarRepository);
1 change: 0 additions & 1 deletion test/application/user_details/user_details_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ void main() {
when(() => tUserRepo.observeUser()).thenAnswer((_) {
final x = StreamController<User>();
x.add(tUser);
print('x.stream is User? ${x.stream.distinct() is Stream<User>}');
return x.stream.distinct();
});

Expand Down
14 changes: 14 additions & 0 deletions test/test_utilities.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import 'dart:io';

import 'package:collaction_app/domain/auth/i_auth_repository.dart';
import 'package:collaction_app/domain/contact_form/contact_form_dto.dart';
import 'package:collaction_app/domain/contact_form/i_contact_form_api.dart';
import 'package:collaction_app/domain/core/i_settings_repository.dart';
import 'package:collaction_app/domain/crowdaction/crowdaction.dart';
import 'package:collaction_app/domain/crowdaction/crowdaction_status.dart';
import 'package:collaction_app/domain/crowdaction/i_crowdaction_repository.dart';
import 'package:collaction_app/domain/user/i_avatar_repository.dart';
import 'package:collaction_app/domain/user/i_profile_repository.dart';
import 'package:collaction_app/domain/user/i_user_repository.dart';
import 'package:collaction_app/domain/user/user.dart';
import 'package:dartz/dartz.dart';
Expand All @@ -24,6 +28,16 @@ class MockSettingsRepository extends Mock implements ISettingsRepository {}

class MockContactFormApi extends Mock implements IContactFormApi {}

class MockAvatarRepository extends Mock implements IAvatarRepository {}

class MockAvatarFile extends Mock implements File {}

class MockProfileRepository extends Mock implements IProfileRepository {}

// ignore: avoid_positional_boolean_parameters
Future<String?> getAnonymousIdToken([bool forceRefresh = false]) =>
Future.value(null);

// ignore: avoid_classes_with_only_static_members
class TestUtilities {
static void mockUser(Stream<User> userStream) {
Expand Down

0 comments on commit 3b75b91

Please sign in to comment.