diff --git a/docs/host-settings.component.md b/docs/host-settings.component.md index 83e221e40d..4d28349dcd 100644 --- a/docs/host-settings.component.md +++ b/docs/host-settings.component.md @@ -22,3 +22,5 @@ Validates the URLs for ACS and APS and saves them in the user's local storage | Name | Type | Description | | ---- | ---- | ----------- | | error | `EventEmitter` | Emitted when the URL is invalid. | +| ecmHostChange | `EventEmitter` | Emitted when the ECM host url is changed. | +| bpmHostChange | `EventEmitter` | Emitted when the BPM host url is changed. | diff --git a/lib/core/settings/host-settings.component.spec.ts b/lib/core/settings/host-settings.component.spec.ts index 99a6412afe..f4b07d233e 100644 --- a/lib/core/settings/host-settings.component.spec.ts +++ b/lib/core/settings/host-settings.component.spec.ts @@ -56,10 +56,26 @@ describe('HostSettingsComponent', () => { done(); }); - let ecmUrlInput = fixture.nativeElement.querySelector('#ecmHost'); + const ecmUrlInput = fixture.nativeElement.querySelector('#ecmHost'); ecmUrlInput.value = 'wrong_url'; - let event: any = {}; + const event: any = {}; + event.target = ecmUrlInput; + component.onChangeECMHost(event); + }); + + it('should emit ecmHostChange when the ECM url inserted is correct', (done) => { + fixture.detectChanges(); + const url = 'http://localhost:9999/ecm'; + component.ecmHostChange.subscribe((message: string) => { + expect(message).toEqual(url); + done(); + }); + + const ecmUrlInput = fixture.nativeElement.querySelector('#ecmHost'); + ecmUrlInput.value = url; + + const event: any = {}; event.target = ecmUrlInput; component.onChangeECMHost(event); }); @@ -72,21 +88,38 @@ describe('HostSettingsComponent', () => { done(); }); - let bpmUrlInput: any = fixture.nativeElement.querySelector('#bpmHost'); + const bpmUrlInput: any = fixture.nativeElement.querySelector('#bpmHost'); bpmUrlInput.value = 'wrong_url'; - let event: any = {}; + const event: any = {}; event.target = bpmUrlInput; component.onChangeBPMHost(event); }); + it('should emit bpmHostChange when the BPM url inserted is correct', (done) => { + fixture.detectChanges(); + const url = 'http://localhost:9999/bpm'; + + component.ecmHostChange.subscribe((message: string) => { + expect(message).toEqual(url); + done(); + }); + + const ecmUrlInput = fixture.nativeElement.querySelector('#bpmHost'); + ecmUrlInput.value = url; + + const event: any = {}; + event.target = ecmUrlInput; + component.onChangeECMHost(event); + }); + it('should not render the ECM url config if setting provider is BPM', () => { component.providers = 'BPM'; fixture.detectChanges(); - let bpmUrlInput = fixture.nativeElement.querySelector('#bpmHost'); - let ecmUrlInput = fixture.nativeElement.querySelector('#ecmHost'); + const bpmUrlInput = fixture.nativeElement.querySelector('#bpmHost'); + const ecmUrlInput = fixture.nativeElement.querySelector('#ecmHost'); expect(ecmUrlInput).toEqual(null); expect(bpmUrlInput).toBeDefined(); }); @@ -96,8 +129,8 @@ describe('HostSettingsComponent', () => { fixture.detectChanges(); - let ecmUrlInput = fixture.nativeElement.querySelector('#ecmHost'); - let bpmUrlInput = fixture.nativeElement.querySelector('#bpmHost'); + const ecmUrlInput = fixture.nativeElement.querySelector('#ecmHost'); + const bpmUrlInput = fixture.nativeElement.querySelector('#bpmHost'); expect(bpmUrlInput).toEqual(null); expect(ecmUrlInput).toBeDefined(); }); diff --git a/lib/core/settings/host-settings.component.ts b/lib/core/settings/host-settings.component.ts index 9801f22750..e240b31a2b 100644 --- a/lib/core/settings/host-settings.component.ts +++ b/lib/core/settings/host-settings.component.ts @@ -50,6 +50,14 @@ export class HostSettingsComponent { @Output() error = new EventEmitter(); + /** Emitted when the ecm host URL is changed. */ + @Output() + ecmHostChange = new EventEmitter(); + + /** Emitted when the bpm host URL is changed. */ + @Output() + bpmHostChange = new EventEmitter(); + constructor(private settingsService: SettingsService, private storage: StorageService, private logService: LogService, @@ -63,6 +71,7 @@ export class HostSettingsComponent { if (value && this.isValidUrl(value)) { this.logService.info(`ECM host: ${value}`); this.ecmHostTmp = value; + this.ecmHostChange.emit(value); } else { this.translationService.get('CORE.HOST_SETTING.CS_URL_ERROR').subscribe((message) => { this.error.emit(message); @@ -75,6 +84,7 @@ export class HostSettingsComponent { if (value && this.isValidUrl(value)) { this.logService.info(`BPM host: ${value}`); this.bpmHostTmp = value; + this.bpmHostChange.emit(value); } else { this.translationService.get('CORE.HOST_SETTING.PS_URL_ERROR').subscribe((message) => { this.error.emit(message);