mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +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:
@@ -7,7 +7,7 @@
|
||||
<span *ngIf="showTitle">{{ 'ADF_CLOUD_EDIT_TASK_FILTER.TITLE' | translate}}</span>
|
||||
<div *ngIf="showActions()" class="adf-cloud-edit-task-filter-actions">
|
||||
<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>
|
||||
</button>
|
||||
</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', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
|
@@ -107,6 +107,10 @@ export class EditTaskFilterCloudComponent implements OnInit, OnChanges, OnDestro
|
||||
{ label: 'ASC', value: 'ASC' },
|
||||
{ label: 'DESC', value: 'DESC' }
|
||||
];
|
||||
actionDisabledForDefault = [
|
||||
EditTaskFilterCloudComponent.ACTION_SAVE,
|
||||
EditTaskFilterCloudComponent.ACTION_DELETE
|
||||
];
|
||||
|
||||
private applicationNames: any[] = [];
|
||||
private formHasBeenChanged = false;
|
||||
@@ -447,7 +451,18 @@ export class EditTaskFilterCloudComponent implements OnInit, OnChanges, OnDestro
|
||||
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) {
|
||||
return !this.formHasBeenChanged;
|
||||
}
|
||||
|
@@ -220,6 +220,14 @@ describe('TaskFilterCloudService', () => {
|
||||
});
|
||||
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', () => {
|
||||
|
@@ -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
|
||||
* @param appName Name of the target app
|
||||
@@ -264,13 +274,13 @@ export class TaskFilterCloudService {
|
||||
* @param appName Name of the target app
|
||||
* @returns Array of TaskFilterCloudModel
|
||||
*/
|
||||
private defaultTaskFilters(appName: string): TaskFilterCloudModel[] {
|
||||
private defaultTaskFilters(appName?: string): TaskFilterCloudModel[] {
|
||||
return [
|
||||
new TaskFilterCloudModel({
|
||||
name: 'ADF_CLOUD_TASK_FILTERS.MY_TASKS',
|
||||
key: 'my-tasks',
|
||||
icon: 'inbox',
|
||||
appName: appName,
|
||||
appName,
|
||||
status: 'ASSIGNED',
|
||||
assignee: this.getUsername(),
|
||||
sort: 'createdDate',
|
||||
@@ -280,7 +290,7 @@ export class TaskFilterCloudService {
|
||||
name: 'ADF_CLOUD_TASK_FILTERS.QUEUED_TASKS',
|
||||
key: 'queued-tasks',
|
||||
icon: 'queue',
|
||||
appName: appName,
|
||||
appName,
|
||||
status: 'CREATED',
|
||||
assignee: '',
|
||||
sort: 'createdDate',
|
||||
@@ -290,7 +300,7 @@ export class TaskFilterCloudService {
|
||||
name: 'ADF_CLOUD_TASK_FILTERS.COMPLETED_TASKS',
|
||||
key: 'completed-tasks',
|
||||
icon: 'done',
|
||||
appName: appName,
|
||||
appName,
|
||||
status: 'COMPLETED',
|
||||
assignee: '',
|
||||
sort: 'createdDate',
|
||||
|
Reference in New Issue
Block a user