Skip to content

Commit

Permalink
Added tests for StatisticsBreadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Schüler committed Aug 26, 2024
1 parent 39cbe29 commit d52f441
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
4 changes: 2 additions & 2 deletions new/src/components/Scenarios/StatisticsBreadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
<MemoryRouter>
<StatisticBreadcrumbs statistic={statistic} />
</MemoryRouter>
);

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(
<MemoryRouter>
<StatisticBreadcrumbs statistic={statistic} />
</MemoryRouter>
);

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(
<MemoryRouter>
<StatisticBreadcrumbs statistic={statistic} />
</MemoryRouter>
);

expect(screen.queryByText("(", { exact: false })).not.toBeInTheDocument();
expect(screen.queryByText(")", { exact: false })).not.toBeInTheDocument();
}
);
});
18 changes: 17 additions & 1 deletion new/src/components/Scenarios/__test__/scenarioTestData.ts
Original file line number Diff line number Diff line change
@@ -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>): 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>): Word {
return {
Expand Down

0 comments on commit d52f441

Please sign in to comment.