Skip to content

Commit

Permalink
fix(#9612): hide last submitted task from task list (#9650)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dianabarsan authored and sugat009 committed Nov 18, 2024
1 parent 06ff5e5 commit eba7aac
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/page-objects/default/tasks/tasks.wdio.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
1 change: 1 addition & 0 deletions webapp/src/ts/reducers/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/ts/services/rules-engine.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions webapp/tests/karma/ts/reducers/tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 5 additions & 1 deletion webapp/tests/karma/ts/services/rules-engine.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,19 +468,23 @@ 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);

tick(1000);

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;
Expand Down

0 comments on commit eba7aac

Please sign in to comment.