Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#8745): don't evaluate form context when opening a task (#8746) #8748

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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');
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 @@ -653,6 +653,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);
});
});