From 9ced8e597a2491e2de59b2a244000c3fd64fd0f9 Mon Sep 17 00:00:00 2001 From: kurilova Date: Wed, 17 Jul 2024 09:25:00 +0000 Subject: [PATCH] Get reports when app is opened and when report page is opened; change status if testrun does not exist in reports; do not change status if testrun is just finished but not in reports yet --- .../pages/reports/reports.component.spec.ts | 7 ++++ .../app/pages/reports/reports.component.ts | 1 + .../ui/src/app/pages/reports/reports.store.ts | 11 +++++- modules/ui/src/app/store/effects.spec.ts | 11 +++--- modules/ui/src/app/store/effects.ts | 35 +++++++++++-------- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/modules/ui/src/app/pages/reports/reports.component.spec.ts b/modules/ui/src/app/pages/reports/reports.component.spec.ts index 0e0fc7b1a..580b3a5c4 100644 --- a/modules/ui/src/app/pages/reports/reports.component.spec.ts +++ b/modules/ui/src/app/pages/reports/reports.component.spec.ts @@ -87,6 +87,7 @@ describe('ReportsComponent', () => { 'setFilterOpened', 'updateSort', 'getHistory', + 'getReports', ]); mockLiveAnnouncer = jasmine.createSpyObj(['announce']); @@ -119,6 +120,12 @@ describe('ReportsComponent', () => { expect(mockReportsStore.updateSort).toHaveBeenCalledWith(sort); })); + + it('should get reports', fakeAsync(() => { + component.ngOnInit(); + + expect(mockReportsStore.getReports).toHaveBeenCalled(); + })); }); it('#sortData should call update sort', () => { diff --git a/modules/ui/src/app/pages/reports/reports.component.ts b/modules/ui/src/app/pages/reports/reports.component.ts index 9d5a5914d..5531bb42c 100644 --- a/modules/ui/src/app/pages/reports/reports.component.ts +++ b/modules/ui/src/app/pages/reports/reports.component.ts @@ -56,6 +56,7 @@ export class ReportsComponent implements OnInit, OnDestroy { ) {} ngOnInit() { + this.store.getReports(); this.store.updateSort(this.sort); } diff --git a/modules/ui/src/app/pages/reports/reports.store.ts b/modules/ui/src/app/pages/reports/reports.store.ts index cb1c98fb7..249a4174a 100644 --- a/modules/ui/src/app/pages/reports/reports.store.ts +++ b/modules/ui/src/app/pages/reports/reports.store.ts @@ -11,7 +11,7 @@ import { MatSort } from '@angular/material/sort'; import { selectReports, selectRiskProfiles } from '../../store/selectors'; import { Store } from '@ngrx/store'; import { AppState } from '../../store/state'; -import { setReports } from '../../store/actions'; +import { fetchReports, setReports } from '../../store/actions'; export interface ReportsComponentState { displayedColumns: string[]; @@ -205,6 +205,15 @@ export class ReportsStore extends ComponentStore { }) ); }); + + getReports = this.effect(trigger$ => { + return trigger$.pipe( + tap(() => { + this.store.dispatch(fetchReports()); + }) + ); + }); + private removeReport( mac_addr: string, started: string | null, diff --git a/modules/ui/src/app/store/effects.spec.ts b/modules/ui/src/app/store/effects.spec.ts index 8d7f8c225..17b5c2d07 100644 --- a/modules/ui/src/app/store/effects.spec.ts +++ b/modules/ui/src/app/store/effects.spec.ts @@ -552,14 +552,15 @@ describe('Effects', () => { describe('checkStatusInReports$', () => { it('should call setTestrunStatus if current test run is completed and not present in reports', done => { + store.overrideSelector( + selectSystemStatus, + Object.assign({}, MOCK_PROGRESS_DATA_COMPLIANT, { + mac_addr: '01:02:03:04:05:07', + }) + ); actions$ = of( actions.setReports({ reports: HISTORY, - }), - actions.fetchSystemStatusSuccess({ - systemStatus: Object.assign({}, MOCK_PROGRESS_DATA_COMPLIANT, { - mac_addr: '01:02:03:04:05:07', - }), }) ); diff --git a/modules/ui/src/app/store/effects.ts b/modules/ui/src/app/store/effects.ts index 350380b16..0a58035fa 100644 --- a/modules/ui/src/app/store/effects.ts +++ b/modules/ui/src/app/store/effects.ts @@ -309,31 +309,36 @@ export class AppEffects { ); }); - checkStatusInReports$ = createEffect(() => - combineLatest([ - this.actions$.pipe(ofType(AppActions.setReports)), - this.actions$.pipe(ofType(AppActions.fetchSystemStatusSuccess)), - ]).pipe( - filter(([, { systemStatus }]) => { + checkStatusInReports$ = createEffect(() => { + return this.actions$.pipe( + ofType(AppActions.setReports), + withLatestFrom(this.store.select(selectSystemStatus)), + filter(([, systemStatus]) => { return ( - systemStatus.status === StatusOfTestrun.Compliant || - systemStatus.status === StatusOfTestrun.NonCompliant || - systemStatus.status === StatusOfTestrun.Error + systemStatus != null && this.isTestrunFinished(systemStatus.status) ); }), - filter(([{ reports }, { systemStatus }]) => { + filter(([{ reports }, systemStatus]) => { return ( !reports?.some( report => - report.report === systemStatus.report && - report.started === systemStatus.started && - report.finished === systemStatus.finished + report.report === systemStatus!.report && + report.started === systemStatus!.started && + report.finished === systemStatus!.finished ) || false ); }), map(() => AppActions.setTestrunStatus({ systemStatus: IDLE_STATUS })) - ) - ); + ); + }); + + private isTestrunFinished(status: string) { + return ( + status === StatusOfTestrun.Compliant || + status === StatusOfTestrun.NonCompliant || + status === StatusOfTestrun.Error + ); + } private showSnackBar() { timer(WAIT_TO_OPEN_SNACKBAR_MS)