Skip to content

Commit

Permalink
fix(#8745): don't evaluate form context when opening a task (#8746)
Browse files Browse the repository at this point in the history
  • Loading branch information
dianabarsan authored Dec 8, 2023
1 parent fec1410 commit 34edb11
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/default/tasks/forms/home-visit.properties.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"context": {
"expression": "!contact || contact.type === 'person'",
"expression": "false",
"person": true,
"place": false
},
Expand Down
7 changes: 7 additions & 0 deletions tests/e2e/default/tasks/tasks-breadcrumbs.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ describe('Tasks tab breadcrumbs', () => {
},
]);
});

it('should open task with expression', async () => {
await tasksPage.goToTasksTab();
const task = await tasksPage.getTaskByContactAndForm('patient1', 'person_create');
await task.click();
await tasksPage.waitForTaskContentLoaded('Home Visit');
});
});

describe('for supervisor', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default/tasks/tasks.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const compileTasks = async (tasksFileName) => {
return await chtConfUtils.compileNoolsConfig({ tasks: tasksFilePath });
};

describe('Task list', () => {
describe('Tasks', () => {
const places = placeFactory.generateHierarchy();
const clinic = places.get('clinic');
const healthCenter = places.get('health_center');
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/ts/services/enketo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@ export class EnketoFormContext {
}

shouldEvaluateExpression() {
if (this.type === 'task') {
return false;
}

if (this.type === 'report' && this.editing) {
return false;
}
Expand Down
41 changes: 41 additions & 0 deletions webapp/tests/karma/ts/services/enketo.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1209,3 +1209,44 @@ describe('Enketo service', () => {
}));
});
});

describe('EnketoFormContext', () => {
it('should construct object correctly', () => {
const context = new EnketoFormContext('#sel', 'task', { doc: 1 }, { data: 1 });
expect(context).to.deep.include({
selector: '#sel',
type: 'task',
formDoc: { doc: 1 },
instanceData: { data: 1 },
});
});

it('shouldEvaluateExpression should return false for tasks', () => {
const ctx = new EnketoFormContext('a', 'task', {}, {});
expect(ctx.shouldEvaluateExpression()).to.eq(false);
});

it('shouldEvaluateExpression should return false for editing reports', () => {
const ctx = new EnketoFormContext('a', 'report', {}, {});
ctx.editing = true;
expect(ctx.shouldEvaluateExpression()).to.eq(false);
});

it('shouldEvaluateExpression should return true for reports and contact forms', () => {
const ctxReport = new EnketoFormContext('a', 'report', {}, {});
expect(ctxReport.shouldEvaluateExpression()).to.eq(true);

const ctxContact = new EnketoFormContext('a', 'contact', {}, {});
expect(ctxContact.shouldEvaluateExpression()).to.eq(true);
});

it('requiresContact should return true when type is not contact', () => {
const ctxReport = new EnketoFormContext('a', 'report', {}, {});
expect(ctxReport.requiresContact()).to.eq(true);
});

it('requiresContact should return false when type is contact', () => {
const ctxReport = new EnketoFormContext('a', 'contact', {}, {});
expect(ctxReport.requiresContact()).to.eq(false);
});
});

0 comments on commit 34edb11

Please sign in to comment.