Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {

Expand Down Expand Up @@ -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' }
}),
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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' }
});

Expand Down Expand Up @@ -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();
Expand All @@ -253,15 +265,15 @@ 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();
});
});

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);
Expand All @@ -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();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down