Skip to content

Commit

Permalink
test: cleanup a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesvedder committed Jun 26, 2024
1 parent 7a7d604 commit 1398eaa
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 154 deletions.
200 changes: 49 additions & 151 deletions designer_v2/integration_test/app_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: dead_code

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand All @@ -23,138 +25,46 @@ void main() {
await SecureStorage.deleteAll();
});

group('end-to-end tests', () {
// NOTE:
// the hydration of user is inconsistent and derails the tests
// thus, we need to clear the storage so that the
// hydration does not happen
// When 'Remember me is added, this method can be removed - but
// it could be a good practice to keep it so that the test instances
// do not share any information in the app cache
setUp(() async => await SecureStorage.deleteAll()); // RM

// todo Find a way to run tests consecutively

// Disable semantics because of known Flutter test issue:
// https://github.com/flutter/flutter/issues/97606
/*
patrolWidgetTest('Sign up -> Sign out flow test', semanticsEnabled: false, ($) async {
final appRobot = AppRobot($);
final authRobot = AuthRobot($);
final studiesRobot = StudiesRobot($);
await $.pumpWidgetAndSettle(const ProviderScope(child: App()));
await appRobot.validateOnLoginScreen();
await authRobot.navigateToSignUpScreen();
await authRobot.enterEmail('test@email.com');
await authRobot.enterPassword('password');
await authRobot.enterPasswordConfirmation('password');
await authRobot.tapTermsCheckbox();
await authRobot.tapSignUpButton();
await studiesRobot.validateOnStudiesScreen();
await studiesRobot.tapSignOutButton();
group('Test all', () {
const randomTest = true;
final email = randomTest
? '${DateTime.now().millisecondsSinceEpoch}@studyu.health'
: 'test@studyu.health';
const password = 'password';

await appRobot.validateOnLoginScreen();
});
patrolWidgetTest('Sign in test', semanticsEnabled: false, ($) async {
final appRobot = AppRobot($);
patrolWidgetTest('TestAll', (PatrolTester $) async {
final authRobot = AuthRobot($);
final studiesRobot = StudiesRobot($);
await $.pumpWidgetAndSettle(const ProviderScope(child: App()));
await appRobot.validateOnLoginScreen();
await authRobot.enterEmail('test@email.com');
await authRobot.enterPassword('password');
await authRobot.tapSignInButton();
await studiesRobot.validateOnStudiesScreen();
await studiesRobot.tapSignOutButton(); // RM
});
*/
/* NOTE:
* remove skip value when remember me is implemented
* also remove all lines marked by RM
The hope is that the Session key will persist across test app instances
and the user will stay logged in
*/
/*
patrolWidgetTest('Remember me function test', semanticsEnabled: false, skip: true, ($) async {
final studiesRobot = StudiesRobot($);
await $.pumpWidgetAndSettle(const ProviderScope(child: App()));
studiesRobot.validateOnStudiesScreen();
});
patrolWidgetTest('Create a study/rename it test', semanticsEnabled: false, ($) async {
final appRobot = AppRobot($); // RM
final authRobot = AuthRobot($); // RM
final studiesRobot = StudiesRobot($);
final studyDesignRobot = StudyDesignRobot($);
final studyInfoRobot = StudyInfoRobot($);
await $.pumpWidgetAndSettle(const ProviderScope(child: App()));
await appRobot.validateOnLoginScreen(); // RM
await authRobot.enterEmail('test@email.com'); // RM
await authRobot.enterPassword('password'); // RM
await authRobot.tapSignInButton(); // RM
//await studiesRobot.validateNoStudiesFound();
await studiesRobot.tapNewStudyButton();
await studyDesignRobot.validateOnDesignScreen();
await studyInfoRobot.validateOnStudyInfoScreen();
await studyInfoRobot.enterStudyName('Create Test Study');
await studyDesignRobot.validateChangesSaved();
await studyDesignRobot.tapLeftDrawerButton();
await studyDesignRobot.tapMyStudiesButton();
await studiesRobot.validateOnStudiesScreen();
await studiesRobot.validateStudyDraftExists();
await studiesRobot.tapSignOutButton(); // RM
});
*/
// We start with a new account and study here, since tests run asynchronously and
// previous tests might not have been completed when running this one
patrolWidgetTest('Publish a study', (PatrolTester $) async {
final appRobot = AppRobot($); // RM
final authRobot = AuthRobot($); // RM
final studiesRobot = StudiesRobot($);
final studyDesignRobot = StudyDesignRobot($);
final studyInfoRobot = StudyInfoRobot($);
final studyInterventionsRobot = StudyInterventionsRobot($);
final studyMeasurementsRobot = StudyMeasurementsRobot($);

await $.pumpWidgetAndSettle(const ProviderScope(child: App()));

/* START SIGN UP */
await appRobot.validateOnLoginScreen();
await authRobot.navigateToSignUpScreen();
await authRobot.enterEmail('test@email.com');
await authRobot.enterPassword('password');
await authRobot.enterPasswordConfirmation('password');
await authRobot.tapTermsCheckbox();
await authRobot.tapSignUpButton();
await studiesRobot.validateOnStudiesScreen();
await studiesRobot.tapSignOutButton();
/* FINISH SIGN UP */

/* START SIGN IN */
await appRobot.validateOnLoginScreen();
await authRobot.enterEmail('test@email.com');
await authRobot.enterPassword('password');
await $.pumpWidgetAndSettle(
const ExcludeSemantics(child: ProviderScope(child: App())),
);

if (randomTest) {
// START SIGN UP
await authRobot.navigateToSignUpScreen();
await authRobot.enterEmail(email);
await authRobot.enterPassword(password);
await authRobot.enterPasswordConfirmation(password);
await authRobot.tapTermsCheckbox();
await authRobot.tapSignUpButton();
await studiesRobot.tapSignOutButton();
// FINISH SIGN UP
}

// START SIGN IN
await authRobot.enterEmail(email);
await authRobot.enterPassword(password);
await authRobot.tapSignInButton();
/* FINISH SIGN IN */
// FINISH SIGN IN

// START CREATE STUDY
await studiesRobot.tapNewStudyButton();

await studyDesignRobot.validateOnDesignScreen();
await studyInfoRobot.validateOnStudyInfoScreen();
await studyInfoRobot.enterStudyName('Publish Test Study');

await $.pump(const Duration(milliseconds: 1500));
Expand All @@ -165,14 +75,9 @@ void main() {
// FINISH CREATE STUDY

// START FILL AND PUBLISH STUDY
await studiesRobot.validateOnStudiesScreen();
await studiesRobot.validateStudyDraftExists();
// todo specify the exact study that should be tapped by name
await studiesRobot.tapOnExistingStudy();

await studyDesignRobot.validateOnDesignScreen();

await studyInfoRobot.validateOnStudyInfoScreen();
await studyInfoRobot.enterStudyDescription('Test study description');
await studyInfoRobot.enterResponsibleOrg('Test Organization, Inc.');
await studyInfoRobot
Expand All @@ -189,33 +94,24 @@ void main() {
// NO-OP because exception in participation screening questionnaire

await studyDesignRobot.navigateToInterventionsScreen();
// Repeat twice for two interventions
await studyInterventionsRobot.tapAddInterventionButton();
await studyInterventionsRobot
.enterInterventionName('Test Intervention A');
await studyInterventionsRobot
.enterInterventionDesciption('Test Intervention Description A');
await studyInterventionsRobot.tapAddInterventionTaskButton();
await studyInterventionsRobot.enterInterventionTaskName('Task 1A');
await studyInterventionsRobot
.enterInterventionTaskDescription('Task 1A Description');
await studyInterventionsRobot.tapSaveInterventionTaskButton();
await studyInterventionsRobot.tapSaveInterventionButton();
await studyDesignRobot.validateChangesSaved();

await studyInterventionsRobot.tapAddInterventionButton();
await studyInterventionsRobot
.enterInterventionName('Test Intervention B');
await studyInterventionsRobot
.enterInterventionDesciption('Test Intervention Description B');
await studyInterventionsRobot.tapAddInterventionTaskButton();
await studyInterventionsRobot.enterInterventionTaskName('Task 1B');
await studyInterventionsRobot
.enterInterventionTaskDescription('Task 1B Description');
await studyInterventionsRobot.tapSaveInterventionTaskButton();
await studyInterventionsRobot.tapSaveInterventionButton();
// Create two interventions
await studyInterventionsRobot.createIntervention(
interventionName: 'Test Intervention A',
interventionDescription: 'Test Intervention Description A',
taskName: 'Task 1A',
taskDescription: 'Task 1A Description',
);

await studyDesignRobot.validateChangesSaved();

await studyInterventionsRobot.createIntervention(
interventionName: 'Test Intervention B',
interventionDescription: 'Test Intervention Description B',
taskName: 'Task 1B',
taskDescription: 'Task 1B Description',
);

await studyDesignRobot.navigateToMeasurementsScreen();
await studyMeasurementsRobot.tapAddSurveyButton();
await studyMeasurementsRobot.enterSurveyName('Test Survey');
Expand All @@ -237,11 +133,13 @@ void main() {

await studyDesignRobot.tapLeftDrawerButton();
await studyDesignRobot.tapMyStudiesButton();
await studiesRobot.validateOnStudiesScreen();

await studiesRobot.tapSignOutButton();
/*env.client.from('study').select().then((value) {
print(value);
// todo parse and validate
});*/

// todo dump database data and validate its state
//await studiesRobot.tapSignOutButton();
});
});
}
3 changes: 1 addition & 2 deletions designer_v2/integration_test/robots/studies_robot.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:patrol_finders/patrol_finders.dart';
import 'package:studyu_designer_v2/localization/app_translation.dart';
Expand Down Expand Up @@ -33,6 +32,6 @@ class StudiesRobot {
}

Future<void> tapSignOutButton() async {
await $(Icons.logout_rounded).tap();
await $(tr.navlink_logout).tap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ class StudyInterventionsRobot {

final PatrolTester $;

Future<void> createIntervention({
required String interventionName,
required String interventionDescription,
required String taskName,
required String taskDescription,
}) async {
await tapAddInterventionButton();
await enterInterventionName(interventionName);
await enterInterventionDescription(interventionDescription);
await tapAddInterventionTaskButton();
await enterInterventionTaskName(taskName);
await enterInterventionTaskDescription(taskDescription);
await tapSaveInterventionTaskButton();
await tapSaveInterventionButton();
}

Future<void> tapAddInterventionButton() async {
await $(tr.form_array_interventions_new).tap();
}
Expand Down Expand Up @@ -36,7 +52,7 @@ class StudyInterventionsRobot {
.enterText(interventionName);
}

Future<void> enterInterventionDesciption(
Future<void> enterInterventionDescription(
String interventionDescription,
) async {
await $(TextField)
Expand Down

0 comments on commit 1398eaa

Please sign in to comment.