fixture.debugElement.nativeElement.querySelector('input[id=contact]');
const getDescriptionField = () =>
fixture.debugElement.nativeElement.querySelector('input[id=description]');
+ const checkVisibility = () => {
+ if (component.showContactInfo) {
+ expect(getContactField()).toBeTruthy();
+ expect(getDescriptionField()).toBeTruthy();
+ } else {
+ expect(getContactField()).toBeFalsy();
+ expect(getDescriptionField()).toBeFalsy();
+ }
+ };
- // Initially hidden.
- expect(getContactField()).toBeFalsy();
- expect(getDescriptionField()).toBeFalsy();
+ // Initial check.
+ checkVisibility();
- // Show fields.
+ // toggle fields.
component.toggleIdent();
fixture.detectChanges();
- expect(getContactField()).toBeTruthy();
- expect(getDescriptionField()).toBeTruthy();
+ checkVisibility();
- // Hide fields.
+ // toggle fields again.
component.toggleIdent();
fixture.detectChanges();
- expect(getContactField()).toBeFalsy();
- expect(getDescriptionField()).toBeFalsy();
+ checkVisibility();
});
it('should set module enability to true correctly', () => {
expect(downloadSpy).toHaveBeenCalledWith(JSON.stringify(reportText, null, 2), filename);
});
- it('should submit ', () => {
+ it('should submit', () => {
component.onSubmit();
const req1 = httpTesting.expectOne('api/telemetry');
expect(req1.request.method).toBe('PUT');
loading = false;
moduleEnabled: boolean;
options: Object = {};
- updatedConfig: Object = {};
+ newConfig: Object = {};
+ configResp: object = {};
previewForm: CdFormGroup;
requiredFields = [
'channel_basic',
'interval',
'proxy',
'contact',
- 'description'
+ 'description',
+ 'organization'
];
+ contactInfofields = ['contact', 'description', 'organization'];
report: object = undefined;
reportId: number = undefined;
sendToUrl = '';
sendToDeviceUrl = '';
step = 1;
- showContactInfo = false;
+ showContactInfo: boolean;
constructor(
private formBuilder: CdFormBuilder,
this.moduleEnabled = configResp['enabled'];
this.sendToUrl = configResp['url'];
this.sendToDeviceUrl = configResp['device_url'];
+ this.showContactInfo = configResp['channel_ident'];
this.options = _.pick(resp[0], this.requiredFields);
- const configs = _.pick(configResp, this.requiredFields);
+ this.configResp = _.pick(configResp, this.requiredFields);
this.createConfigForm();
- this.configForm.setValue(configs);
+ this.configForm.setValue(this.configResp);
this.loading = false;
},
(_error) => {
return result;
}
- private updateChannelsInReport(updatedConfig: Object = {}) {
- const channels: string[] = this.report['report']['channels'];
+ private updateReportFromConfig(updatedConfig: Object = {}) {
+ // update channels
const availableChannels: string[] = this.report['report']['channels_available'];
const updatedChannels = [];
for (const channel of availableChannels) {
const key = `channel_${channel}`;
- // channel unchanged or toggled on
- if (
- (!updatedConfig.hasOwnProperty(key) && channels.includes(channel)) ||
- updatedConfig[key]
- ) {
+ if (updatedConfig[key]) {
updatedChannels.push(channel);
}
}
this.report['report']['channels'] = updatedChannels;
+ // update contactInfo
+ for (const contactInfofield of this.contactInfofields) {
+ this.report['report'][contactInfofield] = updatedConfig[contactInfofield];
+ }
}
private getReport() {
(resp: object) => {
this.report = resp;
this.reportId = resp['report']['report_id'];
- this.updateChannelsInReport(this.updatedConfig);
+ this.updateReportFromConfig(this.newConfig);
this.createPreviewForm();
this.loading = false;
this.step++;
this.showContactInfo = !this.showContactInfo;
}
- updateConfig() {
- this.updatedConfig = {};
+ buildReport() {
+ this.newConfig = {};
for (const option of Object.values(this.options)) {
const control = this.configForm.get(option.name);
- if (!control.valid) {
+ // Append the option only if they are valid
+ if (control.valid) {
+ this.newConfig[option.name] = control.value;
+ } else {
this.configForm.setErrors({ cdSubmitButton: true });
return;
}
- // Append the option only if the value has been modified.
- if (control.dirty && control.valid) {
- this.updatedConfig[option.name] = control.value;
+ }
+ // reset contact info field if ident channel is off
+ if (!this.newConfig['channel_ident']) {
+ for (const contactInfofield of this.contactInfofields) {
+ this.newConfig[contactInfofield] = '';
}
}
this.getReport();
}
next() {
- if (this.configForm.pristine) {
- this.getReport();
- } else {
- this.updateConfig();
- }
+ this.buildReport();
}
back() {
this.step--;
}
+ getChangedConfig() {
+ const updatedConfig = {};
+ _.forEach(this.requiredFields, (configField) => {
+ if (!_.isEqual(this.configResp[configField], this.newConfig[configField])) {
+ updatedConfig[configField] = this.newConfig[configField];
+ }
+ });
+ return updatedConfig;
+ }
+
onSubmit() {
+ const updatedConfig = this.getChangedConfig();
const observables = [
this.telemetryService.enable(),
- this.mgrModuleService.updateConfig('telemetry', this.updatedConfig)
+ this.mgrModuleService.updateConfig('telemetry', updatedConfig)
];
observableForkJoin(observables).subscribe(
this.previewForm.setErrors({ cdSubmitButton: true });
},
() => {
- this.updatedConfig = {};
+ this.newConfig = {};
this.router.navigate(['']);
}
);