[AAE-1952] Task › Edit task filters › Actions E2E Unit test (#5492)

* [AAE-1952] Task › Edit task filters › Actions E2E Unit test

* fixed error
This commit is contained in:
dhrn
2020-02-20 18:02:35 +05:30
committed by GitHub
parent 8fc69b89ec
commit a256a6b7d5
5 changed files with 29 additions and 80 deletions

View File

@@ -49,8 +49,6 @@
(dateChange)="onDateChanged($event.value, processFilterProperty)"
[matDatepicker]="dateController"
placeholder="{{processFilterProperty.label | translate}}"
[(ngModel)]="dateFilter[processFilterProperty.key]"
[ngModelOptions]="{standalone: true}"
[attr.data-automation-id]="'adf-cloud-edit-process-property-' + processFilterProperty.key">
<mat-datepicker-toggle matSuffix [for]="dateController" [attr.data-automation-id]="'adf-cloud-edit-process-property-date-toggle-' + processFilterProperty.key"></mat-datepicker-toggle>
<mat-datepicker #dateController [attr.data-automation-id]="'adf-cloud-edit-process-property-date-picker-' + processFilterProperty.key"></mat-datepicker>

View File

@@ -104,7 +104,6 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes
directions = [{ label: 'ASC', value: 'ASC' }, { label: 'DESC', value: 'DESC' }];
applicationNames: any[] = [];
formHasBeenChanged = false;
dateFilter: any[] = [];
editProcessFilterForm: FormGroup;
processFilterProperties: ProcessFilterProperties[] = [];
processFilterActions: ProcessFilterAction[] = [];

View File

@@ -49,8 +49,6 @@
(dateChange)="onDateChanged($event.value, taskFilterProperty)"
[matDatepicker]="dateController"
placeholder="{{taskFilterProperty.label | translate}}"
[(ngModel)]="dateFilter[taskFilterProperty.key]"
[ngModelOptions]="{standalone: true}"
[attr.data-automation-id]="'adf-cloud-edit-task-`perty-' + taskFilterProperty.key">
<mat-datepicker-toggle matSuffix [for]="dateController" [attr.data-automation-id]="'adf-cloud-edit-task-property-date-toggle-' + taskFilterProperty.key"></mat-datepicker-toggle>
<mat-datepicker #dateController [attr.data-automation-id]="'adf-cloud-edit-task-property-date-picker-' + taskFilterProperty.key"></mat-datepicker>

View File

@@ -68,9 +68,7 @@ describe('EditTaskFilterCloudComponent', () => {
fixture.detectChanges();
});
it('should create EditTaskFilterCloudComponent', () => {
expect(component instanceof EditTaskFilterCloudComponent).toBeTruthy();
});
afterEach(() => fixture.destroy());
it('should fetch task filter by taskId', () => {
const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true);
@@ -92,8 +90,6 @@ describe('EditTaskFilterCloudComponent', () => {
fixture.detectChanges();
const title = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-title-id');
const subTitle = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-sub-title-id');
expect(title).toBeDefined();
expect(subTitle).toBeDefined();
expect(title.innerText).toEqual('FakeInvolvedTasks');
expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_TASK_FILTER.TITLE');
}));
@@ -108,8 +104,6 @@ describe('EditTaskFilterCloudComponent', () => {
fixture.whenStable().then(() => {
expect(matSpinnerElement).toBeNull();
expect(title).toBeDefined();
expect(subTitle).toBeDefined();
expect(title.innerText).toEqual('FakeInvolvedTasks');
expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_TASK_FILTER.TITLE');
});
@@ -148,11 +142,7 @@ describe('EditTaskFilterCloudComponent', () => {
const orderController = component.editTaskFilterForm.get('order');
const assigneeController = component.editTaskFilterForm.get('assignee');
expect(component.editTaskFilterForm).toBeDefined();
expect(stateController).toBeDefined();
expect(sortController).toBeDefined();
expect(orderController).toBeDefined();
expect(assigneeController).toBeDefined();
expect(stateController.value).toBe('CREATED');
expect(sortController.value).toBe('id');
expect(orderController.value).toBe('ASC');
@@ -204,10 +194,7 @@ describe('EditTaskFilterCloudComponent', () => {
const assigneeElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-assignee"]');
const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]');
const orderElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-order"]');
expect(stateElement).toBeDefined();
expect(assigneeElement).toBeDefined();
expect(sortElement).toBeDefined();
expect(orderElement).toBeDefined();
expect(stateElement.textContent.trim()).toBe('CREATED');
expect(sortElement.textContent.trim()).toBe('Id');
expect(orderElement.textContent.trim()).toBe('ASC');
@@ -272,12 +259,8 @@ describe('EditTaskFilterCloudComponent', () => {
const orderController = component.editTaskFilterForm.get('order');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(component.taskFilterProperties).toBeDefined();
expect(component.taskFilterProperties.length).toBe(4);
expect(component.editTaskFilterForm).toBeDefined();
expect(stateController).toBeDefined();
expect(sortController).toBeDefined();
expect(orderController).toBeDefined();
expect(stateController.value).toBe('CREATED');
expect(sortController.value).toBe('id');
expect(orderController.value).toBe('ASC');
@@ -314,7 +297,6 @@ describe('EditTaskFilterCloudComponent', () => {
fixture.whenStable().then(() => {
const sortController = component.editTaskFilterForm.get('sort');
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortController).toBeDefined();
expect(sortController.value).toBe('id');
expect(sortOptions.length).toEqual(4);
});
@@ -340,8 +322,6 @@ describe('EditTaskFilterCloudComponent', () => {
fixture.whenStable().then(() => {
const sortController = component.editTaskFilterForm.get('sort');
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortController).toBeDefined();
expect(component.sortProperties).toBeDefined();
expect(component.sortProperties.length).toBe(3);
expect(sortController.value).toBe('my-custom-sort');
expect(sortOptions.length).toEqual(3);
@@ -363,7 +343,6 @@ describe('EditTaskFilterCloudComponent', () => {
fixture.whenStable().then(() => {
const sortController = component.editTaskFilterForm.get('sort');
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(sortController).toBeDefined();
expect(sortController.value).toBe('id');
expect(sortOptions.length).toEqual(4);
});
@@ -384,13 +363,10 @@ describe('EditTaskFilterCloudComponent', () => {
const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]');
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]');
expect(component.taskFilterActions).toBeDefined();
expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save', 'saveAs', 'delete']);
expect(component.taskFilterActions.length).toBe(3);
expect(saveButton).toBeDefined();
expect(saveAsButton).toBeDefined();
expect(deleteButton).toBeDefined();
expect(saveButton.disabled).toBeTruthy();
expect(saveAsButton.disabled).toBeTruthy(false);
expect(saveButton.disabled).toBe(true);
expect(saveAsButton.disabled).toBe(true);
expect(deleteButton.disabled).toBe(false);
});
}));
@@ -408,34 +384,13 @@ describe('EditTaskFilterCloudComponent', () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
expect(component.taskFilterActions).toBeDefined();
expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save']);
expect(component.taskFilterActions.length).toBe(1);
expect(saveButton).toBeDefined();
expect(saveButton.disabled).toBeTruthy();
});
}));
it('should display default filter actions if input is empty', async(() => {
component.toggleFilterActions = true;
component.actions = [];
const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true);
component.ngOnChanges({ 'id': taskFilterIdChange });
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]');
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]');
expect(component.taskFilterActions).toBeDefined();
expect(component.taskFilterActions.length).toBe(3);
expect(saveButton).toBeDefined();
expect(saveAsButton).toBeDefined();
expect(deleteButton).toBeDefined();
expect(saveButton.disabled).toBeTruthy();
expect(saveAsButton.disabled).toBeTruthy(false);
expect(deleteButton.disabled).toBe(false);
expect(saveAsButton).toBeFalsy();
expect(deleteButton).toBeFalsy();
});
}));
@@ -469,13 +424,12 @@ describe('EditTaskFilterCloudComponent', () => {
const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true);
component.ngOnChanges({ 'id': taskFilterIdChange });
fixture.detectChanges();
spyOn(component.action, 'emit').and.callThrough();
});
it('should emit save event and save the filter on click save button', async(() => {
component.toggleFilterActions = true;
const saveFilterSpy = spyOn(service, 'updateFilter');
const saveSpy: jasmine.Spy = spyOn(component.action, 'emit');
spyOn(service, 'updateFilter').and.returnValue(of({}));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
@@ -487,18 +441,18 @@ describe('EditTaskFilterCloudComponent', () => {
sortOptions[3].nativeElement.click();
fixture.detectChanges();
const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]');
saveButton.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(saveFilterSpy).toHaveBeenCalled();
expect(saveSpy).toHaveBeenCalled();
fixture.detectChanges();
expect(saveButton.disabled).toBe(false);
saveButton.click();
expect(service.updateFilter).toHaveBeenCalled();
expect(component.action.emit).toHaveBeenCalled();
});
}));
it('should emit delete event and delete the filter on click of delete button', async(() => {
component.toggleFilterActions = true;
const deleteFilterSpy = spyOn(service, 'deleteFilter');
const deleteSpy: jasmine.Spy = spyOn(component.action, 'emit');
spyOn(service, 'deleteFilter').and.returnValue(of({}));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
@@ -507,18 +461,18 @@ describe('EditTaskFilterCloudComponent', () => {
stateElement.click();
fixture.detectChanges();
const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]');
deleteButton.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(deleteFilterSpy).toHaveBeenCalled();
expect(deleteSpy).toHaveBeenCalled();
fixture.detectChanges();
expect(deleteButton.disabled).toBe(false);
deleteButton.click();
expect(service.deleteFilter).toHaveBeenCalled();
expect(component.action.emit).toHaveBeenCalled();
});
}));
it('should emit saveAs event and add filter on click saveAs button', async(() => {
component.toggleFilterActions = true;
const saveAsFilterSpy = spyOn(service, 'addFilter').and.callThrough();
const saveAsSpy: jasmine.Spy = spyOn(component.action, 'emit');
spyOn(service, 'addFilter').and.returnValue(of({}));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
@@ -526,15 +480,16 @@ describe('EditTaskFilterCloudComponent', () => {
const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger');
sortElement.click();
fixture.detectChanges();
const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]');
const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
sortOptions[2].nativeElement.click();
fixture.detectChanges();
saveAsButton.click();
fixture.detectChanges();
const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]');
fixture.whenStable().then(() => {
expect(saveAsFilterSpy).toHaveBeenCalled();
expect(saveAsSpy).toHaveBeenCalled();
fixture.detectChanges();
expect(saveAsButton.disabled).toBe(false);
saveAsButton.click();
expect(service.addFilter).toHaveBeenCalled();
expect(component.action.emit).toHaveBeenCalled();
expect(dialog.open).toHaveBeenCalled();
});
}));

View File

@@ -107,9 +107,8 @@ export class EditTaskFilterCloudComponent implements OnInit, OnChanges, OnDestro
{ label: 'DESC', value: 'DESC' }
];
applicationNames: any[] = [];
dateFilter: any[] = [];
formHasBeenChanged = false;
private applicationNames: any[] = [];
private formHasBeenChanged = false;
editTaskFilterForm: FormGroup;
taskFilterProperties: TaskFilterProperties[] = [];
taskFilterActions: TaskFilterAction[] = [];