From ec45b569f66ba6367d9f2990f92dcae36ff75063 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Thu, 14 Sep 2023 19:58:45 +0530 Subject: [PATCH] #1079 - running two tests for now --- .../integrationTest/IntegrationTestApp.js | 2 +- .../integrationTest/IntegrationTestRunner.js | 14 ++++- .../PersonRegisterActionsIntegrationTest.js | 56 +------------------ 3 files changed, 15 insertions(+), 57 deletions(-) diff --git a/packages/openchs-android/integrationTest/IntegrationTestApp.js b/packages/openchs-android/integrationTest/IntegrationTestApp.js index 0ce782ef9..2b49a77ac 100644 --- a/packages/openchs-android/integrationTest/IntegrationTestApp.js +++ b/packages/openchs-android/integrationTest/IntegrationTestApp.js @@ -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}; } diff --git a/packages/openchs-android/integrationTest/IntegrationTestRunner.js b/packages/openchs-android/integrationTest/IntegrationTestRunner.js index 682b9fe0d..77e715d2c 100644 --- a/packages/openchs-android/integrationTest/IntegrationTestRunner.js +++ b/packages/openchs-android/integrationTest/IntegrationTestRunner.js @@ -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); @@ -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()); } diff --git a/packages/openchs-android/integrationTest/PersonRegisterActionsIntegrationTest.js b/packages/openchs-android/integrationTest/PersonRegisterActionsIntegrationTest.js index e85ed8a10..eec7f4720 100644 --- a/packages/openchs-android/integrationTest/PersonRegisterActionsIntegrationTest.js +++ b/packages/openchs-android/integrationTest/PersonRegisterActionsIntegrationTest.js @@ -1,5 +1,5 @@ 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"; @@ -7,18 +7,12 @@ 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; @@ -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; @@ -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})); }); @@ -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); } }