diff --git a/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.spec.ts index cc59fcebcc..27e547dc75 100644 --- a/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.spec.ts @@ -424,9 +424,10 @@ describe('ProcessListCloudComponent', () => { done(); }); + + component.ngAfterContentInit(); component.appName = appName.currentValue; - component.ngOnChanges({ appName }); - fixture.detectChanges(); + component.reload(); }); it('should shown columns selector', () => { @@ -758,9 +759,9 @@ describe('ProcessListCloudComponent', () => { done(); }); + component.ngAfterContentInit(); component.appName = appName.currentValue; - component.ngOnChanges({ appName }); - fixture.detectChanges(); + component.reload(); }); it('should shown columns selector', () => { @@ -954,6 +955,30 @@ describe('ProcessListCloudComponent', () => { component.resetPagination(); }); }); + + it('should call loadPreferencesAndInitialize when appName changes', () => { + spyOn(preferencesService, 'getPreferences').and.returnValue(of({})); + + spyOn(processListCloudService, 'fetchProcessList').and.returnValue(of(fakeProcessCloudList)); + spyOn(component as any, 'createDatatableSchema'); + spyOn(component as any, 'createColumns'); + + const appName = new SimpleChange('old-app-name', 'new-app-name', false); + component.ngOnChanges({ appName }); + + expect(preferencesService.getPreferences).toHaveBeenCalledWith('new-app-name'); + expect((component as any).createDatatableSchema).toHaveBeenCalled(); + expect((component as any).createColumns).toHaveBeenCalled(); + }); + + it('should not call loadPreferencesAndInitialize when appName does not change', () => { + spyOn(preferencesService, 'getPreferences'); + + const status = new SimpleChange('old-status', 'new-status', false); + component.ngOnChanges({ status }); + + expect(preferencesService.getPreferences).not.toHaveBeenCalled(); + }); }); }); diff --git a/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.ts b/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.ts index 67595a64ae..e74f0894f8 100644 --- a/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.ts @@ -397,8 +397,12 @@ export class ProcessListCloudComponent } ngAfterContentInit() { + this.loadPreferencesAndInitialize(this.appName); + } + + private loadPreferencesAndInitialize(appName: string): void { this.cloudPreferenceService - .getPreferences(this.appName) + .getPreferences(appName) .pipe( take(1), map((preferences) => { @@ -441,13 +445,19 @@ export class ProcessListCloudComponent } this.createDatatableSchema(); + this.createColumns(); }); } + ngOnChanges(changes: SimpleChanges) { if (this.isPropertyChanged(changes, 'sorting')) { this.formatSorting(changes['sorting'].currentValue); } + if (changes['appName']) { + this.loadPreferencesAndInitialize(changes['appName'].currentValue); + } + if (this.isAnyPropertyChanged(changes)) { this.reload(); }