From 4ecea64e19fea6fa4ab9d7274efc3437a39d013f Mon Sep 17 00:00:00 2001 From: bbcodrin Date: Mon, 9 Jul 2018 10:39:39 +0300 Subject: [PATCH] [ADF-3284] filterParam checking in onChanges (#3561) * filterParam checking in onChanges * test improvement --- .../process-filters.component.spec.ts | 21 +++++++++++++++++++ .../components/process-filters.component.ts | 13 ++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/process-services/process-list/components/process-filters.component.spec.ts b/lib/process-services/process-list/components/process-filters.component.spec.ts index fef42446e2..919c15ff4e 100644 --- a/lib/process-services/process-list/components/process-filters.component.spec.ts +++ b/lib/process-services/process-list/components/process-filters.component.spec.ts @@ -196,4 +196,25 @@ describe('ProcessFiltersComponent', () => { 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(); + }); }); diff --git a/lib/process-services/process-list/components/process-filters.component.ts b/lib/process-services/process-list/components/process-filters.component.ts index 9a6b8eb9c2..7f79b368ab 100644 --- a/lib/process-services/process-list/components/process-filters.component.ts +++ b/lib/process-services/process-list/components/process-filters.component.ts @@ -78,15 +78,16 @@ export class ProcessFiltersComponent implements OnInit, OnChanges { } 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)) { this.getFiltersByAppId(appId.currentValue); - return; - } - let appName = changes['appName']; - if (appName && appName.currentValue) { + } else if (appName && appName.currentValue) { this.getFiltersByAppName(appName.currentValue); - return; + } else if (filter && filter.currentValue !== filter.previousValue) { + this.selectProcessFilter(filter.currentValue); } }