Skip to content

Commit

Permalink
fix: tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinHairSaintClair committed Nov 6, 2024
1 parent 472c791 commit d0a9a86
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
27 changes: 1 addition & 26 deletions webapp/src/ts/modules/contacts/contacts-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,48 +211,23 @@ export class ContactsEditComponent implements OnInit, OnDestroy, AfterViewInit {
}

const docId = this.enketoContact.docId;
console.log('Doc ID: ', docId);

// eslint-disable-next-line eqeqeq
this.isEdit = docId != null;
console.log('Is edit: ', this.isEdit);

// this.parentId = ((contact || {}).parent || {})._id ?? this.routeSnapshot.params.parent_id;
this.parentId = contact?.parent?._id ?? this.routeSnapshot.params.parent_id;
console.log('Parent ID: ', this.parentId);

// this.contactType = (contactType || {}).id ?? (this.enketoContact || {}).type;
this.contactType = contactType?.id ?? this.enketoContact?.type;
console.log('Contact type: ', this.contactType);

const temp = this.enketoContact.userContact;
console.log('User contact: ', temp); // This never seems to get populated

// We could load "config" from our namespace:
if (window?._phdcChanges?.hierarchyDuplicatePrevention){
console.log('Hierarchy duplicate config: ');
console.log(window._phdcChanges.hierarchyDuplicatePrevention);
if (this.contactType in window._phdcChanges.hierarchyDuplicatePrevention){
const ct: KeysType = (this.contactType as KeysType);
console.log('Keys type ct: ', ct);
const conf: StrategyForContactType<typeof ct> = window._phdcChanges.hierarchyDuplicatePrevention[ct];
console.log('Conf: ');
console.log(conf);

if (conf){
const strategyType = conf.type;
console.log('Strategy type', strategyType);
this.strategy = this.strategies[strategyType];

this.formPropPathsToCheck = conf.props ? conf.props:
[{form_prop_path: `/data/${this.contactType}/name`, db_doc_ref: 'name'}];

this.duplicateThreshold = conf.threshold;
console.log('Threshold: ', this.duplicateThreshold);

this.queryParams = conf.queryParams;
console.log('Query params: ');
console.log(this.queryParams);
} else {
console.error('No config has been loaded!');
}
Expand Down Expand Up @@ -404,7 +379,7 @@ export class ContactsEditComponent implements OnInit, OnDestroy, AfterViewInit {

private parseXmlForm(form): Document | undefined {
// Below line is taken from enketo-core form-model line 114
const xmlDoc = this.parser.parseFromString(form.getDataStr({ irrelevant: false }), 'text/xml');
const xmlDoc = this.parser.parseFromString(form.getDataStr({ irrelevant: false }), 'text/xml');
console.log('Doc');
console.log(xmlDoc);
if (xmlDoc.getElementsByTagName('parsererror').length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/ts/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ declare global {
type Strategy = {
// Name is used by default (since it's hardcoded in the system) if no props are specified.
// Should props be specified, only those items will be considered
props?: {form_prop_path: string; db_doc_ref: string}[];
props?: {form_prop_path: string; db_doc_ref: string}[]; // TODO: perhaps add a weight to each property
queryParams?: { // Usage example - see main.ts
valuePaths: string[];
//https://stackoverflow.com/questions/76130608/in-typescript-can-you-define-a-function-type-where-each-argument-can-be-one-of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('ContactsEdit component', () => {
let routeSnapshot;
let stopPerformanceTrackStub;
let performanceService;
let dummyFormXml;

beforeEach(() => {
contactTypesService = {
Expand Down Expand Up @@ -101,9 +102,16 @@ describe('ContactsEdit component', () => {
return TestBed.compileComponents().then(() => {
fixture = TestBed.createComponent(ContactsEditComponent);
component = fixture.componentInstance;
component.dbLookupRef = Promise.resolve({
total_rows: 0,
offset: 0,
rows: []
});
fixture.detectChanges();
});
};

dummyFormXml = `<data><health_center><name>test</name><external_id/></health_center></data>`;
});

afterEach(() => sinon.restore());
Expand Down Expand Up @@ -637,6 +645,7 @@ describe('ContactsEdit component', () => {
component.enketoContact = {
formInstance: {
validate: sinon.stub().resolves(false),
getDataStr: sinon.stub().returns(dummyFormXml)
},
};

Expand All @@ -656,6 +665,7 @@ describe('ContactsEdit component', () => {
component.enketoContact = {
formInstance: {
validate: sinon.stub().resolves(true),
getDataStr: sinon.stub().returns(dummyFormXml)
},
type: 'some_contact',
};
Expand All @@ -682,13 +692,21 @@ describe('ContactsEdit component', () => {
dbGet.resolves({ _id: 'clinic_create_form_id', the: 'form' });
const form = {
validate: sinon.stub().resolves(true),
getDataStr: sinon.stub().returns(dummyFormXml)
};
formService.render.resolves(form);

await createComponent();
await fixture.whenStable();

formService.saveContact.resolves({ docId: 'new_clinic_id' });

// TODO: figure out why this test's dbLookupRef is null despite being set in the beforeEach
component.dbLookupRef = Promise.resolve({
total_rows: 0,
offset: 0,
rows: []
});

await component.save();
expect(performanceService.track.calledThrice).to.be.true;
Expand Down Expand Up @@ -732,12 +750,20 @@ describe('ContactsEdit component', () => {
dbGet.resolves({ _id: 'person_edit_form_id', the: 'form' });
const form = {
validate: sinon.stub().resolves(true),
getDataStr: sinon.stub().returns(dummyFormXml)
};
formService.render.resolves(form);

await createComponent();
await fixture.whenStable();

// TODO: figure out why this test's dbLookupRef is null despite being set in the beforeEach
component.dbLookupRef = Promise.resolve({
total_rows: 0,
offset: 0,
rows: []
});

formService.saveContact.resolves({ docId: 'the_person' });

await component.save();
Expand Down Expand Up @@ -780,12 +806,20 @@ describe('ContactsEdit component', () => {
dbGet.resolves({ _id: 'patient_create_form_id', the: 'form' });
const form = {
validate: sinon.stub().resolves(true),
getDataStr: sinon.stub().returns(dummyFormXml)
};
formService.render.resolves(form);

await createComponent();
await fixture.whenStable();

// TODO: figure out why this test's dbLookupRef is null despite being set in the beforeEach
component.dbLookupRef = Promise.resolve({
total_rows: 0,
offset: 0,
rows: []
});

formService.saveContact.resolves({ docId: 'the_patient' });

await component.save();
Expand Down

0 comments on commit d0a9a86

Please sign in to comment.