mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ACA-3751] Disable save & delete buttons for default task filters (#5897)
* [ACA-3751] Disable save & delete buttons for default task filters * Added unit tests * Added param types * Updated e2e * Updated e2e title
This commit is contained in:
@@ -97,7 +97,7 @@ describe('Edit task filters cloud', () => {
|
|||||||
await tasksCloudDemoPage.editTaskFilterCloudComponent().openFilter();
|
await tasksCloudDemoPage.editTaskFilterCloudComponent().openFilter();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('[C306896] Delete Save and Save as actions should be displayed when clicking on custom filter header', async () => {
|
it('[C306896] Delete Save and Save as actions should be displayed and disabled when clicking on default filter header', async () => {
|
||||||
await tasksCloudDemoPage.taskFilterCloudComponent.clickTaskFilter('my-tasks');
|
await tasksCloudDemoPage.taskFilterCloudComponent.clickTaskFilter('my-tasks');
|
||||||
await tasksCloudDemoPage.editTaskFilterCloudComponent().openFilter();
|
await tasksCloudDemoPage.editTaskFilterCloudComponent().openFilter();
|
||||||
await tasksCloudDemoPage.taskFilterCloudComponent.clickTaskFilter('my-tasks');
|
await tasksCloudDemoPage.taskFilterCloudComponent.clickTaskFilter('my-tasks');
|
||||||
@@ -110,7 +110,7 @@ describe('Edit task filters cloud', () => {
|
|||||||
|
|
||||||
await expect(await tasksCloudDemoPage.editTaskFilterCloudComponent().checkSaveButtonIsEnabled()).toEqual(false);
|
await expect(await tasksCloudDemoPage.editTaskFilterCloudComponent().checkSaveButtonIsEnabled()).toEqual(false);
|
||||||
await expect(await tasksCloudDemoPage.editTaskFilterCloudComponent().checkSaveAsButtonIsEnabled()).toEqual(false);
|
await expect(await tasksCloudDemoPage.editTaskFilterCloudComponent().checkSaveAsButtonIsEnabled()).toEqual(false);
|
||||||
await expect(await tasksCloudDemoPage.editTaskFilterCloudComponent().checkDeleteButtonIsEnabled()).toEqual(true);
|
await expect(await tasksCloudDemoPage.editTaskFilterCloudComponent().checkDeleteButtonIsEnabled()).toEqual(false);
|
||||||
await tasksCloudDemoPage.editTaskFilterCloudComponent().openFilter();
|
await tasksCloudDemoPage.editTaskFilterCloudComponent().openFilter();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
<span *ngIf="showTitle">{{ 'ADF_CLOUD_EDIT_TASK_FILTER.TITLE' | translate}}</span>
|
<span *ngIf="showTitle">{{ 'ADF_CLOUD_EDIT_TASK_FILTER.TITLE' | translate}}</span>
|
||||||
<div *ngIf="showActions()" class="adf-cloud-edit-task-filter-actions">
|
<div *ngIf="showActions()" class="adf-cloud-edit-task-filter-actions">
|
||||||
<ng-container *ngIf="toggleFilterActions">
|
<ng-container *ngIf="toggleFilterActions">
|
||||||
<button *ngFor="let filterAction of taskFilterActions" mat-icon-button matTooltip="{{ filterAction.tooltip | translate}}" [attr.data-automation-id]="'adf-filter-action-' + filterAction.actionType" [disabled]="hasFormChanged(filterAction)" (click)="executeFilterActions(filterAction)">
|
<button *ngFor="let filterAction of taskFilterActions" mat-icon-button matTooltip="{{ filterAction.tooltip | translate}}" [attr.data-automation-id]="'adf-filter-action-' + filterAction.actionType" [disabled]="isDisabledAction(filterAction)" (click)="executeFilterActions(filterAction)">
|
||||||
<mat-icon>{{filterAction.icon}}</mat-icon>
|
<mat-icon>{{filterAction.icon}}</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
@@ -127,6 +127,50 @@ describe('EditTaskFilterCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should disable save and delete button for default task filters', () => {
|
||||||
|
getTaskFilterSpy.and.returnValue(of({
|
||||||
|
name: 'ADF_CLOUD_TASK_FILTERS.MY_TASKS',
|
||||||
|
id: 'filter-id',
|
||||||
|
key: 'all-fake-task',
|
||||||
|
icon: 'adjust',
|
||||||
|
sort: 'startDate',
|
||||||
|
status: 'ALL',
|
||||||
|
order: 'DESC'
|
||||||
|
}));
|
||||||
|
|
||||||
|
const taskFilterIdChange = new SimpleChange(null, 'filter-id', true);
|
||||||
|
component.ngOnChanges({ 'id': taskFilterIdChange });
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
component.toggleFilterActions = true;
|
||||||
|
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
|
||||||
|
expansionPanel.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
|
||||||
|
expect(saveButton.disabled).toBe(true);
|
||||||
|
const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]');
|
||||||
|
expect(deleteButton.disabled).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should enable save and delete button for custom task filters', () => {
|
||||||
|
const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true);
|
||||||
|
component.ngOnChanges({ 'id': taskFilterIdChange });
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
component.toggleFilterActions = true;
|
||||||
|
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
|
||||||
|
expansionPanel.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
|
||||||
|
expect(saveButton.disabled).toBe(true);
|
||||||
|
const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]');
|
||||||
|
expect(deleteButton.disabled).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('EditTaskFilter form', () => {
|
describe('EditTaskFilter form', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -107,6 +107,10 @@ export class EditTaskFilterCloudComponent implements OnInit, OnChanges, OnDestro
|
|||||||
{ label: 'ASC', value: 'ASC' },
|
{ label: 'ASC', value: 'ASC' },
|
||||||
{ label: 'DESC', value: 'DESC' }
|
{ label: 'DESC', value: 'DESC' }
|
||||||
];
|
];
|
||||||
|
actionDisabledForDefault = [
|
||||||
|
EditTaskFilterCloudComponent.ACTION_SAVE,
|
||||||
|
EditTaskFilterCloudComponent.ACTION_DELETE
|
||||||
|
];
|
||||||
|
|
||||||
private applicationNames: any[] = [];
|
private applicationNames: any[] = [];
|
||||||
private formHasBeenChanged = false;
|
private formHasBeenChanged = false;
|
||||||
@@ -447,7 +451,18 @@ export class EditTaskFilterCloudComponent implements OnInit, OnChanges, OnDestro
|
|||||||
return property.type === 'checkbox';
|
return property.type === 'checkbox';
|
||||||
}
|
}
|
||||||
|
|
||||||
hasFormChanged(action: any): boolean {
|
isDisabledAction(action: TaskFilterAction): boolean {
|
||||||
|
return this.isDisabledForDefaultFilters(action) ? true : this.hasFormChanged(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
isDisabledForDefaultFilters(action: TaskFilterAction): boolean {
|
||||||
|
return (
|
||||||
|
this.taskFilterCloudService.isDefaultFilter(this.taskFilter.name) &&
|
||||||
|
this.actionDisabledForDefault.includes(action.actionType)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
hasFormChanged(action: TaskFilterAction): boolean {
|
||||||
if (action.actionType === EditTaskFilterCloudComponent.ACTION_SAVE) {
|
if (action.actionType === EditTaskFilterCloudComponent.ACTION_SAVE) {
|
||||||
return !this.formHasBeenChanged;
|
return !this.formHasBeenChanged;
|
||||||
}
|
}
|
||||||
|
@@ -220,6 +220,14 @@ describe('TaskFilterCloudService', () => {
|
|||||||
});
|
});
|
||||||
expect(updatePreferenceSpy).toHaveBeenCalled();
|
expect(updatePreferenceSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should check if given filter is a default filter', () => {
|
||||||
|
const fakeFilterName = 'fake-task-filter';
|
||||||
|
const defaultFilterName = 'ADF_CLOUD_TASK_FILTERS.MY_TASKS';
|
||||||
|
|
||||||
|
expect(service.isDefaultFilter(defaultFilterName)).toBe(true);
|
||||||
|
expect(service.isDefaultFilter(fakeFilterName)).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Inject [LocalPreferenceCloudService] into the TaskFilterCloudService', () => {
|
describe('Inject [LocalPreferenceCloudService] into the TaskFilterCloudService', () => {
|
||||||
|
@@ -216,6 +216,16 @@ export class TaskFilterCloudService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if given filter is a default filter
|
||||||
|
* @param filterName Name of the target task filter
|
||||||
|
* @returns Boolean value for whether the filter is a default filter
|
||||||
|
*/
|
||||||
|
isDefaultFilter(filterName: string): boolean {
|
||||||
|
const defaultFilters = this.defaultTaskFilters();
|
||||||
|
return defaultFilters.findIndex((filter) => filterName === filter.name) !== -1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls update preference api to update task filter
|
* Calls update preference api to update task filter
|
||||||
* @param appName Name of the target app
|
* @param appName Name of the target app
|
||||||
@@ -264,13 +274,13 @@ export class TaskFilterCloudService {
|
|||||||
* @param appName Name of the target app
|
* @param appName Name of the target app
|
||||||
* @returns Array of TaskFilterCloudModel
|
* @returns Array of TaskFilterCloudModel
|
||||||
*/
|
*/
|
||||||
private defaultTaskFilters(appName: string): TaskFilterCloudModel[] {
|
private defaultTaskFilters(appName?: string): TaskFilterCloudModel[] {
|
||||||
return [
|
return [
|
||||||
new TaskFilterCloudModel({
|
new TaskFilterCloudModel({
|
||||||
name: 'ADF_CLOUD_TASK_FILTERS.MY_TASKS',
|
name: 'ADF_CLOUD_TASK_FILTERS.MY_TASKS',
|
||||||
key: 'my-tasks',
|
key: 'my-tasks',
|
||||||
icon: 'inbox',
|
icon: 'inbox',
|
||||||
appName: appName,
|
appName,
|
||||||
status: 'ASSIGNED',
|
status: 'ASSIGNED',
|
||||||
assignee: this.getUsername(),
|
assignee: this.getUsername(),
|
||||||
sort: 'createdDate',
|
sort: 'createdDate',
|
||||||
@@ -280,7 +290,7 @@ export class TaskFilterCloudService {
|
|||||||
name: 'ADF_CLOUD_TASK_FILTERS.QUEUED_TASKS',
|
name: 'ADF_CLOUD_TASK_FILTERS.QUEUED_TASKS',
|
||||||
key: 'queued-tasks',
|
key: 'queued-tasks',
|
||||||
icon: 'queue',
|
icon: 'queue',
|
||||||
appName: appName,
|
appName,
|
||||||
status: 'CREATED',
|
status: 'CREATED',
|
||||||
assignee: '',
|
assignee: '',
|
||||||
sort: 'createdDate',
|
sort: 'createdDate',
|
||||||
@@ -290,7 +300,7 @@ export class TaskFilterCloudService {
|
|||||||
name: 'ADF_CLOUD_TASK_FILTERS.COMPLETED_TASKS',
|
name: 'ADF_CLOUD_TASK_FILTERS.COMPLETED_TASKS',
|
||||||
key: 'completed-tasks',
|
key: 'completed-tasks',
|
||||||
icon: 'done',
|
icon: 'done',
|
||||||
appName: appName,
|
appName,
|
||||||
status: 'COMPLETED',
|
status: 'COMPLETED',
|
||||||
assignee: '',
|
assignee: '',
|
||||||
sort: 'createdDate',
|
sort: 'createdDate',
|
||||||
|
Reference in New Issue
Block a user