mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACA-3678] Disable save & delete buttons for default process filters (#5896)
* [ACA-3678] Disable save & delete buttons for default process filters * Added unit test * Added types for params * Updated e2e * Updated test
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<span *ngIf="showTitle"> {{ 'ADF_CLOUD_EDIT_PROCESS_FILTER.TITLE' | translate}}</span>
|
||||
<div *ngIf="showActions()" class="adf-cloud-edit-process-filter-actions">
|
||||
<ng-container *ngIf="toggleFilterActions">
|
||||
<button *ngFor="let filterAction of processFilterActions" 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 processFilterActions" 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>
|
||||
|
@@ -153,6 +153,50 @@ describe('EditProcessFilterCloudComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should disable save and delete button for default process filters', () => {
|
||||
getProcessFilterByIdSpy.and.returnValue(of({
|
||||
id: 'filter-id',
|
||||
processName: 'ADF_CLOUD_PROCESS_FILTERS.RUNNING_PROCESSES',
|
||||
sort: 'my-custom-sort',
|
||||
processDefinitionId: 'process-definition-id',
|
||||
priority: '12'
|
||||
}));
|
||||
|
||||
const processFilterIdChange = new SimpleChange(null, 'filter-id', true);
|
||||
component.ngOnChanges({ 'id': processFilterIdChange });
|
||||
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).toEqual(true);
|
||||
const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]');
|
||||
expect(deleteButton.disabled).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should enable save and delete button for custom process filters', () => {
|
||||
const disableCheckSpy = spyOn(component, 'isDisabledAction');
|
||||
const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true);
|
||||
component.ngOnChanges({ 'id': processFilterIdChange });
|
||||
fixture.detectChanges();
|
||||
|
||||
component.toggleFilterActions = true;
|
||||
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
|
||||
expansionPanel.click();
|
||||
fixture.detectChanges();
|
||||
expect(disableCheckSpy).toHaveBeenCalled();
|
||||
fixture.whenStable().then(() => {
|
||||
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
|
||||
expect(saveButton.disabled).toEqual(false);
|
||||
const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]');
|
||||
expect(deleteButton.disabled).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('EditProcessFilter form', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
|
@@ -103,6 +103,10 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes
|
||||
];
|
||||
|
||||
directions = [{ label: 'ASC', value: 'ASC' }, { label: 'DESC', value: 'DESC' }];
|
||||
actionDisabledForDefault = [
|
||||
EditProcessFilterCloudComponent.ACTION_SAVE,
|
||||
EditProcessFilterCloudComponent.ACTION_DELETE
|
||||
];
|
||||
applicationNames: any[] = [];
|
||||
formHasBeenChanged = false;
|
||||
editProcessFilterForm: FormGroup;
|
||||
@@ -433,7 +437,18 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes
|
||||
return property.type === 'number';
|
||||
}
|
||||
|
||||
hasFormChanged(action: any): boolean {
|
||||
isDisabledAction(action: ProcessFilterAction): boolean {
|
||||
return this.isDisabledForDefaultFilters(action) ? true : this.hasFormChanged(action);
|
||||
}
|
||||
|
||||
isDisabledForDefaultFilters(action: ProcessFilterAction): boolean {
|
||||
return (
|
||||
this.processFilterCloudService.isDefaultFilter(this.processFilter.name) &&
|
||||
this.actionDisabledForDefault.includes(action.actionType)
|
||||
);
|
||||
}
|
||||
|
||||
hasFormChanged(action: ProcessFilterAction): boolean {
|
||||
if (action.actionType === EditProcessFilterCloudComponent.ACTION_SAVE) {
|
||||
return !this.formHasBeenChanged;
|
||||
}
|
||||
|
@@ -381,4 +381,12 @@ describe('ProcessFilterCloudService', () => {
|
||||
});
|
||||
expect(updatePreferenceSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should check if given filter is a default filter', () => {
|
||||
const fakeFilterName = 'fake-process-filter';
|
||||
const defaultFilterName = 'ADF_CLOUD_PROCESS_FILTERS.RUNNING_PROCESSES';
|
||||
|
||||
expect(service.isDefaultFilter(defaultFilterName)).toBe(true);
|
||||
expect(service.isDefaultFilter(fakeFilterName)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
@@ -170,6 +170,16 @@ export class ProcessFilterCloudService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if given filter is a default filter
|
||||
* @param filterName Name of the target process filter
|
||||
* @returns Boolean value for whether the filter is a default filter
|
||||
*/
|
||||
isDefaultFilter(filterName: string): boolean {
|
||||
const defaultFilters = this.defaultProcessFilters();
|
||||
return defaultFilters.findIndex((filter) => filterName === filter.name) !== -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks user preference are empty or not
|
||||
* @param preferences User preferences of the target app
|
||||
@@ -256,13 +266,13 @@ export class ProcessFilterCloudService {
|
||||
* @param appName Name of the target app
|
||||
* @returns Array of ProcessFilterCloudModel
|
||||
*/
|
||||
private defaultProcessFilters(appName: string): ProcessFilterCloudModel[] {
|
||||
private defaultProcessFilters(appName?: string): ProcessFilterCloudModel[] {
|
||||
return [
|
||||
new ProcessFilterCloudModel({
|
||||
name: 'ADF_CLOUD_PROCESS_FILTERS.RUNNING_PROCESSES',
|
||||
icon: 'inbox',
|
||||
key: 'running-processes',
|
||||
appName: appName,
|
||||
appName,
|
||||
sort: 'startDate',
|
||||
status: 'RUNNING',
|
||||
order: 'DESC'
|
||||
@@ -271,7 +281,7 @@ export class ProcessFilterCloudService {
|
||||
name: 'ADF_CLOUD_PROCESS_FILTERS.COMPLETED_PROCESSES',
|
||||
icon: 'done',
|
||||
key: 'completed-processes',
|
||||
appName: appName,
|
||||
appName,
|
||||
sort: 'startDate',
|
||||
status: 'COMPLETED',
|
||||
order: 'DESC'
|
||||
@@ -280,7 +290,7 @@ export class ProcessFilterCloudService {
|
||||
name: 'ADF_CLOUD_PROCESS_FILTERS.ALL_PROCESSES',
|
||||
key: 'all-processes',
|
||||
icon: 'adjust',
|
||||
appName: appName,
|
||||
appName,
|
||||
sort: 'startDate',
|
||||
status: '',
|
||||
order: 'DESC'
|
||||
|
Reference in New Issue
Block a user