[ACA-3316] Fix process filters selection should reset if input changes to non ex… (#5698)

* [ACA-3316] Fix process filter should reset if input changes to non existing filter

* [ACA-3316] Add unit tests
This commit is contained in:
arditdomi
2020-05-14 12:22:14 +01:00
committed by GitHub
parent 78332449a5
commit 7d4a956833
4 changed files with 47 additions and 20 deletions

View File

@@ -24,6 +24,7 @@ import { ProcessFiltersComponent } from './process-filters.component';
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { fakeProcessFilters } from '../../mock';
describe('ProcessFiltersComponent', () => { describe('ProcessFiltersComponent', () => {
@@ -51,13 +52,13 @@ describe('ProcessFiltersComponent', () => {
fakeGlobalFilterPromise = Promise.resolve([ fakeGlobalFilterPromise = Promise.resolve([
new FilterProcessRepresentationModel({ new FilterProcessRepresentationModel({
id: 10, id: 10,
name: 'FakeInvolvedTasks', name: 'FakeCompleted',
icon: 'glyphicon-th', icon: 'glyphicon-th',
filter: { state: 'open', assignment: 'fake-involved' } filter: { state: 'open', assignment: 'fake-involved' }
}), }),
new FilterProcessRepresentationModel({ new FilterProcessRepresentationModel({
id: 20, id: 20,
name: 'FakeMyTasks', name: 'FakeAll',
icon: 'glyphicon-random', icon: 'glyphicon-random',
filter: { state: 'open', assignment: 'fake-assignee' } filter: { state: 'open', assignment: 'fake-assignee' }
}), }),
@@ -87,8 +88,8 @@ describe('ProcessFiltersComponent', () => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(filterList.filters).toBeDefined(); expect(filterList.filters).toBeDefined();
expect(filterList.filters.length).toEqual(3); expect(filterList.filters.length).toEqual(3);
expect(filterList.filters[0].name).toEqual('FakeInvolvedTasks'); expect(filterList.filters[0].name).toEqual('FakeCompleted');
expect(filterList.filters[1].name).toEqual('FakeMyTasks'); expect(filterList.filters[1].name).toEqual('FakeAll');
expect(filterList.filters[2].name).toEqual('Running'); expect(filterList.filters[2].name).toEqual('Running');
done(); done();
}); });
@@ -123,12 +124,23 @@ describe('ProcessFiltersComponent', () => {
expect(filterList.currentFilter).toBeUndefined(); expect(filterList.currentFilter).toBeUndefined();
filterList.filterSelected.subscribe((filter) => { filterList.filterSelected.subscribe((filter) => {
expect(filter.name).toEqual('FakeInvolvedTasks'); expect(filter.name).toEqual('FakeCompleted');
done(); done();
}); });
fixture.detectChanges(); 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) => { 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) => { it('should emit an event when a filter is selected', (done) => {
const currentFilter = new FilterProcessRepresentationModel({ const currentFilter = new FilterProcessRepresentationModel({
id: 10, id: 10,
name: 'FakeInvolvedTasks', name: 'FakeCompleted',
filter: { state: 'open', assignment: 'fake-involved' } filter: { state: 'open', assignment: 'fake-involved' }
}); });
@@ -230,7 +242,7 @@ describe('ProcessFiltersComponent', () => {
it('should return the current filter after one is selected', () => { it('should return the current filter after one is selected', () => {
const filter = new FilterProcessRepresentationModel({ const filter = new FilterProcessRepresentationModel({
name: 'FakeMyTasks', name: 'FakeAll',
filter: { state: 'open', assignment: 'fake-assignee' } filter: { state: 'open', assignment: 'fake-assignee' }
}); });
expect(filterList.currentFilter).toBeUndefined(); expect(filterList.currentFilter).toBeUndefined();
@@ -253,7 +265,7 @@ describe('ProcessFiltersComponent', () => {
expect(filterList.filters).toBeDefined(); expect(filterList.filters).toBeDefined();
expect(filterList.filters.length).toEqual(3); expect(filterList.filters.length).toEqual(3);
expect(filterList.currentFilter).toBeDefined(); expect(filterList.currentFilter).toBeDefined();
expect(filterList.currentFilter.name).toEqual('FakeMyTasks'); expect(filterList.currentFilter.name).toEqual('FakeAll');
done(); done();
}); });
}); });
@@ -261,7 +273,7 @@ describe('ProcessFiltersComponent', () => {
it('should select the filter passed as input by name', (done) => { it('should select the filter passed as input by name', (done) => {
spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise));
filterList.filterParam = new FilterProcessRepresentationModel({ name: 'FakeMyTasks' }); filterList.filterParam = new FilterProcessRepresentationModel({ name: 'FakeAll' });
const appId = 1; const appId = 1;
const change = new SimpleChange(null, appId, true); const change = new SimpleChange(null, appId, true);
@@ -273,7 +285,7 @@ describe('ProcessFiltersComponent', () => {
expect(filterList.filters).toBeDefined(); expect(filterList.filters).toBeDefined();
expect(filterList.filters.length).toEqual(3); expect(filterList.filters.length).toEqual(3);
expect(filterList.currentFilter).toBeDefined(); expect(filterList.currentFilter).toBeDefined();
expect(filterList.currentFilter.name).toEqual('FakeMyTasks'); expect(filterList.currentFilter.name).toEqual('FakeAll');
done(); done();
}); });
}); });

View File

@@ -157,14 +157,17 @@ export class ProcessFiltersComponent implements OnInit, OnChanges {
*/ */
selectProcessFilter(filterParam: FilterProcessRepresentationModel) { selectProcessFilter(filterParam: FilterProcessRepresentationModel) {
if (filterParam) { if (filterParam) {
this.filters.filter((processFilter: UserProcessInstanceFilterRepresentation, index) => { const newFilter = this.filters.find((processFilter, index) =>
if (filterParam.name && filterParam.name.toLowerCase() === processFilter.name.toLowerCase() || filterParam.index === index ||
filterParam.id === processFilter.id || filterParam.id === processFilter.id ||
filterParam.index === index) { (filterParam.name &&
this.currentFilter = processFilter; (filterParam.name.toLocaleLowerCase() === processFilter.name.toLocaleLowerCase())
this.filterSelected.emit(processFilter); ));
} this.currentFilter = newFilter;
});
if (newFilter) {
this.filterSelected.emit(newFilter);
}
} }
} }

View File

@@ -343,4 +343,16 @@ describe('TaskFiltersComponent', () => {
done(); 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);
});
}); });

View File

@@ -155,7 +155,7 @@ export class TaskFiltersComponent implements OnInit, OnChanges {
/** /**
* Pass the selected filter as next * Pass the selected filter as next
* @param filter * @param newFilter
*/ */
public selectFilter(newFilter: FilterParamsModel) { public selectFilter(newFilter: FilterParamsModel) {
if (newFilter) { if (newFilter) {