-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from CollActionteam/test/application
Test/application: Test coverage for application layer
- Loading branch information
Showing
14 changed files
with
521 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:collaction_app/application/contact_form/contact_form_bloc.dart'; | ||
import 'package:collaction_app/domain/contact_form/contact_form_dto.dart'; | ||
|
||
import '../../test_utilities.dart'; | ||
|
||
final tContactFormApi = MockContactFormApi(); | ||
final tContactFormBloc = ContactFormBloc(tContactFormApi); | ||
final tContactFormDtoS = | ||
ContactFormDto(email: '[email protected]', message: 'Success'); | ||
final tContactFormDtoF = | ||
ContactFormDto(email: '[email protected]', message: 'Failure'); | ||
final tContactFormDtoE = | ||
ContactFormDto(email: '[email protected]', message: 'Error'); |
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,59 @@ | ||
import 'package:bloc_test/bloc_test.dart'; | ||
import 'package:collaction_app/application/contact_form/contact_form_bloc.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'contact_form_fixture.dart'; | ||
|
||
void main() { | ||
group('Testing Contact Form BLoC', () { | ||
test('Initial ContactForm BLoC state', () { | ||
expect(tContactFormBloc.state, const ContactFormState.initial()); | ||
}); | ||
|
||
{ | ||
when(() => tContactFormApi.sendContactFormContents(tContactFormDtoS)) | ||
.thenAnswer((_) => Future.value(true)); | ||
blocTest( | ||
'Testing submit event success', | ||
build: () => ContactFormBloc(tContactFormApi), | ||
act: (ContactFormBloc bloc) { | ||
bloc.add(ContactFormEvent.submitted(tContactFormDtoS)); | ||
}, | ||
expect: () => [ | ||
const ContactFormState.submitting(), | ||
const ContactFormState.submissionSuccessful(), | ||
], | ||
); | ||
} | ||
{ | ||
when(() => tContactFormApi.sendContactFormContents(tContactFormDtoF)) | ||
.thenAnswer((_) => Future.value(false)); | ||
blocTest( | ||
'Testing submit event failure', | ||
build: () => ContactFormBloc(tContactFormApi), | ||
act: (ContactFormBloc bloc) { | ||
bloc.add(ContactFormEvent.submitted(tContactFormDtoF)); | ||
}, | ||
expect: () => [ | ||
const ContactFormState.submitting(), | ||
const ContactFormState.failed('Submission not successful!'), | ||
], | ||
); | ||
} | ||
{ | ||
when(() => tContactFormApi.sendContactFormContents(tContactFormDtoE)) | ||
.thenAnswer((_) => Future.error('error')); | ||
blocTest( | ||
'Testing submit event Error', | ||
build: () => ContactFormBloc(tContactFormApi), | ||
act: (ContactFormBloc bloc) { | ||
bloc.add(ContactFormEvent.submitted(tContactFormDtoE)); | ||
}, | ||
expect: () => [ | ||
const ContactFormState.submitting(), | ||
const ContactFormState.failed('Error submitting form!'), | ||
], | ||
); | ||
} | ||
}); | ||
} |
89 changes: 89 additions & 0 deletions
89
test/application/crowdaction/crowdaction_getter_bloc_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,89 @@ | ||
import 'package:bloc_test/bloc_test.dart'; | ||
import 'package:collaction_app/application/crowdaction/crowdaction_getter/crowdaction_getter_bloc.dart'; | ||
import 'package:collaction_app/domain/crowdaction/crowdaction_failures.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
|
||
import '../../test_utilities.dart'; | ||
import 'spotlight_bloc_fixtures.dart'; | ||
|
||
void main() { | ||
final tCAList = [tCrowdaction, tCrowdaction.copyWith(crowdactionID: 'id2')]; | ||
group('Testing Crowdaction Getter BLoC for defined amount', () { | ||
final caGetter = CrowdActionGetterBloc(tCrowdactionRepo); | ||
test('Testing initial state', () { | ||
expect( | ||
caGetter.state, | ||
const CrowdActionGetterState.initial(), | ||
); | ||
}); | ||
|
||
{ | ||
when(() => tCrowdactionRepo.getCrowdActions(amount: 4)).thenAnswer( | ||
(_) => | ||
Future.value(left(const CrowdActionFailure.networkRequestFailed())), | ||
); | ||
when(() => tCrowdactionRepo.getCrowdActions(amount: 5)).thenAnswer( | ||
(_) => Future.error('error'), | ||
); | ||
blocTest( | ||
'Testing getMore event error and failure', | ||
build: () => CrowdActionGetterBloc(tCrowdactionRepo), | ||
act: (CrowdActionGetterBloc bloc) { | ||
bloc.add( | ||
const CrowdActionGetterEvent.getMore(4), | ||
); | ||
bloc.add( | ||
const CrowdActionGetterEvent.getMore(5), | ||
); | ||
}, | ||
expect: () => [ | ||
const CrowdActionGetterState.fetchingCrowdActions(), | ||
const CrowdActionGetterState.noCrowdActions(), | ||
const CrowdActionGetterState.fetchingCrowdActions(), | ||
const CrowdActionGetterState.noCrowdActions(), | ||
], | ||
); | ||
} | ||
{ | ||
when(() => tCrowdactionRepo.getCrowdActions(amount: 2)).thenAnswer( | ||
(_) => Future.value(right(tCAList)), | ||
); | ||
|
||
blocTest( | ||
'Testing getMore event success', | ||
build: () => CrowdActionGetterBloc(tCrowdactionRepo), | ||
act: (CrowdActionGetterBloc bloc) { | ||
bloc.add( | ||
const CrowdActionGetterEvent.getMore(2), | ||
); | ||
}, | ||
expect: () => [ | ||
const CrowdActionGetterState.fetchingCrowdActions(), | ||
CrowdActionGetterState.fetched(tCAList) | ||
], | ||
); | ||
} | ||
{ | ||
final tCrowdActionRepo2 = MockCrowdActionRepository(); | ||
|
||
when(() => tCrowdActionRepo2.getCrowdActions()).thenAnswer( | ||
(_) => Future.value( | ||
right(tCAList), | ||
), | ||
); | ||
blocTest( | ||
'Testing getMore event when amount is not passed', | ||
build: () => CrowdActionGetterBloc(tCrowdActionRepo2), | ||
act: (CrowdActionGetterBloc bloc) { | ||
bloc.add(const CrowdActionGetterEvent.getMore(null)); | ||
}, | ||
expect: () => [ | ||
const CrowdActionGetterState.fetchingCrowdActions(), | ||
CrowdActionGetterState.fetched(tCAList) | ||
], | ||
); | ||
} | ||
}); | ||
} |
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,6 @@ | ||
import 'package:collaction_app/application/crowdaction/spotlight/spotlight_bloc.dart'; | ||
import '../../test_utilities.dart'; | ||
|
||
final tCrowdactionRepo = MockCrowdActionRepository(); | ||
final tCrowdactionRepo2 = MockCrowdActionRepository(); | ||
final tSpotlightBloc = SpotlightBloc(tCrowdactionRepo); |
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,52 @@ | ||
import 'package:bloc_test/bloc_test.dart'; | ||
import 'package:collaction_app/application/crowdaction/spotlight/spotlight_bloc.dart'; | ||
import 'package:collaction_app/domain/crowdaction/crowdaction_failures.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import '../../test_utilities.dart'; | ||
import 'spotlight_bloc_fixtures.dart'; | ||
|
||
void main() { | ||
group('Testing Spotlight BLoC', () { | ||
test('Testing initial state', () { | ||
expect(tSpotlightBloc.state, const SpotlightState.initial()); | ||
}); | ||
|
||
{ | ||
when(() => tCrowdactionRepo.getSpotlightCrowdActions()).thenAnswer( | ||
(_) => Future.value(left(const CrowdActionFailure.serverError())), | ||
); | ||
|
||
blocTest( | ||
'Testing getSpotlightCrowdaction Event Failure', | ||
build: () => tSpotlightBloc, | ||
act: (SpotlightBloc bloc) { | ||
bloc.add(const SpotlightEvent.getSpotLightCrowdActions()); | ||
}, | ||
expect: () => [ | ||
const SpotlightState.fetchingCrowdSpotLightActions(), | ||
const SpotlightState.spotLightCrowdActionsError( | ||
CrowdActionFailure.serverError(), | ||
) | ||
], | ||
); | ||
} | ||
{ | ||
when(() => tCrowdactionRepo2.getSpotlightCrowdActions()).thenAnswer( | ||
(_) => Future.value(right([tCrowdaction])), | ||
); | ||
blocTest( | ||
'Testing getSpotlightCrowdaction Event Success', | ||
build: () => SpotlightBloc(tCrowdactionRepo2), | ||
act: (SpotlightBloc bloc) { | ||
bloc.add(const SpotlightEvent.getSpotLightCrowdActions()); | ||
}, | ||
expect: () => [ | ||
const SpotlightState.fetchingCrowdSpotLightActions(), | ||
SpotlightState.spotLightCrowdActions([tCrowdaction]) | ||
], | ||
); | ||
} | ||
}); | ||
} |
5 changes: 5 additions & 0 deletions
5
test/application/crowdaction/subscription_status_fixtures.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,5 @@ | ||
import '../../test_utilities.dart'; | ||
|
||
final mockCARepo = MockCrowdActionRepository(); | ||
final mockCARepo1 = MockCrowdActionRepository(); | ||
final mockCARepo2 = MockCrowdActionRepository(); |
83 changes: 83 additions & 0 deletions
83
test/application/crowdaction/subscription_status_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,83 @@ | ||
import 'package:bloc_test/bloc_test.dart'; | ||
import 'package:collaction_app/application/crowdaction/subscription_status/subscription_status_bloc.dart'; | ||
import 'package:collaction_app/domain/crowdaction/crowdaction_failures.dart'; | ||
import 'package:collaction_app/domain/crowdaction/crowdaction_status.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
|
||
import '../../test_utilities.dart'; | ||
import 'subscription_status_fixtures.dart'; | ||
|
||
void main() { | ||
group('Testing Subscription status BLoC', () { | ||
test('Testing initial state', () { | ||
final subsStatusBloc = SubscriptionStatusBloc(mockCARepo); | ||
expect(subsStatusBloc.state, const SubscriptionStatusState.initial()); | ||
}); | ||
|
||
{ | ||
when(() => mockCARepo1.checkCrowdActionSubscriptionStatus(tCrowdaction)) | ||
.thenAnswer( | ||
(_) => Future.value( | ||
left(const CrowdActionFailure.networkRequestFailed()), | ||
), | ||
); | ||
blocTest( | ||
'Testing check participation event failure', | ||
build: () => SubscriptionStatusBloc(mockCARepo1), | ||
act: (SubscriptionStatusBloc bloc) => bloc.add( | ||
SubscriptionStatusEvent.checkParticipationStatus(tCrowdaction), | ||
), | ||
expect: () => [ | ||
const SubscriptionStatusState.checkingSubscriptionStatus(), | ||
const SubscriptionStatusState.checkingSubscriptionStatusFailed(), | ||
], | ||
); | ||
} | ||
{ | ||
when(() => mockCARepo.checkCrowdActionSubscriptionStatus(tCrowdaction)) | ||
.thenAnswer( | ||
(_) => Future.value( | ||
right(const CrowdActionStatus.subscribed(['tCommitment'])), | ||
), | ||
); | ||
blocTest( | ||
'Testing check participation event success and subscribed', | ||
build: () => SubscriptionStatusBloc(mockCARepo), | ||
act: (SubscriptionStatusBloc bloc) => bloc.add( | ||
SubscriptionStatusEvent.checkParticipationStatus(tCrowdaction), | ||
), | ||
expect: () => [ | ||
const SubscriptionStatusState.checkingSubscriptionStatus(), | ||
const SubscriptionStatusState.subscriptionStatus( | ||
CrowdActionStatus.subscribed(['tCommitment']), | ||
), | ||
], | ||
); | ||
} | ||
{ | ||
when(() => mockCARepo2.checkCrowdActionSubscriptionStatus(tCrowdaction)) | ||
.thenAnswer( | ||
(_) => Future.value( | ||
right(const CrowdActionStatus.notSubscribed()), | ||
), | ||
); | ||
blocTest( | ||
'Testing check participation event success and unsubscribed', | ||
build: () => SubscriptionStatusBloc(mockCARepo2), | ||
act: (SubscriptionStatusBloc bloc) { | ||
bloc.add( | ||
SubscriptionStatusEvent.checkParticipationStatus(tCrowdaction), | ||
); | ||
}, | ||
expect: () => [ | ||
const SubscriptionStatusState.checkingSubscriptionStatus(), | ||
const SubscriptionStatusState.subscriptionStatus( | ||
CrowdActionStatus.notSubscribed(), | ||
), | ||
], | ||
); | ||
} | ||
}); | ||
} |
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,37 @@ | ||
import 'package:bloc_test/bloc_test.dart'; | ||
import 'package:collaction_app/application/settings/build_information/build_information_bloc.dart'; | ||
import 'package:collaction_app/domain/settings/build_information.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
|
||
import '../../test_utilities.dart'; | ||
|
||
void main() { | ||
group('Testing Build Information BLoC', () { | ||
final tSettingsRepo = MockSettingsRepository(); | ||
final tBuildInfoBloc = BuildInformationBloc(tSettingsRepo); | ||
const tBuildInfo = | ||
BuildInformation(buildNumber: 'tBuildNum', version: 'tVersion'); | ||
test('Testing initial state', () { | ||
expect( | ||
tBuildInfoBloc.state, | ||
const BuildInformationState.loading(), | ||
); | ||
}); | ||
|
||
when(() => tSettingsRepo.getBuildInformation()) | ||
.thenAnswer((_) => Future.value(tBuildInfo)); | ||
|
||
blocTest( | ||
'Testing fetch event', | ||
build: () => tBuildInfoBloc, | ||
act: (BuildInformationBloc bloc) { | ||
bloc.add(const BuildInformationEvent.fetch()); | ||
}, | ||
expect: () => [ | ||
const BuildInformationState.loading(), | ||
const BuildInformationState.fetched(tBuildInfo), | ||
], | ||
); | ||
}); | ||
} |
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,15 @@ | ||
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 {} | ||
|
||
final avatarRepo = MockAvatarRepo(); | ||
final avatarRepo2 = MockAvatarRepo(); | ||
final tAvatarBloc = AvatarBloc(avatarRepo); | ||
final tAvatarFile = MockAvatarFile(); | ||
final tUri = Uri.parse('testAvatarUploadUri'); |
Oops, something went wrong.