From 81401cdb051503f5cea69c4dbcc96ca896ab44e0 Mon Sep 17 00:00:00 2001 From: silviu popa Date: Thu, 4 Feb 2021 17:09:57 +0200 Subject: [PATCH] [ADF-5328] - fix error on replacing priority values --- .../base-task-list-cloud.component.ts | 4 +- .../task-list-cloud.component.spec.ts | 67 +++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/lib/process-services-cloud/src/lib/task/task-list/components/base-task-list-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-list/components/base-task-list-cloud.component.ts index 04309937393..438cf71b8ba 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/components/base-task-list-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/components/base-task-list-cloud.component.ts @@ -257,10 +257,10 @@ export abstract class BaseTaskListCloudComponent extends DataTableSchema impleme replacePriorityValues(row: DataRow, column: DataColumn) { return column.key.split('.').reduce((source, key) => { - if (key === 'priority' && typeof(source[key]) === 'number') { + if (key === 'priority' && source && typeof(source[key]) === 'number') { return source[key] = this.taskCloudService.getPriorityLabel(source[key]); } - return source ? source[key] : ''; + return source && typeof(source) === 'object' ? source[key] : undefined; }, row.obj); } diff --git a/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.spec.ts index 5cd91b4a9f5..5d7c9eecd5a 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.spec.ts @@ -517,6 +517,12 @@ describe('TaskListCloudComponent', () => { 'type': 'text', 'title': 'ADF_CLOUD_TASK_LIST.PROPERTIES.TASK_FAKE', 'sortable': true + }, + { + 'key': 'entry.priority', + 'type': 'text', + 'title': 'ADF_TASK_LIST.PROPERTIES.PRIORITY', + 'sortable': true } ] } @@ -569,5 +575,66 @@ describe('TaskListCloudComponent', () => { component.ngOnChanges({ 'appName': appName }); component.ngAfterContentInit(); })); + + it('should replace priority values', (done) => { + taskSpy.and.returnValue(of(fakeGlobalTask)); + component.presetColumn = 'fakeCustomSchema'; + const appName = new SimpleChange(null, 'FAKE-APP-NAME', true); + component.ngOnChanges({ appName }); + + component.success.subscribe(() => { + const cell = fixture.nativeElement.querySelector('[data-automation-id="text_ADF_CLOUD_TASK_LIST.PROPERTIES.PRIORITY_VALUES.NONE"]'); + expect(cell.textContent).toEqual('ADF_CLOUD_TASK_LIST.PROPERTIES.PRIORITY_VALUES.NONE'); + done(); + }); + + fixture.detectChanges(); + component.reload(); + }); + + it('replacePriorityValues should return undefined when no rows defined', () => { + const emptyList = { list: { entries: [] } }; + taskSpy.and.returnValue(of(emptyList)); + fixture.detectChanges(); + + const appName = new SimpleChange(null, 'FAKE-APP-NAME', true); + component.ngOnChanges({ appName }); + fixture.detectChanges(); + + const emptyContent = fixture.debugElement.query(By.css('.adf-empty-content')); + expect(emptyContent.nativeElement).toBeDefined(); + expect(component.replacePriorityValues({ + obj: {}, + isSelected: false, + hasValue: () => false, + getValue: () => undefined + }, { + type: 'text', + key: 'entry.priority' + })).toEqual(undefined); + }); + + it('replacePriorityValues should return replaced value when rows are defined', () => { + taskSpy.and.returnValue(of(fakeGlobalTask)); + fixture.detectChanges(); + + const appName = new SimpleChange(null, 'FAKE-APP-NAME', true); + component.ngOnChanges({ appName }); + fixture.detectChanges(); + + expect(component.replacePriorityValues({ + obj: { + entry: { + priority: 1 + } + }, + isSelected: false, + hasValue: () => false, + getValue: () => undefined + }, { + type: 'text', + key: 'entry.priority' + })).toEqual('ADF_CLOUD_TASK_LIST.PROPERTIES.PRIORITY_VALUES.LOW'); + }); }); });