Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Download PDF button is enabled for the latest test run on the Testing page if the report was deleted on the Reports page #613

Merged
merged 1 commit into from
Jul 17, 2024
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
7 changes: 7 additions & 0 deletions modules/ui/src/app/pages/reports/reports.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('ReportsComponent', () => {
'setFilterOpened',
'updateSort',
'getHistory',
'getReports',
]);
mockLiveAnnouncer = jasmine.createSpyObj(['announce']);

Expand Down Expand Up @@ -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', () => {
Expand Down
1 change: 1 addition & 0 deletions modules/ui/src/app/pages/reports/reports.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class ReportsComponent implements OnInit, OnDestroy {
) {}

ngOnInit() {
this.store.getReports();
this.store.updateSort(this.sort);
}

Expand Down
11 changes: 10 additions & 1 deletion modules/ui/src/app/pages/reports/reports.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -205,6 +205,15 @@ export class ReportsStore extends ComponentStore<ReportsComponentState> {
})
);
});

getReports = this.effect(trigger$ => {
return trigger$.pipe(
tap(() => {
this.store.dispatch(fetchReports());
})
);
});

private removeReport(
mac_addr: string,
started: string | null,
Expand Down
11 changes: 6 additions & 5 deletions modules/ui/src/app/store/effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
})
);

Expand Down
35 changes: 20 additions & 15 deletions modules/ui/src/app/store/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down