diff --git a/tests/e2e/default/tasks/forms/home-visit.properties.json b/tests/e2e/default/tasks/forms/home-visit.properties.json index 7d629e5a219..be17f733fd1 100644 --- a/tests/e2e/default/tasks/forms/home-visit.properties.json +++ b/tests/e2e/default/tasks/forms/home-visit.properties.json @@ -1,6 +1,6 @@ { "context": { - "expression": "!contact || contact.type === 'person'", + "expression": "false", "person": true, "place": false }, diff --git a/tests/e2e/default/tasks/tasks-breadcrumbs.wdio-spec.js b/tests/e2e/default/tasks/tasks-breadcrumbs.wdio-spec.js index 138c9074685..6343411d1cb 100644 --- a/tests/e2e/default/tasks/tasks-breadcrumbs.wdio-spec.js +++ b/tests/e2e/default/tasks/tasks-breadcrumbs.wdio-spec.js @@ -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', () => { diff --git a/tests/e2e/default/tasks/tasks.wdio-spec.js b/tests/e2e/default/tasks/tasks.wdio-spec.js index fb8d3040956..0805361f8b5 100644 --- a/tests/e2e/default/tasks/tasks.wdio-spec.js +++ b/tests/e2e/default/tasks/tasks.wdio-spec.js @@ -19,7 +19,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'); diff --git a/webapp/src/ts/services/enketo.service.ts b/webapp/src/ts/services/enketo.service.ts index 4026d025b96..21a0fcc9ceb 100644 --- a/webapp/src/ts/services/enketo.service.ts +++ b/webapp/src/ts/services/enketo.service.ts @@ -653,6 +653,10 @@ export class EnketoFormContext { } shouldEvaluateExpression() { + if (this.type === 'task') { + return false; + } + if (this.type === 'report' && this.editing) { return false; } diff --git a/webapp/tests/karma/ts/services/enketo.service.spec.ts b/webapp/tests/karma/ts/services/enketo.service.spec.ts index 5fe2cbc5953..a0f7eebb201 100644 --- a/webapp/tests/karma/ts/services/enketo.service.spec.ts +++ b/webapp/tests/karma/ts/services/enketo.service.spec.ts @@ -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); + }); +});