diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts index 26de9a8a69..5a43ab41a8 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts @@ -81,7 +81,7 @@ describe('ProcessFiltersCloudComponent', () => { it('should not attach icons for each filter if hasIcon is false', async () => { component.showIcons = false; const change = new SimpleChange(undefined, 'my-app-1', true); - component.ngOnChanges({'appName': change}); + component.ngOnChanges({ 'appName': change }); fixture.detectChanges(); await fixture.whenStable(); @@ -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'; diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.ts index 4afbc28cf0..cf5132872b 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.ts @@ -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) => { diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts index 755ad5cb90..a944b28c7b 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts @@ -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'; diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.ts index 17d99991b7..7550c54509 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.ts @@ -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(); - } - - private ensureFilterSelected() { - if (!this.currentFilter && this.filters.length > 0) { - this.currentFilter = this.filters[0]; + if (this.currentFilter) { + this.filterSelected.emit(this.currentFilter); + } } } diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.spec.ts index c2e82c7f9e..8d07b8736f 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.spec.ts @@ -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 }); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.ts index cccad6ff4f..739beba7d8 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.ts @@ -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]; - } } /** diff --git a/lib/process-services-cloud/src/lib/task/task-filters/mock/task-filters-cloud.mock.ts b/lib/process-services-cloud/src/lib/task/task-filters/mock/task-filters-cloud.mock.ts index 45788643e7..44e59eefc1 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/mock/task-filters-cloud.mock.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/mock/task-filters-cloud.mock.ts @@ -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'