-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: write tests for survey detail screen
- Loading branch information
1 parent
450df07
commit 7ec307c
Showing
13 changed files
with
594 additions
and
55 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
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
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
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
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
77 changes: 77 additions & 0 deletions
77
test/modules/survey_detail/survey_detail_interactor_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,77 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:quick_test/quick_test.dart'; | ||
import 'package:survey/models/detailed_survey_info.dart'; | ||
import 'package:survey/models/survey_info.dart'; | ||
import 'package:survey/modules/survey_detail/survey_detail_module.dart'; | ||
import 'package:survey/repositories/survey_repository.dart'; | ||
import 'package:survey/services/locator/locator_service.dart'; | ||
import '../../helpers/behavior_subject_generator.dart'; | ||
import 'survey_detail_interactor_test.mocks.dart'; | ||
|
||
@GenerateMocks([SurveyDetailInteractorDelegate, SurveyRepository]) | ||
void main() { | ||
describe("a SurveyDetail interactor", () { | ||
late SurveyDetailInteractor interactor; | ||
late MockSurveyDetailInteractorDelegate delegate; | ||
late BehaviorSubjectGenerator generator; | ||
late MockSurveyRepository surveyRepository; | ||
|
||
final survey = SurveyInfo(); | ||
survey.id = "id"; | ||
|
||
beforeEach(() { | ||
generator = BehaviorSubjectGenerator(); | ||
|
||
surveyRepository = MockSurveyRepository(); | ||
locator.registerSingleton<SurveyRepository>(surveyRepository); | ||
|
||
delegate = MockSurveyDetailInteractorDelegate(); | ||
when(delegate.detailedSurveyDidFetch) | ||
.thenAnswer((realInvocation) => generator.make(0)); | ||
when(delegate.detailedSurveyDidFailToFetch) | ||
.thenAnswer((realInvocation) => generator.make(1)); | ||
|
||
interactor = SurveyDetailInteractorImpl(); | ||
interactor.delegate = delegate; | ||
interactor.arguments = SurveyDetailArguments(survey: survey); | ||
}); | ||
|
||
describe("it's survey is got", () { | ||
it("returns correct survey", () { | ||
expect(interactor.survey, survey); | ||
}); | ||
}); | ||
|
||
describe("it's fetchDetailedSurvey() is called", () { | ||
context("when survey repository's fetchDetailedSurvey() return success", | ||
() { | ||
final detailedSurvey = DetailedSurveyInfo(); | ||
beforeEach(() { | ||
when(surveyRepository.fetchDetailedSurvey(any)) | ||
.thenAnswer((realInvocation) => Future.value(detailedSurvey)); | ||
interactor.fetchDetailedSurvey(); | ||
}); | ||
|
||
it("triggers delegate's detailedSurveyDidFetch emits", () { | ||
expect(delegate.detailedSurveyDidFetch, emits(detailedSurvey)); | ||
}); | ||
}); | ||
|
||
context("when survey repository's fetchDetailedSurvey() return failure", | ||
() { | ||
final exception = Exception(); | ||
beforeEach(() { | ||
when(surveyRepository.fetchDetailedSurvey(any)) | ||
.thenAnswer((realInvocation) => Future.error(exception)); | ||
interactor.fetchDetailedSurvey(); | ||
}); | ||
|
||
it("triggers delegate's detailedSurveyDidFailToFetch emits", () { | ||
expect(delegate.detailedSurveyDidFailToFetch, emits(exception)); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.