-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: improved integration test architecture
- Loading branch information
1 parent
0657928
commit a017eec
Showing
19 changed files
with
526 additions
and
121 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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
23 changes: 23 additions & 0 deletions
23
designer_v2/integration_test/controller/robots/study_robots.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,23 @@ | ||
import 'package:patrol_finders/patrol_finders.dart'; | ||
|
||
import 'robots.dart'; | ||
|
||
abstract class StudyRobots { | ||
final PatrolTester $; | ||
final AppRobot appRobot; | ||
final AuthRobot authRobot; | ||
final StudiesRobot studiesRobot; | ||
final StudyDesignRobot studyDesignRobot; | ||
final StudyInfoRobot studyInfoRobot; | ||
final StudyInterventionsRobot studyInterventionsRobot; | ||
final StudyMeasurementsRobot studyMeasurementsRobot; | ||
|
||
StudyRobots(this.$) | ||
: appRobot = AppRobot($), | ||
authRobot = AuthRobot($), | ||
studiesRobot = StudiesRobot($), | ||
studyDesignRobot = StudyDesignRobot($), | ||
studyInfoRobot = StudyInfoRobot($), | ||
studyInterventionsRobot = StudyInterventionsRobot($), | ||
studyMeasurementsRobot = StudyMeasurementsRobot($); | ||
} |
138 changes: 138 additions & 0 deletions
138
designer_v2/integration_test/controller/study_integration_controller.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,138 @@ | ||
import 'package:studyu_core/core.dart'; | ||
|
||
import '../mockup/mockup_loader.dart'; | ||
import '../mockup/mockup_studies.dart'; | ||
import 'robots/robots.dart'; | ||
import 'study_validator.dart'; | ||
|
||
abstract class StudyIntegrationActions { | ||
Future<void> fillTitle(); | ||
Future<void> fillInfoPage(); | ||
Future<void> fillInterventions( | ||
List<Intervention> Function(List<Intervention> interventionList) | ||
interventionsToCreate, | ||
); | ||
Future<void> fillObservations( | ||
List<Observation> Function(List<Observation> observationList) | ||
observationsToCreate, | ||
); | ||
} | ||
|
||
class StudyIntegrationController extends StudyRobots | ||
implements StudyIntegrationActions { | ||
final Study Function() _mockStudyRef; | ||
|
||
// Only available after login | ||
late final String userID; | ||
late final MockupLoader mockupLoader; | ||
late final Study _intermediateMockStudy; | ||
late final Study mockStudy; | ||
|
||
StudyIntegrationController( | ||
super.$, | ||
this._mockStudyRef, | ||
); | ||
|
||
Future<void> init(String userID_) async { | ||
userID = userID_; | ||
mockupLoader = MockupLoader(userID, _mockStudyRef); | ||
_intermediateMockStudy = mockupLoader.emptyMockupStudy(); | ||
mockStudy = MockupStudies.study; | ||
} | ||
|
||
@override | ||
Future<void> fillTitle() async { | ||
await studyInfoRobot.enterStudyName(mockStudy.title!); | ||
|
||
_intermediateMockStudy.title = mockStudy.title; | ||
// await _endActions(); // does not work | ||
await studyDesignRobot.validateChangesSaved(); | ||
} | ||
|
||
@override | ||
Future<void> fillInfoPage() async { | ||
await studyInfoRobot.enterStudyDescription(mockStudy.description!); | ||
await studyInfoRobot.enterResponsibleOrg(mockStudy.contact.organization); | ||
await studyInfoRobot.enterInstitutionalReviewBoard( | ||
mockStudy.contact.institutionalReviewBoard!, | ||
); | ||
await studyInfoRobot.enterIRBProtocolNumber( | ||
mockStudy.contact.institutionalReviewBoardNumber!, | ||
); | ||
await studyInfoRobot.enterResponsiblePerson(mockStudy.contact.researchers!); | ||
await studyInfoRobot.enterWebsite(mockStudy.contact.website); | ||
await studyInfoRobot.enterContactEmail(mockStudy.contact.email); | ||
await studyInfoRobot.enterContactPhone(mockStudy.contact.phone); | ||
|
||
_intermediateMockStudy.contact = mockStudy.contact; | ||
await _endActions(); | ||
} | ||
|
||
@override | ||
Future<void> fillInterventions( | ||
List<Intervention> Function(List<Intervention> interventionList) | ||
interventionsToCreate, | ||
) async { | ||
final interventions = interventionsToCreate(mockStudy.interventions); | ||
|
||
for (final intervention in interventions) { | ||
await studyInterventionsRobot.createIntervention( | ||
interventionName: intervention.name!, | ||
interventionDescription: intervention.description!, | ||
taskName: intervention.tasks[0].title!, | ||
taskDescription: intervention.tasks[0].header!, | ||
); | ||
} | ||
|
||
_intermediateMockStudy.interventions.addAll(interventions); | ||
await _endActions(); | ||
} | ||
|
||
@override | ||
Future<void> fillObservations( | ||
List<Observation> Function(List<Observation> observationList) | ||
observationsToCreate, | ||
) async { | ||
final observations = observationsToCreate(mockStudy.observations); | ||
|
||
for (final observation in observations) { | ||
await studyMeasurementsRobot.createObservation( | ||
observationTitle: observation.title!, | ||
observationHeader: observation.header!, | ||
observationFooter: observation.footer!, | ||
); | ||
// todo support other question types | ||
for (final (question as ChoiceQuestion) | ||
in (observation as QuestionnaireTask).questions.questions) { | ||
await studyMeasurementsRobot.createObservationQuestion( | ||
questionText: question.prompt!, | ||
option1: question.choices[0].text, | ||
option2: question.choices[1].text, | ||
); | ||
} | ||
} | ||
await studyMeasurementsRobot.tapSaveSurveyQuestionButton(); | ||
await studyMeasurementsRobot.tapSaveSurveyButton(); | ||
|
||
_intermediateMockStudy.observations.addAll(observations); | ||
await _endActions(); | ||
} | ||
|
||
Future<void> _endActions() async { | ||
await studyDesignRobot.validateChangesSaved(); | ||
// todo find a way to validate the changes directly after auto-save | ||
// await validateIntermediate(); | ||
} | ||
|
||
Future<bool> validateIntermediate() { | ||
return StudyValidator(userID).compare(_intermediateMockStudy); | ||
} | ||
|
||
Future<bool> validateFinal() async { | ||
final res = await StudyValidator(userID).compare(mockStudy); | ||
if (res) { | ||
print('Final validation succeeded!'); | ||
} | ||
return res; | ||
} | ||
} |
Oops, something went wrong.