From 813759357c7fa0435803d0a7e9a5a2ab48d45890 Mon Sep 17 00:00:00 2001 From: Sofia Kurilova Date: Tue, 4 Jun 2024 09:43:07 +0000 Subject: [PATCH] Updates status with data from start response (#494) --- .../pages/devices/devices.component.spec.ts | 7 ++++++- .../app/pages/devices/devices.component.ts | 5 +++-- .../app/pages/devices/devices.store.spec.ts | 19 +++++++++++++++++- .../ui/src/app/pages/devices/devices.store.ts | 20 ++++++++++++++++++- .../testrun-initiate-form.component.html | 2 +- .../testrun-initiate-form.component.spec.ts | 5 +++-- .../testrun-initiate-form.component.ts | 9 +++++---- .../pages/testrun/testrun.component.spec.ts | 14 ++++++++++--- .../app/pages/testrun/testrun.component.ts | 6 +++--- .../app/pages/testrun/testrun.store.spec.ts | 13 ++++++++++++ .../ui/src/app/pages/testrun/testrun.store.ts | 12 +++++++++++ .../src/app/services/test-run.service.spec.ts | 4 ++-- .../ui/src/app/services/test-run.service.ts | 12 +++++------ 13 files changed, 101 insertions(+), 27 deletions(-) diff --git a/modules/ui/src/app/pages/devices/devices.component.spec.ts b/modules/ui/src/app/pages/devices/devices.component.spec.ts index 26fcda197..d463fcbec 100644 --- a/modules/ui/src/app/pages/devices/devices.component.spec.ts +++ b/modules/ui/src/app/pages/devices/devices.component.spec.ts @@ -41,6 +41,7 @@ import { Routes } from '../../model/routes'; import { Router } from '@angular/router'; import { RouterTestingModule } from '@angular/router/testing'; import { Component } from '@angular/core'; +import { MOCK_PROGRESS_DATA_IN_PROGRESS } from '../../mocks/testrun.mock'; describe('DevicesComponent', () => { let component: DevicesComponent; @@ -59,6 +60,7 @@ describe('DevicesComponent', () => { 'setIsOpenAddDevice', 'selectDevice', 'deleteDevice', + 'setStatus', ]); mockDevicesStore.testModules = MOCK_TEST_MODULES; @@ -299,7 +301,7 @@ describe('DevicesComponent', () => { describe('#openStartTestrun', () => { it('should open initiate test run modal', fakeAsync(() => { const openSpy = spyOn(component.dialog, 'open').and.returnValue({ - afterClosed: () => of(true), + afterClosed: () => of(MOCK_PROGRESS_DATA_IN_PROGRESS), } as MatDialogRef); fixture.ngZone?.run(() => { @@ -319,6 +321,9 @@ describe('DevicesComponent', () => { tick(); expect(router.url).toBe(Routes.Testing); + expect(mockDevicesStore.setStatus).toHaveBeenCalledWith( + MOCK_PROGRESS_DATA_IN_PROGRESS + ); openSpy.calls.reset(); }); diff --git a/modules/ui/src/app/pages/devices/devices.component.ts b/modules/ui/src/app/pages/devices/devices.component.ts index d8c840a5f..1476de6fc 100644 --- a/modules/ui/src/app/pages/devices/devices.component.ts +++ b/modules/ui/src/app/pages/devices/devices.component.ts @@ -91,8 +91,9 @@ export class DevicesComponent implements OnInit, OnDestroy { dialogRef ?.afterClosed() .pipe(takeUntil(this.destroy$)) - .subscribe(testrunStarted => { - if (testrunStarted) { + .subscribe(status => { + if (status) { + this.devicesStore.setStatus(status); // @ts-expect-error data layer is not null window.dataLayer.push({ event: 'successful_testrun_initiation', diff --git a/modules/ui/src/app/pages/devices/devices.store.spec.ts b/modules/ui/src/app/pages/devices/devices.store.spec.ts index 0cf340b32..4d2f1bd20 100644 --- a/modules/ui/src/app/pages/devices/devices.store.spec.ts +++ b/modules/ui/src/app/pages/devices/devices.store.spec.ts @@ -24,9 +24,14 @@ import { import { TestRunService } from '../../services/test-run.service'; import SpyObj = jasmine.SpyObj; import { device, updated_device } from '../../mocks/device.mock'; -import { setDevices, setIsOpenAddDevice } from '../../store/actions'; +import { + fetchSystemStatusSuccess, + setDevices, + setIsOpenAddDevice, +} from '../../store/actions'; import { selectDevices, selectIsOpenAddDevice } from '../../store/selectors'; import { DevicesStore } from './devices.store'; +import { MOCK_PROGRESS_DATA_IN_PROGRESS } from '../../mocks/testrun.mock'; describe('DevicesStore', () => { let devicesStore: DevicesStore; @@ -183,5 +188,17 @@ describe('DevicesStore', () => { ); }); }); + + describe('setStatus', () => { + it('should dispatch action fetchSystemStatusSuccess', () => { + devicesStore.setStatus(MOCK_PROGRESS_DATA_IN_PROGRESS); + + expect(store.dispatch).toHaveBeenCalledWith( + fetchSystemStatusSuccess({ + systemStatus: MOCK_PROGRESS_DATA_IN_PROGRESS, + }) + ); + }); + }); }); }); diff --git a/modules/ui/src/app/pages/devices/devices.store.ts b/modules/ui/src/app/pages/devices/devices.store.ts index 58cc131fd..282275f7d 100644 --- a/modules/ui/src/app/pages/devices/devices.store.ts +++ b/modules/ui/src/app/pages/devices/devices.store.ts @@ -27,7 +27,12 @@ import { selectDevices, selectIsOpenAddDevice, } from '../../store/selectors'; -import { setDevices, setIsOpenAddDevice } from '../../store/actions'; +import { + fetchSystemStatusSuccess, + setDevices, + setIsOpenAddDevice, +} from '../../store/actions'; +import { TestrunStatus } from '../../model/testrun-status'; export interface DevicesComponentState { devices: Device[]; @@ -111,6 +116,19 @@ export class DevicesStore extends ComponentStore { ) ); }); + + setStatus = this.effect(status$ => { + return status$.pipe( + tap(status => { + this.store.dispatch( + fetchSystemStatusSuccess({ + systemStatus: status, + }) + ); + }) + ); + }); + private addDevice(device: Device, devices: Device[]): void { this.updateDevices(devices.concat([device])); } diff --git a/modules/ui/src/app/pages/testrun/components/testrun-initiate-form/testrun-initiate-form.component.html b/modules/ui/src/app/pages/testrun/components/testrun-initiate-form/testrun-initiate-form.component.html index 02fa4f2f8..c576d242e 100644 --- a/modules/ui/src/app/pages/testrun/components/testrun-initiate-form/testrun-initiate-form.component.html +++ b/modules/ui/src/app/pages/testrun/components/testrun-initiate-form/testrun-initiate-form.component.html @@ -78,7 +78,7 @@ type="button"> Change Device -