mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACA-3368] Update datatable columns when presetColumn schema changes (#5732)
* [ACA-3368] Update datatable columns when presetColumn schema changes * [ACA-3368] Add presetColumn change detection for task list * [ACA-3368] Improve unit tests, fix comments * [ACA-3368] More unit test improvements
This commit is contained in:
@@ -15,8 +15,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ObjectDataColumn } from '@alfresco/adf-core';
|
||||
|
||||
export let fakeProcessInstance = {
|
||||
size: 2,
|
||||
total: 2,
|
||||
@@ -133,28 +131,42 @@ export let fakeProcessInstancesEmpty = {
|
||||
};
|
||||
|
||||
export let fakeProcessCustomSchema = [
|
||||
new ObjectDataColumn({
|
||||
{
|
||||
key: 'fakeName',
|
||||
type: 'text',
|
||||
title: 'ADF_PROCESS_LIST.PROPERTIES.FAKE',
|
||||
sortable: true
|
||||
}),
|
||||
new ObjectDataColumn({
|
||||
},
|
||||
{
|
||||
key: 'fakeProcessName',
|
||||
type: 'text',
|
||||
title: 'ADF_PROCESS_LIST.PROPERTIES.PROCESS_FAKE',
|
||||
sortable: true
|
||||
})
|
||||
}
|
||||
];
|
||||
|
||||
export let fakeProcessColumnSchema = {
|
||||
default: [
|
||||
{
|
||||
key: 'name',
|
||||
key: 'default-name',
|
||||
type: 'text',
|
||||
title: 'ADF_PROCESS_LIST.PROPERTIES.NAME',
|
||||
sortable: true
|
||||
}
|
||||
],
|
||||
fakeRunningProcessSchema: [
|
||||
{
|
||||
key: 'process-id',
|
||||
type: 'text',
|
||||
title: 'ADF_PROCESS_LIST.PROPERTIES.FAKE',
|
||||
sortable: true
|
||||
},
|
||||
{
|
||||
key: 'process-name',
|
||||
type: 'text',
|
||||
title: 'ADF_PROCESS_LIST.PROPERTIES.PROCESS_FAKE',
|
||||
sortable: true
|
||||
}
|
||||
],
|
||||
fakeProcessCustomSchema
|
||||
};
|
||||
|
@@ -15,8 +15,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ObjectDataColumn } from '@alfresco/adf-core';
|
||||
|
||||
export const fakeGlobalTask = {
|
||||
size: 2,
|
||||
start: 0,
|
||||
@@ -79,29 +77,43 @@ export const fakeGlobalTask = {
|
||||
};
|
||||
|
||||
export let fakeCustomSchema = [
|
||||
new ObjectDataColumn({
|
||||
{
|
||||
key: 'fakeName',
|
||||
type: 'text',
|
||||
title: 'ADF_TASK_LIST.PROPERTIES.FAKE',
|
||||
sortable: true
|
||||
}),
|
||||
new ObjectDataColumn({
|
||||
},
|
||||
{
|
||||
key: 'fakeTaskName',
|
||||
type: 'text',
|
||||
title: 'ADF_TASK_LIST.PROPERTIES.TASK_FAKE',
|
||||
sortable: true
|
||||
})
|
||||
}
|
||||
];
|
||||
|
||||
export let fakeColumnSchema = {
|
||||
default: [
|
||||
{
|
||||
key: 'name',
|
||||
key: 'default-name',
|
||||
type: 'text',
|
||||
title: 'ADF_TASK_LIST.PROPERTIES.NAME',
|
||||
sortable: true
|
||||
}
|
||||
],
|
||||
fakeMyTasksSchema: [
|
||||
{
|
||||
key: 'task-id',
|
||||
type: 'text',
|
||||
title: 'ADF_TASK_LIST.PROPERTIES.FAKE',
|
||||
sortable: true
|
||||
},
|
||||
{
|
||||
key: 'task-name',
|
||||
type: 'text',
|
||||
title: 'ADF_TASK_LIST.PROPERTIES.PROCESS_FAKE',
|
||||
sortable: true
|
||||
}
|
||||
],
|
||||
fakeCustomSchema
|
||||
};
|
||||
|
||||
|
@@ -22,9 +22,14 @@ import { By } from '@angular/platform-browser';
|
||||
import { ProcessInstanceListComponent } from './process-list.component';
|
||||
import {
|
||||
AppConfigService, setupTestBed, DataRow, DataColumn,
|
||||
DataRowEvent, ObjectDataRow, ObjectDataTableAdapter, DataCellEvent
|
||||
DataRowEvent, ObjectDataRow, ObjectDataTableAdapter, DataCellEvent, ObjectDataColumn
|
||||
} from '@alfresco/adf-core';
|
||||
import { fakeProcessInstance, fakeProcessInstancesWithNoName, fakeProcessInstancesEmpty, fakeProcessCustomSchema } from '../../mock';
|
||||
import {
|
||||
fakeProcessInstance,
|
||||
fakeProcessInstancesWithNoName,
|
||||
fakeProcessInstancesEmpty,
|
||||
fakeProcessColumnSchema
|
||||
} from '../../mock';
|
||||
import { ProcessService } from '../services/process.service';
|
||||
import { ProcessTestingModule } from '../../testing/process.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
@@ -60,22 +65,7 @@ describe('ProcessInstanceListComponent', () => {
|
||||
|
||||
getProcessInstancesSpy = spyOn(service, 'getProcessInstances').and.returnValue(of(fakeProcessInstance));
|
||||
appConfig.config['adf-process-list'] = {
|
||||
'presets': {
|
||||
'fakeProcessCustomSchema': [
|
||||
{
|
||||
'key': 'fakeName',
|
||||
'type': 'text',
|
||||
'title': 'ADF_PROCESS_LIST.PROPERTIES.FAKE',
|
||||
'sortable': true
|
||||
},
|
||||
{
|
||||
'key': 'fakeProcessName',
|
||||
'type': 'text',
|
||||
'title': 'ADF_PROCESS_LIST.PROPERTIES.PROCESS_FAKE',
|
||||
'sortable': true
|
||||
}
|
||||
]
|
||||
}
|
||||
'presets': fakeProcessColumnSchema
|
||||
};
|
||||
}));
|
||||
|
||||
@@ -89,7 +79,8 @@ describe('ProcessInstanceListComponent', () => {
|
||||
it('should use the default schemaColumn as default', () => {
|
||||
component.ngAfterContentInit();
|
||||
expect(component.columns).toBeDefined();
|
||||
expect(component.columns.length).toEqual(2);
|
||||
expect(component.columns.length).toEqual(1);
|
||||
expect(component.columns[0]).toEqual(new ObjectDataColumn(fakeProcessColumnSchema.default[0]));
|
||||
});
|
||||
|
||||
it('should use the schemaColumn passed in input', () => {
|
||||
@@ -109,7 +100,9 @@ describe('ProcessInstanceListComponent', () => {
|
||||
component.presetColumn = 'fakeProcessCustomSchema';
|
||||
component.ngAfterContentInit();
|
||||
fixture.detectChanges();
|
||||
expect(component.columns).toEqual(fakeProcessCustomSchema);
|
||||
expect(component.columns.length).toEqual(2);
|
||||
expect(component.columns[0]).toEqual(new ObjectDataColumn(fakeProcessColumnSchema.fakeProcessCustomSchema[0]));
|
||||
expect(component.columns[1]).toEqual(new ObjectDataColumn(fakeProcessColumnSchema.fakeProcessCustomSchema[1]));
|
||||
});
|
||||
|
||||
it('should fetch custom schemaColumn when the input presetColumn is defined', () => {
|
||||
@@ -437,6 +430,27 @@ describe('ProcessInstanceListComponent', () => {
|
||||
|
||||
component.ngOnChanges({'processInstanceId': change});
|
||||
});
|
||||
|
||||
it('should update the columns when presetColumn schema changes', () => {
|
||||
component.presetColumn = 'fakeProcessCustomSchema';
|
||||
component.ngAfterContentInit();
|
||||
const initialColumnSchema = component.mergeJsonAndHtmlSchema();
|
||||
expect(component.columns).toEqual(initialColumnSchema);
|
||||
|
||||
component.presetColumn = 'fakeRunningProcessSchema';
|
||||
const presetColumnChange = new SimpleChange(null, 'fakeRunningProcessSchema', false);
|
||||
component.ngOnChanges({ 'presetColumn': presetColumnChange });
|
||||
|
||||
const newColumnSchema = component.mergeJsonAndHtmlSchema();
|
||||
const expectedColumn1 = new ObjectDataColumn(fakeProcessColumnSchema.fakeRunningProcessSchema[0]);
|
||||
const expectedColumn2 = new ObjectDataColumn(fakeProcessColumnSchema.fakeRunningProcessSchema[1]);
|
||||
|
||||
expect(component.columns).toEqual(newColumnSchema);
|
||||
expect(initialColumnSchema).not.toEqual(newColumnSchema);
|
||||
expect(component.columns.length).toEqual(2);
|
||||
expect(component.columns[0]).toEqual(expectedColumn1);
|
||||
expect(component.columns[1]).toEqual(expectedColumn2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -181,6 +181,11 @@ export class ProcessInstanceListComponent extends DataTableSchema implements OnC
|
||||
}
|
||||
this.reload();
|
||||
}
|
||||
|
||||
const presetColumnChanges = changes['presetColumn'];
|
||||
if (presetColumnChanges && !presetColumnChanges.firstChange) {
|
||||
this.columns = this.mergeJsonAndHtmlSchema();
|
||||
}
|
||||
}
|
||||
|
||||
private isSortChanged(changes: SimpleChanges): boolean {
|
||||
|
@@ -18,11 +18,16 @@
|
||||
import { Component, SimpleChange, ViewChild, OnInit, Output, EventEmitter } from '@angular/core';
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { AppConfigService, setupTestBed, DataRowEvent, ObjectDataRow, DataCellEvent } from '@alfresco/adf-core';
|
||||
import { AppConfigService, setupTestBed, DataRowEvent, ObjectDataRow, DataCellEvent, ObjectDataColumn } from '@alfresco/adf-core';
|
||||
import { TaskListService } from '../services/tasklist.service';
|
||||
import { TaskListComponent } from './task-list.component';
|
||||
import { ProcessTestingModule } from '../../testing/process.testing.module';
|
||||
import { fakeGlobalTask, fakeCustomSchema, fakeEmptyTask, paginatedTask } from '../../mock';
|
||||
import {
|
||||
fakeGlobalTask,
|
||||
fakeEmptyTask,
|
||||
paginatedTask,
|
||||
fakeColumnSchema, fakeCustomSchema
|
||||
} from '../../mock';
|
||||
import { TranslateService, TranslateModule } from '@ngx-translate/core';
|
||||
import { of, Subject } from 'rxjs';
|
||||
|
||||
@@ -52,24 +57,10 @@ describe('TaskListComponent', () => {
|
||||
appConfig.config = Object.assign(appConfig.config, {
|
||||
'adf-task-list': {
|
||||
'presets': {
|
||||
'fakeCustomSchema': [
|
||||
{
|
||||
'key': 'fakeName',
|
||||
'type': 'text',
|
||||
'title': 'ADF_TASK_LIST.PROPERTIES.FAKE',
|
||||
'sortable': true
|
||||
},
|
||||
{
|
||||
'key': 'fakeTaskName',
|
||||
'type': 'text',
|
||||
'title': 'ADF_TASK_LIST.PROPERTIES.TASK_FAKE',
|
||||
'sortable': true
|
||||
}
|
||||
]
|
||||
fakeCustomSchema
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -114,7 +105,9 @@ describe('TaskListComponent', () => {
|
||||
component.presetColumn = 'fakeCustomSchema';
|
||||
component.ngAfterContentInit();
|
||||
fixture.detectChanges();
|
||||
expect(component.columns).toEqual(fakeCustomSchema);
|
||||
expect(component.columns.length).toEqual(2);
|
||||
expect(component.columns[0]).toEqual(new ObjectDataColumn(fakeCustomSchema[0]));
|
||||
expect(component.columns[1]).toEqual(new ObjectDataColumn(fakeCustomSchema[1]));
|
||||
});
|
||||
|
||||
it('should fetch custom schemaColumn when the input presetColumn is defined', () => {
|
||||
@@ -535,6 +528,33 @@ describe('TaskListComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should update the columns when presetColumn schema changes', () => {
|
||||
appConfig.config = Object.assign(appConfig.config, {
|
||||
'adf-task-list': {
|
||||
'presets': fakeColumnSchema
|
||||
}
|
||||
});
|
||||
|
||||
component.presetColumn = 'fakeCustomSchema';
|
||||
component.ngAfterContentInit();
|
||||
const initialColumnSchema = component.mergeJsonAndHtmlSchema();
|
||||
expect(component.columns).toEqual(initialColumnSchema);
|
||||
|
||||
component.presetColumn = 'fakeMyTasksSchema';
|
||||
const presetColumnChange = new SimpleChange(null, 'fakeMyTasksSchema', false);
|
||||
component.ngOnChanges({ 'presetColumn': presetColumnChange });
|
||||
|
||||
const newColumnSchema = component.mergeJsonAndHtmlSchema();
|
||||
const expectedColumn1 = new ObjectDataColumn(fakeColumnSchema.fakeMyTasksSchema[0]);
|
||||
const expectedColumn2 = new ObjectDataColumn(fakeColumnSchema.fakeMyTasksSchema[1]);
|
||||
|
||||
expect(component.columns).toEqual(newColumnSchema);
|
||||
expect(initialColumnSchema).not.toEqual(newColumnSchema);
|
||||
expect(component.columns.length).toEqual(2);
|
||||
expect(component.columns[0]).toEqual(expectedColumn1);
|
||||
expect(component.columns[1]).toEqual(expectedColumn2);
|
||||
});
|
||||
|
||||
it('should show the updated list when pagination changes', async(() => {
|
||||
spyOn(taskListService, 'findTasksByState').and.returnValues(of(fakeGlobalTask), of(paginatedTask));
|
||||
const state = new SimpleChange(null, 'open', true);
|
||||
|
@@ -235,6 +235,11 @@ export class TaskListComponent extends DataTableSchema implements OnChanges, Aft
|
||||
}
|
||||
this.reload();
|
||||
}
|
||||
|
||||
const presetColumnChanges = changes['presetColumn'];
|
||||
if (presetColumnChanges && !presetColumnChanges.firstChange) {
|
||||
this.columns = this.mergeJsonAndHtmlSchema();
|
||||
}
|
||||
}
|
||||
|
||||
private isSortChanged(changes: SimpleChanges): boolean {
|
||||
|
Reference in New Issue
Block a user