diff --git a/modules/ui/src/app/components/device-tests/device-tests.component.spec.ts b/modules/ui/src/app/components/device-tests/device-tests.component.spec.ts index 0599af372..b959bc1db 100644 --- a/modules/ui/src/app/components/device-tests/device-tests.component.spec.ts +++ b/modules/ui/src/app/components/device-tests/device-tests.component.spec.ts @@ -65,14 +65,14 @@ describe('DeviceTestsComponent', () => { }); it('should fill tests with device test values if device not present', () => { - component.deviceTestModules = { + fixture.componentRef.setInput('deviceTestModules', { connection: { enabled: false, }, dns: { enabled: true, }, - }; + }); component.ngOnInit(); expect(component.test_modules.controls[0].value).toEqual(false); diff --git a/modules/ui/src/app/components/device-tests/device-tests.component.ts b/modules/ui/src/app/components/device-tests/device-tests.component.ts index 5ad9d4336..a0df852e4 100644 --- a/modules/ui/src/app/components/device-tests/device-tests.component.ts +++ b/modules/ui/src/app/components/device-tests/device-tests.component.ts @@ -16,6 +16,8 @@ import { ChangeDetectionStrategy, Component, + effect, + input, Input, OnInit, } from '@angular/core'; @@ -39,11 +41,15 @@ import { MatCheckboxModule } from '@angular/material/checkbox'; }) export class DeviceTestsComponent implements OnInit { @Input() deviceForm!: FormGroup; - @Input() deviceTestModules?: TestModules | null; @Input() testModules: TestModule[] = []; // For initiate test run form tests should be displayed and disabled for change @Input() disabled = false; + deviceTestModules = input(); + deviceTestModulesEffect = effect(() => { + this.fillTestModulesFormControls(); + }); + get test_modules() { return this.deviceForm?.controls['test_modules'] as FormArray; } @@ -54,11 +60,12 @@ export class DeviceTestsComponent implements OnInit { fillTestModulesFormControls() { this.test_modules.controls = []; - if (this.deviceTestModules) { + if (this.deviceTestModules()) { this.testModules.forEach(test => { this.test_modules.push( new FormControl( - (this.deviceTestModules as TestModules)[test.name]?.enabled || false + (this.deviceTestModules() as TestModules)[test.name]?.enabled || + false ) ); }); diff --git a/modules/ui/src/app/pages/devices/components/device-qualification-from/device-qualification-from.component.ts b/modules/ui/src/app/pages/devices/components/device-qualification-from/device-qualification-from.component.ts index 899266123..eff9c63e8 100644 --- a/modules/ui/src/app/pages/devices/components/device-qualification-from/device-qualification-from.component.ts +++ b/modules/ui/src/app/pages/devices/components/device-qualification-from/device-qualification-from.component.ts @@ -107,6 +107,8 @@ export class DeviceQualificationFromComponent implements OnInit, OnDestroy { const device = this.initialDevice(); if (device && device.mac_addr) { this.fillDeviceForm(this.format, device); + } else { + this.resetForm(); } }); @@ -193,6 +195,12 @@ export class DeviceQualificationFromComponent implements OnInit, OnDestroy { this.delete.emit(this.initialDevice()!); } + resetForm() { + this.deviceQualificationForm.reset({ + test_pack: TestingType.Qualification, + }); + } + private fillDeviceForm(format: QuestionFormat[], device: Device): void { format.forEach((question, index) => { const answer = device.additional_info?.find(