mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-5432] - Fix no filter should be selected by default (#7136)
* Fix no filter should be selected by default * Replace not.toBeDefined with toBeUndefined * Fix comment - Trigger onChanges with filter change instead of appName
This commit is contained in:
@@ -129,6 +129,7 @@ describe('ProcessFiltersCloudComponent', () => {
|
||||
});
|
||||
|
||||
it('should emit success with the filters when filters are loaded', async () => {
|
||||
const successSpy = spyOn(component.success, 'emit');
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
@@ -136,13 +137,14 @@ describe('ProcessFiltersCloudComponent', () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(successSpy).toHaveBeenCalledWith(mockProcessFilters);
|
||||
expect(component.filters).toBeDefined();
|
||||
expect(component.filters[0].name).toEqual('FakeAllProcesses');
|
||||
expect(component.filters[1].name).toEqual('FakeRunningProcesses');
|
||||
expect(component.filters[2].name).toEqual('FakeCompletedProcesses');
|
||||
});
|
||||
|
||||
it('should select the first process cloud filter as default', async () => {
|
||||
it('should not select any filter as default', async () => {
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
@@ -150,69 +152,68 @@ describe('ProcessFiltersCloudComponent', () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeAllProcesses');
|
||||
expect(component.currentFilter).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not select any process filter if filter input does not exist', async () => {
|
||||
const change = new SimpleChange(null, { name: 'nonexistentFilter' }, true);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should select the filter based on the input by name param', async () => {
|
||||
component.filterParam = { name: 'FakeRunningProcesses' };
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
const filterSelectedSpy = spyOn(component.filterSelected, 'emit');
|
||||
const change = new SimpleChange(null, { name: 'FakeRunningProcesses' }, true);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeRunningProcesses');
|
||||
expect(component.currentFilter).toEqual(mockProcessFilters[1]);
|
||||
expect(filterSelectedSpy).toHaveBeenCalledWith(mockProcessFilters[1]);
|
||||
});
|
||||
|
||||
it('should select the filter based on the input by key param', async () => {
|
||||
component.filterParam = { key: 'completed-processes' };
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
const filterSelectedSpy = spyOn(component.filterSelected, 'emit');
|
||||
const change = new SimpleChange(null, { key: 'completed-processes' }, true);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeCompletedProcesses');
|
||||
expect(component.currentFilter).toEqual(mockProcessFilters[2]);
|
||||
expect(filterSelectedSpy).toHaveBeenCalledWith(mockProcessFilters[2]);
|
||||
});
|
||||
|
||||
it('should select the filter based on the input by index param', async () => {
|
||||
component.filterParam = { index: 2 };
|
||||
const filterSelectedSpy = spyOn(component.filterSelected, 'emit');
|
||||
const change = new SimpleChange(null, { index: 2 }, true);
|
||||
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeCompletedProcesses');
|
||||
expect(component.currentFilter).toEqual(mockProcessFilters[2]);
|
||||
expect(filterSelectedSpy).toHaveBeenCalledWith(mockProcessFilters[2]);
|
||||
});
|
||||
|
||||
it('should select the filter based on the input by id param', async () => {
|
||||
component.filterParam = { id: '12' };
|
||||
const filterSelectedSpy = spyOn(component.filterSelected, 'emit');
|
||||
const change = new SimpleChange(null, { id: '12' }, true);
|
||||
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeCompletedProcesses');
|
||||
expect(component.currentFilter).toEqual(mockProcessFilters[2]);
|
||||
expect(filterSelectedSpy).toHaveBeenCalledWith(mockProcessFilters[2]);
|
||||
});
|
||||
|
||||
it('should filterClicked emit when a filter is clicked from the UI', async () => {
|
||||
component.filterParam = { id: '10' };
|
||||
|
||||
const filterClickedSpy = spyOn(component.filterClicked, 'emit');
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
@@ -226,19 +227,31 @@ describe('ProcessFiltersCloudComponent', () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeAllProcesses');
|
||||
expect(component.currentFilter).toEqual(mockProcessFilters[0]);
|
||||
expect(filterClickedSpy).toHaveBeenCalledWith(mockProcessFilters[0]);
|
||||
});
|
||||
|
||||
it('should not emit a filter click event on binding changes', () => {
|
||||
spyOn(component, 'selectFilterAndEmit').and.callThrough();
|
||||
|
||||
const change = new SimpleChange(null, undefined, false);
|
||||
it('should reset the filter when the param is undefined', async () => {
|
||||
const change = new SimpleChange(mockProcessFilters[0], undefined, false);
|
||||
component.currentFilter = mockProcessFilters[0];
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.currentFilter).toEqual(undefined);
|
||||
});
|
||||
|
||||
it('should not emit a filter clicked event when a filter is selected through the filterParam input (filterClicked emits only through a UI click action)', async () => {
|
||||
const filterClickedSpy = spyOn(component.filterClicked, 'emit');
|
||||
const change = new SimpleChange(null, { id: '10' }, true);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.selectFilterAndEmit).toHaveBeenCalled();
|
||||
expect(component.currentFilter).toBe(mockProcessFilters[0]);
|
||||
expect(filterClickedSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should reload filters by appName on binding changes', () => {
|
||||
@@ -261,18 +274,6 @@ describe('ProcessFiltersCloudComponent', () => {
|
||||
expect(component.getFilters).not.toHaveBeenCalledWith(appName);
|
||||
});
|
||||
|
||||
it('should change current filter when filterParam (name) changes', () => {
|
||||
component.filters = mockProcessFilters;
|
||||
component.currentFilter = null;
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.currentFilter.name).toEqual(mockProcessFilters[2].name);
|
||||
});
|
||||
|
||||
const change = new SimpleChange(null, { name: mockProcessFilters[2].name }, true);
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
});
|
||||
|
||||
it('should reload filters by app name on binding changes', () => {
|
||||
spyOn(component, 'getFilters').and.stub();
|
||||
const appName = 'fake-app-name';
|
||||
|
@@ -99,11 +99,6 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges, OnDestro
|
||||
if (this.filterParam) {
|
||||
this.selectFilterAndEmit(this.filterParam);
|
||||
}
|
||||
|
||||
if (!this.currentFilter && this.filters.length > 0) {
|
||||
this.currentFilter = this.filters[0];
|
||||
}
|
||||
|
||||
this.success.emit(res);
|
||||
},
|
||||
(err: any) => {
|
||||
|
@@ -132,7 +132,7 @@ describe('ServiceTaskFiltersCloudComponent', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should return the filter task list', async () => {
|
||||
it('should not select any filter as default', async () => {
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
@@ -141,108 +141,67 @@ describe('ServiceTaskFiltersCloudComponent', () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.filters).toBeDefined();
|
||||
expect(component.filters.length).toEqual(3);
|
||||
expect(component.currentFilter).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return the filter task list, filtered By Name', async () => {
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
it('should select the service task filter based on the input by name param', async () => {
|
||||
const filterSelectedSpy = spyOn(component.filterSelected, 'emit');
|
||||
const change = new SimpleChange(null, { name: 'FakeMyServiceTasks1' }, true);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.filters).toBeDefined();
|
||||
expect(component.filters[0].name).toEqual('FakeServiceTasks');
|
||||
expect(component.filters[1].name).toEqual('FakeMyServiceTasks1');
|
||||
expect(component.filters[2].name).toEqual('FakeMyServiceTasks2');
|
||||
});
|
||||
|
||||
it('should select the first service task filter as default', async () => {
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeServiceTasks');
|
||||
});
|
||||
|
||||
it('should select the task filter based on the input by name param', async () => {
|
||||
component.filterParam = { name: 'FakeMyServiceTasks1' };
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeMyServiceTasks1');
|
||||
});
|
||||
|
||||
it('should select the default task filter if filter input does not exist', async () => {
|
||||
component.filterParam = { name: 'UnexistableFilter' };
|
||||
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.currentFilter).toBeDefined('current filter not found');
|
||||
expect(component.currentFilter.name).toEqual('FakeServiceTasks');
|
||||
});
|
||||
|
||||
it('should select the task filter based on the input by index param', async () => {
|
||||
component.filterParam = { index: 2 };
|
||||
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeMyServiceTasks2');
|
||||
});
|
||||
|
||||
it('should select the task filter based on the input by id param', async () => {
|
||||
component.filterParam = { id: '12' };
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeMyServiceTasks2');
|
||||
});
|
||||
|
||||
it('should emit the selected filter based on the filterParam input', async () => {
|
||||
spyOn(component.filterSelected, 'emit');
|
||||
|
||||
const filterParam = { id: '10' };
|
||||
const change = new SimpleChange(null, filterParam, true);
|
||||
component.filterParam = filterParam;
|
||||
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toEqual(fakeGlobalServiceFilters[1]);
|
||||
expect(filterSelectedSpy).toHaveBeenCalledWith(fakeGlobalServiceFilters[1]);
|
||||
});
|
||||
|
||||
it('should not select any service task filter if filter input does not exist', async () => {
|
||||
const change = new SimpleChange(null, { name: 'nonexistentFilter' }, true);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should select the service task filter based on the input by index param', async () => {
|
||||
const filterSelectedSpy = spyOn(component.filterSelected, 'emit');
|
||||
const change = new SimpleChange(null, { index: 2 }, true);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.filterSelected.emit).toHaveBeenCalledWith(fakeGlobalServiceFilters[0]);
|
||||
expect(component.currentFilter).toEqual(fakeGlobalServiceFilters[2]);
|
||||
expect(filterSelectedSpy).toHaveBeenCalledWith(fakeGlobalServiceFilters[2]);
|
||||
});
|
||||
|
||||
it('should select the service task filter based on the input by id param', async () => {
|
||||
const filterSelectedSpy = spyOn(component.filterSelected, 'emit');
|
||||
const change = new SimpleChange(null, { id: '12' }, true);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toEqual(fakeGlobalServiceFilters[2]);
|
||||
expect(filterSelectedSpy).toHaveBeenCalledWith(fakeGlobalServiceFilters[2]);
|
||||
});
|
||||
|
||||
it('should select the service task filter based on the input by key param', async () => {
|
||||
const filterSelectedSpy = spyOn(component.filterSelected, 'emit');
|
||||
const change = new SimpleChange(null, { key: 'fake-involved-tasks' }, true);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toEqual(fakeGlobalServiceFilters[0]);
|
||||
expect(filterSelectedSpy).toHaveBeenCalledWith(fakeGlobalServiceFilters[0]);
|
||||
});
|
||||
|
||||
it('should filterClicked emit when a filter is clicked from the UI', async () => {
|
||||
@@ -260,17 +219,27 @@ describe('ServiceTaskFiltersCloudComponent', () => {
|
||||
expect(component.filterClicked.emit).toHaveBeenCalledWith(fakeGlobalServiceFilters[0]);
|
||||
});
|
||||
|
||||
it('should reset the filter when the param is undefined', async () => {
|
||||
component.currentFilter = null;
|
||||
it('should not emit a filter clicked event when a filter is selected through the filterParam input (filterClicked emits only through a UI click action)', async () => {
|
||||
const filterClickedSpy = spyOn(component.filterClicked, 'emit');
|
||||
const change = new SimpleChange(null, { id: '10' }, true);
|
||||
|
||||
const filterName = undefined;
|
||||
const change = new SimpleChange(null, filterName, false);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toBe(fakeGlobalServiceFilters[0]);
|
||||
expect(filterClickedSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should reset the filter when the param is undefined', async () => {
|
||||
const change = new SimpleChange(null, undefined, false);
|
||||
component.currentFilter = fakeGlobalServiceFilters[0];
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.currentFilter).toBe(fakeGlobalServiceFilters[0]);
|
||||
expect(component.currentFilter).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should reload filters by appName on binding changes', () => {
|
||||
@@ -283,41 +252,6 @@ describe('ServiceTaskFiltersCloudComponent', () => {
|
||||
expect(component.getFilters).toHaveBeenCalledWith(appName);
|
||||
});
|
||||
|
||||
it('should change current filter when filterParam (name) changes', () => {
|
||||
component.filters = fakeGlobalServiceFilters;
|
||||
component.currentFilter = null;
|
||||
|
||||
const name = fakeGlobalServiceFilters[1].name;
|
||||
const change = new SimpleChange(null, { name }, true);
|
||||
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toBeDefined('current filter not found');
|
||||
expect(component.currentFilter.name).toEqual(name);
|
||||
});
|
||||
|
||||
it('should change current filter when filterParam (key) changes', () => {
|
||||
component.filters = fakeGlobalServiceFilters;
|
||||
component.currentFilter = null;
|
||||
|
||||
const key = fakeGlobalServiceFilters[2].key;
|
||||
const change = new SimpleChange(null, { key }, true);
|
||||
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter.key).toEqual(key);
|
||||
});
|
||||
|
||||
it('should change current filter when filterParam (index) changes', () => {
|
||||
component.filters = fakeGlobalServiceFilters;
|
||||
component.currentFilter = null;
|
||||
|
||||
const change = new SimpleChange(null, { index: 1 }, true);
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter.name).toEqual(fakeGlobalServiceFilters[1].name);
|
||||
});
|
||||
|
||||
it('should reload filters by app name on binding changes', () => {
|
||||
spyOn(component, 'getFilters').and.stub();
|
||||
const appName = 'fake-app-name';
|
||||
|
@@ -74,8 +74,6 @@ export class ServiceTaskFiltersCloudComponent extends BaseTaskFiltersCloudCompon
|
||||
if (this.filterParam) {
|
||||
this.selectFilterAndEmit(this.filterParam);
|
||||
}
|
||||
|
||||
this.ensureFilterSelected();
|
||||
this.success.emit(res);
|
||||
},
|
||||
(err: any) => {
|
||||
@@ -93,24 +91,16 @@ export class ServiceTaskFiltersCloudComponent extends BaseTaskFiltersCloudCompon
|
||||
(paramFilter.name &&
|
||||
(paramFilter.name.toLocaleLowerCase() === this.translationService.instant(filter.name).toLocaleLowerCase())
|
||||
));
|
||||
|
||||
if (this.currentFilter) {
|
||||
this.filterSelected.emit(this.currentFilter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public selectFilterAndEmit(newParamFilter: FilterParamsModel) {
|
||||
if (newParamFilter) {
|
||||
this.selectFilter(newParamFilter);
|
||||
}
|
||||
|
||||
this.ensureFilterSelected();
|
||||
if (this.currentFilter) {
|
||||
this.filterSelected.emit(this.currentFilter);
|
||||
}
|
||||
|
||||
private ensureFilterSelected() {
|
||||
if (!this.currentFilter && this.filters.length > 0) {
|
||||
this.currentFilter = this.filters[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -111,6 +111,7 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
await fixture.whenStable();
|
||||
|
||||
const filters = fixture.debugElement.queryAll(By.css('.adf-task-filters__entry'));
|
||||
|
||||
expect(component.filters.length).toBe(3);
|
||||
expect(filters.length).toBe(3);
|
||||
expect(filters[0].nativeElement.innerText).toContain('FakeInvolvedTasks');
|
||||
@@ -135,7 +136,7 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
});
|
||||
|
||||
it('should return the filter task list', async () => {
|
||||
it('should display the task filters', async () => {
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
@@ -144,26 +145,15 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.filters).toBeDefined();
|
||||
expect(component.filters.length).toEqual(3);
|
||||
const filters = fixture.debugElement.queryAll(By.css('.adf-task-filters__entry'));
|
||||
expect(component.filters).toEqual(fakeGlobalFilter);
|
||||
expect(filters.length).toBe(3);
|
||||
expect(filters[0].nativeElement.innerText).toContain('FakeInvolvedTasks');
|
||||
expect(filters[1].nativeElement.innerText).toContain('FakeMyTasks1');
|
||||
expect(filters[2].nativeElement.innerText).toContain('FakeMyTasks2');
|
||||
});
|
||||
|
||||
it('should return the filter task list, filtered By Name', async () => {
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.filters).toBeDefined();
|
||||
expect(component.filters[0].name).toEqual('FakeInvolvedTasks');
|
||||
expect(component.filters[1].name).toEqual('FakeMyTasks1');
|
||||
expect(component.filters[2].name).toEqual('FakeMyTasks2');
|
||||
});
|
||||
|
||||
it('should select the first cloud task filter as default', async () => {
|
||||
it('should not select any filter as default', async () => {
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
@@ -171,81 +161,64 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.filters.length).toBe(fakeGlobalFilter.length);
|
||||
expect(component.currentFilter).toBeDefined('current filter not found');
|
||||
expect(component.currentFilter.name).toEqual('FakeInvolvedTasks');
|
||||
expect(component.currentFilter).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should select the task filter based on the input by name param', async () => {
|
||||
component.filterParam = { name: 'FakeMyTasks1' };
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
const filterSelectedSpy = spyOn(component.filterSelected, 'emit');
|
||||
const change = new SimpleChange(null, { name: 'FakeMyTasks2' }, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeMyTasks1');
|
||||
expect(component.currentFilter).toEqual(fakeGlobalFilter[2]);
|
||||
expect(filterSelectedSpy).toHaveBeenCalledWith(fakeGlobalFilter[2]);
|
||||
});
|
||||
|
||||
it('should select the default task filter if filter input does not exist', async () => {
|
||||
component.filterParam = { name: 'UnexistableFilter' };
|
||||
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
|
||||
it('should not select any task filter if filter input does not exist', async () => {
|
||||
const change = new SimpleChange(null, { name: 'nonexistentFilter' }, true);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toBeDefined('current filter not found');
|
||||
expect(component.currentFilter.name).toEqual('FakeInvolvedTasks');
|
||||
expect(component.currentFilter).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should select the task filter based on the input by index param', async () => {
|
||||
component.filterParam = { index: 2 };
|
||||
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
const filterSelectedSpy = spyOn(component.filterSelected, 'emit');
|
||||
const change = new SimpleChange(null, { index: 2 }, true);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeMyTasks2');
|
||||
expect(component.currentFilter).toEqual(fakeGlobalFilter[2]);
|
||||
expect(filterSelectedSpy).toHaveBeenCalledWith(fakeGlobalFilter[2]);
|
||||
});
|
||||
|
||||
it('should select the task filter based on the input by id param', async () => {
|
||||
component.filterParam = { id: '12' };
|
||||
const appName = 'my-app-1';
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
const filterSelectedSpy = spyOn(component.filterSelected, 'emit');
|
||||
const change = new SimpleChange(null, { id: '12' }, true);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeMyTasks2');
|
||||
});
|
||||
|
||||
it('should emit the selected filter based on the filterParam input', async () => {
|
||||
spyOn(component.filterSelected, 'emit');
|
||||
|
||||
const filterParam = { id: '10' };
|
||||
const change = new SimpleChange(null, filterParam, true);
|
||||
component.filterParam = filterParam;
|
||||
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toEqual(fakeGlobalFilter[2]);
|
||||
expect(filterSelectedSpy).toHaveBeenCalledWith(fakeGlobalFilter[2]);
|
||||
});
|
||||
|
||||
it('should select the task filter based on the input by key param', async () => {
|
||||
const filterSelectedSpy = spyOn(component.filterSelected, 'emit');
|
||||
const change = new SimpleChange(null, { key: 'fake-my-task2' }, true);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.filterSelected.emit).toHaveBeenCalledWith(fakeGlobalFilter[0]);
|
||||
expect(component.currentFilter).toEqual(fakeGlobalFilter[2]);
|
||||
expect(filterSelectedSpy).toHaveBeenCalledWith(fakeGlobalFilter[2]);
|
||||
});
|
||||
|
||||
it('should filterClicked emit when a filter is clicked from the UI', async () => {
|
||||
@@ -263,17 +236,27 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
expect(component.filterClicked.emit).toHaveBeenCalledWith(fakeGlobalFilter[0]);
|
||||
});
|
||||
|
||||
it('should reset the filter when the param is undefined', async () => {
|
||||
component.currentFilter = null;
|
||||
it('should not emit a filter clicked event when a filter is selected through the filterParam input (filterClicked emits only through a UI click action)', async () => {
|
||||
const filterClickedSpy = spyOn(component.filterClicked, 'emit');
|
||||
const change = new SimpleChange(null, { id: '10' }, true);
|
||||
|
||||
const filterName = undefined;
|
||||
const change = new SimpleChange(null, filterName, false);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter).toBe(fakeGlobalFilter[0]);
|
||||
expect(filterClickedSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should reset the filter when the param is undefined', async () => {
|
||||
const change = new SimpleChange(fakeGlobalFilter[0], undefined, false);
|
||||
component.currentFilter = fakeGlobalFilter[0];
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.currentFilter).toEqual(fakeGlobalFilter[0]);
|
||||
expect(component.currentFilter).toEqual(undefined);
|
||||
});
|
||||
|
||||
it('should reload filters by appName on binding changes', () => {
|
||||
@@ -286,58 +269,6 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
expect(component.getFilters).toHaveBeenCalledWith(appName);
|
||||
});
|
||||
|
||||
it('should change current filter when filterParam (name) changes', () => {
|
||||
component.filters = fakeGlobalFilter;
|
||||
component.currentFilter = null;
|
||||
|
||||
const change = new SimpleChange(null, { name: fakeGlobalFilter[1].name }, true);
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.currentFilter.name).toEqual(fakeGlobalFilter[1].name);
|
||||
});
|
||||
});
|
||||
|
||||
it('should change current filter when filterParam (key) changes', () => {
|
||||
component.filters = fakeGlobalFilter;
|
||||
component.currentFilter = null;
|
||||
|
||||
const change = new SimpleChange(null, { key: fakeGlobalFilter[2].key }, true);
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter.key).toEqual(fakeGlobalFilter[2].key);
|
||||
});
|
||||
|
||||
it('should change current filter when filterParam (index) changes', () => {
|
||||
component.filters = fakeGlobalFilter;
|
||||
component.currentFilter = null;
|
||||
const position = 1;
|
||||
|
||||
const change = new SimpleChange(null, { index: position }, true);
|
||||
component.ngOnChanges({ 'filterParam': change });
|
||||
|
||||
expect(component.currentFilter.name).toEqual(fakeGlobalFilter[position].name);
|
||||
});
|
||||
|
||||
it('should reload filters by app name on binding changes', () => {
|
||||
spyOn(component, 'getFilters').and.stub();
|
||||
const appName = 'fake-app-name';
|
||||
|
||||
const change = new SimpleChange(null, appName, true);
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
|
||||
expect(component.getFilters).toHaveBeenCalledWith(appName);
|
||||
});
|
||||
|
||||
it('should return the current filter after one is selected', () => {
|
||||
const filter = { name: 'FakeInvolvedTasks' };
|
||||
component.filters = fakeGlobalFilter;
|
||||
|
||||
expect(component.currentFilter).toBeUndefined();
|
||||
component.selectFilter(filter);
|
||||
expect(component.currentFilter).toBe(fakeGlobalFilter[0]);
|
||||
});
|
||||
|
||||
it('should display filter counter if property set to true', async () => {
|
||||
const change = new SimpleChange(undefined, 'my-app-1', true);
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
|
@@ -85,10 +85,6 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
|
||||
this.selectFilterAndEmit(this.filterParam);
|
||||
}
|
||||
|
||||
if (!this.currentFilter && this.filters.length > 0) {
|
||||
this.currentFilter = this.filters[0];
|
||||
}
|
||||
|
||||
this.updateFilterCounters();
|
||||
this.success.emit(res);
|
||||
},
|
||||
@@ -159,14 +155,6 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
|
||||
this.filterSelected.emit(this.currentFilter);
|
||||
}
|
||||
}
|
||||
|
||||
this.ensureFilterSelected();
|
||||
}
|
||||
|
||||
private ensureFilterSelected() {
|
||||
if (!this.currentFilter && this.filters.length > 0) {
|
||||
this.currentFilter = this.filters[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -30,7 +30,7 @@ export const fakeGlobalFilter: any[] = [
|
||||
},
|
||||
{
|
||||
name: 'FakeMyTasks1',
|
||||
key: 'fake-my-tast1',
|
||||
key: 'fake-my-task1',
|
||||
icon: 'done',
|
||||
id: '11',
|
||||
status: 'open',
|
||||
@@ -39,7 +39,7 @@ export const fakeGlobalFilter: any[] = [
|
||||
},
|
||||
{
|
||||
name: 'FakeMyTasks2',
|
||||
key: 'fake-my-tast2',
|
||||
key: 'fake-my-task2',
|
||||
icon: 'inbox',
|
||||
id: '12',
|
||||
status: 'open',
|
||||
@@ -57,14 +57,14 @@ export const fakeGlobalServiceFilters: ServiceTaskFilterCloudModel[] = [
|
||||
} as ServiceTaskFilterCloudModel,
|
||||
{
|
||||
name: 'FakeMyServiceTasks1',
|
||||
key: 'fake-my-tast1',
|
||||
key: 'fake-my-task1',
|
||||
icon: 'done',
|
||||
id: '11',
|
||||
status: 'open'
|
||||
} as ServiceTaskFilterCloudModel,
|
||||
{
|
||||
name: 'FakeMyServiceTasks2',
|
||||
key: 'fake-my-tast2',
|
||||
key: 'fake-my-task2',
|
||||
icon: 'inbox',
|
||||
id: '12',
|
||||
status: 'open'
|
||||
|
Reference in New Issue
Block a user