Skip to content

Commit

Permalink
#1079 - running two tests for now
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Sep 14, 2023
1 parent 83adfdd commit ec45b56
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class IntegrationTestApp extends Component {
super(props, context);
FileSystem.init();
this.getBean = this.getBean.bind(this);
this.integrationTestRunner = new IntegrationTestRunner(DatabaseTest);
this.integrationTestRunner = new IntegrationTestRunner(DatabaseTest, PersonRegisterActionsIntegrationTest);
this.state = {isInitialisationDone: false, integrationTests: this.integrationTestRunner.integrationTests};
}

Expand Down
14 changes: 11 additions & 3 deletions packages/openchs-android/integrationTest/IntegrationTestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ export class IntegrationTests {
}
}

const nonTestMethods = ["constructor", "setup", "teardown"];

class IntegrationTestRunner {
integrationTests;

constructor(...testClasses) {
this.integrationTests = new IntegrationTests();
testClasses.forEach((testClass) => {
const testMethods = Object.getOwnPropertyNames(testClass.prototype).filter((method) => method !== "constructor");
const testMethods = Object.getOwnPropertyNames(testClass.prototype).filter((method) => !nonTestMethods.includes(method));
testMethods.forEach((testMethod) => {
const integrationTestMethod = new IntegrationTestMethod(testClass, testMethod);
this.integrationTests.push(integrationTestMethod);
Expand All @@ -62,11 +64,17 @@ class IntegrationTestRunner {
this.integrationTests.testMethods.forEach((testMethod) => {
console.log("IntegrationTestRunner", "Running", testMethod.toString());
try {
new testMethod.testClass()[testMethod.methodName]();
const testObject = new testMethod.testClass();
if (_.isFunction(testObject.setup))
testObject.setup();
testObject[testMethod.methodName]();
if (_.isFunction(testObject.tearDown))
testObject.tearDown();
testMethod.success();
} catch (error) {
console.error("IntegrationTestRunner", testMethod.toString(), error);
console.error("IntegrationTestRunner", testMethod.toString(), error, error.stack);
testMethod.failure(error);
throw error;
} finally {
notify(this.integrationTests.clone());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import TestConceptFactory from "../test/model/TestConceptFactory";
import {Gender, Settings, Individual, OrganisationConfig, AddressLevel, Concept, Form, SubjectType, WorkList, WorkLists, FormMapping} from "openchs-models";
import {AddressLevel, Concept, Form, FormMapping, Gender, OrganisationConfig, Settings, SubjectType, WorkList, WorkLists} from "openchs-models";
import BaseIntegrationTest from "./BaseIntegrationTest";
import TestFormFactory from "../test/model/form/TestFormFactory";
import TestFormElementGroupFactory from "../test/model/form/TestFormElementGroupFactory";
import TestFormElementFactory from "../test/model/form/TestFormElementFactory";
import TestSubjectTypeFactory from "../test/model/TestSubjectTypeFactory";
import TestAddressLevelFactory from "../test/model/TestAddressLevelFactory";
import {Actions} from "../src/action/individual/PersonRegisterActions";
import {AddNewMemberActions} from "../src/action/groupSubject/MemberAction";
import {IndividualEncounterViewActions} from "../src/action/individual/EncounterActions";
import {PersonRegisterActions} from "../src/action/individual/PersonRegisterActions";
import TestGenderFactory from "../test/model/TestGenderFactory";
import TestFormMappingFactory from "../test/model/form/TestFormMappingFactory";
import Reducers from "../src/reducer";
import TestOrganisationConfigFactory from "../test/model/TestOrganisationConfigFactory";
import TestSubjectFactory from "../test/model/txn/TestSubjectFactory";
import WorklistsFactory from "../src/model/WorklistsFactory";
import TestSettingsFactory from "../test/model/user/TestSettingsFactory";
import {assert} from 'chai';
import _ from 'lodash';

const rule = `({params, imports}) => {
const workLists = params.workLists;
Expand All @@ -40,12 +34,6 @@ const rule = `({params, imports}) => {
return workLists;
};`;

const noOpRule = `({params, imports}) => {
console.log("No Op Rule Started");
const workLists = params.workLists;
return workLists;
};`;

class PersonRegisterActionsIntegrationTest extends BaseIntegrationTest {
concept; addressLevel; gender;

Expand All @@ -60,14 +48,13 @@ class PersonRegisterActionsIntegrationTest extends BaseIntegrationTest {
return this;
}

person_registration_should_show_worklist_correctly(context) {
context.starting(arguments);
person_registration_should_show_worklist_correctly() {
let subjectType;
this.executeInWrite((db) => {
subjectType = db.create(SubjectType, TestSubjectTypeFactory.createWithDefaults({type: SubjectType.types.Person, name: 'Family Member'}));
const form = db.create(Form, TestFormFactory.createWithDefaults({formType: Form.formTypes.IndividualProfile}));
const formElementGroup = TestFormElementGroupFactory.create({form: form});
TestFormElementFactory.create({concept: concept, displayOrder: 1, formElementGroup: formElementGroup});
TestFormElementFactory.create({concept: this.concept, displayOrder: 1, formElementGroup: formElementGroup});
db.create(FormMapping, TestFormMappingFactory.createWithDefaults({subjectType: subjectType, form: form}))
db.create(OrganisationConfig, TestOrganisationConfigFactory.createWithDefaults({worklistUpdationRule: rule}));
});
Expand All @@ -86,43 +73,6 @@ class PersonRegisterActionsIntegrationTest extends BaseIntegrationTest {
const workItems = state.workListState.workLists.currentWorkList.workItems;
assert.equal("ENCOUNTER", workItems[1].type);
assert.equal("Covid Survey", workItems[1].parameters.encounterType);
context.ending(arguments);
}

person_registration_via_add_member_should_show_worklist_correctly(context) {
context.starting(arguments);
let householdSubjectType, personSubjectType, household;
this.executeInWrite((db) => {
householdSubjectType = db.create(SubjectType, TestSubjectTypeFactory.createWithDefaults({type: SubjectType.types.Household, name: 'Family', isGroup: true}));
personSubjectType = db.create(SubjectType, TestSubjectTypeFactory.createWithDefaults({type: SubjectType.types.Person, name: 'Family Member', isGroup: false}));
const form = db.create(Form, TestFormFactory.createWithDefaults({formType: Form.formTypes.IndividualProfile}));
const formElementGroup = TestFormElementGroupFactory.create({form: form});
TestFormElementFactory.create({concept: this.concept, displayOrder: 1, formElementGroup: formElementGroup});
db.create(FormMapping, TestFormMappingFactory.createWithDefaults({subjectType: personSubjectType, form: form}))
db.create(OrganisationConfig, TestOrganisationConfigFactory.createWithDefaults({worklistUpdationRule: noOpRule}));
household = db.create(Individual, TestSubjectFactory.createWithDefaults({subjectType: householdSubjectType, firstName: "House1", address: this.addressLevel}));
});

this.initialDataSetupComplete();

this.dispatch({type: AddNewMemberActions.ON_LOAD, groupSubject: household});
const memberActionsState = this.getState(Reducers.reducerKeys.addNewMember);
const workLists = WorklistsFactory.createForAddMemberStart(personSubjectType, memberActionsState.member, null, false, null);
this.dispatch({type: Actions.ON_LOAD, isDraftEntity: false, workLists: workLists});
this.dispatch({type: Actions.REGISTRATION_ENTER_FIRST_NAME, value: "foo"});
this.dispatch({type: Actions.REGISTRATION_ENTER_LAST_NAME, value: "bar"});
this.dispatch({type: Actions.REGISTRATION_ENTER_GENDER, value: this.gender});
this.dispatch({type: Actions.REGISTRATION_ENTER_DOB, value: new Date()});
this.dispatch({type: Actions.REGISTRATION_ENTER_ADDRESS_LEVEL, value: this.addressLevel});
this.dispatch({type: Actions.NEXT, completed: () => {}});
const state = this.getState(Reducers.reducerKeys.personRegister);
const workItems = state.workListState.workLists.currentWorkList.workItems;
assert.equal("ENCOUNTER", workItems[1].type);
assert.equal("Covid Survey", workItems[1].parameters.encounterType);

this.dispatch({type: PersonRegisterActions.SAVE, decisions: [], checklists: [], nextScheduledVisits: [], cb: _.noop});
this.dispatch({type: IndividualEncounterViewActions.ON_ENCOUNTER_LANDING_LOAD, pageNumber: 0, editing: true, workLists: [], cb: _.noop});
context.ending(arguments);
}
}

Expand Down

0 comments on commit ec45b56

Please sign in to comment.