[ADF-3284] filterParam checking in onChanges (#3561)

* filterParam checking in onChanges

* test improvement
This commit is contained in:
bbcodrin
2018-07-09 10:39:39 +03:00
committed by Eugenio Romano
parent a6a77b8561
commit 4ecea64e19
2 changed files with 28 additions and 6 deletions

View File

@@ -196,4 +196,25 @@ describe('ProcessFiltersComponent', () => {
expect(filterList.getCurrentFilter()).toBe(filter); expect(filterList.getCurrentFilter()).toBe(filter);
}); });
it ('should select current process filter', (done) => {
spyOn(processFilterService, 'getProcessFilters').and.returnValue(Observable.fromPromise(fakeGlobalFilterPromise));
const appId = '1';
let change = new SimpleChange(null, appId, true);
filterList.ngOnChanges({ 'appId': change });
expect(filterList.currentFilter).toBeUndefined();
const selectedFilter = new FilterProcessRepresentationModel({
name: 'FakeMyTasks',
filter: { state: 'open', assignment: 'fake-assignee' }
});
filterList.success.subscribe(() => {
filterList.selectProcessFilter(selectedFilter);
expect(filterList.currentFilter.name).toEqual('FakeMyTasks');
done();
});
filterList.ngOnInit();
});
}); });

View File

@@ -78,15 +78,16 @@ export class ProcessFiltersComponent implements OnInit, OnChanges {
} }
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {
let appId = changes['appId']; const appId = changes['appId'];
const appName = changes['appName'];
const filter = changes['filterParam'];
if (appId && (appId.currentValue || appId.currentValue === null)) { if (appId && (appId.currentValue || appId.currentValue === null)) {
this.getFiltersByAppId(appId.currentValue); this.getFiltersByAppId(appId.currentValue);
return; } else if (appName && appName.currentValue) {
}
let appName = changes['appName'];
if (appName && appName.currentValue) {
this.getFiltersByAppName(appName.currentValue); this.getFiltersByAppName(appName.currentValue);
return; } else if (filter && filter.currentValue !== filter.previousValue) {
this.selectProcessFilter(filter.currentValue);
} }
} }