diff --git a/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts b/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts index ac6a1df3d4..0ed4ea75bc 100644 --- a/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts @@ -24,6 +24,7 @@ import { ProcessFiltersComponent } from './process-filters.component'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; +import { fakeProcessFilters } from '../../mock'; describe('ProcessFiltersComponent', () => { @@ -51,13 +52,13 @@ describe('ProcessFiltersComponent', () => { fakeGlobalFilterPromise = Promise.resolve([ new FilterProcessRepresentationModel({ id: 10, - name: 'FakeInvolvedTasks', + name: 'FakeCompleted', icon: 'glyphicon-th', filter: { state: 'open', assignment: 'fake-involved' } }), new FilterProcessRepresentationModel({ id: 20, - name: 'FakeMyTasks', + name: 'FakeAll', icon: 'glyphicon-random', filter: { state: 'open', assignment: 'fake-assignee' } }), @@ -87,8 +88,8 @@ describe('ProcessFiltersComponent', () => { expect(res).toBeDefined(); expect(filterList.filters).toBeDefined(); expect(filterList.filters.length).toEqual(3); - expect(filterList.filters[0].name).toEqual('FakeInvolvedTasks'); - expect(filterList.filters[1].name).toEqual('FakeMyTasks'); + expect(filterList.filters[0].name).toEqual('FakeCompleted'); + expect(filterList.filters[1].name).toEqual('FakeAll'); expect(filterList.filters[2].name).toEqual('Running'); done(); }); @@ -123,12 +124,23 @@ describe('ProcessFiltersComponent', () => { expect(filterList.currentFilter).toBeUndefined(); filterList.filterSelected.subscribe((filter) => { - expect(filter.name).toEqual('FakeInvolvedTasks'); + expect(filter.name).toEqual('FakeCompleted'); done(); }); fixture.detectChanges(); - filterList.selectRunningFilter(); + }); + + it('should reset selection when filterParam is a filter that does not exist', async () => { + spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); + filterList.currentFilter = fakeProcessFilters.data[0]; + filterList.filterParam = new FilterProcessRepresentationModel({ name: 'non-existing-filter' }); + const appId = '1'; + const change = new SimpleChange(null, appId, true); + filterList.ngOnChanges({ 'appId': change }); + fixture.detectChanges(); + await fixture.whenStable(); + expect(filterList.currentFilter).toBe(undefined); }); it('should return the filter task list, filtered By Name', (done) => { @@ -184,7 +196,7 @@ describe('ProcessFiltersComponent', () => { it('should emit an event when a filter is selected', (done) => { const currentFilter = new FilterProcessRepresentationModel({ id: 10, - name: 'FakeInvolvedTasks', + name: 'FakeCompleted', filter: { state: 'open', assignment: 'fake-involved' } }); @@ -230,7 +242,7 @@ describe('ProcessFiltersComponent', () => { it('should return the current filter after one is selected', () => { const filter = new FilterProcessRepresentationModel({ - name: 'FakeMyTasks', + name: 'FakeAll', filter: { state: 'open', assignment: 'fake-assignee' } }); expect(filterList.currentFilter).toBeUndefined(); @@ -253,7 +265,7 @@ describe('ProcessFiltersComponent', () => { expect(filterList.filters).toBeDefined(); expect(filterList.filters.length).toEqual(3); expect(filterList.currentFilter).toBeDefined(); - expect(filterList.currentFilter.name).toEqual('FakeMyTasks'); + expect(filterList.currentFilter.name).toEqual('FakeAll'); done(); }); }); @@ -261,7 +273,7 @@ describe('ProcessFiltersComponent', () => { it('should select the filter passed as input by name', (done) => { spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); - filterList.filterParam = new FilterProcessRepresentationModel({ name: 'FakeMyTasks' }); + filterList.filterParam = new FilterProcessRepresentationModel({ name: 'FakeAll' }); const appId = 1; const change = new SimpleChange(null, appId, true); @@ -273,7 +285,7 @@ describe('ProcessFiltersComponent', () => { expect(filterList.filters).toBeDefined(); expect(filterList.filters.length).toEqual(3); expect(filterList.currentFilter).toBeDefined(); - expect(filterList.currentFilter.name).toEqual('FakeMyTasks'); + expect(filterList.currentFilter.name).toEqual('FakeAll'); done(); }); }); diff --git a/lib/process-services/src/lib/process-list/components/process-filters.component.ts b/lib/process-services/src/lib/process-list/components/process-filters.component.ts index 5c28287b0b..4ef01a0fe4 100644 --- a/lib/process-services/src/lib/process-list/components/process-filters.component.ts +++ b/lib/process-services/src/lib/process-list/components/process-filters.component.ts @@ -157,14 +157,17 @@ export class ProcessFiltersComponent implements OnInit, OnChanges { */ selectProcessFilter(filterParam: FilterProcessRepresentationModel) { if (filterParam) { - this.filters.filter((processFilter: UserProcessInstanceFilterRepresentation, index) => { - if (filterParam.name && filterParam.name.toLowerCase() === processFilter.name.toLowerCase() || - filterParam.id === processFilter.id || - filterParam.index === index) { - this.currentFilter = processFilter; - this.filterSelected.emit(processFilter); - } - }); + const newFilter = this.filters.find((processFilter, index) => + filterParam.index === index || + filterParam.id === processFilter.id || + (filterParam.name && + (filterParam.name.toLocaleLowerCase() === processFilter.name.toLocaleLowerCase()) + )); + this.currentFilter = newFilter; + + if (newFilter) { + this.filterSelected.emit(newFilter); + } } } diff --git a/lib/process-services/src/lib/task-list/components/task-filters.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-filters.component.spec.ts index e2473ea30b..48620b7a5a 100644 --- a/lib/process-services/src/lib/task-list/components/task-filters.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-filters.component.spec.ts @@ -343,4 +343,16 @@ describe('TaskFiltersComponent', () => { done(); }); }); + + it('should reset selection when filterParam is a filter that does not exist', async () => { + spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); + component.currentFilter = fakeGlobalFilter[0]; + component.filterParam = new FilterRepresentationModel( {name: 'non-existing-filter'}); + const appId = '1'; + const change = new SimpleChange(null, appId, true); + component.ngOnChanges({ 'appId': change }); + fixture.detectChanges(); + await fixture.whenStable(); + expect(component.currentFilter).toBe(undefined); + }); }); diff --git a/lib/process-services/src/lib/task-list/components/task-filters.component.ts b/lib/process-services/src/lib/task-list/components/task-filters.component.ts index 4af32a0256..f38998a479 100644 --- a/lib/process-services/src/lib/task-list/components/task-filters.component.ts +++ b/lib/process-services/src/lib/task-list/components/task-filters.component.ts @@ -155,7 +155,7 @@ export class TaskFiltersComponent implements OnInit, OnChanges { /** * Pass the selected filter as next - * @param filter + * @param newFilter */ public selectFilter(newFilter: FilterParamsModel) { if (newFilter) {