diff --git a/new/src/ReportFilter.test.ts b/new/src/ReportFilter.test.ts index 0f462cd9..a8d8db8f 100644 --- a/new/src/ReportFilter.test.ts +++ b/new/src/ReportFilter.test.ts @@ -27,29 +27,27 @@ describe("Report filter status filter", () => { test("should filter by status", () => { jest.spyOn(repository, "getReport").mockReturnValue(fullReport); - expect(filterByStatus(ScenarioStatusFilter.SUCCESS) - .flatMap(rep => rep.scenarios)) + expect(filterByStatus(ScenarioStatusFilter.SUCCESS)) .toEqual([fullReport.scenarios[0].scenarios[0]]); }); test("should ignore null status", () => { jest.spyOn(repository, "getReport").mockReturnValue(fullReport); - expect(filterByStatus(ScenarioStatusFilter.SUCCESS, null) - .flatMap(rep => rep.scenarios)) + expect(filterByStatus(ScenarioStatusFilter.SUCCESS, null)) .toEqual([fullReport.scenarios[0].scenarios[0]]); }); test('should return the full report if no status is provided', () => { jest.spyOn(repository, "getReport").mockReturnValue(fullReport); - expect(filterByStatus()).toEqual(fullReport.scenarios); + expect(filterByStatus()).toEqual(fullReport.scenarios.flatMap(s => s.scenarios)); }); test('should return the full report if null is provided', () => { jest.spyOn(repository, "getReport").mockReturnValue(fullReport); - expect(filterByStatus(null)).toEqual(fullReport.scenarios); + expect(filterByStatus(null)).toEqual(fullReport.scenarios.flatMap(s => s.scenarios)); }); }); diff --git a/new/src/ReportFilter.ts b/new/src/ReportFilter.ts index ac48ba5e..c8f57323 100644 --- a/new/src/ReportFilter.ts +++ b/new/src/ReportFilter.ts @@ -1,21 +1,19 @@ import {repository} from "./repository"; -import ReportModel from "./reportModel"; +import ReportModel, {ScenarioModel} from "./reportModel"; import {ScenarioStatusFilter} from "./components/ScenarioOverview/ScenarioCollectionHead"; -export function filterByStatus(...statusParameter: (ScenarioStatusFilter | null)[]): ReportModel[] { +export function filterByStatus(...statusParameter: (ScenarioStatusFilter | null)[]): ScenarioModel[] { const fullReport = repository.getReport(); const status = statusParameter .filter(status => status !== null) .map(s => s as ScenarioStatusFilter); - if (status.length === 0) { - return fullReport.scenarios; - } + const filteredReports = status.length === 0 ? fullReport.scenarios : filterReportByScenarioStatus(fullReport.scenarios, ...status); - return filterScenarios(fullReport.scenarios, ...status); + return filteredReports.flatMap(report => report.scenarios); } -function filterScenarios(reports: ReportModel[], ...status: ScenarioStatusFilter[]) { +function filterReportByScenarioStatus(reports: ReportModel[], ...status: ScenarioStatusFilter[]) { const filteredReports = []; for (const report of reports) { const filteredScenarios = report.scenarios.filter( diff --git a/new/src/components/Scenarios/ScenarioOverview.tsx b/new/src/components/Scenarios/ScenarioOverview.tsx index b79d4e36..798b8779 100644 --- a/new/src/components/Scenarios/ScenarioOverview.tsx +++ b/new/src/components/Scenarios/ScenarioOverview.tsx @@ -1,14 +1,10 @@ -import { ReportStatistics, ScenarioModel } from "../../reportModel"; -import { - MenuBar, - ScenarioCollectionHead, - ScenarioStatusFilter -} from "../ScenarioOverview/ScenarioCollectionHead"; -import { Scenario } from "./Scenario"; -import { useState } from "react"; -import { Grid } from "@mui/material"; -import { filterByStatus } from "../../ReportFilter"; -import { useSearchParams } from "react-router-dom"; +import {ReportStatistics, ScenarioModel} from "../../reportModel"; +import {MenuBar, ScenarioCollectionHead, ScenarioStatusFilter} from "../ScenarioOverview/ScenarioCollectionHead"; +import {Scenario} from "./Scenario"; +import {useState} from "react"; +import {Grid} from "@mui/material"; +import {filterByStatus} from "../../ReportFilter"; +import {useSearchParams} from "react-router-dom"; export enum ExpansionState { COLLAPSED, @@ -64,8 +60,8 @@ export function ScenarioOverview(props: {