Skip to content

Commit

Permalink
[ACA-3678] Disable save & delete buttons for default process filters (#…
Browse files Browse the repository at this point in the history
…5896)

* [ACA-3678] Disable save & delete buttons for default process filters

* Added unit test

* Added types for params

* Updated e2e

* Updated test
  • Loading branch information
mcchrys committed Jul 26, 2020
1 parent ef73d81 commit 8d43155
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 7 deletions.
Expand Up @@ -81,7 +81,7 @@ describe('Edit process filters cloud', () => {
await processCloudDemoPage.editProcessFilterCloudComponent().checkDeleteButtonIsDisplayed();
await expect(await processCloudDemoPage.editProcessFilterCloudComponent().checkSaveButtonIsEnabled()).toEqual(false);
await expect(await processCloudDemoPage.editProcessFilterCloudComponent().checkSaveAsButtonIsEnabled()).toEqual(false);
await expect(await processCloudDemoPage.editProcessFilterCloudComponent().checkDeleteButtonIsEnabled()).toEqual(true);
await expect(await processCloudDemoPage.editProcessFilterCloudComponent().checkDeleteButtonIsEnabled()).toEqual(false);
await processCloudDemoPage.editProcessFilterCloudComponent().openFilter();
});

Expand Down
Expand Up @@ -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>
Expand Down
Expand Up @@ -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(() => {
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Expand Up @@ -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);
});
});
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down

0 comments on commit 8d43155

Please sign in to comment.