[ADF-2245] Setting Component - Emit an event to detect the changed url (#2907)

* [ADF-2245] Setting Component - Emit an event to detect the changed url

* Added change event emitters

* * Updated documentation
This commit is contained in:
Deepak Paul 2018-02-05 15:22:44 +05:30 committed by Eugenio Romano
parent 0f6ac42e4c
commit 05659b3837
3 changed files with 53 additions and 8 deletions

View File

@ -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<string>` | Emitted when the URL is invalid. |
| ecmHostChange | `EventEmitter<string>` | Emitted when the ECM host url is changed. |
| bpmHostChange | `EventEmitter<string>` | Emitted when the BPM host url is changed. |

View File

@ -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();
});

View File

@ -50,6 +50,14 @@ export class HostSettingsComponent {
@Output()
error = new EventEmitter<string>();
/** Emitted when the ecm host URL is changed. */
@Output()
ecmHostChange = new EventEmitter<string>();
/** Emitted when the bpm host URL is changed. */
@Output()
bpmHostChange = new EventEmitter<string>();
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);