From eba7aac775f664ac95479cfd17d4eb0febb3094b Mon Sep 17 00:00:00 2001 From: Diana Barsan <35681649+dianabarsan@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:50:16 +0300 Subject: [PATCH] fix(#9612): hide last submitted task from task list (#9650) Due to a recent debounce in setting contacts as dirty, task-list ended up waiting for two debounce delays when reloading tasks: one from rules engine and one from tasks component itself. It previously had only one debounce, so this issue was less visible, but still existed. As a fix: - emit the change notification early in rules engine, this way both debounces are in parallel - hide the last submitted task from the task list immediately after submission. if the task was not completed by the action, it will show up again when the task list refreshes. Optimizing an e2e test that took a long time due to getting info from "not rendered" angular elements. #9612 --- tests/page-objects/default/tasks/tasks.wdio.page.js | 1 + webapp/src/ts/reducers/tasks.ts | 1 + webapp/src/ts/services/rules-engine.service.ts | 2 +- webapp/tests/karma/ts/reducers/tasks.spec.ts | 1 + webapp/tests/karma/ts/services/rules-engine.service.spec.ts | 6 +++++- 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/page-objects/default/tasks/tasks.wdio.page.js b/tests/page-objects/default/tasks/tasks.wdio.page.js index c9fc2a98177..3c9ffee7c35 100644 --- a/tests/page-objects/default/tasks/tasks.wdio.page.js +++ b/tests/page-objects/default/tasks/tasks.wdio.page.js @@ -12,6 +12,7 @@ const getTaskById = (emissionId) => $(`${TASK_LIST_SELECTOR} li[data-record-id=" const getTasks = () => $$(`${TASK_LIST_SELECTOR} li.content-row`); const getTaskInfo = async (taskElement) => { + await taskElement.scrollIntoView(); const contactName = await (await taskElement.$('h4 span')).getText(); const formTitle = await (await taskElement.$('.summary p')).getText(); let lineage = ''; diff --git a/webapp/src/ts/reducers/tasks.ts b/webapp/src/ts/reducers/tasks.ts index 8768ff14d90..6bad3eb217b 100644 --- a/webapp/src/ts/reducers/tasks.ts +++ b/webapp/src/ts/reducers/tasks.ts @@ -47,6 +47,7 @@ const _tasksReducer = createReducer( on(Actions.setLastSubmittedTask, (state, { payload: { task } }) => ({ ...state, + tasksList: state.tasksList.filter(t => task?._id !== t._id), taskGroup: { ...state.taskGroup, lastSubmittedTask: task diff --git a/webapp/src/ts/services/rules-engine.service.ts b/webapp/src/ts/services/rules-engine.service.ts index 8e7a4712e90..cf16f0e1380 100644 --- a/webapp/src/ts/services/rules-engine.service.ts +++ b/webapp/src/ts/services/rules-engine.service.ts @@ -214,6 +214,7 @@ export class RulesEngineService implements OnDestroy { private dirtyContactCallback(change) { const subjectIds = [this.isReport(change.doc) ? RegistrationUtils.getSubjectId(change.doc) : change.id]; + this.observable.next(subjectIds); if (this.debounceActive[this.CHANGE_WATCHER_KEY]?.active) { const oldSubjectIds = this.debounceActive[this.CHANGE_WATCHER_KEY].params; @@ -238,7 +239,6 @@ export class RulesEngineService implements OnDestroy { this.telemetryService.record(this.getTelemetryTrackName('refresh', 'dirty-contacts'), contactIds.length); await this.rulesEngineCore.updateEmissionsFor(contactIds); - this.observable.next(contactIds); trackPerformance?.stop({ name: this.getTelemetryTrackName('refresh') }); }, this.DEBOUNCE_CHANGE_MILLIS); diff --git a/webapp/tests/karma/ts/reducers/tasks.spec.ts b/webapp/tests/karma/ts/reducers/tasks.spec.ts index 97403ef4997..acfc397952f 100644 --- a/webapp/tests/karma/ts/reducers/tasks.spec.ts +++ b/webapp/tests/karma/ts/reducers/tasks.spec.ts @@ -277,6 +277,7 @@ describe('Tasks reducer', () => { tasksList: [ { _id: 'task1', dueDate: 22, state: 'Ready' }, { _id: 'task2', dueDate: 33, state: 'Ready' }, + { _id: 'task_id2', due: '33', field: 2 } ], loaded: true, taskGroup: { diff --git a/webapp/tests/karma/ts/services/rules-engine.service.spec.ts b/webapp/tests/karma/ts/services/rules-engine.service.spec.ts index a3dbc7e793d..9b20579d25c 100644 --- a/webapp/tests/karma/ts/services/rules-engine.service.spec.ts +++ b/webapp/tests/karma/ts/services/rules-engine.service.spec.ts @@ -468,11 +468,15 @@ describe('RulesEngineService', () => { const change = changesService.subscribe.args[0][0]; await change.callback(changeFeedFormat({ type: 'data_record', form: 'f', fields: { patient_id: 'p1' } })); + expect(callback.callCount).to.equal(1); await change.callback(changeFeedFormat({ _id: '2', type: 'person', patient_id: 'p2' })); + expect(callback.callCount).to.equal(2); tick(500); await change.callback(changeFeedFormat({ _id: '3', type: 'person', patient_id: 'p3' })); + expect(callback.callCount).to.equal(3); tick(900); await change.callback(changeFeedFormat({ type: 'data_record', form: 'f', fields: { patient_id: 'p3' }})); + expect(callback.callCount).to.equal(4); expect(rulesEngineCoreStubs.updateEmissionsFor.callCount).to.equal(0); @@ -480,7 +484,7 @@ describe('RulesEngineService', () => { expect(rulesEngineCoreStubs.updateEmissionsFor.callCount).to.equal(1); expect(rulesEngineCoreStubs.updateEmissionsFor.args[0][0]).to.have.members([ 'p3', '3', '2', 'p1' ]); - expect(callback.callCount).to.equal(1); + expect(callback.callCount).to.equal(4); subscription.unsubscribe(); expect(telemetryService.record.calledOnce).to.be.true;