Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@
<app-device-tests
[deviceForm]="initiateForm"
[deviceTestModules]="selectedDevice.test_modules"
[disabled]="true"
[testModules]="testModules">
</app-device-tests>
</ng-container>
<mat-error *ngIf="error$ | async">
<span>{{ error$ | async }}</span>
</mat-error>
</section>

<mat-dialog-actions class="progress-initiate-form-actions">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,27 @@ describe('ProgressInitiateFormComponent', () => {
});
});

it('should not start if no test selected', () => {
component.firmware.setValue('firmware');
component.selectedDevice = device;
fixture.detectChanges();
component.test_modules.setValue([false, false]);

component.startTestRun();
fixture.detectChanges();

const error = compiled.querySelector('mat-error');
expect(error?.innerHTML).toContain(
'At least one test has to be selected to start test run.'
);
});

describe('when selectedDevice is present and firmware is filled', () => {
beforeEach(() => {
component.firmware.setValue('firmware');
component.selectedDevice = device;
fixture.detectChanges();
component.test_modules.setValue([true, true]);
});

it('should call startTestRun with device', () => {
Expand All @@ -193,6 +210,9 @@ describe('ProgressInitiateFormComponent', () => {
mac_addr: '00:1e:42:35:73:c4',
firmware: 'firmware',
test_modules: {
connection: {
enabled: true,
},
dns: {
enabled: true,
},
Expand Down Expand Up @@ -309,7 +329,7 @@ describe('ProgressInitiateFormComponent', () => {
const tests = compiled.querySelectorAll('.device-form-test-modules p');

expect(testsForm).toBeTruthy();
expect(tests[0].classList.contains('disabled')).toEqual(true);
expect(tests[0].classList.contains('disabled')).toEqual(false);
expect(tests.length).toEqual(2);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { take } from 'rxjs';
import { Store } from '@ngrx/store';
import { AppState } from '../../../../store/state';
import { selectDevices } from '../../../../store/selectors';
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';

interface DialogData {
device?: Device;
Expand All @@ -59,6 +60,9 @@ export class ProgressInitiateFormComponent
prevDevice: Device | null = null;
setFirmwareFocus = false;
readonly DeviceView = DeviceView;
error$: BehaviorSubject<string | null> = new BehaviorSubject<string | null>(
null
);

constructor(
public override dialogRef: MatDialogRef<ProgressInitiateFormComponent>,
Expand All @@ -76,6 +80,10 @@ export class ProgressInitiateFormComponent
return this.initiateForm.get('firmware') as AbstractControl;
}

get test_modules() {
return this.initiateForm.controls['test_modules'] as FormArray;
}

cancel(startTestrun: boolean): void {
this.dialogRef.close(startTestrun);
}
Expand Down Expand Up @@ -131,12 +139,29 @@ export class ProgressInitiateFormComponent
return;
}

if (this.isAllTestsDisabled()) {
this.error$.next(
'At least one test has to be selected to start test run.'
);
return;
}

const testModules: { [key: string]: { enabled: boolean } } = {};
this.initiateForm.value.test_modules.forEach(
(enabled: boolean, i: number) => {
testModules[this.testModules[i]?.name] = {
enabled: enabled,
};
}
);

if (this.selectedDevice) {
this.testRunService.fetchVersion();
this.testRunService
.startTestrun({
...this.selectedDevice,
firmware: this.firmware.value.trim(),
test_modules: testModules,
})
.pipe(take(1))
.subscribe(() => {
Expand All @@ -151,4 +176,10 @@ export class ProgressInitiateFormComponent
test_modules: new FormArray([]),
});
}

private isAllTestsDisabled(): boolean {
return this.initiateForm.value.test_modules.every((enabled: boolean) => {
return !enabled;
});
}
}
7 changes: 1 addition & 6 deletions modules/ui/src/app/services/test-run.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import {
TestrunStatus,
} from '../model/testrun-status';
import { Version } from '../model/version';
import { Store } from '@ngrx/store';
import { AppState } from '../store/state';
import { Certificate } from '../model/certificate';

const API_URL = `http://${window.location.hostname}:8000`;
Expand Down Expand Up @@ -80,10 +78,7 @@ export class TestRunService {

private version = new BehaviorSubject<Version | null>(null);

constructor(
private http: HttpClient,
private store: Store<AppState>
) {}
constructor(private http: HttpClient) {}

fetchDevices(): Observable<Device[]> {
return this.http.get<Device[]>(`${API_URL}/devices`);
Expand Down