mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
@@ -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() ||
|
||||
const newFilter = this.filters.find((processFilter, index) =>
|
||||
filterParam.index === index ||
|
||||
filterParam.id === processFilter.id ||
|
||||
filterParam.index === index) {
|
||||
this.currentFilter = processFilter;
|
||||
this.filterSelected.emit(processFilter);
|
||||
(filterParam.name &&
|
||||
(filterParam.name.toLocaleLowerCase() === processFilter.name.toLocaleLowerCase())
|
||||
));
|
||||
this.currentFilter = newFilter;
|
||||
|
||||
if (newFilter) {
|
||||
this.filterSelected.emit(newFilter);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
});
|
||||
});
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user