diff --git a/new/src/components/Scenarios/StatisticsBreadcrumbs.tsx b/new/src/components/Scenarios/StatisticsBreadcrumbs.tsx index 3c807eee..4bbdba26 100644 --- a/new/src/components/Scenarios/StatisticsBreadcrumbs.tsx +++ b/new/src/components/Scenarios/StatisticsBreadcrumbs.tsx @@ -8,11 +8,11 @@ import { addRuntimeInSeconds } from "../utils"; import { ScenarioStatusFilter } from "../ScenarioOverview/ScenarioCollectionHead"; import { ReportStatistics } from "../../reportModel"; -export interface StatisticsBreadcrumbProps { +export interface statisticsBreadcrumbProps { statistic: ReportStatistics; } -export function StatisticBreadcrumbs({ statistic }: StatisticsBreadcrumbProps) { +export function StatisticBreadcrumbs({ statistic }: statisticsBreadcrumbProps) { const { setUrlSearchParams } = useFilters(); return ( diff --git a/new/src/components/Scenarios/__test__/StatisticsBreadcrumbs.test.tsx b/new/src/components/Scenarios/__test__/StatisticsBreadcrumbs.test.tsx new file mode 100644 index 00000000..d2950814 --- /dev/null +++ b/new/src/components/Scenarios/__test__/StatisticsBreadcrumbs.test.tsx @@ -0,0 +1,63 @@ +import { createReportStatistics } from "./scenarioTestData"; +import { StatisticBreadcrumbs } from "../StatisticsBreadcrumbs"; +import { render, screen } from "@testing-library/react"; +import { MemoryRouter } from "react-router-dom"; + +describe("StatisticsBreadcrumbs", () => { + it("should display statistics", () => { + const numSuccessfulScenarios = 1; + const numFailedScenarios = 2; + const numPendingScenarios = 3; + const numScenarios = 4; + const statistic = createReportStatistics({ + numSuccessfulScenarios, + numFailedScenarios, + numPendingScenarios, + numScenarios + }); + + render( + + + + ); + + expect(screen.getByText(`${numSuccessfulScenarios} Successful,`)).toBeVisible(); + expect(screen.getByText(`${numFailedScenarios} failed,`)).toBeVisible(); + expect(screen.getByText(`${numPendingScenarios} pending,`)).toBeVisible(); + expect(screen.getByText(`${numScenarios} Total`)).toBeVisible(); + }); + + it.each([ + [1e7 + 1, "(0.010s)"], + [1e9, "(1.000s)"], + [234123455532, "(234.123s)"] + ])( + "should display the runtime in seconds if durationInNanos = %s", + (durationInNanos, expectedDisplayValue) => { + const statistic = createReportStatistics({ durationInNanos }); + render( + + + + ); + + expect(screen.getByText(expectedDisplayValue)).toBeVisible(); + } + ); + + it.each([[-1e16], [0], [100], [1e7]])( + "should not display the duration if durationInNanos = %s", + durationInNanos => { + const statistic = createReportStatistics({ durationInNanos }); + render( + + + + ); + + expect(screen.queryByText("(", { exact: false })).not.toBeInTheDocument(); + expect(screen.queryByText(")", { exact: false })).not.toBeInTheDocument(); + } + ); +}); diff --git a/new/src/components/Scenarios/__test__/scenarioTestData.ts b/new/src/components/Scenarios/__test__/scenarioTestData.ts index 640baa8a..a2352448 100644 --- a/new/src/components/Scenarios/__test__/scenarioTestData.ts +++ b/new/src/components/Scenarios/__test__/scenarioTestData.ts @@ -1,4 +1,20 @@ -import { ScenarioCaseModel, ScenarioModel, StepModel, Word } from "../../../reportModel"; +import { + ReportStatistics, + ScenarioCaseModel, + ScenarioModel, + StepModel, + Word +} from "../../../reportModel"; + +export function createReportStatistics(props?: Partial): ReportStatistics { + return { + numScenarios: props?.numScenarios ?? 1, + numFailedScenarios: props?.numFailedScenarios ?? 2, + durationInNanos: props?.durationInNanos ?? 1000, + numPendingScenarios: props?.numPendingScenarios ?? 3, + numSuccessfulScenarios: props?.numSuccessfulScenarios ?? 4 + }; +} export function createWord(props?: Partial): Word { return {