From cdcf4da653e6f642d851b5154205df9e00f1bc32 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Tue, 16 Aug 2022 21:16:52 +0000 Subject: [PATCH 01/72] remove own place for offline users reports breadcrumbs --- .../ts/modules/reports/reports.component.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 8612eb4eb9f..259370e42ef 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -21,6 +21,8 @@ import { AddReadStatusService } from '@mm-services/add-read-status.service'; import { ExportService } from '@mm-services/export.service'; import { ResponsiveService } from '@mm-services/responsive.service'; import { TranslateService } from '@mm-services/translate.service'; +import {UserContactService} from '@mm-services/user-contact.service'; +import {SessionService} from "@mm-services/session.service"; const PAGE_SIZE = 50; @@ -50,6 +52,7 @@ export class ReportsComponent implements OnInit, OnDestroy { verifyingReport; showContent; enketoEdited; + currentLevel; constructor( private store:Store, @@ -64,6 +67,8 @@ export class ReportsComponent implements OnInit, OnDestroy { private ngZone:NgZone, private scrollLoaderProvider: ScrollLoaderProvider, private responsiveService:ResponsiveService, + private userContactService:UserContactService, + private sessionService:SessionService, ) { this.globalActions = new GlobalActions(store); this.reportsActions = new ReportsActions(store); @@ -134,6 +139,10 @@ export class ReportsComponent implements OnInit, OnDestroy { this.search(); this.setActionBarData(); + this.userContactService.get().then((user) => { + this.currentLevel = user?.parent?.name; + console.log('user ', user, 'currentLevel', this.currentLevel); + }); } ngOnDestroy() { @@ -167,6 +176,16 @@ export class ReportsComponent implements OnInit, OnDestroy { report.heading = this.getReportHeading(form, report); report.summary = form ? form.title : report.form; report.lineage = report.subject && report.subject.lineage || report.lineage; + // filter out the lineage level that belongs to the logged in user + console.log('lineage ', report.lineage); + if(!this.sessionService.isOnlineOnly()) { + report.lineage = report.lineage.filter((level) => { + console.log('level currentLevel ', level, this.currentLevel); + const result = level !== this.currentLevel; + console.log(result); + return result; + }); + } report.unread = !report.read; return report; From 7538e37d1cd0c33f28e83f46b07b3b6619508d3a Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Wed, 17 Aug 2022 15:41:02 +0000 Subject: [PATCH 02/72] fix ponctuation coding style --- webapp/src/ts/modules/reports/reports.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 259370e42ef..b38db740fbf 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -22,7 +22,7 @@ import { ExportService } from '@mm-services/export.service'; import { ResponsiveService } from '@mm-services/responsive.service'; import { TranslateService } from '@mm-services/translate.service'; import {UserContactService} from '@mm-services/user-contact.service'; -import {SessionService} from "@mm-services/session.service"; +import {SessionService} from '@mm-services/session.service'; const PAGE_SIZE = 50; From eceb40ed51d082a6c056b7581bae6de8c96375de Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 19 Aug 2022 12:06:05 +0000 Subject: [PATCH 03/72] minor changes --- webapp/src/ts/modules/reports/reports.component.ts | 3 +++ webapp/src/ts/services/search.service.ts | 1 + 2 files changed, 4 insertions(+) diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index b38db740fbf..2672eb299f9 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -171,12 +171,15 @@ export class ReportsComponent implements OnInit, OnDestroy { private prepareReports(reports) { return reports.map(report => { + console.log('report ', report); const form = _find(this.forms, { code: report.form }); report.icon = form && form.icon; report.heading = this.getReportHeading(form, report); report.summary = form ? form.title : report.form; report.lineage = report.subject && report.subject.lineage || report.lineage; // filter out the lineage level that belongs to the logged in user + console.log('report.subject ', report.subject); + console.log('report.subject.lineage ', report.subject.lineage); console.log('lineage ', report.lineage); if(!this.sessionService.isOnlineOnly()) { report.lineage = report.lineage.filter((level) => { diff --git a/webapp/src/ts/services/search.service.ts b/webapp/src/ts/services/search.service.ts index 1f916ffb5fd..e1268ff7fdc 100644 --- a/webapp/src/ts/services/search.service.ts +++ b/webapp/src/ts/services/search.service.ts @@ -138,6 +138,7 @@ export class SearchService { return Promise.resolve([]); } const before = performance.now(); + return this .searchFactory(type, filters, options, extensions) .then((searchResults) => { From ea0fbfc79d56406c1d37dce779f578b627639bb3 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Thu, 25 Aug 2022 19:23:55 +0000 Subject: [PATCH 04/72] update messages tab breadcrumbs --- .../ts/modules/messages/messages.component.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 67ae9740045..dc4a6989492 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -14,6 +14,8 @@ import { ModalService } from '@mm-modals/mm-modal/mm-modal'; import { SendMessageComponent } from '@mm-modals/send-message/send-message.component'; import { TourService } from '@mm-services/tour.service'; import { ResponsiveService } from '@mm-services/responsive.service'; +import {UserContactService} from '@mm-services/user-contact.service'; +import {SessionService} from '@mm-services/session.service'; @Component({ templateUrl: './messages.component.html' @@ -29,6 +31,7 @@ export class MessagesComponent implements OnInit, OnDestroy { selectedConversationId = null; error = false; private destroyed = false; + private currentLevel; constructor( private route: ActivatedRoute, @@ -40,6 +43,9 @@ export class MessagesComponent implements OnInit, OnDestroy { private modalService: ModalService, private tourService: TourService, private responsiveService: ResponsiveService, + private userContactService:UserContactService, + private sessionService:SessionService, + ) { this.globalActions = new GlobalActions(store); this.messagesActions = new MessagesActions(store); @@ -48,6 +54,10 @@ export class MessagesComponent implements OnInit, OnDestroy { ngOnInit(): void { this.subscribeToStore(); this.tourService.startIfNeeded(this.route.snapshot); + this.userContactService.get().then((user) => { + this.currentLevel = user?.parent?.name; + console.log('user ', user, 'currentLevel', this.currentLevel); + }); this.updateConversations().then(() => this.displayFirstConversation(this.conversations)); this.watchForChanges(); } @@ -152,6 +162,19 @@ export class MessagesComponent implements OnInit, OnDestroy { return this.messageContactService .getList() .then((conversations = []) => { + if(!this.sessionService.isOnlineOnly()) { + conversations.map((conversation) => { + console.log('lineage ', conversation.lineage); + conversation.lineage = conversation.lineage.filter((level) => { + console.log('level currentLevel ', level, this.currentLevel); + const result = level !== this.currentLevel; + console.log(result); + return result; + }); + return conversation; + }); + + } this.setConversations(conversations, { merge }); this.loading = false; }); From 9523922ced79d3cb20c4e268445186b4f82cd88d Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 26 Aug 2022 07:11:21 +0000 Subject: [PATCH 05/72] add breadcrumbs display update to report and message --- .../ts/modules/messages/messages.component.ts | 6 ++--- .../ts/modules/reports/reports.component.ts | 24 +++++++++++++++++++ .../src/ts/services/user-contact.service.ts | 10 ++++++++ .../messages/messages.component.spec.ts | 18 ++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index dc4a6989492..26cef8a7b8c 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -54,9 +54,9 @@ export class MessagesComponent implements OnInit, OnDestroy { ngOnInit(): void { this.subscribeToStore(); this.tourService.startIfNeeded(this.route.snapshot); - this.userContactService.get().then((user) => { - this.currentLevel = user?.parent?.name; - console.log('user ', user, 'currentLevel', this.currentLevel); + this.userContactService.getCurrentLineageLevel().then((currentLevel) => { + this.currentLevel = currentLevel; + console.log('this.currentLevel', this.currentLevel); }); this.updateConversations().then(() => this.displayFirstConversation(this.conversations)); this.watchForChanges(); diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 81bcda061ff..640dc1ea01c 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -26,6 +26,7 @@ import { TranslateService } from '@mm-services/translate.service'; import { ReportsSidebarFilterComponent } from '@mm-modules/reports/reports-sidebar-filter.component'; import { AuthService } from '@mm-services/auth.service'; import { OLD_REPORTS_FILTER_PERMISSION } from '@mm-modules/reports/reports-filters.component'; +import {UserContactService} from '@mm-services/user-contact.service'; import { SessionService } from '@mm-services/session.service'; const PAGE_SIZE = 50; @@ -60,6 +61,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { enketoEdited; useSidebarFilter = true; isSidebarFilterOpen = false; + currentLevel; constructor( private store:Store, @@ -73,9 +75,11 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { private addReadStatusService:AddReadStatusService, private exportService:ExportService, private ngZone:NgZone, + private userContactService:UserContactService, private sessionService:SessionService, private scrollLoaderProvider:ScrollLoaderProvider, private responsiveService:ResponsiveService, + ) { this.globalActions = new GlobalActions(store); this.reportsActions = new ReportsActions(store); @@ -143,6 +147,11 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { this.globalActions.setFilter({ search: this.route.snapshot.queryParams.query || '' }); this.tourService.startIfNeeded(this.route.snapshot); this.setActionBarData(); + + this.userContactService.getCurrentLineageLevel().then((currentLevel) => { + this.currentLevel = currentLevel; + console.log('this.currentLevel in reports', this.currentLevel); + }); } async ngAfterViewInit() { @@ -158,6 +167,8 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { .select(Selectors.getSidebarFilter) .subscribe(({ isOpen }) => this.isSidebarFilterOpen = !!isOpen); this.subscription.add(subscription); + + } ngOnDestroy() { @@ -186,11 +197,24 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { private prepareReports(reports) { return reports.map(report => { + console.log('report ', report); const form = _find(this.forms, { code: report.form }); report.icon = form && form.icon; report.heading = this.getReportHeading(form, report); report.summary = form ? form.title : report.form; report.lineage = report.subject && report.subject.lineage || report.lineage; + // filter out the lineage level that belongs to the logged in user + console.log('report.subject ', report.subject); + console.log('report.subject.lineage ', report.subject.lineage); + console.log('lineage ', report.lineage); + if(!this.sessionService.isOnlineOnly()) { + report.lineage = report.lineage.filter((level) => { + console.log('level currentLevel ', level, this.currentLevel); + const result = level !== this.currentLevel; + console.log(result); + return result; + }); + } report.unread = !report.read; return report; diff --git a/webapp/src/ts/services/user-contact.service.ts b/webapp/src/ts/services/user-contact.service.ts index 0e3c7bbd081..3c092f5222f 100644 --- a/webapp/src/ts/services/user-contact.service.ts +++ b/webapp/src/ts/services/user-contact.service.ts @@ -33,4 +33,14 @@ export class UserContactService { throw err; }); } + + async getCurrentLineageLevel(){ + return this.get().then((user) => { + const currentLevel = user?.parent?.name; + console.log('user ', user, 'currentLevel', currentLevel); + return currentLevel; + }).catch((err) => { + throw err; + }); + } } diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index 4c9aa8fb868..03761c1edf2 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -15,6 +15,7 @@ import { ModalService } from '@mm-modals/mm-modal/mm-modal'; import { NavigationComponent } from '@mm-components/navigation/navigation.component'; import { TourService } from '@mm-services/tour.service'; import { NavigationService } from '@mm-services/navigation.service'; +import {UserContactService} from '@mm-services/user-contact.service'; describe('Messages Component', () => { let component: MessagesComponent; @@ -23,6 +24,17 @@ describe('Messages Component', () => { let changesService; let exportService; let modalService; + let userContactService; + + const userContactGrandparent = { _id: 'grandparent' }; + const userContactDoc = { + _id: 'user', + parent: { + _id: 'parent', + name: 'parent', + parent: userContactGrandparent, + }, + }; beforeEach(waitForAsync(() => { modalService = { show: sinon.stub() }; @@ -33,6 +45,7 @@ describe('Messages Component', () => { changesService = { subscribe: sinon.stub().resolves(of({})) }; + userContactService = { get: sinon.stub().resolves(userContactDoc) }; const tourServiceMock = { startIfNeeded: () => {} }; @@ -63,6 +76,7 @@ describe('Messages Component', () => { { provide: ModalService, useValue: modalService }, { provide: TourService, useValue: tourServiceMock }, { provide: NavigationService, useValue: {} }, + { provide: UserContactService, useValue: userContactService }, ] }) .compileComponents() @@ -81,6 +95,10 @@ describe('Messages Component', () => { expect(component).to.exist; }); + it('should load the user current lineage level', () => { + expect(userContactService.getCurrentLineageLevel()).to.equal('parent'); + }); + it('ngOnInit() should update conversations and watch for changes', () => { const spyUpdateConversations = sinon.spy(component, 'updateConversations'); changesService.subscribe.reset(); From f15dc812d1c0e347511b1a30e55440a45ce7a062 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 26 Aug 2022 08:03:00 +0000 Subject: [PATCH 06/72] fix unit test --- .../karma/ts/modules/messages/messages.component.spec.ts | 7 +++---- .../karma/ts/modules/reports/reports.component.spec.ts | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index 03761c1edf2..9163180f08a 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -16,6 +16,7 @@ import { NavigationComponent } from '@mm-components/navigation/navigation.compon import { TourService } from '@mm-services/tour.service'; import { NavigationService } from '@mm-services/navigation.service'; import {UserContactService} from '@mm-services/user-contact.service'; +import { SessionService } from '@mm-services/session.service'; describe('Messages Component', () => { let component: MessagesComponent; @@ -25,6 +26,7 @@ describe('Messages Component', () => { let exportService; let modalService; let userContactService; + let userCtx; const userContactGrandparent = { _id: 'grandparent' }; const userContactDoc = { @@ -77,6 +79,7 @@ describe('Messages Component', () => { { provide: TourService, useValue: tourServiceMock }, { provide: NavigationService, useValue: {} }, { provide: UserContactService, useValue: userContactService }, + { provide: SessionService, useValue: { userCtx } }, ] }) .compileComponents() @@ -95,10 +98,6 @@ describe('Messages Component', () => { expect(component).to.exist; }); - it('should load the user current lineage level', () => { - expect(userContactService.getCurrentLineageLevel()).to.equal('parent'); - }); - it('ngOnInit() should update conversations and watch for changes', () => { const spyUpdateConversations = sinon.spy(component, 'updateConversations'); changesService.subscribe.reset(); diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index 27b4728080b..7eba0b5408b 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -28,6 +28,7 @@ import { AuthService } from '@mm-services/auth.service'; import { ReportsSidebarFilterComponent } from '@mm-modules/reports/reports-sidebar-filter.component'; import { ReportsActionsBarComponent } from '@mm-modules/reports/reports-actions-bar.component'; import { TelemetryService } from '@mm-services/telemetry.service'; +import {UserContactService} from '@mm-services/user-contact.service'; describe('Reports Component', () => { let component: ReportsComponent; @@ -39,6 +40,7 @@ describe('Reports Component', () => { let listContains; let authService; let datePipe; + let userContactService; beforeEach(waitForAsync(() => { listContains = sinon.stub(); @@ -97,6 +99,7 @@ describe('Reports Component', () => { { provide: TelemetryService, useValue: { record: sinon.stub() } }, { provide: TourService, useValue: tourServiceMock }, { provide: SessionService, useValue: sessionService }, + { provide: UserContactService, useValue: userContactService }, { provide: NavigationService, useValue: {} }, { provide: AuthService, useValue: authService }, { provide: DatePipe, useValue: datePipe }, From 266077263bc0e7b6057fc491f3d9e0420608c64e Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 26 Aug 2022 10:02:45 +0000 Subject: [PATCH 07/72] fix unit test 2 --- .../src/ts/services/user-contact.service.ts | 17 ++++++++------- .../messages/messages.component.spec.ts | 21 ++++++++++++++----- .../modules/reports/reports.component.spec.ts | 3 ++- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/webapp/src/ts/services/user-contact.service.ts b/webapp/src/ts/services/user-contact.service.ts index 3c092f5222f..d729f14b6cd 100644 --- a/webapp/src/ts/services/user-contact.service.ts +++ b/webapp/src/ts/services/user-contact.service.ts @@ -35,12 +35,15 @@ export class UserContactService { } async getCurrentLineageLevel(){ - return this.get().then((user) => { - const currentLevel = user?.parent?.name; - console.log('user ', user, 'currentLevel', currentLevel); - return currentLevel; - }).catch((err) => { - throw err; - }); + return this + .get() + .then((user) => { + const currentLevel = user?.parent?.name; + console.log('user ', user, 'currentLevel', currentLevel); + return currentLevel; + }) + .catch((err) => { + throw err; + }); } } diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index 9163180f08a..6ac3ba70dc9 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -2,7 +2,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { provideMockStore } from '@ngrx/store/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core'; -import { of } from 'rxjs'; +import {of, throwError} from 'rxjs'; import { expect } from 'chai'; import sinon from 'sinon'; @@ -15,7 +15,7 @@ import { ModalService } from '@mm-modals/mm-modal/mm-modal'; import { NavigationComponent } from '@mm-components/navigation/navigation.component'; import { TourService } from '@mm-services/tour.service'; import { NavigationService } from '@mm-services/navigation.service'; -import {UserContactService} from '@mm-services/user-contact.service'; +import { UserContactService } from '@mm-services/user-contact.service'; import { SessionService } from '@mm-services/session.service'; describe('Messages Component', () => { @@ -28,7 +28,7 @@ describe('Messages Component', () => { let userContactService; let userCtx; - const userContactGrandparent = { _id: 'grandparent' }; + /*const userContactGrandparent = { _id: 'grandparent' }; const userContactDoc = { _id: 'user', parent: { @@ -36,7 +36,7 @@ describe('Messages Component', () => { name: 'parent', parent: userContactGrandparent, }, - }; + };*/ beforeEach(waitForAsync(() => { modalService = { show: sinon.stub() }; @@ -47,7 +47,7 @@ describe('Messages Component', () => { changesService = { subscribe: sinon.stub().resolves(of({})) }; - userContactService = { get: sinon.stub().resolves(userContactDoc) }; + userContactService = { get: sinon.stub() }; const tourServiceMock = { startIfNeeded: () => {} }; @@ -198,4 +198,15 @@ describe('Messages Component', () => { expect(spySubscriptionsUnsubscribe.callCount).to.equal(1); }); + +/* it('it should retrieve the hierarchy level of the connected user', () => { + userContactService.get.resolves(userContactDoc); + let level; + userContactService + .getCurrentLineageLevel() + .then((currentLevel) => level = currentLevel) + .catch((error) => throwError(error)); + expect(level).to.equal('parent'); + });*/ + }); diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index 7eba0b5408b..c4b39836485 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -28,7 +28,7 @@ import { AuthService } from '@mm-services/auth.service'; import { ReportsSidebarFilterComponent } from '@mm-modules/reports/reports-sidebar-filter.component'; import { ReportsActionsBarComponent } from '@mm-modules/reports/reports-actions-bar.component'; import { TelemetryService } from '@mm-services/telemetry.service'; -import {UserContactService} from '@mm-services/user-contact.service'; +import { UserContactService } from '@mm-services/user-contact.service'; describe('Reports Component', () => { let component: ReportsComponent; @@ -68,6 +68,7 @@ describe('Reports Component', () => { isOnlineOnly: sinon.stub() }; datePipe = { transform: sinon.stub() }; + userContactService = { get: sinon.stub() }; return TestBed .configureTestingModule({ From 2ddc7523c9a521c233215a7e4204a347f43a4a78 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 26 Aug 2022 10:11:18 +0000 Subject: [PATCH 08/72] fix unit test 2 --- .../karma/ts/modules/messages/messages.component.spec.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index 6ac3ba70dc9..c62a5005d5e 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -2,7 +2,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { provideMockStore } from '@ngrx/store/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core'; -import {of, throwError} from 'rxjs'; +import { of } from 'rxjs'; import { expect } from 'chai'; import sinon from 'sinon'; @@ -199,7 +199,7 @@ describe('Messages Component', () => { expect(spySubscriptionsUnsubscribe.callCount).to.equal(1); }); -/* it('it should retrieve the hierarchy level of the connected user', () => { + /* it('it should retrieve the hierarchy level of the connected user', () => { userContactService.get.resolves(userContactDoc); let level; userContactService @@ -207,6 +207,7 @@ describe('Messages Component', () => { .then((currentLevel) => level = currentLevel) .catch((error) => throwError(error)); expect(level).to.equal('parent'); - });*/ + }); + */ }); From de97add8bd0f4b160165f64d143069f5cfcdf69c Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 26 Aug 2022 10:45:07 +0000 Subject: [PATCH 09/72] fix unit test 3 --- .../ts/modules/messages/messages.component.ts | 6 +++--- .../modules/messages/messages.component.spec.ts | 17 ++++++----------- .../modules/reports/reports.component.spec.ts | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 26cef8a7b8c..8a6e3d55585 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -31,7 +31,7 @@ export class MessagesComponent implements OnInit, OnDestroy { selectedConversationId = null; error = false; private destroyed = false; - private currentLevel; + currentLevel; constructor( private route: ActivatedRoute, @@ -54,10 +54,10 @@ export class MessagesComponent implements OnInit, OnDestroy { ngOnInit(): void { this.subscribeToStore(); this.tourService.startIfNeeded(this.route.snapshot); - this.userContactService.getCurrentLineageLevel().then((currentLevel) => { + /*this.userContactService.getCurrentLineageLevel().then((currentLevel) => { this.currentLevel = currentLevel; console.log('this.currentLevel', this.currentLevel); - }); + });*/ this.updateConversations().then(() => this.displayFirstConversation(this.conversations)); this.watchForChanges(); } diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index c62a5005d5e..76449f6ea1d 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -28,7 +28,7 @@ describe('Messages Component', () => { let userContactService; let userCtx; - /*const userContactGrandparent = { _id: 'grandparent' }; + const userContactGrandparent = { _id: 'grandparent' }; const userContactDoc = { _id: 'user', parent: { @@ -36,7 +36,7 @@ describe('Messages Component', () => { name: 'parent', parent: userContactGrandparent, }, - };*/ + }; beforeEach(waitForAsync(() => { modalService = { show: sinon.stub() }; @@ -47,7 +47,7 @@ describe('Messages Component', () => { changesService = { subscribe: sinon.stub().resolves(of({})) }; - userContactService = { get: sinon.stub() }; + userContactService = { get: sinon.stub().resolves({}) }; const tourServiceMock = { startIfNeeded: () => {} }; @@ -199,15 +199,10 @@ describe('Messages Component', () => { expect(spySubscriptionsUnsubscribe.callCount).to.equal(1); }); - /* it('it should retrieve the hierarchy level of the connected user', () => { + it('it should retrieve the hierarchy level of the connected user', () => { userContactService.get.resolves(userContactDoc); - let level; - userContactService - .getCurrentLineageLevel() - .then((currentLevel) => level = currentLevel) - .catch((error) => throwError(error)); - expect(level).to.equal('parent'); + component.ngOnInit(); + expect(component.currentLevel).to.equal('parent'); }); - */ }); diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index c4b39836485..db970656154 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -68,7 +68,7 @@ describe('Reports Component', () => { isOnlineOnly: sinon.stub() }; datePipe = { transform: sinon.stub() }; - userContactService = { get: sinon.stub() }; + userContactService = { get: sinon.stub().resolves({}) }; return TestBed .configureTestingModule({ From c6152ddf78bef466362f97af9f4e827d3a95e7e3 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 26 Aug 2022 10:47:01 +0000 Subject: [PATCH 10/72] fix unit test 4 --- webapp/src/ts/modules/messages/messages.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 8a6e3d55585..86158599d89 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -54,10 +54,10 @@ export class MessagesComponent implements OnInit, OnDestroy { ngOnInit(): void { this.subscribeToStore(); this.tourService.startIfNeeded(this.route.snapshot); - /*this.userContactService.getCurrentLineageLevel().then((currentLevel) => { + this.userContactService.getCurrentLineageLevel().then((currentLevel) => { this.currentLevel = currentLevel; console.log('this.currentLevel', this.currentLevel); - });*/ + }); this.updateConversations().then(() => this.displayFirstConversation(this.conversations)); this.watchForChanges(); } From 884e3f4911504ca1c398f8f7e46f47674a421359 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 26 Aug 2022 19:38:21 +0000 Subject: [PATCH 11/72] fix unit test 5 --- .../modules/messages/messages.component.spec.ts | 5 ++++- .../ts/modules/reports/reports.component.spec.ts | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index 76449f6ea1d..404d3dcf00d 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -47,7 +47,10 @@ describe('Messages Component', () => { changesService = { subscribe: sinon.stub().resolves(of({})) }; - userContactService = { get: sinon.stub().resolves({}) }; + userContactService = { + get: sinon.stub().resolves(userContactDoc), + getCurrentLineageLevel : sinon.stub().resolves('parent') + }; const tourServiceMock = { startIfNeeded: () => {} }; diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index db970656154..cee5fc5ecf0 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -42,6 +42,16 @@ describe('Reports Component', () => { let datePipe; let userContactService; + const userContactGrandparent = { _id: 'grandparent' }; + const userContactDoc = { + _id: 'user', + parent: { + _id: 'parent', + name: 'parent', + parent: userContactGrandparent, + }, + }; + beforeEach(waitForAsync(() => { listContains = sinon.stub(); const mockedSelectors = [ @@ -68,8 +78,10 @@ describe('Reports Component', () => { isOnlineOnly: sinon.stub() }; datePipe = { transform: sinon.stub() }; - userContactService = { get: sinon.stub().resolves({}) }; - + userContactService = { + get: sinon.stub().resolves(userContactDoc), + getCurrentLineageLevel : sinon.stub().resolves('parent') + }; return TestBed .configureTestingModule({ imports: [ From 3fe346df1fb0c1975cea892e9e6b132abf78534e Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 26 Aug 2022 20:02:54 +0000 Subject: [PATCH 12/72] fix unit tests --- .../karma/ts/modules/messages/messages.component.spec.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index 404d3dcf00d..0ec6067ab71 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -26,7 +26,7 @@ describe('Messages Component', () => { let exportService; let modalService; let userContactService; - let userCtx; + let sessionService; const userContactGrandparent = { _id: 'grandparent' }; const userContactDoc = { @@ -51,6 +51,7 @@ describe('Messages Component', () => { get: sinon.stub().resolves(userContactDoc), getCurrentLineageLevel : sinon.stub().resolves('parent') }; + sessionService = { isOnlineOnly : sinon.stub().resolves(true) }; const tourServiceMock = { startIfNeeded: () => {} }; @@ -82,7 +83,7 @@ describe('Messages Component', () => { { provide: TourService, useValue: tourServiceMock }, { provide: NavigationService, useValue: {} }, { provide: UserContactService, useValue: userContactService }, - { provide: SessionService, useValue: { userCtx } }, + { provide: SessionService, useValue: sessionService }, ] }) .compileComponents() From 0d189c226531cbbd5330a1bb9866bde5272a8fa8 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 26 Aug 2022 20:37:27 +0000 Subject: [PATCH 13/72] fix unit tests functions --- .../tests/karma/ts/modules/messages/messages.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index 0ec6067ab71..7f5dd9c51c2 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -51,7 +51,7 @@ describe('Messages Component', () => { get: sinon.stub().resolves(userContactDoc), getCurrentLineageLevel : sinon.stub().resolves('parent') }; - sessionService = { isOnlineOnly : sinon.stub().resolves(true) }; + sessionService = { isOnlineOnly: sinon.stub() }; const tourServiceMock = { startIfNeeded: () => {} }; From ed07e1c9c117511c3fa1327486e880bb36743c37 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 26 Aug 2022 21:04:50 +0000 Subject: [PATCH 14/72] fix unit tests functions --- .../tests/karma/ts/modules/messages/messages.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index 7f5dd9c51c2..0ec6067ab71 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -51,7 +51,7 @@ describe('Messages Component', () => { get: sinon.stub().resolves(userContactDoc), getCurrentLineageLevel : sinon.stub().resolves('parent') }; - sessionService = { isOnlineOnly: sinon.stub() }; + sessionService = { isOnlineOnly : sinon.stub().resolves(true) }; const tourServiceMock = { startIfNeeded: () => {} }; From cfb46e19518bbfcf2ade4824d2a7913a16fc0ea5 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 26 Aug 2022 21:18:32 +0000 Subject: [PATCH 15/72] fix unit tests messages component --- webapp/src/ts/modules/messages/messages.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 86158599d89..86c29f0499f 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -165,7 +165,7 @@ export class MessagesComponent implements OnInit, OnDestroy { if(!this.sessionService.isOnlineOnly()) { conversations.map((conversation) => { console.log('lineage ', conversation.lineage); - conversation.lineage = conversation.lineage.filter((level) => { + conversation.lineage = conversation.lineage?.filter((level) => { console.log('level currentLevel ', level, this.currentLevel); const result = level !== this.currentLevel; console.log(result); From 791556247cd2b387158a8c6f5620fe2218fca969 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 29 Aug 2022 08:18:27 +0000 Subject: [PATCH 16/72] fix coding style --- .../ts/modules/messages/messages.component.ts | 16 +++++----------- .../src/ts/modules/reports/reports.component.ts | 16 +++------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 86c29f0499f..e74f8316266 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -14,8 +14,8 @@ import { ModalService } from '@mm-modals/mm-modal/mm-modal'; import { SendMessageComponent } from '@mm-modals/send-message/send-message.component'; import { TourService } from '@mm-services/tour.service'; import { ResponsiveService } from '@mm-services/responsive.service'; -import {UserContactService} from '@mm-services/user-contact.service'; -import {SessionService} from '@mm-services/session.service'; +import { UserContactService } from '@mm-services/user-contact.service'; +import { SessionService } from '@mm-services/session.service'; @Component({ templateUrl: './messages.component.html' @@ -30,8 +30,8 @@ export class MessagesComponent implements OnInit, OnDestroy { conversations = []; selectedConversationId = null; error = false; - private destroyed = false; currentLevel; + private destroyed = false; constructor( private route: ActivatedRoute, @@ -45,7 +45,6 @@ export class MessagesComponent implements OnInit, OnDestroy { private responsiveService: ResponsiveService, private userContactService:UserContactService, private sessionService:SessionService, - ) { this.globalActions = new GlobalActions(store); this.messagesActions = new MessagesActions(store); @@ -56,7 +55,6 @@ export class MessagesComponent implements OnInit, OnDestroy { this.tourService.startIfNeeded(this.route.snapshot); this.userContactService.getCurrentLineageLevel().then((currentLevel) => { this.currentLevel = currentLevel; - console.log('this.currentLevel', this.currentLevel); }); this.updateConversations().then(() => this.displayFirstConversation(this.conversations)); this.watchForChanges(); @@ -162,18 +160,14 @@ export class MessagesComponent implements OnInit, OnDestroy { return this.messageContactService .getList() .then((conversations = []) => { + // filter out the lineage level that belongs to the online logged in user if(!this.sessionService.isOnlineOnly()) { conversations.map((conversation) => { - console.log('lineage ', conversation.lineage); conversation.lineage = conversation.lineage?.filter((level) => { - console.log('level currentLevel ', level, this.currentLevel); - const result = level !== this.currentLevel; - console.log(result); - return result; + return (level !== this.currentLevel); }); return conversation; }); - } this.setConversations(conversations, { merge }); this.loading = false; diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 640dc1ea01c..95ebcbb07a3 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -167,8 +167,6 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { .select(Selectors.getSidebarFilter) .subscribe(({ isOpen }) => this.isSidebarFilterOpen = !!isOpen); this.subscription.add(subscription); - - } ngOnDestroy() { @@ -197,26 +195,18 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { private prepareReports(reports) { return reports.map(report => { - console.log('report ', report); const form = _find(this.forms, { code: report.form }); report.icon = form && form.icon; report.heading = this.getReportHeading(form, report); report.summary = form ? form.title : report.form; report.lineage = report.subject && report.subject.lineage || report.lineage; - // filter out the lineage level that belongs to the logged in user - console.log('report.subject ', report.subject); - console.log('report.subject.lineage ', report.subject.lineage); - console.log('lineage ', report.lineage); + // filter out the lineage level that belongs to the online logged in user if(!this.sessionService.isOnlineOnly()) { report.lineage = report.lineage.filter((level) => { - console.log('level currentLevel ', level, this.currentLevel); - const result = level !== this.currentLevel; - console.log(result); - return result; + return (level !== this.currentLevel); }); } report.unread = !report.read; - return report; }); } @@ -287,7 +277,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { search(force = false) { // clears report selection for any text search or filter selection // does not clear selection when someone is editing a form - if ((this.filters.search || Object.keys(this.filters).length > 1) && !this.enketoEdited) { + if((this.filters.search || Object.keys(this.filters).length > 1) && !this.enketoEdited) { this.router.navigate(['reports']); this.reportsActions.clearSelection(); } From dac433f68261206e6e7d290a15acc3c79798074d Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Tue, 30 Aug 2022 13:01:52 +0000 Subject: [PATCH 17/72] some refactoring following PR code review --- .../ts/modules/messages/messages.component.ts | 25 ++++--- .../ts/modules/reports/reports.component.ts | 74 +++++++++---------- webapp/src/ts/services/search.service.ts | 1 - .../src/ts/services/user-contact.service.ts | 9 +-- 4 files changed, 48 insertions(+), 61 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index e74f8316266..44436bc709f 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -43,8 +43,8 @@ export class MessagesComponent implements OnInit, OnDestroy { private modalService: ModalService, private tourService: TourService, private responsiveService: ResponsiveService, - private userContactService:UserContactService, - private sessionService:SessionService, + private userContactService: UserContactService, + private sessionService: SessionService, ) { this.globalActions = new GlobalActions(store); this.messagesActions = new MessagesActions(store); @@ -53,9 +53,13 @@ export class MessagesComponent implements OnInit, OnDestroy { ngOnInit(): void { this.subscribeToStore(); this.tourService.startIfNeeded(this.route.snapshot); - this.userContactService.getCurrentLineageLevel().then((currentLevel) => { - this.currentLevel = currentLevel; - }); + if (!this.sessionService.isOnlineOnly()) { + this.userContactService + .getCurrentLineageLevel() + .then((currentLevel) => { + this.currentLevel = currentLevel; + }); + } this.updateConversations().then(() => this.displayFirstConversation(this.conversations)); this.watchForChanges(); } @@ -160,15 +164,14 @@ export class MessagesComponent implements OnInit, OnDestroy { return this.messageContactService .getList() .then((conversations = []) => { - // filter out the lineage level that belongs to the online logged in user - if(!this.sessionService.isOnlineOnly()) { - conversations.map((conversation) => { - conversation.lineage = conversation.lineage?.filter((level) => { - return (level !== this.currentLevel); - }); + // remove the lineage level that belongs to the offline logged in user, normally the last one + if (this.currentLevel) { + conversations.forEach((conversation) => { + conversation.lineage = conversation.lineage?.filter(level => level !== this.currentLevel); return conversation; }); } + this.setConversations(conversations, { merge }); this.loading = false; }); diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 95ebcbb07a3..f9e4d7619a4 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -1,33 +1,26 @@ -import { find as _find, cloneDeep as _cloneDeep } from 'lodash-es'; -import { - AfterViewInit, - Component, - NgZone, - OnDestroy, - OnInit, - ViewChild, -} from '@angular/core'; -import { Store } from '@ngrx/store'; -import { combineLatest, Subscription } from 'rxjs'; -import { ActivatedRoute, Router } from '@angular/router'; - -import { ScrollLoaderProvider } from '@mm-providers/scroll-loader.provider'; -import { GlobalActions } from '@mm-actions/global'; -import { ReportsActions } from '@mm-actions/reports'; -import { ServicesActions } from '@mm-actions/services'; -import { ChangesService } from '@mm-services/changes.service'; -import { SearchService } from '@mm-services/search.service'; -import { TourService } from '@mm-services/tour.service'; -import { Selectors } from '@mm-selectors/index'; -import { AddReadStatusService } from '@mm-services/add-read-status.service'; -import { ExportService } from '@mm-services/export.service'; -import { ResponsiveService } from '@mm-services/responsive.service'; -import { TranslateService } from '@mm-services/translate.service'; -import { ReportsSidebarFilterComponent } from '@mm-modules/reports/reports-sidebar-filter.component'; -import { AuthService } from '@mm-services/auth.service'; -import { OLD_REPORTS_FILTER_PERMISSION } from '@mm-modules/reports/reports-filters.component'; +import {cloneDeep as _cloneDeep, find as _find} from 'lodash-es'; +import {AfterViewInit, Component, NgZone, OnDestroy, OnInit, ViewChild,} from '@angular/core'; +import {Store} from '@ngrx/store'; +import {combineLatest, Subscription} from 'rxjs'; +import {ActivatedRoute, Router} from '@angular/router'; + +import {ScrollLoaderProvider} from '@mm-providers/scroll-loader.provider'; +import {GlobalActions} from '@mm-actions/global'; +import {ReportsActions} from '@mm-actions/reports'; +import {ServicesActions} from '@mm-actions/services'; +import {ChangesService} from '@mm-services/changes.service'; +import {SearchService} from '@mm-services/search.service'; +import {TourService} from '@mm-services/tour.service'; +import {Selectors} from '@mm-selectors/index'; +import {AddReadStatusService} from '@mm-services/add-read-status.service'; +import {ExportService} from '@mm-services/export.service'; +import {ResponsiveService} from '@mm-services/responsive.service'; +import {TranslateService} from '@mm-services/translate.service'; +import {ReportsSidebarFilterComponent} from '@mm-modules/reports/reports-sidebar-filter.component'; +import {AuthService} from '@mm-services/auth.service'; +import {OLD_REPORTS_FILTER_PERMISSION} from '@mm-modules/reports/reports-filters.component'; import {UserContactService} from '@mm-services/user-contact.service'; -import { SessionService } from '@mm-services/session.service'; +import {SessionService} from '@mm-services/session.service'; const PAGE_SIZE = 50; @@ -79,7 +72,6 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { private sessionService:SessionService, private scrollLoaderProvider:ScrollLoaderProvider, private responsiveService:ResponsiveService, - ) { this.globalActions = new GlobalActions(store); this.reportsActions = new ReportsActions(store); @@ -147,11 +139,13 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { this.globalActions.setFilter({ search: this.route.snapshot.queryParams.query || '' }); this.tourService.startIfNeeded(this.route.snapshot); this.setActionBarData(); - - this.userContactService.getCurrentLineageLevel().then((currentLevel) => { - this.currentLevel = currentLevel; - console.log('this.currentLevel in reports', this.currentLevel); - }); + if (!this.sessionService.isOnlineOnly()) { + this.userContactService + .getCurrentLineageLevel() + .then((currentLevel) => { + this.currentLevel = currentLevel; + }); + } } async ngAfterViewInit() { @@ -200,11 +194,9 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { report.heading = this.getReportHeading(form, report); report.summary = form ? form.title : report.form; report.lineage = report.subject && report.subject.lineage || report.lineage; - // filter out the lineage level that belongs to the online logged in user - if(!this.sessionService.isOnlineOnly()) { - report.lineage = report.lineage.filter((level) => { - return (level !== this.currentLevel); - }); + // remove the lineage level that belongs to the offline logged in user, normally the last one + if (this.currentLevel) { + report.lineage = report.lineage.filter(level => level !== this.currentLevel); } report.unread = !report.read; return report; @@ -277,7 +269,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { search(force = false) { // clears report selection for any text search or filter selection // does not clear selection when someone is editing a form - if((this.filters.search || Object.keys(this.filters).length > 1) && !this.enketoEdited) { + if ((this.filters.search || Object.keys(this.filters).length > 1) && !this.enketoEdited) { this.router.navigate(['reports']); this.reportsActions.clearSelection(); } diff --git a/webapp/src/ts/services/search.service.ts b/webapp/src/ts/services/search.service.ts index e1268ff7fdc..1f916ffb5fd 100644 --- a/webapp/src/ts/services/search.service.ts +++ b/webapp/src/ts/services/search.service.ts @@ -138,7 +138,6 @@ export class SearchService { return Promise.resolve([]); } const before = performance.now(); - return this .searchFactory(type, filters, options, extensions) .then((searchResults) => { diff --git a/webapp/src/ts/services/user-contact.service.ts b/webapp/src/ts/services/user-contact.service.ts index d729f14b6cd..7247ac02004 100644 --- a/webapp/src/ts/services/user-contact.service.ts +++ b/webapp/src/ts/services/user-contact.service.ts @@ -37,13 +37,6 @@ export class UserContactService { async getCurrentLineageLevel(){ return this .get() - .then((user) => { - const currentLevel = user?.parent?.name; - console.log('user ', user, 'currentLevel', currentLevel); - return currentLevel; - }) - .catch((err) => { - throw err; - }); + .then(user => user?.parent?.name); } } From dd233036a235b52719cf2d917070ba46e2e2fc32 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Thu, 1 Sep 2022 08:03:49 +0000 Subject: [PATCH 18/72] add breadcrumbs to tasks tab --- .../ts/modules/messages/messages.component.ts | 2 +- .../ts/modules/reports/reports.component.ts | 3 +- .../src/ts/modules/tasks/tasks.component.html | 1 + .../src/ts/modules/tasks/tasks.component.ts | 51 +++++++++++++++++-- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 44436bc709f..f1d6e116e9a 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -164,7 +164,7 @@ export class MessagesComponent implements OnInit, OnDestroy { return this.messageContactService .getList() .then((conversations = []) => { - // remove the lineage level that belongs to the offline logged in user, normally the last one + // remove the lineage level that belongs to the offline logged-in user, normally the last one if (this.currentLevel) { conversations.forEach((conversation) => { conversation.lineage = conversation.lineage?.filter(level => level !== this.currentLevel); diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index f9e4d7619a4..9921cfb94a7 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -194,7 +194,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { report.heading = this.getReportHeading(form, report); report.summary = form ? form.title : report.form; report.lineage = report.subject && report.subject.lineage || report.lineage; - // remove the lineage level that belongs to the offline logged in user, normally the last one + // remove the lineage level that belongs to the offline logged-in user, normally the last one if (this.currentLevel) { report.lineage = report.lineage.filter(level => level !== this.currentLevel); } @@ -345,4 +345,5 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { resetFilter() { this.reportsSidebarFilter?.resetFilters(); } + } diff --git a/webapp/src/ts/modules/tasks/tasks.component.html b/webapp/src/ts/modules/tasks/tasks.component.html index e8d999675d8..2ff5537dc64 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.html +++ b/webapp/src/ts/modules/tasks/tasks.component.html @@ -32,6 +32,7 @@

{{task.priorityLabel}}
+
diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 2a7946e90df..18ae14b15ad 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -2,7 +2,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { Store } from '@ngrx/store'; import { combineLatest, Subscription } from 'rxjs'; import { ActivatedRoute } from '@angular/router'; -import { debounce as _debounce } from 'lodash-es'; +import { debounce as _debounce, map as _map, find as _find } from 'lodash-es'; import * as moment from 'moment'; import { ChangesService } from '@mm-services/changes.service'; @@ -13,6 +13,9 @@ import { Selectors } from '@mm-selectors/index'; import { TelemetryService } from '@mm-services/telemetry.service'; import { TourService } from '@mm-services/tour.service'; import { GlobalActions } from '@mm-actions/global'; +import { LineageModelGeneratorService } from '@mm-services/lineage-model-generator.service'; +import { UserContactService } from '@mm-services/user-contact.service'; +import { SessionService } from '@mm-services/session.service'; @Component({ templateUrl: './tasks.component.html', @@ -26,6 +29,9 @@ export class TasksComponent implements OnInit, OnDestroy { private telemetryService:TelemetryService, private tourService:TourService, private route:ActivatedRoute, + private lineageModelGeneratorService:LineageModelGeneratorService, + private userContactService:UserContactService, + private sessionService:SessionService, ) { this.tasksActions = new TasksActions(store); this.globalActions = new GlobalActions(store); @@ -41,6 +47,7 @@ export class TasksComponent implements OnInit, OnDestroy { hasTasks; loading; tasksDisabled; + currentLevel; private tasksLoaded; private debouncedReload; @@ -97,6 +104,13 @@ export class TasksComponent implements OnInit, OnDestroy { this.hasTasks = false; this.loading = true; this.debouncedReload = _debounce(this.refreshTasks.bind(this), 1000, { maxWait: 10 * 1000 }); + if (!this.sessionService.isOnlineOnly()) { + this + .getCurrentLineageLevel() + .then((currentLevel) => { + this.currentLevel = currentLevel; + }); + } this.refreshTasks(); this.tourService.startIfNeeded(this.route.snapshot); @@ -116,14 +130,13 @@ export class TasksComponent implements OnInit, OnDestroy { window.location.reload(); } - private hydrateEmissions(taskDocs) { + private async hydrateEmissions(taskDocs) { return taskDocs.map(taskDoc => { const emission = { ...taskDoc.emission }; const dueDate = moment(emission.dueDate, 'YYYY-MM-DD'); emission.date = new Date(dueDate.valueOf()); emission.overdue = dueDate.isBefore(moment()); emission.owner = taskDoc.owner; - return emission; }); } @@ -142,7 +155,27 @@ export class TasksComponent implements OnInit, OnDestroy { .then(taskDocs => { this.hasTasks = taskDocs.length > 0; this.loading = false; - this.tasksActions.setTasksList(this.hydrateEmissions(taskDocs)); + this.hydrateEmissions(taskDocs) + .then((tasks) => { + // get lineages for all tasks + this.getLineagesFromTaskDocs(tasks) + .then((subjects) => { + const deepCopy = obj => JSON.parse(JSON.stringify(obj)); + const lineagedTasks = deepCopy(tasks); + lineagedTasks.forEach((task) => { + // map tasks with lineages + let lineage = _map(_find(subjects, subject => subject._id === task.forId).lineage, 'name'); + // remove the lineage level that belongs to the offline logged-in user, normally the last one + if (this.currentLevel) { + lineage = lineage.filter(level => level && level !== this.currentLevel); + } + task.lineage = lineage; + }); + this.tasksActions.setTasksList(lineagedTasks); + }); + + }); + if (!this.tasksLoaded) { this.tasksActions.setTasksLoaded(true); } @@ -153,7 +186,6 @@ export class TasksComponent implements OnInit, OnDestroy { }) .catch(err => { console.error('Error getting tasks for all contacts', err); - this.error = true; this.loading = false; this.hasTasks = false; @@ -164,4 +196,13 @@ export class TasksComponent implements OnInit, OnDestroy { listTrackBy(index, task) { return task?._id; } + + async getCurrentLineageLevel(){ + return this.userContactService.get().then(user => user?.parent?.name); + } + + async getLineagesFromTaskDocs(taskDocs){ + const ids = _map(taskDocs, 'forId'); + return await this.lineageModelGeneratorService.reportSubjects(ids); + } } From 7d654158d99c7f70be0baff20e811ba6450fbc11 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Thu, 1 Sep 2022 08:16:06 +0000 Subject: [PATCH 19/72] add breadcrumbs to tasks tab --- webapp/src/ts/modules/reports/reports.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 9921cfb94a7..12e79fbfd5a 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -1,5 +1,5 @@ import {cloneDeep as _cloneDeep, find as _find} from 'lodash-es'; -import {AfterViewInit, Component, NgZone, OnDestroy, OnInit, ViewChild,} from '@angular/core'; +import {AfterViewInit, Component, NgZone, OnDestroy, OnInit, ViewChild} from '@angular/core'; import {Store} from '@ngrx/store'; import {combineLatest, Subscription} from 'rxjs'; import {ActivatedRoute, Router} from '@angular/router'; From 00e507a3f1a686cd8dc872384032a128fb5d53ab Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Thu, 1 Sep 2022 15:37:18 +0000 Subject: [PATCH 20/72] breadcrumbs in two lines --- webapp/src/css/common.less | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/webapp/src/css/common.less b/webapp/src/css/common.less index 2f72801f673..7ee5cc566fa 100644 --- a/webapp/src/css/common.less +++ b/webapp/src/css/common.less @@ -76,6 +76,10 @@ ul { .lineage { margin-bottom: 0; + white-space: normal !important; + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; li:after { content: '\2022'; /* bullet */ padding: 0 5px; From fcfdc5ab409bd049ffb2177481c556982986a04d Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 2 Sep 2022 13:23:50 +0000 Subject: [PATCH 21/72] add unit tests to messages tab --- .../ts/modules/messages/messages.component.ts | 12 +- .../ts/modules/reports/reports.component.ts | 8 +- .../src/ts/services/user-contact.service.ts | 6 - .../messages/messages.component.spec.ts | 129 ++++++++++++++++-- .../modules/reports/reports.component.spec.ts | 19 ++- 5 files changed, 153 insertions(+), 21 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 44436bc709f..51f74a3dcfd 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -54,8 +54,7 @@ export class MessagesComponent implements OnInit, OnDestroy { this.subscribeToStore(); this.tourService.startIfNeeded(this.route.snapshot); if (!this.sessionService.isOnlineOnly()) { - this.userContactService - .getCurrentLineageLevel() + this.getCurrentLineageLevel() .then((currentLevel) => { this.currentLevel = currentLevel; }); @@ -164,10 +163,13 @@ export class MessagesComponent implements OnInit, OnDestroy { return this.messageContactService .getList() .then((conversations = []) => { + console.log(conversations); // remove the lineage level that belongs to the offline logged in user, normally the last one if (this.currentLevel) { conversations.forEach((conversation) => { - conversation.lineage = conversation.lineage?.filter(level => level !== this.currentLevel); + if (conversation.lineage) { + conversation.lineage = conversation.lineage.filter(level => level !== this.currentLevel); + } return conversation; }); } @@ -204,4 +206,8 @@ export class MessagesComponent implements OnInit, OnDestroy { const identifier = message.doc ? message.doc.id + message.doc._rev : message.id; return message.key + identifier; } + + async getCurrentLineageLevel(){ + return this.userContactService.get().then(user => user?.parent?.name); + } } diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index f9e4d7619a4..03b66e104ca 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -140,8 +140,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { this.tourService.startIfNeeded(this.route.snapshot); this.setActionBarData(); if (!this.sessionService.isOnlineOnly()) { - this.userContactService - .getCurrentLineageLevel() + this.getCurrentLineageLevel() .then((currentLevel) => { this.currentLevel = currentLevel; }); @@ -188,6 +187,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { } private prepareReports(reports) { + console.log(reports); return reports.map(report => { const form = _find(this.forms, { code: report.form }); report.icon = form && form.icon; @@ -345,4 +345,8 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { resetFilter() { this.reportsSidebarFilter?.resetFilters(); } + + async getCurrentLineageLevel(){ + return this.userContactService.get().then(user => user?.parent?.name); + } } diff --git a/webapp/src/ts/services/user-contact.service.ts b/webapp/src/ts/services/user-contact.service.ts index 7247ac02004..0e3c7bbd081 100644 --- a/webapp/src/ts/services/user-contact.service.ts +++ b/webapp/src/ts/services/user-contact.service.ts @@ -33,10 +33,4 @@ export class UserContactService { throw err; }); } - - async getCurrentLineageLevel(){ - return this - .get() - .then(user => user?.parent?.name); - } } diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index 0ec6067ab71..bd69455dca3 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -49,9 +49,8 @@ describe('Messages Component', () => { }; userContactService = { get: sinon.stub().resolves(userContactDoc), - getCurrentLineageLevel : sinon.stub().resolves('parent') }; - sessionService = { isOnlineOnly : sinon.stub().resolves(true) }; + sessionService = { isOnlineOnly : sinon.stub().resolves(false) }; const tourServiceMock = { startIfNeeded: () => {} }; @@ -193,6 +192,126 @@ describe('Messages Component', () => { expect(component.loading).to.be.false; expect(component.conversations).to.eql( newConversations); }); + + it('it should retrieve the hierarchy level of the connected user', () => { + userContactService.get.resolves(userContactDoc); + sessionService.isOnlineOnly.resolves(false); + component.ngOnInit(); + expect(component.currentLevel).to.equal('parent'); + }); + + it('it should not change the conversations lineage if the connected user is online only', async () => { + const conversations = [ + { key: 'a', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + { key: 'b', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + { key: 'c', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + { key: 'd', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + ]; + messageContactService.getList.reset(); + messageContactService.getList.resolves(conversations); + userContactService.get.resolves(userContactDoc); + sessionService.isOnlineOnly.resolves(true); + //fixture.detectChanges(); + //await component.updateConversations(); + component.ngOnInit(); + expect(messageContactService.getList.callCount).to.equal(1); + expect(component.currentLevel).to.equal('parent'); + //expect(component.conversations).to.equal(conversations); + }); + + it('it should not change the conversations lineage ' + + 'if the connected user is offline only but belongs to a place out of the conversation lineage', async () => { + const offlineUserContactDoc = { + _id: 'user', + parent: { + _id: 'parent', + name: 'parent', + parent: userContactGrandparent, + }, + }; + const conversations = [ + { key: 'a', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + { key: 'b', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + { key: 'c', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + { key: 'd', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + ]; + messageContactService.getList.reset(); + messageContactService.getList.resolves(conversations); + userContactService.get.resolves(offlineUserContactDoc); + sessionService.isOnlineOnly.resolves(false); + //fixture.detectChanges(); + //await component.updateConversations(); + component.ngOnInit(); + expect(await messageContactService.getList.callCount).to.equal(1); + expect(component.currentLevel).to.equal('parent'); + //expect(component.conversations).to.equal(conversations); + }); + + it('it should update the conversations lineage ' + + 'if the connected user is offline and belongs to a place of the conversation lineage', async () => { + const offlineUserContactDoc2 = { + _id: 'user', + parent: { + _id: 'parent', + name: 'CHW Bettys Area', + parent: userContactGrandparent, + }, + }; + const conversations = [ + { key: 'a', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + { key: 'b', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + { key: 'c', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + { key: 'd', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + ]; + const updatedConversations = [ + { key: 'a', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] + }, + { key: 'b', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] + }, + { key: 'c', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] + }, + { key: 'd', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] + }, + ]; + messageContactService.getList.reset(); + messageContactService.getList.resolves(conversations); + userContactService.get.resolves(offlineUserContactDoc2); + sessionService.isOnlineOnly.resolves(false); + //fixture.detectChanges(); + //await component.updateConversations(); + component.ngOnInit(); + expect(messageContactService.getList.callCount).to.equal(1); + expect(component.currentLevel).to.equal('CHW Bettys Area'); + //expect(component.conversations).to.equal(updatedConversations); + }); }); it('ngOnDestroy() should unsubscribe from observables', () => { @@ -203,10 +322,4 @@ describe('Messages Component', () => { expect(spySubscriptionsUnsubscribe.callCount).to.equal(1); }); - it('it should retrieve the hierarchy level of the connected user', () => { - userContactService.get.resolves(userContactDoc); - component.ngOnInit(); - expect(component.currentLevel).to.equal('parent'); - }); - }); diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index cee5fc5ecf0..8894362c050 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -75,12 +75,11 @@ describe('Reports Component', () => { authService = { has: sinon.stub().resolves(false) }; sessionService = { isDbAdmin: sinon.stub().returns(false), - isOnlineOnly: sinon.stub() + isOnlineOnly: sinon.stub().returns(false) }; datePipe = { transform: sinon.stub() }; userContactService = { get: sinon.stub().resolves(userContactDoc), - getCurrentLineageLevel : sinon.stub().resolves('parent') }; return TestBed .configureTestingModule({ @@ -279,4 +278,20 @@ describe('Reports Component', () => { }); }); + describe('lineage updates', () => { + it('it should retrieve the hierarchy level of the connected user', () => { + userContactService.get.resolves(userContactDoc); + sessionService.isOnlineOnly.resolves(false); + component.ngOnInit(); + expect(component.currentLevel).to.equal('parent'); + }); + + it('it should not change the report lineage if the connected user is online only', () => { + userContactService.get.resolves(userContactDoc); + sessionService.isOnlineOnly.resolves(true); + component.ngOnInit(); + expect(component.currentLevel).to.equal('parent'); + }); + + }); }); From cacd0e805399c9bf01ed2a8bec86b559a7e77cbe Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 2 Sep 2022 17:43:04 +0000 Subject: [PATCH 22/72] add unit test to messages breadcrumbs --- .../ts/modules/messages/messages.component.ts | 7 +-- .../messages/messages.component.spec.ts | 46 ++++++++++--------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 51f74a3dcfd..53807838459 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -53,7 +53,8 @@ export class MessagesComponent implements OnInit, OnDestroy { ngOnInit(): void { this.subscribeToStore(); this.tourService.startIfNeeded(this.route.snapshot); - if (!this.sessionService.isOnlineOnly()) { + const isOffline = !this.sessionService.isOnlineOnly(); + if (isOffline) { this.getCurrentLineageLevel() .then((currentLevel) => { this.currentLevel = currentLevel; @@ -163,7 +164,7 @@ export class MessagesComponent implements OnInit, OnDestroy { return this.messageContactService .getList() .then((conversations = []) => { - console.log(conversations); + console.log('conversations before', conversations); // remove the lineage level that belongs to the offline logged in user, normally the last one if (this.currentLevel) { conversations.forEach((conversation) => { @@ -173,7 +174,7 @@ export class MessagesComponent implements OnInit, OnDestroy { return conversation; }); } - + console.log('conversations after', conversations); this.setConversations(conversations, { merge }); this.loading = false; }); diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index bd69455dca3..6a92f6fb7d1 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -1,4 +1,4 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing'; import { provideMockStore } from '@ngrx/store/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core'; @@ -50,13 +50,19 @@ describe('Messages Component', () => { userContactService = { get: sinon.stub().resolves(userContactDoc), }; - sessionService = { isOnlineOnly : sinon.stub().resolves(false) }; + sessionService = { isOnlineOnly : sinon.stub().returns(false) }; const tourServiceMock = { startIfNeeded: () => {} }; const mockedSelectors = [ { selector: 'getSelectedConversation', value: {} }, - { selector: 'getConversations', value: []}, + { selector: 'getConversations', value: + [ + { key: 'a', message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + ], + }, { selector: 'getLoadingContent', value: false }, { selector: 'getMessagesError', value: false }, ]; @@ -194,8 +200,8 @@ describe('Messages Component', () => { }); it('it should retrieve the hierarchy level of the connected user', () => { - userContactService.get.resolves(userContactDoc); - sessionService.isOnlineOnly.resolves(false); + //userContactService.get.resolves(userContactDoc); + sessionService.isOnlineOnly.returns(false); component.ngOnInit(); expect(component.currentLevel).to.equal('parent'); }); @@ -218,13 +224,11 @@ describe('Messages Component', () => { messageContactService.getList.reset(); messageContactService.getList.resolves(conversations); userContactService.get.resolves(userContactDoc); - sessionService.isOnlineOnly.resolves(true); - //fixture.detectChanges(); - //await component.updateConversations(); - component.ngOnInit(); + sessionService.isOnlineOnly.returns(true); + await component.updateConversations({merge : true}); expect(messageContactService.getList.callCount).to.equal(1); expect(component.currentLevel).to.equal('parent'); - //expect(component.conversations).to.equal(conversations); + expect(component.conversations).to.deep.equal(conversations); }); it('it should not change the conversations lineage ' + @@ -254,17 +258,16 @@ describe('Messages Component', () => { messageContactService.getList.reset(); messageContactService.getList.resolves(conversations); userContactService.get.resolves(offlineUserContactDoc); - sessionService.isOnlineOnly.resolves(false); + sessionService.isOnlineOnly.returns(false); //fixture.detectChanges(); - //await component.updateConversations(); - component.ngOnInit(); + await component.updateConversations({merge : true}); expect(await messageContactService.getList.callCount).to.equal(1); expect(component.currentLevel).to.equal('parent'); - //expect(component.conversations).to.equal(conversations); + expect(component.conversations).to.equal(conversations); }); it('it should update the conversations lineage ' + - 'if the connected user is offline and belongs to a place of the conversation lineage', async () => { + 'if the connected user is offline and belongs to a place of the conversation lineage', fakeAsync( () => { const offlineUserContactDoc2 = { _id: 'user', parent: { @@ -304,14 +307,15 @@ describe('Messages Component', () => { messageContactService.getList.reset(); messageContactService.getList.resolves(conversations); userContactService.get.resolves(offlineUserContactDoc2); - sessionService.isOnlineOnly.resolves(false); - //fixture.detectChanges(); - //await component.updateConversations(); + sessionService.isOnlineOnly.returns(false); component.ngOnInit(); - expect(messageContactService.getList.callCount).to.equal(1); + tick(); + component.updateConversations({merge : true}); + tick(); + expect(messageContactService.getList.callCount).to.equal(2); expect(component.currentLevel).to.equal('CHW Bettys Area'); - //expect(component.conversations).to.equal(updatedConversations); - }); + expect(component.conversations).to.deep.equal(updatedConversations); + })); }); it('ngOnDestroy() should unsubscribe from observables', () => { From 65a130d8bbd0d982e10ae476f6ee4240ac3fd273 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Sat, 3 Sep 2022 04:09:48 +0000 Subject: [PATCH 23/72] add unit tests to reports and messages breadcrumbs --- .../ts/modules/messages/messages.component.ts | 2 - .../ts/modules/reports/reports.component.ts | 9 +- .../messages/messages.component.spec.ts | 34 ++--- .../modules/reports/reports.component.spec.ts | 131 +++++++++++++++++- 4 files changed, 148 insertions(+), 28 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 53807838459..2c9f113119f 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -164,7 +164,6 @@ export class MessagesComponent implements OnInit, OnDestroy { return this.messageContactService .getList() .then((conversations = []) => { - console.log('conversations before', conversations); // remove the lineage level that belongs to the offline logged in user, normally the last one if (this.currentLevel) { conversations.forEach((conversation) => { @@ -174,7 +173,6 @@ export class MessagesComponent implements OnInit, OnDestroy { return conversation; }); } - console.log('conversations after', conversations); this.setConversations(conversations, { merge }); this.loading = false; }); diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 03b66e104ca..efce8e97541 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -180,21 +180,20 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { if (report.validSubject) { return report.subject.value; } - if (report.subject.name) { + if (report.subject?.name) { return report.subject.name; } return this.translateService.instant('report.subject.unknown'); } - private prepareReports(reports) { - console.log(reports); + prepareReports(reports) { return reports.map(report => { const form = _find(this.forms, { code: report.form }); report.icon = form && form.icon; report.heading = this.getReportHeading(form, report); report.summary = form ? form.title : report.form; report.lineage = report.subject && report.subject.lineage || report.lineage; - // remove the lineage level that belongs to the offline logged in user, normally the last one + // remove the lineage level that belongs to the offline logged-in user, normally the last one if (this.currentLevel) { report.lineage = report.lineage.filter(level => level !== this.currentLevel); } @@ -230,7 +229,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { .then((reports) => this.addReadStatusService.updateReports(reports)) .then((updatedReports) => { updatedReports = this.prepareReports(updatedReports); - + console.log(updatedReports); this.reportsActions.updateReportsList(updatedReports); this.moreItems = updatedReports.length >= options.limit; diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index 6a92f6fb7d1..5f955c54458 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -200,13 +200,10 @@ describe('Messages Component', () => { }); it('it should retrieve the hierarchy level of the connected user', () => { - //userContactService.get.resolves(userContactDoc); - sessionService.isOnlineOnly.returns(false); - component.ngOnInit(); expect(component.currentLevel).to.equal('parent'); }); - it('it should not change the conversations lineage if the connected user is online only', async () => { + it('it should not change the conversations lineage if the connected user is online only', fakeAsync( () => { const conversations = [ { key: 'a', message: { inAllMessages: true }, lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] @@ -225,14 +222,17 @@ describe('Messages Component', () => { messageContactService.getList.resolves(conversations); userContactService.get.resolves(userContactDoc); sessionService.isOnlineOnly.returns(true); - await component.updateConversations({merge : true}); - expect(messageContactService.getList.callCount).to.equal(1); + component.ngOnInit(); + tick(); + component.updateConversations({merge : true}); + tick(); + expect(messageContactService.getList.callCount).to.equal(2); expect(component.currentLevel).to.equal('parent'); expect(component.conversations).to.deep.equal(conversations); - }); + })); it('it should not change the conversations lineage ' + - 'if the connected user is offline only but belongs to a place out of the conversation lineage', async () => { + 'if the connected user is offline only but belongs to a place out of the conversation lineage', fakeAsync( () => { const offlineUserContactDoc = { _id: 'user', parent: { @@ -259,12 +259,14 @@ describe('Messages Component', () => { messageContactService.getList.resolves(conversations); userContactService.get.resolves(offlineUserContactDoc); sessionService.isOnlineOnly.returns(false); - //fixture.detectChanges(); - await component.updateConversations({merge : true}); - expect(await messageContactService.getList.callCount).to.equal(1); + component.ngOnInit(); + tick(); + component.updateConversations({merge : true}); + tick(); + expect(messageContactService.getList.callCount).to.equal(2); expect(component.currentLevel).to.equal('parent'); - expect(component.conversations).to.equal(conversations); - }); + expect(component.conversations).to.deep.equal(conversations); + })); it('it should update the conversations lineage ' + 'if the connected user is offline and belongs to a place of the conversation lineage', fakeAsync( () => { @@ -281,10 +283,10 @@ describe('Messages Component', () => { lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] }, { key: 'b', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] }, { key: 'c', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'Ramdom Place'] }, { key: 'd', message: { inAllMessages: true }, lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] @@ -298,7 +300,7 @@ describe('Messages Component', () => { lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] }, { key: 'c', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'Ramdom Place'] }, { key: 'd', message: { inAllMessages: true }, lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index 8894362c050..885e38e471f 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -280,17 +280,138 @@ describe('Reports Component', () => { describe('lineage updates', () => { it('it should retrieve the hierarchy level of the connected user', () => { - userContactService.get.resolves(userContactDoc); - sessionService.isOnlineOnly.resolves(false); - component.ngOnInit(); expect(component.currentLevel).to.equal('parent'); }); - it('it should not change the report lineage if the connected user is online only', () => { + it('it should not change the reports lineages if the connected user is online only', async () => { + const reports = [ + {_id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ + 'St Elmos Concession', + 'Chattanooga Village', + 'CHW Bettys Area' + ]}, + {_id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ + 'Chattanooga Village', + 'CHW Bettys Area' + ]}, + {_id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ + 'Chattanooga Village' + ]}, + {_id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ + 'CHW Bettys Area' + ]}, + ]; + const expectedReports = [ + {_id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ + 'St Elmos Concession', + 'Chattanooga Village', + 'CHW Bettys Area' + ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true + }, + {_id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ + 'Chattanooga Village', + 'CHW Bettys Area' + ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true + }, + {_id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ + 'Chattanooga Village' + ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true + }, + {_id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ + 'CHW Bettys Area' + ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true + }, + ]; userContactService.get.resolves(userContactDoc); sessionService.isOnlineOnly.resolves(true); - component.ngOnInit(); + component.currentLevel = await component.getCurrentLineageLevel(); expect(component.currentLevel).to.equal('parent'); + const updatedReports = component.prepareReports(reports); + expect(updatedReports).to.deep.equal(expectedReports); + }); + + it('it should update the reports lineages to remove current level if the connected user is offline', async () => { + const offlineUserContactDoc = { + _id: 'user', + parent: { + _id: 'parent', + name: 'CHW Bettys Area', + parent: userContactGrandparent, + }, + }; + const reports = [ + {_id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ + 'St Elmos Concession', + 'Chattanooga Village', + 'CHW Bettys Area' + ]}, + {_id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ + 'Chattanooga Village', + 'CHW Bettys Area' + ]}, + {_id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ + 'Chattanooga Village' + ]}, + {_id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ + 'CHW Bettys Area' + ]}, + ]; + const expectedReports = [ + {_id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ + 'St Elmos Concession', + 'Chattanooga Village', + ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true + }, + {_id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ + 'Chattanooga Village', + ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true + }, + {_id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ + 'Chattanooga Village' + ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true + }, + {_id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ + ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true + }, + ]; + userContactService.get.resolves(offlineUserContactDoc); + sessionService.isOnlineOnly.resolves(false); + component.currentLevel = await component.getCurrentLineageLevel(); + expect(component.currentLevel).to.equal('CHW Bettys Area'); + const updatedReports = component.prepareReports(reports); + expect(updatedReports).to.deep.equal(expectedReports); }); }); From 81a7bd487e07e25832c7fe8c128957e8d714f58a Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Thu, 1 Sep 2022 08:03:49 +0000 Subject: [PATCH 24/72] add breadcrumbs to tasks tab --- .../ts/modules/messages/messages.component.ts | 2 +- .../ts/modules/reports/reports.component.ts | 3 ++ .../src/ts/modules/tasks/tasks.component.html | 1 + .../src/ts/modules/tasks/tasks.component.ts | 51 +++++++++++++++++-- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 2c9f113119f..018e42670b4 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -164,7 +164,7 @@ export class MessagesComponent implements OnInit, OnDestroy { return this.messageContactService .getList() .then((conversations = []) => { - // remove the lineage level that belongs to the offline logged in user, normally the last one + // remove the lineage level that belongs to the offline logged-in user, normally the last one if (this.currentLevel) { conversations.forEach((conversation) => { if (conversation.lineage) { diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index efce8e97541..bb2417d0351 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -345,7 +345,10 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { this.reportsSidebarFilter?.resetFilters(); } +<<<<<<< HEAD async getCurrentLineageLevel(){ return this.userContactService.get().then(user => user?.parent?.name); } +======= +>>>>>>> dd233036a (add breadcrumbs to tasks tab) } diff --git a/webapp/src/ts/modules/tasks/tasks.component.html b/webapp/src/ts/modules/tasks/tasks.component.html index e8d999675d8..2ff5537dc64 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.html +++ b/webapp/src/ts/modules/tasks/tasks.component.html @@ -32,6 +32,7 @@

{{task.priorityLabel}}
+
diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 2a7946e90df..18ae14b15ad 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -2,7 +2,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { Store } from '@ngrx/store'; import { combineLatest, Subscription } from 'rxjs'; import { ActivatedRoute } from '@angular/router'; -import { debounce as _debounce } from 'lodash-es'; +import { debounce as _debounce, map as _map, find as _find } from 'lodash-es'; import * as moment from 'moment'; import { ChangesService } from '@mm-services/changes.service'; @@ -13,6 +13,9 @@ import { Selectors } from '@mm-selectors/index'; import { TelemetryService } from '@mm-services/telemetry.service'; import { TourService } from '@mm-services/tour.service'; import { GlobalActions } from '@mm-actions/global'; +import { LineageModelGeneratorService } from '@mm-services/lineage-model-generator.service'; +import { UserContactService } from '@mm-services/user-contact.service'; +import { SessionService } from '@mm-services/session.service'; @Component({ templateUrl: './tasks.component.html', @@ -26,6 +29,9 @@ export class TasksComponent implements OnInit, OnDestroy { private telemetryService:TelemetryService, private tourService:TourService, private route:ActivatedRoute, + private lineageModelGeneratorService:LineageModelGeneratorService, + private userContactService:UserContactService, + private sessionService:SessionService, ) { this.tasksActions = new TasksActions(store); this.globalActions = new GlobalActions(store); @@ -41,6 +47,7 @@ export class TasksComponent implements OnInit, OnDestroy { hasTasks; loading; tasksDisabled; + currentLevel; private tasksLoaded; private debouncedReload; @@ -97,6 +104,13 @@ export class TasksComponent implements OnInit, OnDestroy { this.hasTasks = false; this.loading = true; this.debouncedReload = _debounce(this.refreshTasks.bind(this), 1000, { maxWait: 10 * 1000 }); + if (!this.sessionService.isOnlineOnly()) { + this + .getCurrentLineageLevel() + .then((currentLevel) => { + this.currentLevel = currentLevel; + }); + } this.refreshTasks(); this.tourService.startIfNeeded(this.route.snapshot); @@ -116,14 +130,13 @@ export class TasksComponent implements OnInit, OnDestroy { window.location.reload(); } - private hydrateEmissions(taskDocs) { + private async hydrateEmissions(taskDocs) { return taskDocs.map(taskDoc => { const emission = { ...taskDoc.emission }; const dueDate = moment(emission.dueDate, 'YYYY-MM-DD'); emission.date = new Date(dueDate.valueOf()); emission.overdue = dueDate.isBefore(moment()); emission.owner = taskDoc.owner; - return emission; }); } @@ -142,7 +155,27 @@ export class TasksComponent implements OnInit, OnDestroy { .then(taskDocs => { this.hasTasks = taskDocs.length > 0; this.loading = false; - this.tasksActions.setTasksList(this.hydrateEmissions(taskDocs)); + this.hydrateEmissions(taskDocs) + .then((tasks) => { + // get lineages for all tasks + this.getLineagesFromTaskDocs(tasks) + .then((subjects) => { + const deepCopy = obj => JSON.parse(JSON.stringify(obj)); + const lineagedTasks = deepCopy(tasks); + lineagedTasks.forEach((task) => { + // map tasks with lineages + let lineage = _map(_find(subjects, subject => subject._id === task.forId).lineage, 'name'); + // remove the lineage level that belongs to the offline logged-in user, normally the last one + if (this.currentLevel) { + lineage = lineage.filter(level => level && level !== this.currentLevel); + } + task.lineage = lineage; + }); + this.tasksActions.setTasksList(lineagedTasks); + }); + + }); + if (!this.tasksLoaded) { this.tasksActions.setTasksLoaded(true); } @@ -153,7 +186,6 @@ export class TasksComponent implements OnInit, OnDestroy { }) .catch(err => { console.error('Error getting tasks for all contacts', err); - this.error = true; this.loading = false; this.hasTasks = false; @@ -164,4 +196,13 @@ export class TasksComponent implements OnInit, OnDestroy { listTrackBy(index, task) { return task?._id; } + + async getCurrentLineageLevel(){ + return this.userContactService.get().then(user => user?.parent?.name); + } + + async getLineagesFromTaskDocs(taskDocs){ + const ids = _map(taskDocs, 'forId'); + return await this.lineageModelGeneratorService.reportSubjects(ids); + } } From a9531593babfd2cb13c4cb8f855a7cc285a44589 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Thu, 1 Sep 2022 08:16:06 +0000 Subject: [PATCH 25/72] add breadcrumbs to tasks tab --- webapp/src/ts/modules/reports/reports.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index bb2417d0351..145096296d9 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -1,5 +1,5 @@ import {cloneDeep as _cloneDeep, find as _find} from 'lodash-es'; -import {AfterViewInit, Component, NgZone, OnDestroy, OnInit, ViewChild,} from '@angular/core'; +import {AfterViewInit, Component, NgZone, OnDestroy, OnInit, ViewChild} from '@angular/core'; import {Store} from '@ngrx/store'; import {combineLatest, Subscription} from 'rxjs'; import {ActivatedRoute, Router} from '@angular/router'; From 7698d0a96a3c6c22da0790f98e3dbb633549189d Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 2 Sep 2022 15:13:38 +0000 Subject: [PATCH 26/72] fix tests --- .../ts/modules/tasks/tasks.component.spec.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 353b9a69bb2..23bf8bce043 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -16,6 +16,9 @@ import { TasksComponent } from '@mm-modules/tasks/tasks.component'; import { NavigationComponent } from '@mm-components/navigation/navigation.component'; import { Selectors } from '@mm-selectors/index'; import { NavigationService } from '@mm-services/navigation.service'; +import {UserContactService} from '@mm-services/user-contact.service'; +import {SessionService} from '@mm-services/session.service'; +import { LineageModelGeneratorService } from '@mm-services/lineage-model-generator.service'; describe('TasksComponent', () => { let getComponent; @@ -26,10 +29,21 @@ describe('TasksComponent', () => { let contactTypesService; let clock; let store; + let sessionService; + let userContactService; + let lineageModelGeneratorService; let component: TasksComponent; let fixture: ComponentFixture; + const userContactDoc = { + _id: 'user', + parent: { + _id: 'parent', + name: 'parent', + }, + }; + beforeEach(async () => { changesService = { subscribe: sinon.stub() }; rulesEngineService = { @@ -43,6 +57,15 @@ describe('TasksComponent', () => { contactTypesService = { includes: sinon.stub(), }; + sessionService = { + isDbAdmin: sinon.stub().returns(false), + isOnlineOnly: sinon.stub().returns(false), + userCtx: sinon.stub().returns({ name: 'Sarah' }) + }; + userContactService = { + get: sinon.stub().resolves(userContactDoc), + }; + lineageModelGeneratorService = { reportSubjects: sinon.stub() }; TestBed.configureTestingModule({ imports: [ @@ -57,6 +80,9 @@ describe('TasksComponent', () => { { provide: TourService, useValue: tourService }, { provide: ContactTypesService, useValue: contactTypesService }, { provide: NavigationService, useValue: {} }, + { provide: SessionService, useValue: sessionService }, + { provide: UserContactService, useValue: userContactService }, + { provide: LineageModelGeneratorService, useValue: { lineageModelGeneratorService } }, ], declarations: [ TasksComponent, @@ -278,4 +304,14 @@ describe('TasksComponent', () => { expect(component.listTrackBy(0, false)).to.equal(undefined); }); }); + + describe('lineage and breadcrumbs', () => { + it('it should retrieve the hierarchy level of the connected user', () => { + userContactService.get.resolves(userContactDoc); + sessionService.isOnlineOnly.resolves(false); + component.ngOnInit(); + expect(component.currentLevel).to.equal('parent'); + }); + + }); }); From cb066fa31bc71d1dee15ba2571fc1500db65bd41 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Sat, 3 Sep 2022 00:28:05 +0000 Subject: [PATCH 27/72] fix broken unit tests --- webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 23bf8bce043..b58dfee0d5d 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -82,7 +82,7 @@ describe('TasksComponent', () => { { provide: NavigationService, useValue: {} }, { provide: SessionService, useValue: sessionService }, { provide: UserContactService, useValue: userContactService }, - { provide: LineageModelGeneratorService, useValue: { lineageModelGeneratorService } }, + { provide: LineageModelGeneratorService, useValue: lineageModelGeneratorService }, ], declarations: [ TasksComponent, From 30faef10247efdcfd4cc45380d5ca695bec5bdc1 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Sat, 3 Sep 2022 04:16:42 +0000 Subject: [PATCH 28/72] fix unit tests --- webapp/src/ts/modules/reports/reports.component.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 145096296d9..c44dce18adc 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -345,10 +345,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { this.reportsSidebarFilter?.resetFilters(); } -<<<<<<< HEAD async getCurrentLineageLevel(){ return this.userContactService.get().then(user => user?.parent?.name); } -======= ->>>>>>> dd233036a (add breadcrumbs to tasks tab) } From ae37aeddd08f81813803a2fd2eb6bb92a97abb09 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Sat, 3 Sep 2022 04:30:49 +0000 Subject: [PATCH 29/72] minor changes --- webapp/src/ts/modules/reports/reports.component.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index efce8e97541..631866509c9 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -1,5 +1,5 @@ import {cloneDeep as _cloneDeep, find as _find} from 'lodash-es'; -import {AfterViewInit, Component, NgZone, OnDestroy, OnInit, ViewChild,} from '@angular/core'; +import {AfterViewInit, Component, NgZone, OnDestroy, OnInit, ViewChild} from '@angular/core'; import {Store} from '@ngrx/store'; import {combineLatest, Subscription} from 'rxjs'; import {ActivatedRoute, Router} from '@angular/router'; @@ -229,7 +229,6 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { .then((reports) => this.addReadStatusService.updateReports(reports)) .then((updatedReports) => { updatedReports = this.prepareReports(updatedReports); - console.log(updatedReports); this.reportsActions.updateReportsList(updatedReports); this.moreItems = updatedReports.length >= options.limit; From 8344348ae220aeb06d141258d0a26981f15fc7a9 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Sat, 3 Sep 2022 17:22:35 +0000 Subject: [PATCH 30/72] fix task unit test --- webapp/src/ts/modules/tasks/tasks.component.ts | 2 +- .../karma/ts/modules/tasks/tasks.component.spec.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 8c6436af696..019f9d32a85 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -164,7 +164,7 @@ export class TasksComponent implements OnInit, OnDestroy { const lineagedTasks = deepCopy(tasks); lineagedTasks.forEach((task) => { // map tasks with lineages - let lineage = _map(_find(subjects, subject => subject._id === task.forId).lineage, 'name'); + let lineage = _map(_find(subjects, subject => subject._id === task.forId)?.lineage, 'name'); // remove the lineage level that belongs to the offline logged-in user, normally the last one if (this.currentLevel) { lineage = lineage.filter(level => level && level !== this.currentLevel); diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index b58dfee0d5d..0bc541b4cac 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -166,22 +166,23 @@ describe('TasksComponent', () => { expect(consoleErrorMock.args[0][0]).to.equal('Error getting tasks for all contacts'); }); - it('tasks render', async () => { + it('tasks render', fakeAsync( () => { const now = moment('2020-10-20'); const futureDate = now.clone().add(3, 'days'); const pastDate = now.clone().subtract(3, 'days'); clock = sinon.useFakeTimers(now.valueOf()); + const taskDocs = [ { _id: '1', emission: { _id: 'e1', dueDate: futureDate.format('YYYY-MM-DD') }, owner: 'a' }, { _id: '2', emission: { _id: 'e2', dueDate: pastDate.format('YYYY-MM-DD') }, owner: 'b' }, ]; rulesEngineService.fetchTaskDocsForAllContacts.resolves(taskDocs); - - await new Promise(resolve => { + tick(); + new Promise(resolve => { sinon.stub(TasksActions.prototype, 'setTasksList').callsFake(resolve); getComponent(); }); - + tick(); expect(component.loading).to.be.false; expect(component.tasksDisabled).to.be.false; expect(component.hasTasks).to.be.true; @@ -193,6 +194,7 @@ describe('TasksComponent', () => { overdue: false, date: new Date(futureDate.valueOf()), owner: 'a', + lineage: [], }, { _id: 'e2', @@ -200,10 +202,11 @@ describe('TasksComponent', () => { overdue: true, date: new Date(pastDate.valueOf()), owner: 'b', + lineage: [] }, ]; expect((TasksActions.prototype.setTasksList).args).to.deep.eq([[expectedTasks]]); - }); + })); it('rules engine yields no tasks', async () => { await new Promise(resolve => { From ec1c8bc84c2c14817afaa79ee06955ddbb17a40c Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Sat, 3 Sep 2022 19:02:35 +0000 Subject: [PATCH 31/72] fix task unit test --- webapp/src/ts/modules/tasks/tasks.component.ts | 2 +- webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 019f9d32a85..02372391cff 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -134,7 +134,7 @@ export class TasksComponent implements OnInit, OnDestroy { return taskDocs.map(taskDoc => { const emission = { ...taskDoc.emission }; const dueDate = moment(emission.dueDate, 'YYYY-MM-DD'); - emission.date = new Date(dueDate.valueOf()); + emission.date = dueDate.format('YYYY-MM-DD'); emission.overdue = dueDate.isBefore(moment()); emission.owner = taskDoc.owner; return emission; diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 0bc541b4cac..58a097cd315 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -167,7 +167,7 @@ describe('TasksComponent', () => { }); it('tasks render', fakeAsync( () => { - const now = moment('2020-10-20'); + const now = moment(); const futureDate = now.clone().add(3, 'days'); const pastDate = now.clone().subtract(3, 'days'); clock = sinon.useFakeTimers(now.valueOf()); @@ -192,7 +192,7 @@ describe('TasksComponent', () => { _id: 'e1', dueDate: futureDate.format('YYYY-MM-DD'), overdue: false, - date: new Date(futureDate.valueOf()), + date: futureDate.format('YYYY-MM-DD'), owner: 'a', lineage: [], }, @@ -200,7 +200,7 @@ describe('TasksComponent', () => { _id: 'e2', dueDate: pastDate.format('YYYY-MM-DD'), overdue: true, - date: new Date(pastDate.valueOf()), + date: pastDate.format('YYYY-MM-DD'), owner: 'b', lineage: [] }, From b0e05d9df54004f932591ae621eac753202c0cde Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Sat, 3 Sep 2022 22:51:36 +0000 Subject: [PATCH 32/72] fix task unit test --- webapp/src/ts/modules/tasks/tasks.component.ts | 14 +++++++++----- .../karma/ts/modules/tasks/tasks.component.spec.ts | 12 +++++------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 02372391cff..048ac2176a5 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -134,9 +134,11 @@ export class TasksComponent implements OnInit, OnDestroy { return taskDocs.map(taskDoc => { const emission = { ...taskDoc.emission }; const dueDate = moment(emission.dueDate, 'YYYY-MM-DD'); - emission.date = dueDate.format('YYYY-MM-DD'); + emission.date = new Date(dueDate.valueOf()); + emission.moment = moment(); emission.overdue = dueDate.isBefore(moment()); emission.owner = taskDoc.owner; + return emission; }); } @@ -162,14 +164,16 @@ export class TasksComponent implements OnInit, OnDestroy { .then((subjects) => { const deepCopy = obj => JSON.parse(JSON.stringify(obj)); const lineagedTasks = deepCopy(tasks); - lineagedTasks.forEach((task) => { + lineagedTasks?.forEach((task) => { // map tasks with lineages let lineage = _map(_find(subjects, subject => subject._id === task.forId)?.lineage, 'name'); // remove the lineage level that belongs to the offline logged-in user, normally the last one - if (this.currentLevel) { - lineage = lineage.filter(level => level && level !== this.currentLevel); + if (lineage && lineage.length) { + if(this.currentLevel){ + lineage = lineage.filter(level => level && level !== this.currentLevel); + } + task.lineage = lineage; } - task.lineage = lineage; }); this.tasksActions.setTasksList(lineagedTasks); }); diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 58a097cd315..53a1accb2e3 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -167,11 +167,10 @@ describe('TasksComponent', () => { }); it('tasks render', fakeAsync( () => { - const now = moment(); + const now = moment('2020-10-20'); const futureDate = now.clone().add(3, 'days'); const pastDate = now.clone().subtract(3, 'days'); clock = sinon.useFakeTimers(now.valueOf()); - const taskDocs = [ { _id: '1', emission: { _id: 'e1', dueDate: futureDate.format('YYYY-MM-DD') }, owner: 'a' }, { _id: '2', emission: { _id: 'e2', dueDate: pastDate.format('YYYY-MM-DD') }, owner: 'b' }, @@ -192,20 +191,19 @@ describe('TasksComponent', () => { _id: 'e1', dueDate: futureDate.format('YYYY-MM-DD'), overdue: false, - date: futureDate.format('YYYY-MM-DD'), + date: new Date(futureDate.valueOf()).toISOString(), owner: 'a', - lineage: [], }, { _id: 'e2', dueDate: pastDate.format('YYYY-MM-DD'), overdue: true, - date: pastDate.format('YYYY-MM-DD'), + date: new Date(pastDate.valueOf()).toISOString(), owner: 'b', - lineage: [] }, ]; - expect((TasksActions.prototype.setTasksList).args).to.deep.eq([[expectedTasks]]); + const tasks = (TasksActions.prototype.setTasksList).args; + expect(tasks).to.deep.eq([[expectedTasks]]); })); it('rules engine yields no tasks', async () => { From 7a31fcbba2d7491e21683c3d52de06dc4fb32ed2 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Sat, 3 Sep 2022 23:20:00 +0000 Subject: [PATCH 33/72] fix task unit test --- webapp/src/ts/modules/tasks/tasks.component.ts | 2 -- .../tests/karma/ts/modules/tasks/tasks.component.spec.ts | 9 ++++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 048ac2176a5..f6921509686 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -135,10 +135,8 @@ export class TasksComponent implements OnInit, OnDestroy { const emission = { ...taskDoc.emission }; const dueDate = moment(emission.dueDate, 'YYYY-MM-DD'); emission.date = new Date(dueDate.valueOf()); - emission.moment = moment(); emission.overdue = dueDate.isBefore(moment()); emission.owner = taskDoc.owner; - return emission; }); } diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 53a1accb2e3..2bbbe131ab1 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -166,7 +166,7 @@ describe('TasksComponent', () => { expect(consoleErrorMock.args[0][0]).to.equal('Error getting tasks for all contacts'); }); - it('tasks render', fakeAsync( () => { + it('tasks render', async() => { const now = moment('2020-10-20'); const futureDate = now.clone().add(3, 'days'); const pastDate = now.clone().subtract(3, 'days'); @@ -176,12 +176,11 @@ describe('TasksComponent', () => { { _id: '2', emission: { _id: 'e2', dueDate: pastDate.format('YYYY-MM-DD') }, owner: 'b' }, ]; rulesEngineService.fetchTaskDocsForAllContacts.resolves(taskDocs); - tick(); - new Promise(resolve => { + await new Promise(resolve => { sinon.stub(TasksActions.prototype, 'setTasksList').callsFake(resolve); getComponent(); }); - tick(); + clock.tick(); expect(component.loading).to.be.false; expect(component.tasksDisabled).to.be.false; expect(component.hasTasks).to.be.true; @@ -204,7 +203,7 @@ describe('TasksComponent', () => { ]; const tasks = (TasksActions.prototype.setTasksList).args; expect(tasks).to.deep.eq([[expectedTasks]]); - })); + }); it('rules engine yields no tasks', async () => { await new Promise(resolve => { From 4f66eb3eec8c727e42e0ee0f969ce8223d66c8f8 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 5 Sep 2022 00:13:56 +0000 Subject: [PATCH 34/72] add unit tests to tasks lineages --- .../src/ts/modules/tasks/tasks.component.ts | 26 ++- .../ts/modules/tasks/tasks.component.spec.ts | 161 +++++++++++++++++- 2 files changed, 179 insertions(+), 8 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index f6921509686..96517bd1f90 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -164,7 +164,9 @@ export class TasksComponent implements OnInit, OnDestroy { const lineagedTasks = deepCopy(tasks); lineagedTasks?.forEach((task) => { // map tasks with lineages - let lineage = _map(_find(subjects, subject => subject._id === task.forId)?.lineage, 'name'); + let lineage = _map( + _find(subjects, subject => (subject._id === task.forId || subject._id === task.owner))?.lineage, + 'name'); // remove the lineage level that belongs to the offline logged-in user, normally the last one if (lineage && lineage.length) { if(this.currentLevel){ @@ -176,7 +178,6 @@ export class TasksComponent implements OnInit, OnDestroy { this.tasksActions.setTasksList(lineagedTasks); }); }); - if (!this.tasksLoaded) { this.tasksActions.setTasksLoaded(true); } @@ -206,4 +207,25 @@ export class TasksComponent implements OnInit, OnDestroy { const ids = _map(taskDocs, 'forId'); return await this.lineageModelGeneratorService.reportSubjects(ids); } + + async updateTasksWithLineages(tasks){ + // get lineages for all tasks + return this.getLineagesFromTaskDocs(tasks) + .then((subjects) => { + const deepCopy = obj => JSON.parse(JSON.stringify(obj)); + const lineagedTasks = deepCopy(tasks); + lineagedTasks.forEach((task) => { + // map tasks with lineages + let lineage = _map(_find(subjects, subject => subject._id === task.forId).lineage, 'name'); + // remove the lineage level that belongs to the offline logged-in user, normally the last one + if (this.currentLevel) { + lineage = lineage.filter(level => level && level !== this.currentLevel); + } + task.lineage = lineage; + }); + return lineagedTasks; + //this.tasksActions.setTasksList(lineagedTasks); + }); + } + } diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 2bbbe131ab1..7a877b18f56 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -63,7 +63,7 @@ describe('TasksComponent', () => { userCtx: sinon.stub().returns({ name: 'Sarah' }) }; userContactService = { - get: sinon.stub().resolves(userContactDoc), + get: sinon.stub().resolves(), }; lineageModelGeneratorService = { reportSubjects: sinon.stub() }; @@ -201,8 +201,7 @@ describe('TasksComponent', () => { owner: 'b', }, ]; - const tasks = (TasksActions.prototype.setTasksList).args; - expect(tasks).to.deep.eq([[expectedTasks]]); + expect((TasksActions.prototype.setTasksList).args).to.deep.eq([[expectedTasks]]); }); it('rules engine yields no tasks', async () => { @@ -306,11 +305,161 @@ describe('TasksComponent', () => { }); describe('lineage and breadcrumbs', () => { - it('it should retrieve the hierarchy level of the connected user', () => { + const bettysContactDoc = { + _id: 'user', + parent: { + _id: 'parent', + name: 'CHW Bettys Area', + }, + }; + const taskDocs = [ + { _id: '1', emission: { _id: 'e1', dueDate: '2020-10-20' }, forId: 'a', owner: 'a' }, + { _id: '2', emission: { _id: 'e2', dueDate: '2020-10-20' }, forId: 'b', owner: 'b' }, + ]; + const taskLineages = [ + { + _id: 'a', lineage: [ + {name: 'Amy Johnsons Household'}, + {name: 'St Elmos Concession'}, + {name: 'Chattanooga Village'}, + {name: 'CHW Bettys Area'}, + ] + }, + { + _id: 'b', lineage: [ + {name: 'Amy Johnsons Household'}, + {name: 'St Elmos Concession'}, + {name: 'Chattanooga Village'}, + ] + } + ]; + + it('it should not change the reports lineages if the connected user is online only', async() => { + const expectedTasks = + [ + { + _id: 'e1', + date: '2020-10-20T00:00:00.000Z', + dueDate: '2020-10-20', + lineage: [ + 'Amy Johnsons Household', + 'St Elmos Concession', + 'Chattanooga Village', + 'CHW Bettys Area' + ], + overdue: true, + owner: 'a', + }, + { + _id: 'e2', + date: '2020-10-20T00:00:00.000Z', + dueDate: '2020-10-20', + lineage: [ + 'Amy Johnsons Household', + 'St Elmos Concession', + 'Chattanooga Village', + ], + overdue: true, + owner: 'b', + } + ]; + + userContactService.get.resolves(bettysContactDoc); + sessionService.isOnlineOnly.returns(true); + rulesEngineService.fetchTaskDocsForAllContacts.resolves(taskDocs); + lineageModelGeneratorService.reportSubjects.resolves(taskLineages); + await new Promise(resolve => { + sinon.stub(TasksActions.prototype, 'setTasksList').callsFake(resolve); + getComponent(); + }); + expect(component.currentLevel).to.be.undefined; + expect((TasksActions.prototype.setTasksList).args).to.deep.equal([[expectedTasks]]); + }); + + it('it should not change the reports lineages if the connected user is offline with unrelated lineage', async() => { + const expectedTasks = + [ + { + _id: 'e1', + date: '2020-10-20T00:00:00.000Z', + dueDate: '2020-10-20', + lineage: [ + 'Amy Johnsons Household', + 'St Elmos Concession', + 'Chattanooga Village', + 'CHW Bettys Area' + ], + overdue: true, + owner: 'a', + }, + { + _id: 'e2', + date: '2020-10-20T00:00:00.000Z', + dueDate: '2020-10-20', + lineage: [ + 'Amy Johnsons Household', + 'St Elmos Concession', + 'Chattanooga Village', + ], + overdue: true, + owner: 'b', + } + ]; + userContactService.get.resolves(userContactDoc); - sessionService.isOnlineOnly.resolves(false); - component.ngOnInit(); + sessionService.isOnlineOnly.returns(false); + rulesEngineService.fetchTaskDocsForAllContacts.resolves(taskDocs); + lineageModelGeneratorService.reportSubjects.resolves(taskLineages); + //component.ngOnInit(); + await new Promise(resolve => { + sinon.stub(TasksActions.prototype, 'setTasksList').callsFake(resolve); + getComponent(); + }); + const tasks = await (TasksActions.prototype.setTasksList).args; expect(component.currentLevel).to.equal('parent'); + expect(tasks).to.deep.equal([[expectedTasks]]); + }); + + it('it should update the reports lineages if the connected user is offline with related place', async() => { + const expectedTasks = + [ + { + _id: 'e1', + date: '2020-10-20T00:00:00.000Z', + dueDate: '2020-10-20', + lineage: [ + 'Amy Johnsons Household', + 'St Elmos Concession', + 'Chattanooga Village', + ], + overdue: true, + owner: 'a', + }, + { + _id: 'e2', + date: '2020-10-20T00:00:00.000Z', + dueDate: '2020-10-20', + lineage: [ + 'Amy Johnsons Household', + 'St Elmos Concession', + 'Chattanooga Village', + ], + overdue: true, + owner: 'b', + } + ]; + + userContactService.get.resolves(bettysContactDoc); + sessionService.isOnlineOnly.returns(false); + rulesEngineService.fetchTaskDocsForAllContacts.resolves(taskDocs); + lineageModelGeneratorService.reportSubjects.resolves(taskLineages); + await new Promise(resolve => { + sinon.stub(TasksActions.prototype, 'setTasksList').callsFake(resolve); + getComponent(); + }); + const tasks = await (TasksActions.prototype.setTasksList).args; + expect(component.currentLevel).to.equal('CHW Bettys Area'); + expect(tasks).to.deep.equal([[expectedTasks]]); }); }); From 68900b2afaa835866681b305c697b5ae755fd1a4 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 5 Sep 2022 00:15:39 +0000 Subject: [PATCH 35/72] add unit tests to tasks lineages --- .../src/ts/modules/tasks/tasks.component.ts | 20 ------------------- .../ts/modules/tasks/tasks.component.spec.ts | 3 --- 2 files changed, 23 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 96517bd1f90..ae38fbea0be 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -208,24 +208,4 @@ export class TasksComponent implements OnInit, OnDestroy { return await this.lineageModelGeneratorService.reportSubjects(ids); } - async updateTasksWithLineages(tasks){ - // get lineages for all tasks - return this.getLineagesFromTaskDocs(tasks) - .then((subjects) => { - const deepCopy = obj => JSON.parse(JSON.stringify(obj)); - const lineagedTasks = deepCopy(tasks); - lineagedTasks.forEach((task) => { - // map tasks with lineages - let lineage = _map(_find(subjects, subject => subject._id === task.forId).lineage, 'name'); - // remove the lineage level that belongs to the offline logged-in user, normally the last one - if (this.currentLevel) { - lineage = lineage.filter(level => level && level !== this.currentLevel); - } - task.lineage = lineage; - }); - return lineagedTasks; - //this.tasksActions.setTasksList(lineagedTasks); - }); - } - } diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 7a877b18f56..d46cfd5bd0d 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -363,7 +363,6 @@ describe('TasksComponent', () => { owner: 'b', } ]; - userContactService.get.resolves(bettysContactDoc); sessionService.isOnlineOnly.returns(true); rulesEngineService.fetchTaskDocsForAllContacts.resolves(taskDocs); @@ -405,12 +404,10 @@ describe('TasksComponent', () => { owner: 'b', } ]; - userContactService.get.resolves(userContactDoc); sessionService.isOnlineOnly.returns(false); rulesEngineService.fetchTaskDocsForAllContacts.resolves(taskDocs); lineageModelGeneratorService.reportSubjects.resolves(taskLineages); - //component.ngOnInit(); await new Promise(resolve => { sinon.stub(TasksActions.prototype, 'setTasksList').callsFake(resolve); getComponent(); From ca5627c1beb2b3835134ffa8eb380dfba118122e Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 5 Sep 2022 09:58:38 +0000 Subject: [PATCH 36/72] apply code review recommandations --- .../src/ts/modules/messages/messages.component.ts | 15 ++++++--------- .../src/ts/modules/reports/reports.component.ts | 7 +++---- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 2c9f113119f..d681030524b 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -53,12 +53,10 @@ export class MessagesComponent implements OnInit, OnDestroy { ngOnInit(): void { this.subscribeToStore(); this.tourService.startIfNeeded(this.route.snapshot); - const isOffline = !this.sessionService.isOnlineOnly(); - if (isOffline) { - this.getCurrentLineageLevel() - .then((currentLevel) => { - this.currentLevel = currentLevel; - }); + if (!this.sessionService.isOnlineOnly()) { + this + .getCurrentLineageLevel() + .then(currentLevel => this.currentLevel = currentLevel); } this.updateConversations().then(() => this.displayFirstConversation(this.conversations)); this.watchForChanges(); @@ -166,11 +164,10 @@ export class MessagesComponent implements OnInit, OnDestroy { .then((conversations = []) => { // remove the lineage level that belongs to the offline logged in user, normally the last one if (this.currentLevel) { - conversations.forEach((conversation) => { + conversations.forEach(conversation => { if (conversation.lineage) { conversation.lineage = conversation.lineage.filter(level => level !== this.currentLevel); } - return conversation; }); } this.setConversations(conversations, { merge }); @@ -206,7 +203,7 @@ export class MessagesComponent implements OnInit, OnDestroy { return message.key + identifier; } - async getCurrentLineageLevel(){ + getCurrentLineageLevel(){ return this.userContactService.get().then(user => user?.parent?.name); } } diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 631866509c9..aaac5b2fa3e 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -140,10 +140,9 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { this.tourService.startIfNeeded(this.route.snapshot); this.setActionBarData(); if (!this.sessionService.isOnlineOnly()) { - this.getCurrentLineageLevel() - .then((currentLevel) => { - this.currentLevel = currentLevel; - }); + this + .getCurrentLineageLevel() + .then(currentLevel => this.currentLevel = currentLevel); } } From 4aaed95817446de4c715a23beb838f4f1134c0bc Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 5 Sep 2022 10:01:07 +0000 Subject: [PATCH 37/72] apply code review recommandations --- webapp/src/ts/modules/reports/reports.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index aaac5b2fa3e..41a82b56c11 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -343,7 +343,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { this.reportsSidebarFilter?.resetFilters(); } - async getCurrentLineageLevel(){ + getCurrentLineageLevel(){ return this.userContactService.get().then(user => user?.parent?.name); } } From ad8a21eb50ccef20425be83a8155bb2da3b71313 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 5 Sep 2022 12:58:03 +0000 Subject: [PATCH 38/72] refactoring refresh tasks function --- .../src/ts/modules/tasks/tasks.component.ts | 122 +++++++++--------- .../ts/modules/tasks/tasks.component.spec.ts | 16 +-- 2 files changed, 70 insertions(+), 68 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index ae38fbea0be..417a8d20832 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -2,7 +2,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { Store } from '@ngrx/store'; import { combineLatest, Subscription } from 'rxjs'; import { ActivatedRoute } from '@angular/router'; -import { debounce as _debounce, map as _map, find as _find } from 'lodash-es'; +import { debounce as _debounce } from 'lodash-es'; import * as moment from 'moment'; import { ChangesService } from '@mm-services/changes.service'; @@ -107,9 +107,7 @@ export class TasksComponent implements OnInit, OnDestroy { if (!this.sessionService.isOnlineOnly()) { this .getCurrentLineageLevel() - .then((currentLevel) => { - this.currentLevel = currentLevel; - }); + .then(currentLevel => this.currentLevel = currentLevel); } this.refreshTasks(); @@ -141,71 +139,75 @@ export class TasksComponent implements OnInit, OnDestroy { }); } - private refreshTasks() { - const telemetryData:any = { - start: Date.now(), - }; - - return this.rulesEngineService - .isEnabled() - .then(isEnabled => { - this.tasksDisabled = !isEnabled; - return isEnabled ? this.rulesEngineService.fetchTaskDocsForAllContacts() : []; - }) - .then(taskDocs => { - this.hasTasks = taskDocs.length > 0; - this.loading = false; - this.hydrateEmissions(taskDocs) - .then((tasks) => { - // get lineages for all tasks - this.getLineagesFromTaskDocs(tasks) - .then((subjects) => { - const deepCopy = obj => JSON.parse(JSON.stringify(obj)); - const lineagedTasks = deepCopy(tasks); - lineagedTasks?.forEach((task) => { - // map tasks with lineages - let lineage = _map( - _find(subjects, subject => (subject._id === task.forId || subject._id === task.owner))?.lineage, - 'name'); - // remove the lineage level that belongs to the offline logged-in user, normally the last one - if (lineage && lineage.length) { - if(this.currentLevel){ - lineage = lineage.filter(level => level && level !== this.currentLevel); - } - task.lineage = lineage; - } - }); - this.tasksActions.setTasksList(lineagedTasks); - }); - }); - if (!this.tasksLoaded) { - this.tasksActions.setTasksLoaded(true); - } - - telemetryData.end = Date.now(); - const telemetryEntryName = !this.tasksLoaded ? `tasks:load`: `tasks:refresh`; - this.telemetryService.record(telemetryEntryName, telemetryData.end - telemetryData.start); - }) - .catch(err => { - console.error('Error getting tasks for all contacts', err); - this.error = true; - this.loading = false; - this.hasTasks = false; - this.tasksActions.setTasksList([]); - }); + async refreshTasks() { + try { + const telemetryData:any = { + start: Date.now(), + }; + + const isEnabled = await this.rulesEngineService.isEnabled(); + this.tasksDisabled = !isEnabled; + const taskDocs = isEnabled ? await this.rulesEngineService.fetchTaskDocsForAllContacts() : []; + + this.hasTasks = taskDocs.length > 0; + this.loading = false; + + const hydratedTasks = await this.hydrateEmissions(taskDocs) || []; + const subjects = await this.getLineagesFromTaskDocs(hydratedTasks); + + if(subjects) { + hydratedTasks.forEach(task => { + const lineage = this.getTaskLineage(subjects, task); + task.lineage = this.currentLevel ? this.removeCurrentLineage(lineage) : lineage; + }); + } + + this.tasksActions.setTasksList(hydratedTasks); + + if (!this.tasksLoaded) { + this.tasksActions.setTasksLoaded(true); + } + + telemetryData.end = Date.now(); + const telemetryEntryName = !this.tasksLoaded ? `tasks:load`: `tasks:refresh`; + this.telemetryService.record(telemetryEntryName, telemetryData.end - telemetryData.start); + + } catch (exception) { + console.error('Error getting tasks for all contacts', exception); + this.error = true; + this.loading = false; + this.hasTasks = false; + this.tasksActions.setTasksList([]); + } } listTrackBy(index, task) { return task?._id; } - async getCurrentLineageLevel(){ + getCurrentLineageLevel(){ return this.userContactService.get().then(user => user?.parent?.name); } - async getLineagesFromTaskDocs(taskDocs){ - const ids = _map(taskDocs, 'forId'); - return await this.lineageModelGeneratorService.reportSubjects(ids); + getLineagesFromTaskDocs(taskDocs){ + const ids = taskDocs.map(task => task.forId); + return this.lineageModelGeneratorService.reportSubjects(ids); } + private getTaskLineage(subjects, task) { + if (!subjects?.length) { + return; + } + + const lineage = subjects.find(subject => (subject._id === task.forId || subject._id === task.owner))?.lineage; + return lineage.map(lineage => lineage.name); + } + + private removeCurrentLineage(lineage) { + if (!this.currentLevel || !lineage?.length) { + return; + } + + return lineage.filter(level => level && level !== this.currentLevel); + } } diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index d46cfd5bd0d..5a3c0c114ca 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -190,14 +190,14 @@ describe('TasksComponent', () => { _id: 'e1', dueDate: futureDate.format('YYYY-MM-DD'), overdue: false, - date: new Date(futureDate.valueOf()).toISOString(), + date: new Date(futureDate.valueOf()), owner: 'a', }, { _id: 'e2', dueDate: pastDate.format('YYYY-MM-DD'), overdue: true, - date: new Date(pastDate.valueOf()).toISOString(), + date: new Date(pastDate.valueOf()), owner: 'b', }, ]; @@ -339,7 +339,7 @@ describe('TasksComponent', () => { [ { _id: 'e1', - date: '2020-10-20T00:00:00.000Z', + date: new Date('2020-10-20'), dueDate: '2020-10-20', lineage: [ 'Amy Johnsons Household', @@ -352,7 +352,7 @@ describe('TasksComponent', () => { }, { _id: 'e2', - date: '2020-10-20T00:00:00.000Z', + date: new Date('2020-10-20'), dueDate: '2020-10-20', lineage: [ 'Amy Johnsons Household', @@ -380,7 +380,7 @@ describe('TasksComponent', () => { [ { _id: 'e1', - date: '2020-10-20T00:00:00.000Z', + date: new Date('2020-10-20'), dueDate: '2020-10-20', lineage: [ 'Amy Johnsons Household', @@ -393,7 +393,7 @@ describe('TasksComponent', () => { }, { _id: 'e2', - date: '2020-10-20T00:00:00.000Z', + date: new Date('2020-10-20'), dueDate: '2020-10-20', lineage: [ 'Amy Johnsons Household', @@ -422,7 +422,7 @@ describe('TasksComponent', () => { [ { _id: 'e1', - date: '2020-10-20T00:00:00.000Z', + date: new Date('2020-10-20'), dueDate: '2020-10-20', lineage: [ 'Amy Johnsons Household', @@ -434,7 +434,7 @@ describe('TasksComponent', () => { }, { _id: 'e2', - date: '2020-10-20T00:00:00.000Z', + date: new Date('2020-10-20'), dueDate: '2020-10-20', lineage: [ 'Amy Johnsons Household', From 89983126f5fbfc6fb4e386f683d22571a7f806d6 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Tue, 6 Sep 2022 13:47:08 +0000 Subject: [PATCH 39/72] apply most of review recommandations for messages and reports --- .../ts/modules/messages/messages.component.ts | 4 +- .../ts/modules/reports/reports.component.ts | 52 ++-- .../messages/messages.component.spec.ts | 231 +++++++++--------- .../modules/reports/reports.component.spec.ts | 205 +++++++++------- 4 files changed, 252 insertions(+), 240 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index d681030524b..01e0fcdb5a0 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -162,7 +162,7 @@ export class MessagesComponent implements OnInit, OnDestroy { return this.messageContactService .getList() .then((conversations = []) => { - // remove the lineage level that belongs to the offline logged in user, normally the last one + // remove the lineage level that belongs to the offline logged in user if (this.currentLevel) { conversations.forEach(conversation => { if (conversation.lineage) { @@ -203,7 +203,7 @@ export class MessagesComponent implements OnInit, OnDestroy { return message.key + identifier; } - getCurrentLineageLevel(){ + private getCurrentLineageLevel() { return this.userContactService.get().then(user => user?.parent?.name); } } diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 41a82b56c11..5aaa8647d02 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -1,26 +1,26 @@ -import {cloneDeep as _cloneDeep, find as _find} from 'lodash-es'; -import {AfterViewInit, Component, NgZone, OnDestroy, OnInit, ViewChild} from '@angular/core'; -import {Store} from '@ngrx/store'; -import {combineLatest, Subscription} from 'rxjs'; -import {ActivatedRoute, Router} from '@angular/router'; - -import {ScrollLoaderProvider} from '@mm-providers/scroll-loader.provider'; -import {GlobalActions} from '@mm-actions/global'; -import {ReportsActions} from '@mm-actions/reports'; -import {ServicesActions} from '@mm-actions/services'; -import {ChangesService} from '@mm-services/changes.service'; -import {SearchService} from '@mm-services/search.service'; -import {TourService} from '@mm-services/tour.service'; -import {Selectors} from '@mm-selectors/index'; -import {AddReadStatusService} from '@mm-services/add-read-status.service'; -import {ExportService} from '@mm-services/export.service'; -import {ResponsiveService} from '@mm-services/responsive.service'; -import {TranslateService} from '@mm-services/translate.service'; -import {ReportsSidebarFilterComponent} from '@mm-modules/reports/reports-sidebar-filter.component'; -import {AuthService} from '@mm-services/auth.service'; -import {OLD_REPORTS_FILTER_PERMISSION} from '@mm-modules/reports/reports-filters.component'; -import {UserContactService} from '@mm-services/user-contact.service'; -import {SessionService} from '@mm-services/session.service'; +import { cloneDeep as _cloneDeep, find as _find } from 'lodash-es'; +import { AfterViewInit, Component, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'; +import { Store } from '@ngrx/store'; +import { combineLatest, Subscription } from 'rxjs'; +import { ActivatedRoute, Router } from '@angular/router'; + +import { ScrollLoaderProvider } from '@mm-providers/scroll-loader.provider'; +import { GlobalActions } from '@mm-actions/global'; +import { ReportsActions } from '@mm-actions/reports'; +import { ServicesActions } from '@mm-actions/services'; +import { ChangesService } from '@mm-services/changes.service'; +import { SearchService } from '@mm-services/search.service'; +import { TourService } from '@mm-services/tour.service'; +import { Selectors } from '@mm-selectors/index'; +import { AddReadStatusService } from '@mm-services/add-read-status.service'; +import { ExportService } from '@mm-services/export.service'; +import { ResponsiveService } from '@mm-services/responsive.service'; +import { TranslateService } from '@mm-services/translate.service'; +import { ReportsSidebarFilterComponent } from '@mm-modules/reports/reports-sidebar-filter.component'; +import { AuthService } from '@mm-services/auth.service'; +import { OLD_REPORTS_FILTER_PERMISSION } from '@mm-modules/reports/reports-filters.component'; +import { UserContactService } from '@mm-services/user-contact.service'; +import { SessionService } from '@mm-services/session.service'; const PAGE_SIZE = 50; @@ -192,9 +192,9 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { report.heading = this.getReportHeading(form, report); report.summary = form ? form.title : report.form; report.lineage = report.subject && report.subject.lineage || report.lineage; - // remove the lineage level that belongs to the offline logged-in user, normally the last one - if (this.currentLevel) { - report.lineage = report.lineage.filter(level => level !== this.currentLevel); + // remove the lineage level that belongs to the offline logged-in user + if (this.currentLevel && report.lineage && report.lineage.length) { + report.lineage = report.lineage?.filter(level => level !== this.currentLevel); } report.unread = !report.read; return report; diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index 5f955c54458..d52610b0876 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -50,18 +50,21 @@ describe('Messages Component', () => { userContactService = { get: sinon.stub().resolves(userContactDoc), }; - sessionService = { isOnlineOnly : sinon.stub().returns(false) }; + sessionService = { isOnlineOnly: sinon.stub().returns(false) }; const tourServiceMock = { startIfNeeded: () => {} }; const mockedSelectors = [ { selector: 'getSelectedConversation', value: {} }, - { selector: 'getConversations', value: - [ - { key: 'a', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] - }, - ], + { + selector: 'getConversations', + value: [ + { + key: 'a', + message: { inAllMessages: true }, + lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ] + }, + ], }, { selector: 'getLoadingContent', value: false }, { selector: 'getMessagesError', value: false }, @@ -199,133 +202,127 @@ describe('Messages Component', () => { expect(component.conversations).to.eql( newConversations); }); + it('ngOnDestroy() should unsubscribe from observables', () => { + const spySubscriptionsUnsubscribe = sinon.spy(component.subscriptions, 'unsubscribe'); + + component.ngOnDestroy(); + + expect(spySubscriptionsUnsubscribe.callCount).to.equal(1); + }); + }); + + describe('Messages breadcrumbs', () => { + const offlineUserContactDoc = { + _id: 'user', + parent: { + _id: 'parent', + name: 'parent', + parent: userContactGrandparent, + }, + }; + const offlineUserContactDoc2 = { + _id: 'user', + parent: { + _id: 'parent', + name: 'CHW Bettys Area', + parent: userContactGrandparent, + }, + }; + const conversations = [ + { key: 'a', + message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + }, + { key: 'b', + message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] + }, + { key: 'c', + message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'Ramdom Place'] + }, + { key: 'd', + message: { inAllMessages: true }, + lineage : [] + }, + { key: 'e', + message: { inAllMessages: true }, + }, + ]; + it('it should retrieve the hierarchy level of the connected user', () => { expect(component.currentLevel).to.equal('parent'); }); - it('it should not change the conversations lineage if the connected user is online only', fakeAsync( () => { - const conversations = [ - { key: 'a', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] - }, - { key: 'b', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] - }, - { key: 'c', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] - }, - { key: 'd', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] - }, - ]; - messageContactService.getList.reset(); + it('should not alter conversations when user is offline and parent place isnt relevant to the conversation', + fakeAsync( () => { + sinon.resetHistory(); + + messageContactService.getList.resolves(conversations); + userContactService.get.resolves(offlineUserContactDoc); + sessionService.isOnlineOnly.returns(false); + + component.updateConversations({merge : true}); + tick(); + + expect(messageContactService.getList.callCount).to.equal(1); + expect(component.currentLevel).to.equal('parent'); + expect(component.conversations).to.deep.equal(conversations); + })); + + it('should not change the conversations lineage if the connected user is online only', fakeAsync( () => { + sinon.resetHistory(); + messageContactService.getList.resolves(conversations); userContactService.get.resolves(userContactDoc); sessionService.isOnlineOnly.returns(true); - component.ngOnInit(); - tick(); - component.updateConversations({merge : true}); - tick(); - expect(messageContactService.getList.callCount).to.equal(2); - expect(component.currentLevel).to.equal('parent'); - expect(component.conversations).to.deep.equal(conversations); - })); - it('it should not change the conversations lineage ' + - 'if the connected user is offline only but belongs to a place out of the conversation lineage', fakeAsync( () => { - const offlineUserContactDoc = { - _id: 'user', - parent: { - _id: 'parent', - name: 'parent', - parent: userContactGrandparent, - }, - }; - const conversations = [ - { key: 'a', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] - }, - { key: 'b', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] - }, - { key: 'c', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] - }, - { key: 'd', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] - }, - ]; - messageContactService.getList.reset(); - messageContactService.getList.resolves(conversations); - userContactService.get.resolves(offlineUserContactDoc); - sessionService.isOnlineOnly.returns(false); - component.ngOnInit(); - tick(); component.updateConversations({merge : true}); tick(); - expect(messageContactService.getList.callCount).to.equal(2); + + expect(messageContactService.getList.callCount).to.equal(1); expect(component.currentLevel).to.equal('parent'); expect(component.conversations).to.deep.equal(conversations); })); - it('it should update the conversations lineage ' + - 'if the connected user is offline and belongs to a place of the conversation lineage', fakeAsync( () => { - const offlineUserContactDoc2 = { - _id: 'user', - parent: { - _id: 'parent', - name: 'CHW Bettys Area', - parent: userContactGrandparent, - }, - }; - const conversations = [ - { key: 'a', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] - }, - { key: 'b', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] - }, - { key: 'c', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'Ramdom Place'] - }, - { key: 'd', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] - }, - ]; - const updatedConversations = [ - { key: 'a', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] - }, - { key: 'b', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] - }, - { key: 'c', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'Ramdom Place'] - }, - { key: 'd', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] - }, - ]; - messageContactService.getList.reset(); - messageContactService.getList.resolves(conversations); - userContactService.get.resolves(offlineUserContactDoc2); - sessionService.isOnlineOnly.returns(false); - component.ngOnInit(); - tick(); - component.updateConversations({merge : true}); - tick(); - expect(messageContactService.getList.callCount).to.equal(2); - expect(component.currentLevel).to.equal('CHW Bettys Area'); - expect(component.conversations).to.deep.equal(updatedConversations); - })); - }); + it('should remove current level from lineage when user is offline and parent place relevant to the conversation', + fakeAsync( () => { + sinon.resetHistory(); + const updatedConversations = [ + { key: 'a', + message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] + }, + { key: 'b', + message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village'] + }, + { key: 'c', + message: { inAllMessages: true }, + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'Ramdom Place'] + }, + { key: 'd', + message: { inAllMessages: true }, + lineage : [] + }, + { key: 'e', + message: { inAllMessages: true }, + }, + ]; - it('ngOnDestroy() should unsubscribe from observables', () => { - const spySubscriptionsUnsubscribe = sinon.spy(component.subscriptions, 'unsubscribe'); + messageContactService.getList.resolves(conversations); + userContactService.get.resolves(offlineUserContactDoc2); + sessionService.isOnlineOnly.returns(false); - component.ngOnDestroy(); + component.ngOnInit(); + tick(); + component.updateConversations({ merge : true }); + tick(); - expect(spySubscriptionsUnsubscribe.callCount).to.equal(1); + expect(messageContactService.getList.callCount).to.equal(2); + expect(component.currentLevel).to.equal('CHW Bettys Area'); + expect(component.conversations).to.deep.equal(updatedConversations); + })); }); }); diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index 885e38e471f..54c9ed9bdec 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -42,13 +42,13 @@ describe('Reports Component', () => { let datePipe; let userContactService; - const userContactGrandparent = { _id: 'grandparent' }; + const userContactGrandParent = { _id: 'grandparent' }; const userContactDoc = { _id: 'user', parent: { _id: 'parent', name: 'parent', - parent: userContactGrandparent, + parent: userContactGrandParent, }, }; @@ -278,64 +278,82 @@ describe('Reports Component', () => { }); }); - describe('lineage updates', () => { + describe('Reports breadcrumbs', () => { it('it should retrieve the hierarchy level of the connected user', () => { expect(component.currentLevel).to.equal('parent'); }); - it('it should not change the reports lineages if the connected user is online only', async () => { + it('should not change the reports lineage if user is online only', async () => { const reports = [ - {_id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ - 'St Elmos Concession', - 'Chattanooga Village', - 'CHW Bettys Area' - ]}, - {_id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ - 'Chattanooga Village', - 'CHW Bettys Area' - ]}, - {_id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ - 'Chattanooga Village' - ]}, - {_id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ - 'CHW Bettys Area' - ]}, + { + _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', + lineage: [ 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], + }, + { + _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ 'Chattanooga Village', 'CHW Bettys Area'], + }, + { + _id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ 'Chattanooga Village' ], + }, + { + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ 'CHW Bettys Area'], + }, + { + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [], + }, + { + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba965525', + }, ]; const expectedReports = [ - {_id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ - 'St Elmos Concession', - 'Chattanooga Village', - 'CHW Bettys Area' - ], - heading: 'report.subject.unknown', - icon: undefined, - summary: undefined, - unread: true + { + _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', + lineage: [ 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true, }, - {_id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ - 'Chattanooga Village', - 'CHW Bettys Area' - ], - heading: 'report.subject.unknown', - icon: undefined, - summary: undefined, - unread: true + { + _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', + lineage: [ 'Chattanooga Village', 'CHW Bettys Area' ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true, }, - {_id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ - 'Chattanooga Village' - ], - heading: 'report.subject.unknown', - icon: undefined, - summary: undefined, - unread: true + { + _id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', + lineage: [ 'Chattanooga Village' ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true, }, - {_id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ - 'CHW Bettys Area' - ], - heading: 'report.subject.unknown', - icon: undefined, - summary: undefined, - unread: true + { + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', + lineage: [ 'CHW Bettys Area' ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true, + }, + { + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', + lineage: [], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true, + }, + { + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba965525', + lineage: undefined, + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true, + }, ]; userContactService.get.resolves(userContactDoc); @@ -346,64 +364,61 @@ describe('Reports Component', () => { expect(updatedReports).to.deep.equal(expectedReports); }); - it('it should update the reports lineages to remove current level if the connected user is offline', async () => { + it('should remove current level from reports lineage when user is offline', async () => { const offlineUserContactDoc = { _id: 'user', parent: { _id: 'parent', name: 'CHW Bettys Area', - parent: userContactGrandparent, + parent: userContactGrandParent, }, }; const reports = [ - {_id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ - 'St Elmos Concession', - 'Chattanooga Village', - 'CHW Bettys Area' - ]}, - {_id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ - 'Chattanooga Village', - 'CHW Bettys Area' - ]}, - {_id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ - 'Chattanooga Village' - ]}, - {_id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ - 'CHW Bettys Area' - ]}, + { + _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', + lineage: [ 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], + }, + { + _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ 'Chattanooga Village', 'CHW Bettys Area'], + }, + { + _id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ 'Chattanooga Village'], + }, + { + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ 'CHW Bettys Area' ], + }, ]; const expectedReports = [ - {_id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ - 'St Elmos Concession', - 'Chattanooga Village', - ], - heading: 'report.subject.unknown', - icon: undefined, - summary: undefined, - unread: true + { + _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ 'St Elmos Concession', 'Chattanooga Village' ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true, }, - {_id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ - 'Chattanooga Village', - ], - heading: 'report.subject.unknown', - icon: undefined, - summary: undefined, - unread: true + { + _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', + lineage: [ 'Chattanooga Village' ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true, }, - {_id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ - 'Chattanooga Village' - ], - heading: 'report.subject.unknown', - icon: undefined, - summary: undefined, - unread: true + { + _id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', + lineage: [ 'Chattanooga Village' ], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true, }, - {_id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ - ], - heading: 'report.subject.unknown', - icon: undefined, - summary: undefined, - unread: true + { + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', + lineage: [], + heading: 'report.subject.unknown', + icon: undefined, + summary: undefined, + unread: true, }, ]; userContactService.get.resolves(offlineUserContactDoc); From 3f53451370cff5fe1e6f501a1622aeb48db67d17 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Wed, 7 Sep 2022 04:19:50 +0000 Subject: [PATCH 40/72] apply most of review recommandations for tasks --- .../src/ts/modules/tasks/tasks.component.ts | 48 ++--- .../ts/modules/tasks/tasks.component.spec.ts | 185 ++++++++---------- 2 files changed, 104 insertions(+), 129 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 417a8d20832..d1e5b6d35e4 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -22,16 +22,16 @@ import { SessionService } from '@mm-services/session.service'; }) export class TasksComponent implements OnInit, OnDestroy { constructor( - private store:Store, - private changesService:ChangesService, - private contactTypesService:ContactTypesService, - private rulesEngineService:RulesEngineService, - private telemetryService:TelemetryService, - private tourService:TourService, - private route:ActivatedRoute, - private lineageModelGeneratorService:LineageModelGeneratorService, - private userContactService:UserContactService, - private sessionService:SessionService, + private store: Store, + private changesService: ChangesService, + private contactTypesService: ContactTypesService, + private rulesEngineService: RulesEngineService, + private telemetryService: TelemetryService, + private tourService: TourService, + private route: ActivatedRoute, + private lineageModelGeneratorService: LineageModelGeneratorService, + private userContactService: UserContactService, + private sessionService: SessionService, ) { this.tasksActions = new TasksActions(store); this.globalActions = new GlobalActions(store); @@ -58,10 +58,10 @@ export class TasksComponent implements OnInit, OnDestroy { this.store.select(Selectors.getTasksLoaded), this.store.select(Selectors.getSelectedTask), ).subscribe(([ - tasksList, - tasksLoaded, - selectedTask, - ]) => { + tasksList, + tasksLoaded, + selectedTask, + ]) => { this.tasksList = tasksList; this.tasksLoaded = tasksLoaded; this.selectedTask = selectedTask; @@ -103,7 +103,7 @@ export class TasksComponent implements OnInit, OnDestroy { this.error = false; this.hasTasks = false; this.loading = true; - this.debouncedReload = _debounce(this.refreshTasks.bind(this), 1000, { maxWait: 10 * 1000 }); + this.debouncedReload = _debounce(this.refreshTasks.bind(this), 1000, {maxWait: 10 * 1000}); if (!this.sessionService.isOnlineOnly()) { this .getCurrentLineageLevel() @@ -128,9 +128,9 @@ export class TasksComponent implements OnInit, OnDestroy { window.location.reload(); } - private async hydrateEmissions(taskDocs) { + private hydrateEmissions(taskDocs) { return taskDocs.map(taskDoc => { - const emission = { ...taskDoc.emission }; + const emission = {...taskDoc.emission}; const dueDate = moment(emission.dueDate, 'YYYY-MM-DD'); emission.date = new Date(dueDate.valueOf()); emission.overdue = dueDate.isBefore(moment()); @@ -139,9 +139,9 @@ export class TasksComponent implements OnInit, OnDestroy { }); } - async refreshTasks() { + private async refreshTasks() { try { - const telemetryData:any = { + const telemetryData: any = { start: Date.now(), }; @@ -155,7 +155,7 @@ export class TasksComponent implements OnInit, OnDestroy { const hydratedTasks = await this.hydrateEmissions(taskDocs) || []; const subjects = await this.getLineagesFromTaskDocs(hydratedTasks); - if(subjects) { + if (subjects) { hydratedTasks.forEach(task => { const lineage = this.getTaskLineage(subjects, task); task.lineage = this.currentLevel ? this.removeCurrentLineage(lineage) : lineage; @@ -169,9 +169,9 @@ export class TasksComponent implements OnInit, OnDestroy { } telemetryData.end = Date.now(); - const telemetryEntryName = !this.tasksLoaded ? `tasks:load`: `tasks:refresh`; + const telemetryEntryName = !this.tasksLoaded ? `tasks:load` : `tasks:refresh`; this.telemetryService.record(telemetryEntryName, telemetryData.end - telemetryData.start); - + } catch (exception) { console.error('Error getting tasks for all contacts', exception); this.error = true; @@ -185,11 +185,11 @@ export class TasksComponent implements OnInit, OnDestroy { return task?._id; } - getCurrentLineageLevel(){ + private getCurrentLineageLevel() { return this.userContactService.get().then(user => user?.parent?.name); } - getLineagesFromTaskDocs(taskDocs){ + private getLineagesFromTaskDocs(taskDocs) { const ids = taskDocs.map(task => task.forId); return this.lineageModelGeneratorService.reportSubjects(ids); } diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 5a3c0c114ca..e90d3bee69f 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -166,7 +166,7 @@ describe('TasksComponent', () => { expect(consoleErrorMock.args[0][0]).to.equal('Error getting tasks for all contacts'); }); - it('tasks render', async() => { + it('tasks render', async () => { const now = moment('2020-10-20'); const futureDate = now.clone().add(3, 'days'); const pastDate = now.clone().subtract(3, 'days'); @@ -318,146 +318,121 @@ describe('TasksComponent', () => { ]; const taskLineages = [ { - _id: 'a', lineage: [ - {name: 'Amy Johnsons Household'}, - {name: 'St Elmos Concession'}, - {name: 'Chattanooga Village'}, - {name: 'CHW Bettys Area'}, - ] + _id: 'a', + lineage: [ + { name: 'Amy Johnsons Household' }, + { name: 'St Elmos Concession' }, + { name: 'Chattanooga Village' }, + { name: 'CHW Bettys Area' }, + ], }, { - _id: 'b', lineage: [ - {name: 'Amy Johnsons Household'}, - {name: 'St Elmos Concession'}, - {name: 'Chattanooga Village'}, - ] - } + _id: 'b', + lineage: [ + { name: 'Amy Johnsons Household' }, + { name: 'St Elmos Concession' }, + { name: 'Chattanooga Village' }, + ], + }, ]; - it('it should not change the reports lineages if the connected user is online only', async() => { - const expectedTasks = - [ - { - _id: 'e1', - date: new Date('2020-10-20'), - dueDate: '2020-10-20', - lineage: [ - 'Amy Johnsons Household', - 'St Elmos Concession', - 'Chattanooga Village', - 'CHW Bettys Area' - ], - overdue: true, - owner: 'a', - }, - { - _id: 'e2', - date: new Date('2020-10-20'), - dueDate: '2020-10-20', - lineage: [ - 'Amy Johnsons Household', - 'St Elmos Concession', - 'Chattanooga Village', - ], - overdue: true, - owner: 'b', - } - ]; + it('should not alter tasks lineage if user is online only', async () => { + const expectedTasks = [ + { + _id: 'e1', + date: new Date('2020-10-20'), + dueDate: '2020-10-20', + lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], + overdue: true, + owner: 'a', + }, + { + _id: 'e2', + date: new Date('2020-10-20'), + dueDate: '2020-10-20', + lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], + overdue: true, + owner: 'b', + }, + ]; userContactService.get.resolves(bettysContactDoc); sessionService.isOnlineOnly.returns(true); rulesEngineService.fetchTaskDocsForAllContacts.resolves(taskDocs); lineageModelGeneratorService.reportSubjects.resolves(taskLineages); + await new Promise(resolve => { sinon.stub(TasksActions.prototype, 'setTasksList').callsFake(resolve); getComponent(); }); + expect(component.currentLevel).to.be.undefined; expect((TasksActions.prototype.setTasksList).args).to.deep.equal([[expectedTasks]]); }); - it('it should not change the reports lineages if the connected user is offline with unrelated lineage', async() => { - const expectedTasks = - [ - { - _id: 'e1', - date: new Date('2020-10-20'), - dueDate: '2020-10-20', - lineage: [ - 'Amy Johnsons Household', - 'St Elmos Concession', - 'Chattanooga Village', - 'CHW Bettys Area' - ], - overdue: true, - owner: 'a', - }, - { - _id: 'e2', - date: new Date('2020-10-20'), - dueDate: '2020-10-20', - lineage: [ - 'Amy Johnsons Household', - 'St Elmos Concession', - 'Chattanooga Village', - ], - overdue: true, - owner: 'b', - } - ]; + it('should not change the tasks lineage if user is offline with unrelated lineage', async () => { + const expectedTasks = [ + { + _id: 'e1', + date: new Date('2020-10-20'), + dueDate: '2020-10-20', + lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], + overdue: true, + owner: 'a', + }, + { + _id: 'e2', + date: new Date('2020-10-20'), + dueDate: '2020-10-20', + lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], + overdue: true, + owner: 'b', + }, + ]; userContactService.get.resolves(userContactDoc); sessionService.isOnlineOnly.returns(false); rulesEngineService.fetchTaskDocsForAllContacts.resolves(taskDocs); lineageModelGeneratorService.reportSubjects.resolves(taskLineages); + await new Promise(resolve => { sinon.stub(TasksActions.prototype, 'setTasksList').callsFake(resolve); getComponent(); }); - const tasks = await (TasksActions.prototype.setTasksList).args; + expect(component.currentLevel).to.equal('parent'); - expect(tasks).to.deep.equal([[expectedTasks]]); + expect((TasksActions.prototype.setTasksList).args).to.deep.equal([[expectedTasks]]); }); - it('it should update the reports lineages if the connected user is offline with related place', async() => { - const expectedTasks = - [ - { - _id: 'e1', - date: new Date('2020-10-20'), - dueDate: '2020-10-20', - lineage: [ - 'Amy Johnsons Household', - 'St Elmos Concession', - 'Chattanooga Village', - ], - overdue: true, - owner: 'a', - }, - { - _id: 'e2', - date: new Date('2020-10-20'), - dueDate: '2020-10-20', - lineage: [ - 'Amy Johnsons Household', - 'St Elmos Concession', - 'Chattanooga Village', - ], - overdue: true, - owner: 'b', - } - ]; - + it('should update the tasks lineage if user is offline with related place to lineage', async () => { + const expectedTasks = [ + { + _id: 'e1', + date: new Date('2020-10-20'), + dueDate: '2020-10-20', + lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], + overdue: true, + owner: 'a', + }, + { + _id: 'e2', + date: new Date('2020-10-20'), + dueDate: '2020-10-20', + lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], + overdue: true, + owner: 'b', + }, + ]; userContactService.get.resolves(bettysContactDoc); sessionService.isOnlineOnly.returns(false); rulesEngineService.fetchTaskDocsForAllContacts.resolves(taskDocs); lineageModelGeneratorService.reportSubjects.resolves(taskLineages); + await new Promise(resolve => { sinon.stub(TasksActions.prototype, 'setTasksList').callsFake(resolve); getComponent(); }); - const tasks = await (TasksActions.prototype.setTasksList).args; + expect(component.currentLevel).to.equal('CHW Bettys Area'); - expect(tasks).to.deep.equal([[expectedTasks]]); + expect((TasksActions.prototype.setTasksList).args).to.deep.equal([[expectedTasks]]); }); - }); }); From 4a52c83dd5293cbbefb984c517d22786ad0274f1 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Wed, 7 Sep 2022 04:45:16 +0000 Subject: [PATCH 41/72] apply most of review recommandations for messages and reports --- .../modules/reports/reports.component.spec.ts | 95 ++++++++++--------- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index 54c9ed9bdec..d65dfddcf08 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -279,35 +279,36 @@ describe('Reports Component', () => { }); describe('Reports breadcrumbs', () => { + const reports = [ + { + _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', + lineage: [ 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], + }, + { + _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ 'Chattanooga Village', 'CHW Bettys Area'], + }, + { + _id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ 'Chattanooga Village' ], + }, + { + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ 'CHW Bettys Area'], + }, + { + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [], + }, + { + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba965525', + }, + ]; + it('it should retrieve the hierarchy level of the connected user', () => { expect(component.currentLevel).to.equal('parent'); }); it('should not change the reports lineage if user is online only', async () => { - const reports = [ - { - _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', - lineage: [ 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], - }, - { - _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ 'Chattanooga Village', 'CHW Bettys Area'], - }, - { - _id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ 'Chattanooga Village' ], - }, - { - _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ 'CHW Bettys Area'], - }, - { - _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [], - }, - { - _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba965525', - }, - ]; const expectedReports = [ { - _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', + _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], heading: 'report.subject.unknown', icon: undefined, @@ -315,7 +316,7 @@ describe('Reports Component', () => { unread: true, }, { - _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', + _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ 'Chattanooga Village', 'CHW Bettys Area' ], heading: 'report.subject.unknown', icon: undefined, @@ -331,7 +332,7 @@ describe('Reports Component', () => { unread: true, }, { - _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ 'CHW Bettys Area' ], heading: 'report.subject.unknown', icon: undefined, @@ -359,8 +360,10 @@ describe('Reports Component', () => { userContactService.get.resolves(userContactDoc); sessionService.isOnlineOnly.resolves(true); component.currentLevel = await component.getCurrentLineageLevel(); - expect(component.currentLevel).to.equal('parent'); + const updatedReports = component.prepareReports(reports); + + expect(component.currentLevel).to.equal('parent'); expect(updatedReports).to.deep.equal(expectedReports); }); @@ -373,21 +376,6 @@ describe('Reports Component', () => { parent: userContactGrandParent, }, }; - const reports = [ - { - _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', - lineage: [ 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], - }, - { - _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ 'Chattanooga Village', 'CHW Bettys Area'], - }, - { - _id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ 'Chattanooga Village'], - }, - { - _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', lineage: [ 'CHW Bettys Area' ], - }, - ]; const expectedReports = [ { _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ 'St Elmos Concession', 'Chattanooga Village' ], @@ -397,7 +385,7 @@ describe('Reports Component', () => { unread: true, }, { - _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', + _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ 'Chattanooga Village' ], heading: 'report.subject.unknown', icon: undefined, @@ -405,7 +393,7 @@ describe('Reports Component', () => { unread: true, }, { - _id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', + _id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ 'Chattanooga Village' ], heading: 'report.subject.unknown', icon: undefined, @@ -420,14 +408,31 @@ describe('Reports Component', () => { summary: undefined, unread: true, }, - ]; + { + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba357229', + heading: 'report.subject.unknown', + icon: undefined, + lineage: [], + summary: undefined, + unread: true, + }, + { + _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba965525', + heading: 'report.subject.unknown', + icon: undefined, + lineage: undefined, + summary: undefined, + unread: true, + }, + ]; userContactService.get.resolves(offlineUserContactDoc); sessionService.isOnlineOnly.resolves(false); component.currentLevel = await component.getCurrentLineageLevel(); - expect(component.currentLevel).to.equal('CHW Bettys Area'); + const updatedReports = component.prepareReports(reports); + + expect(component.currentLevel).to.equal('CHW Bettys Area'); expect(updatedReports).to.deep.equal(expectedReports); }); - }); }); From 981e9929a7a8a8b907b821d732600b4533ca7a1c Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Wed, 7 Sep 2022 04:46:13 +0000 Subject: [PATCH 42/72] apply most of review recommandations for tasks --- webapp/src/ts/modules/tasks/tasks.component.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index d1e5b6d35e4..76e367fc5f1 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -58,10 +58,10 @@ export class TasksComponent implements OnInit, OnDestroy { this.store.select(Selectors.getTasksLoaded), this.store.select(Selectors.getSelectedTask), ).subscribe(([ - tasksList, - tasksLoaded, - selectedTask, - ]) => { + tasksList, + tasksLoaded, + selectedTask, + ]) => { this.tasksList = tasksList; this.tasksLoaded = tasksLoaded; this.selectedTask = selectedTask; From 6011687b717168d901d0818be98aa7da2acec2c6 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Wed, 7 Sep 2022 11:51:01 +0000 Subject: [PATCH 43/72] apply most of review recommandations for tasks --- webapp/src/css/common.less | 1 + .../ts/modules/messages/messages.component.ts | 4 +-- .../ts/modules/reports/reports.component.ts | 2 +- .../messages/messages.component.spec.ts | 33 ++++--------------- .../modules/reports/reports.component.spec.ts | 17 +++++----- 5 files changed, 19 insertions(+), 38 deletions(-) diff --git a/webapp/src/css/common.less b/webapp/src/css/common.less index 7ee5cc566fa..03427de33e1 100644 --- a/webapp/src/css/common.less +++ b/webapp/src/css/common.less @@ -78,6 +78,7 @@ ul { margin-bottom: 0; white-space: normal !important; display: -webkit-box; + // limit the lineage wrapping to two lines -webkit-line-clamp: 2; -webkit-box-orient: vertical; li:after { diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 01e0fcdb5a0..a1b35512f92 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -54,9 +54,7 @@ export class MessagesComponent implements OnInit, OnDestroy { this.subscribeToStore(); this.tourService.startIfNeeded(this.route.snapshot); if (!this.sessionService.isOnlineOnly()) { - this - .getCurrentLineageLevel() - .then(currentLevel => this.currentLevel = currentLevel); + this.currentLevel = this.getCurrentLineageLevel(); } this.updateConversations().then(() => this.displayFirstConversation(this.conversations)); this.watchForChanges(); diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 5aaa8647d02..fc8c2dfebfb 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -194,7 +194,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { report.lineage = report.subject && report.subject.lineage || report.lineage; // remove the lineage level that belongs to the offline logged-in user if (this.currentLevel && report.lineage && report.lineage.length) { - report.lineage = report.lineage?.filter(level => level !== this.currentLevel); + report.lineage = report.lineage.filter(level => level !== this.currentLevel); } report.unread = !report.read; return report; diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index d52610b0876..240f36b9e27 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -56,16 +56,6 @@ describe('Messages Component', () => { }; const mockedSelectors = [ { selector: 'getSelectedConversation', value: {} }, - { - selector: 'getConversations', - value: [ - { - key: 'a', - message: { inAllMessages: true }, - lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ] - }, - ], - }, { selector: 'getLoadingContent', value: false }, { selector: 'getMessagesError', value: false }, ]; @@ -212,15 +202,7 @@ describe('Messages Component', () => { }); describe('Messages breadcrumbs', () => { - const offlineUserContactDoc = { - _id: 'user', - parent: { - _id: 'parent', - name: 'parent', - parent: userContactGrandparent, - }, - }; - const offlineUserContactDoc2 = { + const bettyOfflineUserContactDoc = { _id: 'user', parent: { _id: 'parent', @@ -254,12 +236,12 @@ describe('Messages Component', () => { expect(component.currentLevel).to.equal('parent'); }); - it('should not alter conversations when user is offline and parent place isnt relevant to the conversation', + it('should not alter conversations when user is offline and parent place is not relevant to the conversation', fakeAsync( () => { sinon.resetHistory(); messageContactService.getList.resolves(conversations); - userContactService.get.resolves(offlineUserContactDoc); + userContactService.get.resolves(userContactDoc); sessionService.isOnlineOnly.returns(false); component.updateConversations({merge : true}); @@ -274,14 +256,14 @@ describe('Messages Component', () => { sinon.resetHistory(); messageContactService.getList.resolves(conversations); - userContactService.get.resolves(userContactDoc); + userContactService.get.resolves(bettyOfflineUserContactDoc); sessionService.isOnlineOnly.returns(true); + component.ngOnInit(); + tick(); component.updateConversations({merge : true}); tick(); - expect(messageContactService.getList.callCount).to.equal(1); - expect(component.currentLevel).to.equal('parent'); expect(component.conversations).to.deep.equal(conversations); })); @@ -311,7 +293,7 @@ describe('Messages Component', () => { ]; messageContactService.getList.resolves(conversations); - userContactService.get.resolves(offlineUserContactDoc2); + userContactService.get.resolves(bettyOfflineUserContactDoc); sessionService.isOnlineOnly.returns(false); component.ngOnInit(); @@ -319,7 +301,6 @@ describe('Messages Component', () => { component.updateConversations({ merge : true }); tick(); - expect(messageContactService.getList.callCount).to.equal(2); expect(component.currentLevel).to.equal('CHW Bettys Area'); expect(component.conversations).to.deep.equal(updatedConversations); })); diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index d65dfddcf08..a5badd25c23 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -300,6 +300,14 @@ describe('Reports Component', () => { _id: 'ee21ea15-1ebb-4d6d-95ea-7073ba965525', }, ]; + const offlineUserContactDoc = { + _id: 'user', + parent: { + _id: 'parent', + name: 'CHW Bettys Area', + parent: userContactGrandParent, + }, + }; it('it should retrieve the hierarchy level of the connected user', () => { expect(component.currentLevel).to.equal('parent'); @@ -368,14 +376,7 @@ describe('Reports Component', () => { }); it('should remove current level from reports lineage when user is offline', async () => { - const offlineUserContactDoc = { - _id: 'user', - parent: { - _id: 'parent', - name: 'CHW Bettys Area', - parent: userContactGrandParent, - }, - }; + const expectedReports = [ { _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ 'St Elmos Concession', 'Chattanooga Village' ], From 70137c5dfc7b0e21942ea632ba7d1d0de6c29328 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Wed, 7 Sep 2022 12:32:46 +0000 Subject: [PATCH 44/72] apply most of review recommandations for messages and reports --- webapp/src/ts/modules/messages/messages.component.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index a1b35512f92..01e0fcdb5a0 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -54,7 +54,9 @@ export class MessagesComponent implements OnInit, OnDestroy { this.subscribeToStore(); this.tourService.startIfNeeded(this.route.snapshot); if (!this.sessionService.isOnlineOnly()) { - this.currentLevel = this.getCurrentLineageLevel(); + this + .getCurrentLineageLevel() + .then(currentLevel => this.currentLevel = currentLevel); } this.updateConversations().then(() => this.displayFirstConversation(this.conversations)); this.watchForChanges(); From eaa98ef61084ecc0e170b34517b72e580b23d2cb Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Wed, 7 Sep 2022 16:42:57 +0000 Subject: [PATCH 45/72] change this.currentLevel to promise --- .../ts/modules/messages/messages.component.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index e038c0af446..e5b1725cb2d 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -50,14 +50,12 @@ export class MessagesComponent implements OnInit, OnDestroy { this.messagesActions = new MessagesActions(store); } - ngOnInit(): void { + ngOnInit() { this.subscribeToStore(); this.tourService.startIfNeeded(this.route.snapshot); - if (!this.sessionService.isOnlineOnly()) { - this - .getCurrentLineageLevel() - .then(currentLevel => this.currentLevel = currentLevel); - } + + this.currentLevel = this.sessionService.isOnlineOnly() ? Promise.resolve() : this.getCurrentLineageLevel(); + this.updateConversations().then(() => this.displayFirstConversation(this.conversations)); this.watchForChanges(); } @@ -158,15 +156,17 @@ export class MessagesComponent implements OnInit, OnDestroy { this.updateActionBar(); } - updateConversations({merge = false} = {}) { - return this.messageContactService - .getList() - .then((conversations = []) => { - // remove the lineage level that belongs to the offline logged-in user - if (this.currentLevel) { - conversations.forEach(conversation => { + updateConversations({ merge = false } = {}) { + return Promise + .all([ this.messageContactService.getList(), this.currentLevel ]) + .then(([ conversations, currentLevel ]) => { + // Remove the lineage level that belongs to the offline logged-in user. + if (currentLevel) { + conversations?.forEach(conversation => { if (conversation.lineage) { - conversation.lineage = conversation.lineage.filter(level => level !== this.currentLevel); + conversation.lineage = conversation.lineage.filter(level => level); + conversation.lineage + //conversation.lineage = conversation.lineage.filter(level => level !== currentLevel); } }); } From 5741c82361b7e1f249d60b9319e5b1810c25693a Mon Sep 17 00:00:00 2001 From: latin-panda <66472237+latin-panda@users.noreply.github.com> Date: Thu, 8 Sep 2022 13:51:47 +0700 Subject: [PATCH 46/72] e2e fix --- tests/page-objects/tasks/tasks.wdio.page.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/page-objects/tasks/tasks.wdio.page.js b/tests/page-objects/tasks/tasks.wdio.page.js index 723e6d99b88..5e4b8d96316 100644 --- a/tests/page-objects/tasks/tasks.wdio.page.js +++ b/tests/page-objects/tasks/tasks.wdio.page.js @@ -6,7 +6,7 @@ const noSelectedTaskSelector = '.empty-selection'; const tasksList = () => $(taskListSelector); const getTaskById = (emissionId) => $(`${taskListSelector} li[data-record-id="${emissionId}"`); -const getTasks = () => $$(`${taskListSelector} li`); +const getTasks = () => $$(`${taskListSelector} li.content-row`); const getTaskInfo = async (taskElement) => { const contactName = await (await taskElement.$('h4 span')).getText(); From 683f668b8f4579cb4c3ba7b3e526087d895f4153 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Sun, 11 Sep 2022 17:19:26 +0000 Subject: [PATCH 47/72] apply recommandations except report unit tests structure for now --- webapp/src/css/common.less | 4 +- .../ts/modules/messages/messages.component.ts | 41 ++++++++++--------- .../ts/modules/reports/reports.component.ts | 23 ++++++----- .../messages/messages.component.spec.ts | 34 ++++++++------- .../modules/reports/reports.component.spec.ts | 8 ++-- 5 files changed, 57 insertions(+), 53 deletions(-) diff --git a/webapp/src/css/common.less b/webapp/src/css/common.less index 03427de33e1..5bd920361f6 100644 --- a/webapp/src/css/common.less +++ b/webapp/src/css/common.less @@ -76,11 +76,13 @@ ul { .lineage { margin-bottom: 0; - white-space: normal !important; display: -webkit-box; // limit the lineage wrapping to two lines -webkit-line-clamp: 2; -webkit-box-orient: vertical; + li{ + white-space: normal; + } li:after { content: '\2022'; /* bullet */ padding: 0 5px; diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 01e0fcdb5a0..4ffae65d6cd 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -50,14 +50,12 @@ export class MessagesComponent implements OnInit, OnDestroy { this.messagesActions = new MessagesActions(store); } - ngOnInit(): void { + ngOnInit() { this.subscribeToStore(); this.tourService.startIfNeeded(this.route.snapshot); - if (!this.sessionService.isOnlineOnly()) { - this - .getCurrentLineageLevel() - .then(currentLevel => this.currentLevel = currentLevel); - } + + this.currentLevel = this.sessionService.isOnlineOnly() ? Promise.resolve() : this.getCurrentLineageLevel(); + this.updateConversations().then(() => this.displayFirstConversation(this.conversations)); this.watchForChanges(); } @@ -77,11 +75,11 @@ export class MessagesComponent implements OnInit, OnDestroy { this.store.select(Selectors.getLoadingContent), this.store.select(Selectors.getMessagesError), ).subscribe(([ - conversations = [], - selectedConversation, - loadingContent, - error, - ]) => { + conversations = [], + selectedConversation, + loadingContent, + error, + ]) => { // Create new reference of conversation's items // because the ones from store can't be modified as they are read only. this.conversations = conversations.map(conversation => { @@ -158,15 +156,18 @@ export class MessagesComponent implements OnInit, OnDestroy { this.updateActionBar(); } - updateConversations({merge = false} = {}) { - return this.messageContactService - .getList() - .then((conversations = []) => { - // remove the lineage level that belongs to the offline logged in user - if (this.currentLevel) { - conversations.forEach(conversation => { - if (conversation.lineage) { - conversation.lineage = conversation.lineage.filter(level => level !== this.currentLevel); + updateConversations({ merge = false } = {}) { + return Promise + .all([ this.messageContactService.getList(), this.currentLevel ]) + .then(([ conversations, currentLevel ]) => { + // Remove the lineage level that belongs to the offline logged-in user. + if (currentLevel) { + conversations?.forEach(conversation => { + if (conversation.lineage && conversation.lineage.length) { + conversation.lineage = conversation.lineage.filter(level => level); + if(conversation.lineage[conversation.lineage.length-1] === currentLevel){ + conversation.lineage.pop(); + } } }); } diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index fc8c2dfebfb..b14dbbc8f2c 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -89,15 +89,15 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { this.store.select(Selectors.getEnketoEditedStatus), this.store.select(Selectors.getSelectMode), ).subscribe(([ - reportsList, - selectedReports, - listContains, - forms, - filters, - showContent, - enketoEdited, - selectMode, - ]) => { + reportsList, + selectedReports, + listContains, + forms, + filters, + showContent, + enketoEdited, + selectMode, + ]) => { this.reportsList = reportsList; // selected objects have the form // { _id: 'abc', summary: { ... }, report: { ... }, expanded: false } @@ -194,7 +194,10 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { report.lineage = report.subject && report.subject.lineage || report.lineage; // remove the lineage level that belongs to the offline logged-in user if (this.currentLevel && report.lineage && report.lineage.length) { - report.lineage = report.lineage.filter(level => level !== this.currentLevel); + report.lineage = report.lineage.filter(level => level); + if(report.lineage[report.lineage.length-1] === this.currentLevel){ + report.lineage.pop(); + } } report.unread = !report.read; return report; diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index 240f36b9e27..18fc6695343 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -213,7 +213,7 @@ describe('Messages Component', () => { const conversations = [ { key: 'a', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area'] + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area', null] }, { key: 'b', message: { inAllMessages: true }, @@ -221,7 +221,7 @@ describe('Messages Component', () => { }, { key: 'c', message: { inAllMessages: true }, - lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'Ramdom Place'] + lineage : [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'Ramdom Place', null, null] }, { key: 'd', message: { inAllMessages: true }, @@ -232,25 +232,24 @@ describe('Messages Component', () => { }, ]; - it('it should retrieve the hierarchy level of the connected user', () => { - expect(component.currentLevel).to.equal('parent'); + it('it should retrieve the hierarchy level of the connected user', async () => { + expect(await component.currentLevel).to.equal('parent'); }); - it('should not alter conversations when user is offline and parent place is not relevant to the conversation', - fakeAsync( () => { - sinon.resetHistory(); + it('should not change the conversations lineage if the connected user is online only', fakeAsync( () => { + sinon.resetHistory(); - messageContactService.getList.resolves(conversations); - userContactService.get.resolves(userContactDoc); - sessionService.isOnlineOnly.returns(false); + messageContactService.getList.resolves(conversations); + userContactService.get.resolves(bettyOfflineUserContactDoc); + sessionService.isOnlineOnly.returns(true); - component.updateConversations({merge : true}); - tick(); + component.ngOnInit(); + tick(); + component.updateConversations({merge : true}); + tick(); - expect(messageContactService.getList.callCount).to.equal(1); - expect(component.currentLevel).to.equal('parent'); - expect(component.conversations).to.deep.equal(conversations); - })); + expect(component.conversations).to.deep.equal(conversations); + })); it('should not change the conversations lineage if the connected user is online only', fakeAsync( () => { sinon.resetHistory(); @@ -301,9 +300,8 @@ describe('Messages Component', () => { component.updateConversations({ merge : true }); tick(); - expect(component.currentLevel).to.equal('CHW Bettys Area'); expect(component.conversations).to.deep.equal(updatedConversations); })); }); - }); + diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index a5badd25c23..5b371b4e85e 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -42,13 +42,13 @@ describe('Reports Component', () => { let datePipe; let userContactService; - const userContactGrandParent = { _id: 'grandparent' }; + const userContactGrandparent = { _id: 'grandparent' }; const userContactDoc = { _id: 'user', parent: { _id: 'parent', name: 'parent', - parent: userContactGrandParent, + parent: userContactGrandparent, }, }; @@ -285,7 +285,7 @@ describe('Reports Component', () => { lineage: [ 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], }, { - _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ 'Chattanooga Village', 'CHW Bettys Area'], + _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', lineage: [ 'Chattanooga Village', 'CHW Bettys Area', null, null], }, { _id: 'd2da792d-e7f1-48b3-8e53-61d331d7e899', lineage: [ 'Chattanooga Village' ], @@ -305,7 +305,7 @@ describe('Reports Component', () => { parent: { _id: 'parent', name: 'CHW Bettys Area', - parent: userContactGrandParent, + parent: userContactGrandparent, }, }; From 4939ebb7972d8165db52821db44ba7beb9b4b2a6 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Sun, 11 Sep 2022 18:09:30 +0000 Subject: [PATCH 48/72] minor changes --- webapp/src/ts/modules/tasks/tasks.component.ts | 4 ++-- webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 76e367fc5f1..0270c1430f6 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -155,7 +155,7 @@ export class TasksComponent implements OnInit, OnDestroy { const hydratedTasks = await this.hydrateEmissions(taskDocs) || []; const subjects = await this.getLineagesFromTaskDocs(hydratedTasks); - if (subjects) { + if (subjects.length) { hydratedTasks.forEach(task => { const lineage = this.getTaskLineage(subjects, task); task.lineage = this.currentLevel ? this.removeCurrentLineage(lineage) : lineage; @@ -190,7 +190,7 @@ export class TasksComponent implements OnInit, OnDestroy { } private getLineagesFromTaskDocs(taskDocs) { - const ids = taskDocs.map(task => task.forId); + const ids = [...new Set(taskDocs.map(task => task.forId))]; return this.lineageModelGeneratorService.reportSubjects(ids); } diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index e90d3bee69f..d35b2daaf44 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -340,7 +340,7 @@ describe('TasksComponent', () => { const expectedTasks = [ { _id: 'e1', - date: new Date('2020-10-20'), + date: moment('2020-10-20').toDate(), dueDate: '2020-10-20', lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], overdue: true, @@ -348,7 +348,7 @@ describe('TasksComponent', () => { }, { _id: 'e2', - date: new Date('2020-10-20'), + date: moment('2020-10-20').toDate(), dueDate: '2020-10-20', lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], overdue: true, From f480f7ca21098bbc6cf635cce6d5c6ce35ef9965 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Sun, 11 Sep 2022 18:11:06 +0000 Subject: [PATCH 49/72] fix indentations --- .../ts/modules/messages/messages.component.ts | 10 +++++----- .../ts/modules/reports/reports.component.ts | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 4ffae65d6cd..656d3f422ee 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -75,11 +75,11 @@ export class MessagesComponent implements OnInit, OnDestroy { this.store.select(Selectors.getLoadingContent), this.store.select(Selectors.getMessagesError), ).subscribe(([ - conversations = [], - selectedConversation, - loadingContent, - error, - ]) => { + conversations = [], + selectedConversation, + loadingContent, + error, + ]) => { // Create new reference of conversation's items // because the ones from store can't be modified as they are read only. this.conversations = conversations.map(conversation => { diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index b14dbbc8f2c..d0593f54206 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -89,15 +89,15 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { this.store.select(Selectors.getEnketoEditedStatus), this.store.select(Selectors.getSelectMode), ).subscribe(([ - reportsList, - selectedReports, - listContains, - forms, - filters, - showContent, - enketoEdited, - selectMode, - ]) => { + reportsList, + selectedReports, + listContains, + forms, + filters, + showContent, + enketoEdited, + selectMode, + ]) => { this.reportsList = reportsList; // selected objects have the form // { _id: 'abc', summary: { ... }, report: { ... }, expanded: false } From 63add58cb085aa144be9fe00f14882397a01dd52 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Sun, 11 Sep 2022 19:39:15 +0000 Subject: [PATCH 50/72] apply code review recommandations for tasks --- .../ts/modules/messages/messages.component.ts | 7 +++-- .../src/ts/modules/tasks/tasks.component.ts | 27 +++++++++------- .../ts/modules/tasks/tasks.component.spec.ts | 31 +++++++++---------- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index e5b1725cb2d..656d3f422ee 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -163,10 +163,11 @@ export class MessagesComponent implements OnInit, OnDestroy { // Remove the lineage level that belongs to the offline logged-in user. if (currentLevel) { conversations?.forEach(conversation => { - if (conversation.lineage) { + if (conversation.lineage && conversation.lineage.length) { conversation.lineage = conversation.lineage.filter(level => level); - conversation.lineage - //conversation.lineage = conversation.lineage.filter(level => level !== currentLevel); + if(conversation.lineage[conversation.lineage.length-1] === currentLevel){ + conversation.lineage.pop(); + } } }); } diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 0270c1430f6..56e624c0e91 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -154,11 +154,9 @@ export class TasksComponent implements OnInit, OnDestroy { const hydratedTasks = await this.hydrateEmissions(taskDocs) || []; const subjects = await this.getLineagesFromTaskDocs(hydratedTasks); - - if (subjects.length) { + if (subjects.size) { hydratedTasks.forEach(task => { - const lineage = this.getTaskLineage(subjects, task); - task.lineage = this.currentLevel ? this.removeCurrentLineage(lineage) : lineage; + task.lineage = this.getTaskLineage(subjects, task); }); } @@ -191,23 +189,30 @@ export class TasksComponent implements OnInit, OnDestroy { private getLineagesFromTaskDocs(taskDocs) { const ids = [...new Set(taskDocs.map(task => task.forId))]; - return this.lineageModelGeneratorService.reportSubjects(ids); + return this + .lineageModelGeneratorService.reportSubjects(ids) + .then(subjects => new Map(subjects.map(subject => [subject._id, subject.lineage]))); } private getTaskLineage(subjects, task) { - if (!subjects?.length) { + if (!subjects?.size) { return; } - - const lineage = subjects.find(subject => (subject._id === task.forId || subject._id === task.owner))?.lineage; - return lineage.map(lineage => lineage.name); + let lineage = subjects + .get(task.forId) + .map(lineage => lineage.name); + lineage = this.currentLevel ? this.removeCurrentLineage(lineage) : lineage; + return lineage; } private removeCurrentLineage(lineage) { if (!this.currentLevel || !lineage?.length) { return; } - - return lineage.filter(level => level && level !== this.currentLevel); + lineage.lineage = lineage.lineage.filter(level => level); + if(lineage.lineage[lineage.lineage.length-1] === this.currentLevel){ + lineage.lineage.pop(); + } + return lineage; } } diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index d35b2daaf44..ae3ab6201e3 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -58,9 +58,7 @@ describe('TasksComponent', () => { includes: sinon.stub(), }; sessionService = { - isDbAdmin: sinon.stub().returns(false), isOnlineOnly: sinon.stub().returns(false), - userCtx: sinon.stub().returns({ name: 'Sarah' }) }; userContactService = { get: sinon.stub().resolves(), @@ -175,16 +173,6 @@ describe('TasksComponent', () => { { _id: '1', emission: { _id: 'e1', dueDate: futureDate.format('YYYY-MM-DD') }, owner: 'a' }, { _id: '2', emission: { _id: 'e2', dueDate: pastDate.format('YYYY-MM-DD') }, owner: 'b' }, ]; - rulesEngineService.fetchTaskDocsForAllContacts.resolves(taskDocs); - await new Promise(resolve => { - sinon.stub(TasksActions.prototype, 'setTasksList').callsFake(resolve); - getComponent(); - }); - clock.tick(); - expect(component.loading).to.be.false; - expect(component.tasksDisabled).to.be.false; - expect(component.hasTasks).to.be.true; - expect(!!component.error).to.be.false; const expectedTasks = [ { _id: 'e1', @@ -201,6 +189,17 @@ describe('TasksComponent', () => { owner: 'b', }, ]; + + rulesEngineService.fetchTaskDocsForAllContacts.resolves(taskDocs); + await new Promise(resolve => { + sinon.stub(TasksActions.prototype, 'setTasksList').callsFake(resolve); + getComponent(); + }); + + expect(component.loading).to.be.false; + expect(component.tasksDisabled).to.be.false; + expect(component.hasTasks).to.be.true; + expect(!!component.error).to.be.false; expect((TasksActions.prototype.setTasksList).args).to.deep.eq([[expectedTasks]]); }); @@ -373,17 +372,17 @@ describe('TasksComponent', () => { const expectedTasks = [ { _id: 'e1', - date: new Date('2020-10-20'), + date: moment('2020-10-20').toDate(), dueDate: '2020-10-20', - lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], + lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area', null ], overdue: true, owner: 'a', }, { _id: 'e2', - date: new Date('2020-10-20'), + date: moment('2020-10-20').toDate(), dueDate: '2020-10-20', - lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], + lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', null, null ], overdue: true, owner: 'b', }, From af6c515d49002af40a014c8616c2dd9774a78e95 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 12 Sep 2022 00:31:36 +0000 Subject: [PATCH 51/72] minor changes --- webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index ae3ab6201e3..94934da5bee 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -58,10 +58,12 @@ describe('TasksComponent', () => { includes: sinon.stub(), }; sessionService = { + isDbAdmin: sinon.stub().returns(false), isOnlineOnly: sinon.stub().returns(false), + userCtx: sinon.stub().returns({ name: 'Sarah' }) }; userContactService = { - get: sinon.stub().resolves(), + get: sinon.stub().resolves(userContactDoc), }; lineageModelGeneratorService = { reportSubjects: sinon.stub() }; From 03915ef7797d6b5d2ac0b8bf48e6683a0f105b3d Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 12 Sep 2022 00:55:54 +0000 Subject: [PATCH 52/72] minor changes --- webapp/src/ts/modules/tasks/tasks.component.ts | 2 +- webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 56e624c0e91..561fcfa4b42 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -200,7 +200,7 @@ export class TasksComponent implements OnInit, OnDestroy { } let lineage = subjects .get(task.forId) - .map(lineage => lineage.name); + ?.map(lineage => lineage.name); lineage = this.currentLevel ? this.removeCurrentLineage(lineage) : lineage; return lineage; } diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 94934da5bee..ae3ab6201e3 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -58,12 +58,10 @@ describe('TasksComponent', () => { includes: sinon.stub(), }; sessionService = { - isDbAdmin: sinon.stub().returns(false), isOnlineOnly: sinon.stub().returns(false), - userCtx: sinon.stub().returns({ name: 'Sarah' }) }; userContactService = { - get: sinon.stub().resolves(userContactDoc), + get: sinon.stub().resolves(), }; lineageModelGeneratorService = { reportSubjects: sinon.stub() }; From cb1b55521d7cde91d82f7ec15e3b96f50b0afd37 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 12 Sep 2022 01:54:17 +0000 Subject: [PATCH 53/72] fix unit tests for null values in lineages --- webapp/src/ts/modules/tasks/tasks.component.ts | 15 ++++++++------- .../ts/modules/tasks/tasks.component.spec.ts | 13 +++++++++++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 561fcfa4b42..8992a1e8ca6 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -135,6 +135,7 @@ export class TasksComponent implements OnInit, OnDestroy { emission.date = new Date(dueDate.valueOf()); emission.overdue = dueDate.isBefore(moment()); emission.owner = taskDoc.owner; + emission.forId = taskDoc.forId; return emission; }); } @@ -200,18 +201,18 @@ export class TasksComponent implements OnInit, OnDestroy { } let lineage = subjects .get(task.forId) - ?.map(lineage => lineage.name); - lineage = this.currentLevel ? this.removeCurrentLineage(lineage) : lineage; + ?.map(lineage => lineage?.name); + lineage = this.cleanAndRemoveCurrentLineage(lineage); return lineage; } - private removeCurrentLineage(lineage) { - if (!this.currentLevel || !lineage?.length) { + private cleanAndRemoveCurrentLineage(lineage) { + if(!lineage?.length){ return; } - lineage.lineage = lineage.lineage.filter(level => level); - if(lineage.lineage[lineage.lineage.length-1] === this.currentLevel){ - lineage.lineage.pop(); + lineage = lineage.filter(level => level); + if(this.currentLevel === lineage[lineage.length-1]){ + lineage.pop(); } return lineage; } diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index ae3ab6201e3..0b96b28c37f 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -323,6 +323,7 @@ describe('TasksComponent', () => { { name: 'St Elmos Concession' }, { name: 'Chattanooga Village' }, { name: 'CHW Bettys Area' }, + null, ], }, { @@ -331,6 +332,8 @@ describe('TasksComponent', () => { { name: 'Amy Johnsons Household' }, { name: 'St Elmos Concession' }, { name: 'Chattanooga Village' }, + null, + null, ], }, ]; @@ -344,6 +347,7 @@ describe('TasksComponent', () => { lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], overdue: true, owner: 'a', + forId: 'a', }, { _id: 'e2', @@ -352,6 +356,7 @@ describe('TasksComponent', () => { lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], overdue: true, owner: 'b', + forId: 'b', }, ]; userContactService.get.resolves(bettysContactDoc); @@ -374,17 +379,19 @@ describe('TasksComponent', () => { _id: 'e1', date: moment('2020-10-20').toDate(), dueDate: '2020-10-20', - lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area', null ], + lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], overdue: true, owner: 'a', + forId: 'a', }, { _id: 'e2', date: moment('2020-10-20').toDate(), dueDate: '2020-10-20', - lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', null, null ], + lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], overdue: true, owner: 'b', + forId: 'b', }, ]; userContactService.get.resolves(userContactDoc); @@ -410,6 +417,7 @@ describe('TasksComponent', () => { lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], overdue: true, owner: 'a', + forId: 'a', }, { _id: 'e2', @@ -418,6 +426,7 @@ describe('TasksComponent', () => { lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], overdue: true, owner: 'b', + forId: 'b', }, ]; userContactService.get.resolves(bettysContactDoc); From d6a31372f427004891b0e4ac559e723173c1fe62 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 12 Sep 2022 02:46:35 +0000 Subject: [PATCH 54/72] fix unit tests forID missing in taskDocs --- webapp/src/ts/modules/tasks/tasks.component.ts | 6 +++--- webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 8992a1e8ca6..9487c050f24 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -135,7 +135,7 @@ export class TasksComponent implements OnInit, OnDestroy { emission.date = new Date(dueDate.valueOf()); emission.overdue = dueDate.isBefore(moment()); emission.owner = taskDoc.owner; - emission.forId = taskDoc.forId; + emission.forId = taskDoc.forId ? taskDoc.forId : taskDoc.owner; return emission; }); } @@ -155,7 +155,7 @@ export class TasksComponent implements OnInit, OnDestroy { const hydratedTasks = await this.hydrateEmissions(taskDocs) || []; const subjects = await this.getLineagesFromTaskDocs(hydratedTasks); - if (subjects.size) { + if (subjects?.size) { hydratedTasks.forEach(task => { task.lineage = this.getTaskLineage(subjects, task); }); @@ -192,7 +192,7 @@ export class TasksComponent implements OnInit, OnDestroy { const ids = [...new Set(taskDocs.map(task => task.forId))]; return this .lineageModelGeneratorService.reportSubjects(ids) - .then(subjects => new Map(subjects.map(subject => [subject._id, subject.lineage]))); + ?.then(subjects => new Map(subjects.map(subject => [subject._id, subject.lineage]))); } private getTaskLineage(subjects, task) { diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 0b96b28c37f..8b1b6a1954b 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -180,6 +180,7 @@ describe('TasksComponent', () => { overdue: false, date: new Date(futureDate.valueOf()), owner: 'a', + forId: 'a', }, { _id: 'e2', @@ -187,6 +188,7 @@ describe('TasksComponent', () => { overdue: true, date: new Date(pastDate.valueOf()), owner: 'b', + forId: 'b', }, ]; From 2602efeac1160785c530d6df6c239f05e3129fde Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 12 Sep 2022 04:43:25 +0000 Subject: [PATCH 55/72] trying report unit tests refactoring --- .../ts/modules/reports/reports.component.ts | 6 ++- .../modules/reports/reports.component.spec.ts | 44 +++++++++++++------ 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index d0593f54206..46706c104e0 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -185,7 +185,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { return this.translateService.instant('report.subject.unknown'); } - prepareReports(reports) { + private prepareReports(reports) { return reports.map(report => { const form = _find(this.forms, { code: report.form }); report.icon = form && form.icon; @@ -231,7 +231,9 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { .then((reports) => this.addReadStatusService.updateReports(reports)) .then((updatedReports) => { updatedReports = this.prepareReports(updatedReports); + console.log(updatedReports); this.reportsActions.updateReportsList(updatedReports); + console.log(updatedReports); this.moreItems = updatedReports.length >= options.limit; this.hasReports = !!updatedReports.length; @@ -346,7 +348,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { this.reportsSidebarFilter?.resetFilters(); } - getCurrentLineageLevel(){ + private getCurrentLineageLevel(){ return this.userContactService.get().then(user => user?.parent?.name); } } diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index a04d4a26ca6..242e62f13ac 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -278,7 +278,12 @@ describe('Reports Component', () => { }); }); - describe('Reports breadcrumbs', () => { + xdescribe('Reports breadcrumbs', () => { + let updateReportsList; + + beforeEach(() => { + updateReportsList = sinon.stub(ReportsActions.prototype, 'updateReportsList'); + }); const reports = [ { _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', @@ -309,11 +314,11 @@ describe('Reports Component', () => { }, }; - it('it should retrieve the hierarchy level of the connected user', () => { - expect(component.currentLevel).to.equal('parent'); - }); - it('should not change the reports lineage if user is online only', async () => { + sinon.resetHistory; + + searchService.search.resolves(reports); + addReadStatusService.updateReports.resolves(reports); const expectedReports = [ { _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', @@ -367,16 +372,17 @@ describe('Reports Component', () => { ]; userContactService.get.resolves(userContactDoc); sessionService.isOnlineOnly.resolves(true); - component.currentLevel = await component.getCurrentLineageLevel(); - const updatedReports = component.prepareReports(reports); + component.ngOnInit(); + await component.ngAfterViewInit(); - expect(component.currentLevel).to.equal('parent'); - expect(updatedReports).to.deep.equal(expectedReports); + //expect(updateReportsList.callCount).to.equal(1); + const updatedReports = updateReportsList.args[0]; + expect(updatedReports).to.deep.equal([expectedReports]); }); it('should remove current level from reports lineage when user is offline', async () => { - + /* const expectedReports = [ { _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ 'St Elmos Concession', 'Chattanooga Village' ], @@ -426,14 +432,24 @@ describe('Reports Component', () => { unread: true, }, ]; + + */ userContactService.get.resolves(offlineUserContactDoc); sessionService.isOnlineOnly.resolves(false); - component.currentLevel = await component.getCurrentLineageLevel(); + //component.currentLevel = await component.getCurrentLineageLevel(); - const updatedReports = component.prepareReports(reports); + //const updatedReports = component.prepareReports(reports); + + //expect(component.currentLevel).to.equal('CHW Bettys Area'); + //expect(updatedReports).to.deep.equal(expectedReports); + }); - expect(component.currentLevel).to.equal('CHW Bettys Area'); - expect(updatedReports).to.deep.equal(expectedReports); + /* + it('it should retrieve the hierarchy level of the connected user', () => { + expect(component.currentLevel).to.equal('parent'); }); + */ + }); + }); From 03bd4166f1dd44fbab254d24606c16d130f3556d Mon Sep 17 00:00:00 2001 From: latin-panda <66472237+latin-panda@users.noreply.github.com> Date: Mon, 12 Sep 2022 14:22:38 +0700 Subject: [PATCH 56/72] Fixing unit test --- .../facility-filter.component.ts | 2 +- .../modules/reports/reports.component.spec.ts | 61 ++++++++----------- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/webapp/src/ts/components/filters/facility-filter/facility-filter.component.ts b/webapp/src/ts/components/filters/facility-filter/facility-filter.component.ts index fd451d3843a..7398974ac08 100644 --- a/webapp/src/ts/components/filters/facility-filter/facility-filter.component.ts +++ b/webapp/src/ts/components/filters/facility-filter/facility-filter.component.ts @@ -79,7 +79,7 @@ export class FacilityFilterComponent implements OnInit, AfterViewInit, AbstractF return this.placeHierarchyService .get() - .then(hierarchy => { + .then((hierarchy = []) => { hierarchy = this.sortHierarchyAndAddFacilityLabels(hierarchy); this.facilities = hierarchy; this.flattenedFacilities = _flatten(this.facilities.map(facility => this.getFacilitiesRecursive(facility))); diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index 242e62f13ac..ee3c397c543 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -1,4 +1,4 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, flush, TestBed, waitForAsync } from '@angular/core/testing'; import { DatePipe } from '@angular/common'; import { provideMockStore } from '@ngrx/store/testing'; import { RouterTestingModule } from '@angular/router/testing'; @@ -81,6 +81,7 @@ describe('Reports Component', () => { userContactService = { get: sinon.stub().resolves(userContactDoc), }; + return TestBed .configureTestingModule({ imports: [ @@ -278,12 +279,7 @@ describe('Reports Component', () => { }); }); - xdescribe('Reports breadcrumbs', () => { - let updateReportsList; - - beforeEach(() => { - updateReportsList = sinon.stub(ReportsActions.prototype, 'updateReportsList'); - }); + describe.only('Reports breadcrumbs', () => { const reports = [ { _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', @@ -314,11 +310,15 @@ describe('Reports Component', () => { }, }; - it('should not change the reports lineage if user is online only', async () => { - sinon.resetHistory; + let updateReportsListStub; + beforeEach(() => { + updateReportsListStub = sinon.stub(ReportsActions.prototype, 'updateReportsList'); searchService.search.resolves(reports); - addReadStatusService.updateReports.resolves(reports); + }); + + it('should not change the reports lineage if user is online only', fakeAsync(() => { + sessionService.isOnlineOnly.returns(true); const expectedReports = [ { _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', @@ -370,22 +370,22 @@ describe('Reports Component', () => { }, ]; - userContactService.get.resolves(userContactDoc); - sessionService.isOnlineOnly.resolves(true); component.ngOnInit(); - await component.ngAfterViewInit(); + component.ngAfterViewInit(); + flush(); - //expect(updateReportsList.callCount).to.equal(1); - const updatedReports = updateReportsList.args[0]; - expect(updatedReports).to.deep.equal([expectedReports]); - }); + expect(updateReportsListStub.callCount).to.equal(1); + expect(updateReportsListStub.args[0]).to.deep.equal([ expectedReports ]); + })); - it('should remove current level from reports lineage when user is offline', async () => { - /* + it('should remove current level from reports lineage when user is offline', fakeAsync(() => { + userContactService.get.resolves(offlineUserContactDoc); + sessionService.isOnlineOnly.returns(false); const expectedReports = [ { - _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', lineage: [ 'St Elmos Concession', 'Chattanooga Village' ], + _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', + lineage: [ 'St Elmos Concession', 'Chattanooga Village' ], heading: 'report.subject.unknown', icon: undefined, summary: undefined, @@ -433,22 +433,13 @@ describe('Reports Component', () => { }, ]; - */ - userContactService.get.resolves(offlineUserContactDoc); - sessionService.isOnlineOnly.resolves(false); - //component.currentLevel = await component.getCurrentLineageLevel(); - - //const updatedReports = component.prepareReports(reports); - - //expect(component.currentLevel).to.equal('CHW Bettys Area'); - //expect(updatedReports).to.deep.equal(expectedReports); - }); + component.ngOnInit(); + component.ngAfterViewInit(); + flush(); - /* - it('it should retrieve the hierarchy level of the connected user', () => { - expect(component.currentLevel).to.equal('parent'); - }); - */ + expect(updateReportsListStub.callCount).to.equal(1); + expect(updateReportsListStub.args[0]).to.deep.equal([ expectedReports ]); + })); }); From a38ded8e7f020f1a7b6efc6124ffb2e64265e816 Mon Sep 17 00:00:00 2001 From: latin-panda <66472237+latin-panda@users.noreply.github.com> Date: Mon, 12 Sep 2022 14:27:03 +0700 Subject: [PATCH 57/72] removing .only() from unit tests --- webapp/tests/karma/ts/modules/reports/reports.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index ee3c397c543..0f783dd9bb3 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -279,7 +279,7 @@ describe('Reports Component', () => { }); }); - describe.only('Reports breadcrumbs', () => { + describe('Reports breadcrumbs', () => { const reports = [ { _id: '88b0dfff-4a82-4202-abea-d0cabe5aa9bd', From ff93496c68a72040d75d1deaccfe7a5d88008029 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 12 Sep 2022 09:27:08 +0000 Subject: [PATCH 58/72] remove console.log for report component --- webapp/src/ts/modules/reports/reports.component.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 46706c104e0..34f96311cb6 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -231,9 +231,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { .then((reports) => this.addReadStatusService.updateReports(reports)) .then((updatedReports) => { updatedReports = this.prepareReports(updatedReports); - console.log(updatedReports); this.reportsActions.updateReportsList(updatedReports); - console.log(updatedReports); this.moreItems = updatedReports.length >= options.limit; this.hasReports = !!updatedReports.length; From c5bd08acf4a053852b5741a7c86caf3450a0a860 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 12 Sep 2022 15:30:08 +0000 Subject: [PATCH 59/72] minor changes --- webapp/src/ts/modules/tasks/tasks.component.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 9487c050f24..98f7b438b11 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -107,9 +107,13 @@ export class TasksComponent implements OnInit, OnDestroy { if (!this.sessionService.isOnlineOnly()) { this .getCurrentLineageLevel() - .then(currentLevel => this.currentLevel = currentLevel); + .then(currentLevel => { + this.currentLevel = currentLevel; + this.refreshTasks(); + }); + } else { + this.refreshTasks(); } - this.refreshTasks(); this.tourService.startIfNeeded(this.route.snapshot); } From 6d7cb7f820293979ed263ddd4b7371a63f397283 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 12 Sep 2022 17:05:30 +0000 Subject: [PATCH 60/72] make this.currentLevel a promise for report component --- .../ts/modules/reports/reports.component.ts | 50 ++++++++++--------- .../modules/reports/reports.component.spec.ts | 4 +- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 34f96311cb6..e7b5a45d705 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -139,11 +139,9 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { this.globalActions.setFilter({ search: this.route.snapshot.queryParams.query || '' }); this.tourService.startIfNeeded(this.route.snapshot); this.setActionBarData(); - if (!this.sessionService.isOnlineOnly()) { - this - .getCurrentLineageLevel() - .then(currentLevel => this.currentLevel = currentLevel); - } + + this.currentLevel = this.sessionService.isOnlineOnly() ? Promise.resolve() : this.getCurrentLineageLevel(); + } async ngAfterViewInit() { @@ -186,22 +184,27 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { } private prepareReports(reports) { - return reports.map(report => { - const form = _find(this.forms, { code: report.form }); - report.icon = form && form.icon; - report.heading = this.getReportHeading(form, report); - report.summary = form ? form.title : report.form; - report.lineage = report.subject && report.subject.lineage || report.lineage; - // remove the lineage level that belongs to the offline logged-in user - if (this.currentLevel && report.lineage && report.lineage.length) { - report.lineage = report.lineage.filter(level => level); - if(report.lineage[report.lineage.length-1] === this.currentLevel){ - report.lineage.pop(); - } + return this.currentLevel.then( + currentLevel => { + return reports.map(report => { + const form = _find(this.forms, { code: report.form }); + report.icon = form && form.icon; + report.heading = this.getReportHeading(form, report); + report.summary = form ? form.title : report.form; + report.lineage = report.subject && report.subject.lineage || report.lineage; + // remove the lineage level that belongs to the offline logged-in user + if (currentLevel && report.lineage && report.lineage.length) { + report.lineage = report.lineage.filter(level => level); + if(report.lineage[report.lineage.length-1] === currentLevel){ + report.lineage.pop(); + } + } + report.unread = !report.read; + return report; + }); } - report.unread = !report.read; - return report; - }); + ); + } private query(opts) { @@ -229,9 +232,10 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { return this.searchService .search('reports', this.filters, options) .then((reports) => this.addReadStatusService.updateReports(reports)) - .then((updatedReports) => { - updatedReports = this.prepareReports(updatedReports); - this.reportsActions.updateReportsList(updatedReports); + .then(updatedReports => { + this + .prepareReports(updatedReports) + .then(updatedReports => this.reportsActions.updateReportsList(updatedReports)); this.moreItems = updatedReports.length >= options.limit; this.hasReports = !!updatedReports.length; diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index 0f783dd9bb3..795ed4db19c 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -1,4 +1,4 @@ -import { ComponentFixture, fakeAsync, flush, TestBed, waitForAsync } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, flush, TestBed, tick, waitForAsync } from '@angular/core/testing'; import { DatePipe } from '@angular/common'; import { provideMockStore } from '@ngrx/store/testing'; import { RouterTestingModule } from '@angular/router/testing'; @@ -330,7 +330,7 @@ describe('Reports Component', () => { }, { _id: 'a86f238a-ad81-4780-9552-c7248864d1b2', - lineage: [ 'Chattanooga Village', 'CHW Bettys Area' ], + lineage: [ 'Chattanooga Village', 'CHW Bettys Area', null, null ], heading: 'report.subject.unknown', icon: undefined, summary: undefined, From 5b64c06b6ed8b35866de5b129320199b47025651 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 12 Sep 2022 17:14:16 +0000 Subject: [PATCH 61/72] make this.currentLevel a promise for task component --- .../src/ts/modules/tasks/tasks.component.ts | 22 ++++++++----------- .../ts/modules/tasks/tasks.component.spec.ts | 6 ++--- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 98f7b438b11..c28ed0a9a65 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -104,16 +104,10 @@ export class TasksComponent implements OnInit, OnDestroy { this.hasTasks = false; this.loading = true; this.debouncedReload = _debounce(this.refreshTasks.bind(this), 1000, {maxWait: 10 * 1000}); - if (!this.sessionService.isOnlineOnly()) { - this - .getCurrentLineageLevel() - .then(currentLevel => { - this.currentLevel = currentLevel; - this.refreshTasks(); - }); - } else { - this.refreshTasks(); - } + + this.currentLevel = this.sessionService.isOnlineOnly() ? Promise.resolve() : this.getCurrentLineageLevel(); + + this.refreshTasks(); this.tourService.startIfNeeded(this.route.snapshot); } @@ -215,9 +209,11 @@ export class TasksComponent implements OnInit, OnDestroy { return; } lineage = lineage.filter(level => level); - if(this.currentLevel === lineage[lineage.length-1]){ - lineage.pop(); - } + this.currentLevel.then(currentLevel => { + if(currentLevel === lineage[lineage.length-1]){ + lineage.pop(); + } + }); return lineage; } } diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 8b1b6a1954b..3cd523a8d3b 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -371,7 +371,7 @@ describe('TasksComponent', () => { getComponent(); }); - expect(component.currentLevel).to.be.undefined; + expect(await component.currentLevel).to.be.undefined; expect((TasksActions.prototype.setTasksList).args).to.deep.equal([[expectedTasks]]); }); @@ -406,7 +406,7 @@ describe('TasksComponent', () => { getComponent(); }); - expect(component.currentLevel).to.equal('parent'); + expect(await component.currentLevel).to.equal('parent'); expect((TasksActions.prototype.setTasksList).args).to.deep.equal([[expectedTasks]]); }); @@ -441,7 +441,7 @@ describe('TasksComponent', () => { getComponent(); }); - expect(component.currentLevel).to.equal('CHW Bettys Area'); + expect(await component.currentLevel).to.equal('CHW Bettys Area'); expect((TasksActions.prototype.setTasksList).args).to.deep.equal([[expectedTasks]]); }); }); From 46441e7e0d8b47b9c28da22ff7e9621d1ebe4b91 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Mon, 12 Sep 2022 17:16:47 +0000 Subject: [PATCH 62/72] remove tick for imports --- webapp/tests/karma/ts/modules/reports/reports.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts index 795ed4db19c..48a28e2b411 100644 --- a/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts +++ b/webapp/tests/karma/ts/modules/reports/reports.component.spec.ts @@ -1,4 +1,4 @@ -import { ComponentFixture, fakeAsync, flush, TestBed, tick, waitForAsync } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, flush, TestBed, waitForAsync } from '@angular/core/testing'; import { DatePipe } from '@angular/common'; import { provideMockStore } from '@ngrx/store/testing'; import { RouterTestingModule } from '@angular/router/testing'; From 9f9752547b3ff04012b7c2fed173c8322843fa97 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Tue, 13 Sep 2022 15:13:16 +0000 Subject: [PATCH 63/72] apply code review requested changes --- .../ts/modules/reports/reports.component.ts | 45 +++++++++---------- .../messages/messages.component.spec.ts | 22 ++++----- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index e7b5a45d705..288907a8867 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -183,28 +183,28 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { return this.translateService.instant('report.subject.unknown'); } - private prepareReports(reports) { - return this.currentLevel.then( - currentLevel => { - return reports.map(report => { - const form = _find(this.forms, { code: report.form }); - report.icon = form && form.icon; - report.heading = this.getReportHeading(form, report); - report.summary = form ? form.title : report.form; - report.lineage = report.subject && report.subject.lineage || report.lineage; - // remove the lineage level that belongs to the offline logged-in user - if (currentLevel && report.lineage && report.lineage.length) { - report.lineage = report.lineage.filter(level => level); - if(report.lineage[report.lineage.length-1] === currentLevel){ - report.lineage.pop(); - } - } - report.unread = !report.read; - return report; - }); + private async prepareReports(reports) { + const userLineageLevel = await this.currentLevel; + + return reports.map(report => { + const form = _find(this.forms, { code: report.form }); + report.icon = form && form.icon; + report.heading = this.getReportHeading(form, report); + report.summary = form ? form.title : report.form; + report.lineage = report.subject && report.subject.lineage || report.lineage; + report.unread = !report.read; + + // remove the lineage level that belongs to the offline logged-in user + if (userLineageLevel && report?.lineage?.length) { + report.lineage = report.lineage.filter(level => level); + const item = report.lineage?.length && report.lineage[report.lineage.length -1]; + if (item === userLineageLevel) { + report.lineage.pop(); + } } - ); + return report; + }); } private query(opts) { @@ -232,10 +232,9 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { return this.searchService .search('reports', this.filters, options) .then((reports) => this.addReadStatusService.updateReports(reports)) + .then(updatedReports => this.prepareReports(updatedReports)) .then(updatedReports => { - this - .prepareReports(updatedReports) - .then(updatedReports => this.reportsActions.updateReportsList(updatedReports)); + this.reportsActions.updateReportsList(updatedReports); this.moreItems = updatedReports.length >= options.limit; this.hasReports = !!updatedReports.length; diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index 18fc6695343..f952a8088cd 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -123,6 +123,14 @@ describe('Messages Component', () => { expect(resultNoDoc).to.equal('134abc'); }); + it('ngOnDestroy() should unsubscribe from observables', () => { + const spySubscriptionsUnsubscribe = sinon.spy(component.subscriptions, 'unsubscribe'); + + component.ngOnDestroy(); + + expect(spySubscriptionsUnsubscribe.callCount).to.equal(1); + }); + describe('updateConversations()', () => { it('should get conversations and add new one', async () => { const newConversations = [ @@ -191,14 +199,6 @@ describe('Messages Component', () => { expect(component.loading).to.be.false; expect(component.conversations).to.eql( newConversations); }); - - it('ngOnDestroy() should unsubscribe from observables', () => { - const spySubscriptionsUnsubscribe = sinon.spy(component.subscriptions, 'unsubscribe'); - - component.ngOnDestroy(); - - expect(spySubscriptionsUnsubscribe.callCount).to.equal(1); - }); }); describe('Messages breadcrumbs', () => { @@ -236,7 +236,7 @@ describe('Messages Component', () => { expect(await component.currentLevel).to.equal('parent'); }); - it('should not change the conversations lineage if the connected user is online only', fakeAsync( () => { + it('should not change the conversations lineage if the connected user is online only', fakeAsync(() => { sinon.resetHistory(); messageContactService.getList.resolves(conversations); @@ -251,7 +251,7 @@ describe('Messages Component', () => { expect(component.conversations).to.deep.equal(conversations); })); - it('should not change the conversations lineage if the connected user is online only', fakeAsync( () => { + it('should not change the conversations lineage if the connected user is online only', fakeAsync(() => { sinon.resetHistory(); messageContactService.getList.resolves(conversations); @@ -267,7 +267,7 @@ describe('Messages Component', () => { })); it('should remove current level from lineage when user is offline and parent place relevant to the conversation', - fakeAsync( () => { + fakeAsync(() => { sinon.resetHistory(); const updatedConversations = [ { key: 'a', From 0098a5830c3ec367abf36fc4f517409ee6fd47d9 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Tue, 13 Sep 2022 15:41:36 +0000 Subject: [PATCH 64/72] apply code review requested changes --- .../src/ts/modules/tasks/tasks.component.ts | 27 +++++++++---------- .../ts/modules/tasks/tasks.component.spec.ts | 8 +++--- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index c28ed0a9a65..fa6ca77f221 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -154,9 +154,9 @@ export class TasksComponent implements OnInit, OnDestroy { const hydratedTasks = await this.hydrateEmissions(taskDocs) || []; const subjects = await this.getLineagesFromTaskDocs(hydratedTasks); if (subjects?.size) { - hydratedTasks.forEach(task => { - task.lineage = this.getTaskLineage(subjects, task); - }); + for (const task of hydratedTasks) { + task.lineage = await this.getTaskLineage(subjects, task); + } } this.tasksActions.setTasksList(hydratedTasks); @@ -188,8 +188,8 @@ export class TasksComponent implements OnInit, OnDestroy { private getLineagesFromTaskDocs(taskDocs) { const ids = [...new Set(taskDocs.map(task => task.forId))]; - return this - .lineageModelGeneratorService.reportSubjects(ids) + return this.lineageModelGeneratorService + .reportSubjects(ids) ?.then(subjects => new Map(subjects.map(subject => [subject._id, subject.lineage]))); } @@ -197,23 +197,22 @@ export class TasksComponent implements OnInit, OnDestroy { if (!subjects?.size) { return; } - let lineage = subjects + const lineage = subjects .get(task.forId) ?.map(lineage => lineage?.name); - lineage = this.cleanAndRemoveCurrentLineage(lineage); - return lineage; + return this.cleanAndRemoveCurrentLineage(lineage); } - private cleanAndRemoveCurrentLineage(lineage) { + private async cleanAndRemoveCurrentLineage(lineage) { if(!lineage?.length){ return; } lineage = lineage.filter(level => level); - this.currentLevel.then(currentLevel => { - if(currentLevel === lineage[lineage.length-1]){ - lineage.pop(); - } - }); + const userLineageLevel = await this.currentLevel; + const item = lineage[lineage.length - 1]; + if (item === userLineageLevel) { + lineage.pop(); + } return lineage; } } diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 3cd523a8d3b..675f75b130f 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -16,8 +16,8 @@ import { TasksComponent } from '@mm-modules/tasks/tasks.component'; import { NavigationComponent } from '@mm-components/navigation/navigation.component'; import { Selectors } from '@mm-selectors/index'; import { NavigationService } from '@mm-services/navigation.service'; -import {UserContactService} from '@mm-services/user-contact.service'; -import {SessionService} from '@mm-services/session.service'; +import { UserContactService } from '@mm-services/user-contact.service'; +import { SessionService } from '@mm-services/session.service'; import { LineageModelGeneratorService } from '@mm-services/lineage-model-generator.service'; describe('TasksComponent', () => { @@ -414,7 +414,7 @@ describe('TasksComponent', () => { const expectedTasks = [ { _id: 'e1', - date: new Date('2020-10-20'), + date: moment('2020-10-20').toDate(), dueDate: '2020-10-20', lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], overdue: true, @@ -423,7 +423,7 @@ describe('TasksComponent', () => { }, { _id: 'e2', - date: new Date('2020-10-20'), + date: moment('2020-10-20').toDate(), dueDate: '2020-10-20', lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], overdue: true, From 5d3648ec9eb19b5622e4eeb39edd440698a3a5b4 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Tue, 13 Sep 2022 15:48:27 +0000 Subject: [PATCH 65/72] apply code review requested changes --- webapp/src/ts/modules/messages/messages.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index 656d3f422ee..b857e5dfc4f 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -165,7 +165,7 @@ export class MessagesComponent implements OnInit, OnDestroy { conversations?.forEach(conversation => { if (conversation.lineage && conversation.lineage.length) { conversation.lineage = conversation.lineage.filter(level => level); - if(conversation.lineage[conversation.lineage.length-1] === currentLevel){ + if(conversation.lineage[conversation.lineage.length -1] === currentLevel){ conversation.lineage.pop(); } } From bcf98705292d19efacd6c4d753ae44db072078eb Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Wed, 14 Sep 2022 16:26:04 +0000 Subject: [PATCH 66/72] apply code review requested changes --- webapp/src/ts/modules/messages/messages.component.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/webapp/src/ts/modules/messages/messages.component.ts b/webapp/src/ts/modules/messages/messages.component.ts index b857e5dfc4f..737934aa408 100644 --- a/webapp/src/ts/modules/messages/messages.component.ts +++ b/webapp/src/ts/modules/messages/messages.component.ts @@ -163,11 +163,12 @@ export class MessagesComponent implements OnInit, OnDestroy { // Remove the lineage level that belongs to the offline logged-in user. if (currentLevel) { conversations?.forEach(conversation => { - if (conversation.lineage && conversation.lineage.length) { - conversation.lineage = conversation.lineage.filter(level => level); - if(conversation.lineage[conversation.lineage.length -1] === currentLevel){ - conversation.lineage.pop(); - } + if (!conversation.lineage?.length) { + return; + } + conversation.lineage = conversation.lineage.filter(level => level); + if(conversation.lineage[conversation.lineage.length -1] === currentLevel){ + conversation.lineage.pop(); } }); } From 8a60b20e18ca8d13daacb0c53c6fea6bb860fced Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Wed, 14 Sep 2022 17:04:15 +0000 Subject: [PATCH 67/72] apply code review requested changes --- webapp/src/ts/modules/tasks/tasks.component.ts | 12 ++++++------ .../karma/ts/modules/tasks/tasks.component.spec.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index fa6ca77f221..7fb641cea93 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -154,8 +154,9 @@ export class TasksComponent implements OnInit, OnDestroy { const hydratedTasks = await this.hydrateEmissions(taskDocs) || []; const subjects = await this.getLineagesFromTaskDocs(hydratedTasks); if (subjects?.size) { + const userLineageLevel = await this.currentLevel; for (const task of hydratedTasks) { - task.lineage = await this.getTaskLineage(subjects, task); + task.lineage = await this.getTaskLineage(subjects, task, userLineageLevel); } } @@ -190,25 +191,24 @@ export class TasksComponent implements OnInit, OnDestroy { const ids = [...new Set(taskDocs.map(task => task.forId))]; return this.lineageModelGeneratorService .reportSubjects(ids) - ?.then(subjects => new Map(subjects.map(subject => [subject._id, subject.lineage]))); + .then(subjects => new Map(subjects.map(subject => [subject._id, subject.lineage]))); } - private getTaskLineage(subjects, task) { + private getTaskLineage(subjects, task, userLineageLevel) { if (!subjects?.size) { return; } const lineage = subjects .get(task.forId) ?.map(lineage => lineage?.name); - return this.cleanAndRemoveCurrentLineage(lineage); + return this.cleanAndRemoveCurrentLineage(lineage, userLineageLevel); } - private async cleanAndRemoveCurrentLineage(lineage) { + private async cleanAndRemoveCurrentLineage(lineage, userLineageLevel) { if(!lineage?.length){ return; } lineage = lineage.filter(level => level); - const userLineageLevel = await this.currentLevel; const item = lineage[lineage.length - 1]; if (item === userLineageLevel) { lineage.pop(); diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 675f75b130f..4d78b9d75de 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -63,7 +63,7 @@ describe('TasksComponent', () => { userContactService = { get: sinon.stub().resolves(), }; - lineageModelGeneratorService = { reportSubjects: sinon.stub() }; + lineageModelGeneratorService = { reportSubjects: sinon.stub().resolves([]) }; TestBed.configureTestingModule({ imports: [ From 919d64fb69bb21b627c32ca7253c43390d3be7a7 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Thu, 15 Sep 2022 07:11:08 +0000 Subject: [PATCH 68/72] apply code review requested changes --- .../ts/modules/reports/reports.component.ts | 2 +- .../messages/messages.component.spec.ts | 23 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/webapp/src/ts/modules/reports/reports.component.ts b/webapp/src/ts/modules/reports/reports.component.ts index 288907a8867..4dd24cfd040 100644 --- a/webapp/src/ts/modules/reports/reports.component.ts +++ b/webapp/src/ts/modules/reports/reports.component.ts @@ -197,7 +197,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy { // remove the lineage level that belongs to the offline logged-in user if (userLineageLevel && report?.lineage?.length) { report.lineage = report.lineage.filter(level => level); - const item = report.lineage?.length && report.lineage[report.lineage.length -1]; + const item = report.lineage[report.lineage.length -1]; if (item === userLineageLevel) { report.lineage.pop(); } diff --git a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts index f952a8088cd..e52fb13ceae 100644 --- a/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts +++ b/webapp/tests/karma/ts/modules/messages/messages.component.spec.ts @@ -236,20 +236,21 @@ describe('Messages Component', () => { expect(await component.currentLevel).to.equal('parent'); }); - it('should not change the conversations lineage if the connected user is online only', fakeAsync(() => { - sinon.resetHistory(); + it('should not alter conversations when user is offline and parent place is not relevant to the conversation', + fakeAsync( () => { + sinon.resetHistory(); - messageContactService.getList.resolves(conversations); - userContactService.get.resolves(bettyOfflineUserContactDoc); - sessionService.isOnlineOnly.returns(true); + messageContactService.getList.resolves(conversations); + userContactService.get.resolves(userContactDoc); + sessionService.isOnlineOnly.returns(false); - component.ngOnInit(); - tick(); - component.updateConversations({merge : true}); - tick(); + component.ngOnInit(); + tick(); + component.updateConversations({merge : true}); + tick(); - expect(component.conversations).to.deep.equal(conversations); - })); + expect(component.conversations).to.deep.equal(conversations); + })); it('should not change the conversations lineage if the connected user is online only', fakeAsync(() => { sinon.resetHistory(); From 6414d8b343863fe74c4c252c387044677a7f3bda Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Thu, 15 Sep 2022 08:45:49 +0000 Subject: [PATCH 69/72] apply code review requested changes --- webapp/src/ts/modules/tasks/tasks.component.ts | 15 ++++++--------- .../ts/modules/tasks/tasks.component.spec.ts | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index 7fb641cea93..c419547db4e 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -133,7 +133,7 @@ export class TasksComponent implements OnInit, OnDestroy { emission.date = new Date(dueDate.valueOf()); emission.overdue = dueDate.isBefore(moment()); emission.owner = taskDoc.owner; - emission.forId = taskDoc.forId ? taskDoc.forId : taskDoc.owner; + emission.forId = taskDoc.forId; return emission; }); } @@ -155,9 +155,9 @@ export class TasksComponent implements OnInit, OnDestroy { const subjects = await this.getLineagesFromTaskDocs(hydratedTasks); if (subjects?.size) { const userLineageLevel = await this.currentLevel; - for (const task of hydratedTasks) { - task.lineage = await this.getTaskLineage(subjects, task, userLineageLevel); - } + hydratedTasks.forEach(task => { + task.lineage = this.getTaskLineage(subjects, task, userLineageLevel); + }); } this.tasksActions.setTasksList(hydratedTasks); @@ -188,23 +188,20 @@ export class TasksComponent implements OnInit, OnDestroy { } private getLineagesFromTaskDocs(taskDocs) { - const ids = [...new Set(taskDocs.map(task => task.forId))]; + const ids = [...new Set(taskDocs.map(task => task.forId || task.owner))]; return this.lineageModelGeneratorService .reportSubjects(ids) .then(subjects => new Map(subjects.map(subject => [subject._id, subject.lineage]))); } private getTaskLineage(subjects, task, userLineageLevel) { - if (!subjects?.size) { - return; - } const lineage = subjects .get(task.forId) ?.map(lineage => lineage?.name); return this.cleanAndRemoveCurrentLineage(lineage, userLineageLevel); } - private async cleanAndRemoveCurrentLineage(lineage, userLineageLevel) { + private cleanAndRemoveCurrentLineage(lineage, userLineageLevel) { if(!lineage?.length){ return; } diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 4d78b9d75de..412fd327cb0 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -180,7 +180,7 @@ describe('TasksComponent', () => { overdue: false, date: new Date(futureDate.valueOf()), owner: 'a', - forId: 'a', + forId: undefined, }, { _id: 'e2', @@ -188,7 +188,7 @@ describe('TasksComponent', () => { overdue: true, date: new Date(pastDate.valueOf()), owner: 'b', - forId: 'b', + forId: undefined, }, ]; From d6eec6cd578578daa43631d79042c18d66723f19 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 16 Sep 2022 17:11:58 +0000 Subject: [PATCH 70/72] add e2e tests for reports breadcrumbs --- .../default/reports/breadcrumbs.wdio-spec.js | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 tests/e2e/default/reports/breadcrumbs.wdio-spec.js diff --git a/tests/e2e/default/reports/breadcrumbs.wdio-spec.js b/tests/e2e/default/reports/breadcrumbs.wdio-spec.js new file mode 100644 index 00000000000..f24f084a157 --- /dev/null +++ b/tests/e2e/default/reports/breadcrumbs.wdio-spec.js @@ -0,0 +1,98 @@ +const moment = require('moment'); + +const utils = require('../../../utils'); +const commonElements = require('../../../page-objects/common/common.wdio.page'); +const reportsPage = require('../../../page-objects/reports/reports.wdio.page'); +const loginPage = require('../../../page-objects/login/login.wdio.page'); +const userFactory = require('../../../factories/cht/users/users'); +const placeFactory = require('../../../factories/cht/contacts/place'); +const personFactory = require('../../../factories/cht/contacts/person'); +const reportFactory = require('../../../factories/cht/reports/generic-report'); + +describe('Reports tab breadcrumbs', () => { + const today = moment(); + const places = placeFactory.generateHierarchy(); + const clinic = places.find(p => p.type === 'clinic'); + const health_center = places.find(p => p.type === 'health_center'); + const district_hospital = places.find(p => p.type === 'district_hospital'); + const contact = { + _id: 'fixture:user:user1', + name: 'OfflineUser', + phone: '+12068881234', + place: health_center._id, + type: 'person', + parent: { + _id: health_center._id, + parent: health_center.parent + }, + }; + const contact2 = { + _id: 'fixture:user:user2', + name: 'OnlineUser', + phone: '+12068881235', + place: district_hospital._id, + type: 'person', + parent: { + _id: district_hospital._id, + }, + }; + const offlineUser = userFactory.build({ + username: 'offlineuser', + isOffline: true, + place: health_center._id, + contact: contact._id, + }); + const onlineUser = userFactory.build({ + username: 'onlineuser', + roles: [ 'program_officer' ], + place: district_hospital._id, + contact: contact2._id, + }); + const patient = personFactory.build({ + _id: 'patient1', + parent: { _id: clinic._id, parent: { _id: health_center._id, parent: { _id: district_hospital._id }} } }); + const reports = [ + reportFactory.build( + { + form: 'P', + reported_date: moment([ today.year(), today.month() - 4, 1, 23, 30 ]).valueOf(), + patient_id: 'patient1', + }, + { + patient, submitter: offlineUser.contact, fields: { lmp_date: 'Feb 3, 2022', patient_id: 'patient1' }, + }), + ]; + + before(async () => { + await utils.saveDocs([ ...places, contact, contact2, patient, ...reports ]); + await utils.createUsers([ onlineUser, offlineUser ]); + }); + + afterEach(async () => await commonElements.logout()); + + it('should display reports with breadcrumbs for online user', async () => { + await loginPage.login(onlineUser); + await commonElements.waitForPageLoaded(); + await commonElements.goToReports(); + await (await reportsPage.firstReport()).waitForDisplayed(); + await commonElements.waitForPageLoaded(); + + const reportLineages = await reportsPage.reportsListDetails(); + const expectedLineage = clinic.name.concat(health_center.name, district_hospital.name); + + expect(reportLineages[0].lineage).to.equal(expectedLineage); + }); + + it('should display updated reports with breadcrumbs for offline user', async () => { + await loginPage.login(offlineUser); + await commonElements.waitForPageLoaded(); + await commonElements.goToReports(); + await (await reportsPage.firstReport()).waitForDisplayed(); + await commonElements.waitForPageLoaded(); + + const reportLineages = await reportsPage.reportsListDetails(); + const expectedLineage = clinic.name; + + expect(reportLineages[0].lineage).to.equal(expectedLineage); + }); +}); From 5430cc31a986e02ef7939ee524927e8ff95a5bb0 Mon Sep 17 00:00:00 2001 From: elvisdorkenoo Date: Fri, 16 Sep 2022 18:02:17 +0000 Subject: [PATCH 71/72] add e2e tests for reports breadcrumbs --- tests/e2e/default/reports/breadcrumbs.wdio-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/default/reports/breadcrumbs.wdio-spec.js b/tests/e2e/default/reports/breadcrumbs.wdio-spec.js index f24f084a157..0e43acba850 100644 --- a/tests/e2e/default/reports/breadcrumbs.wdio-spec.js +++ b/tests/e2e/default/reports/breadcrumbs.wdio-spec.js @@ -83,7 +83,7 @@ describe('Reports tab breadcrumbs', () => { expect(reportLineages[0].lineage).to.equal(expectedLineage); }); - it('should display updated reports with breadcrumbs for offline user', async () => { + it('should display reports with updated breadcrumbs for offline user', async () => { await loginPage.login(offlineUser); await commonElements.waitForPageLoaded(); await commonElements.goToReports(); From 1ecad5d8ccb2a56555ffe27bba84ed9b6508dbd3 Mon Sep 17 00:00:00 2001 From: latin-panda <66472237+latin-panda@users.noreply.github.com> Date: Wed, 21 Sep 2022 13:12:09 +0700 Subject: [PATCH 72/72] fix e2e --- webapp/src/ts/modules/tasks/tasks.component.ts | 12 ++++++------ .../karma/ts/modules/tasks/tasks.component.spec.ts | 8 -------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts index c419547db4e..12479796f60 100644 --- a/webapp/src/ts/modules/tasks/tasks.component.ts +++ b/webapp/src/ts/modules/tasks/tasks.component.ts @@ -103,7 +103,7 @@ export class TasksComponent implements OnInit, OnDestroy { this.error = false; this.hasTasks = false; this.loading = true; - this.debouncedReload = _debounce(this.refreshTasks.bind(this), 1000, {maxWait: 10 * 1000}); + this.debouncedReload = _debounce(this.refreshTasks.bind(this), 1000, { maxWait: 10 * 1000 }); this.currentLevel = this.sessionService.isOnlineOnly() ? Promise.resolve() : this.getCurrentLineageLevel(); @@ -128,12 +128,12 @@ export class TasksComponent implements OnInit, OnDestroy { private hydrateEmissions(taskDocs) { return taskDocs.map(taskDoc => { - const emission = {...taskDoc.emission}; + const emission = { ...taskDoc.emission }; const dueDate = moment(emission.dueDate, 'YYYY-MM-DD'); emission.date = new Date(dueDate.valueOf()); emission.overdue = dueDate.isBefore(moment()); emission.owner = taskDoc.owner; - emission.forId = taskDoc.forId; + return emission; }); } @@ -188,7 +188,7 @@ export class TasksComponent implements OnInit, OnDestroy { } private getLineagesFromTaskDocs(taskDocs) { - const ids = [...new Set(taskDocs.map(task => task.forId || task.owner))]; + const ids = [...new Set(taskDocs.map(task => task.owner))]; return this.lineageModelGeneratorService .reportSubjects(ids) .then(subjects => new Map(subjects.map(subject => [subject._id, subject.lineage]))); @@ -196,13 +196,13 @@ export class TasksComponent implements OnInit, OnDestroy { private getTaskLineage(subjects, task, userLineageLevel) { const lineage = subjects - .get(task.forId) + .get(task.owner) ?.map(lineage => lineage?.name); return this.cleanAndRemoveCurrentLineage(lineage, userLineageLevel); } private cleanAndRemoveCurrentLineage(lineage, userLineageLevel) { - if(!lineage?.length){ + if (!lineage?.length) { return; } lineage = lineage.filter(level => level); diff --git a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts index 412fd327cb0..dee17f7f3af 100644 --- a/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts +++ b/webapp/tests/karma/ts/modules/tasks/tasks.component.spec.ts @@ -180,7 +180,6 @@ describe('TasksComponent', () => { overdue: false, date: new Date(futureDate.valueOf()), owner: 'a', - forId: undefined, }, { _id: 'e2', @@ -188,7 +187,6 @@ describe('TasksComponent', () => { overdue: true, date: new Date(pastDate.valueOf()), owner: 'b', - forId: undefined, }, ]; @@ -349,7 +347,6 @@ describe('TasksComponent', () => { lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], overdue: true, owner: 'a', - forId: 'a', }, { _id: 'e2', @@ -358,7 +355,6 @@ describe('TasksComponent', () => { lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], overdue: true, owner: 'b', - forId: 'b', }, ]; userContactService.get.resolves(bettysContactDoc); @@ -384,7 +380,6 @@ describe('TasksComponent', () => { lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village', 'CHW Bettys Area' ], overdue: true, owner: 'a', - forId: 'a', }, { _id: 'e2', @@ -393,7 +388,6 @@ describe('TasksComponent', () => { lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], overdue: true, owner: 'b', - forId: 'b', }, ]; userContactService.get.resolves(userContactDoc); @@ -419,7 +413,6 @@ describe('TasksComponent', () => { lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], overdue: true, owner: 'a', - forId: 'a', }, { _id: 'e2', @@ -428,7 +421,6 @@ describe('TasksComponent', () => { lineage: [ 'Amy Johnsons Household', 'St Elmos Concession', 'Chattanooga Village' ], overdue: true, owner: 'b', - forId: 'b', }, ]; userContactService.get.resolves(bettysContactDoc);