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

Increase test coverage #109

Merged
merged 3 commits into from
Aug 27, 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
6,467 changes: 5,281 additions & 1,186 deletions new/package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions new/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"react-dom": "^18.2.0",
"react-i18next": "^14.0.1",
"react-router-dom": "^6.22.2",
"react-scripts": "5.0.1",
"typescript": "^4.9.3",
"web-vitals": "^2.1.4"
"web-vitals": "^2.1.4",
"nth-check": "^2.1.1"
},
"scripts": {
"start": "react-scripts start",
Expand Down Expand Up @@ -71,6 +71,7 @@
]
},
"devDependencies": {
"react-scripts": "5.0.1",
"prettier": "3.2.5"
}
}
92 changes: 28 additions & 64 deletions new/src/components/ScenarioOverview/ScenarioCollectionHead.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,22 @@
import type { ReportStatistics } from "../../reportModel";
import {
Breadcrumbs,
Divider,
Grid,
Link,
List,
ListItem,
ListItemText,
Typography
} from "@mui/material";
import CheckIcon from "@mui/icons-material/CheckBox";
import ErrorIcon from "@mui/icons-material/Error";
import DoNotDisturbAltIcon from "@mui/icons-material/DoNotDisturbAlt";
import type { ReportStatistics, ScenarioModel } from "../../reportModel";
import { Divider, Grid, Link, List, ListItem, ListItemText, Typography } from "@mui/material";
import RemoveIcon from "@mui/icons-material/Remove";
import AddIcon from "@mui/icons-material/Add";
import PrintOutlinedIcon from "@mui/icons-material/PrintOutlined";
import BookmarkOutlinedIcon from "@mui/icons-material/BookmarkOutlined";
import { createReportCircle } from "./DonutChart";
import { PropsWithChildren } from "react";
import { PropsWithChildren, useMemo } from "react";
import { processWords } from "../../wordProcessor";
import {
StyledContent,
StyledDrawer,
StyledIconButton,
StyledIconContainer,
StyledLink
StyledIconContainer
} from "./ScenarioHead.styles";
import { useFilters } from "../../hooks/useFilters";
import { addRuntimeInSeconds } from "../utils";

export enum HeaderIconType {}
import { StatisticBreadcrumbs } from "../Scenarios/StatisticsBreadcrumbs";

export interface ScenarioOverviewProps {
statistic: ReportStatistics;
export interface ScenarioCollectionHeadProps {
scenarios: ScenarioModel[];
onCollapseButtonClick: () => void;
onExpandButtonClick: () => void;
onPrintButtonClick: () => void;
Expand All @@ -46,8 +30,10 @@ interface Headers {
belowHeader?: string;
}

export function ScenarioCollectionHead(props: ScenarioOverviewProps) {
const { statistic, headers, ...iconClickHandlers } = props;
export function ScenarioCollectionHead(props: ScenarioCollectionHeadProps) {
const { scenarios, headers, ...iconClickHandlers } = props;

const statistic = useMemo(() => createStatistics(scenarios), [scenarios]);

return (
<div style={{ display: "flex" }}>
Expand All @@ -64,15 +50,15 @@ export function ScenarioCollectionHead(props: ScenarioOverviewProps) {
<ScenarioTitles headers={headers} />
</Grid>
<Grid item sx={{ flexGrow: 1 }} />
<Grid item>{createReportCircle(props)}</Grid>
<Grid item>{createReportCircle({ statistic })}</Grid>
<Grid item>
<ScenarioActionButtons {...iconClickHandlers} />
</Grid>
</Grid>
</ListItem>
<Divider />
<ListItem>
<ListItemText primary={StatisticBreadcrumbs(props)} />
<ListItemText primary={StatisticBreadcrumbs({ statistic })} />
</ListItem>
<ListItem>
<canvas id={"symbol-canvas"} width={"50"} height={"2"} />
Expand Down Expand Up @@ -204,42 +190,20 @@ export enum ScenarioStatusFilter {
PENDING = "PENDING"
}

function StatisticBreadcrumbs(props: { statistic: ReportStatistics }) {
const { setUrlSearchParams } = useFilters();

return (
<Breadcrumbs separator=" " aria-label="breadcrumb">
<StyledLink
aria-label="filter-for-successful-tests"
underline="hover"
color={"black"}
onClick={() => setUrlSearchParams({ status: ScenarioStatusFilter.SUCCESS })}
>
<CheckIcon sx={{ mr: 0.5 }} fontSize={"small"} />
{props.statistic.numSuccessfulScenarios} Successful,
</StyledLink>
<StyledLink
aria-label="filter-for-failed-tests"
underline="hover"
color={"red"}
onClick={() => setUrlSearchParams({ status: ScenarioStatusFilter.FAILED })}
>
<ErrorIcon sx={{ mr: 0.5 }} fontSize={"small"} />
{props.statistic.numFailedScenarios} failed,
</StyledLink>
<StyledLink
aria-label="filter-for-pending-tests"
underline="hover"
color={"grey"}
onClick={() => setUrlSearchParams({ status: ScenarioStatusFilter.PENDING })}
>
<DoNotDisturbAltIcon sx={{ mr: 0.5 }} fontSize={"small"} />
{props.statistic.numPendingScenarios} pending,
</StyledLink>
<Typography color="text.primary">{props.statistic.numScenarios} Total</Typography>
<Typography color={"text.primary"}>
{addRuntimeInSeconds(props.statistic.durationInNanos)}
</Typography>
</Breadcrumbs>
function createStatistics(scenarios: ScenarioModel[]): ReportStatistics {
const allCases = scenarios.flatMap(scenario => scenario.scenarioCases);
const failedScenarios = scenarios.filter(scenario => scenario.executionStatus === "FAILED");
const pendingScenarios = scenarios.filter(scenario => scenario.executionStatus === "PENDING");
const successfulScenarios = scenarios.filter(
scenario => scenario.executionStatus === "SUCCESS"
);
return {
numScenarios: scenarios.length,
numFailedScenarios: failedScenarios.length,
durationInNanos: allCases
.map(scenarioCase => scenarioCase.durationInNanos)
.reduce((totalDuration, current) => totalDuration + current),
numPendingScenarios: pendingScenarios.length,
numSuccessfulScenarios: successfulScenarios.length
};
}
22 changes: 2 additions & 20 deletions new/src/components/Scenarios/ScenarioOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReportStatistics, ScenarioModel } from "../../reportModel";
import { ScenarioModel } from "../../reportModel";
import { MenuBar, ScenarioCollectionHead } from "../ScenarioOverview/ScenarioCollectionHead";
import { Scenario } from "./Scenario";
import { useState } from "react";
Expand Down Expand Up @@ -41,7 +41,7 @@ export function ScenarioOverview(props: {
aboveHeader: props.description,
header: props.title
}}
statistic={createStatistics(scenarios)}
scenarios={scenarios}
onCollapseButtonClick={() => {
setAllExpanded(ExpansionState.COLLAPSED);
}}
Expand Down Expand Up @@ -82,24 +82,6 @@ export function ScenarioOverview(props: {
);
}

function createStatistics(scenarios: ScenarioModel[]): ReportStatistics {
const allCases = scenarios.flatMap(scenario => scenario.scenarioCases);
const failedScenarios = scenarios.filter(scenario => scenario.executionStatus === "FAILED");
const pendingScenarios = scenarios.filter(scenario => scenario.executionStatus === "PENDING");
const successfulScenarios = scenarios.filter(
scenario => scenario.executionStatus === "SUCCESS"
);
return {
numScenarios: scenarios.length,
numFailedScenarios: failedScenarios.length,
durationInNanos: allCases
.map(scenarioCase => scenarioCase.durationInNanos)
.reduce((totalDuration, current) => totalDuration + current),
numPendingScenarios: pendingScenarios.length,
numSuccessfulScenarios: successfulScenarios.length
};
}

const compareByClassTitleAndDescriptionFn = (a: ScenarioModel, b: ScenarioModel) => {
const sortValueByClassTitle = a.classTitle.localeCompare(b.classTitle);
if (sortValueByClassTitle === 0) {
Expand Down
53 changes: 53 additions & 0 deletions new/src/components/Scenarios/StatisticsBreadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useFilters } from "../../hooks/useFilters";
import { Breadcrumbs, Typography } from "@mui/material";
import { StyledLink } from "../ScenarioOverview/ScenarioHead.styles";
import CheckIcon from "@mui/icons-material/CheckBox";
import ErrorIcon from "@mui/icons-material/Error";
import DoNotDisturbAltIcon from "@mui/icons-material/DoNotDisturbAlt";
import { addRuntimeInSeconds } from "../utils";
import { ScenarioStatusFilter } from "../ScenarioOverview/ScenarioCollectionHead";
import { ReportStatistics } from "../../reportModel";

export interface statisticsBreadcrumbProps {
statistic: ReportStatistics;
}

export function StatisticBreadcrumbs({ statistic }: statisticsBreadcrumbProps) {
const { setUrlSearchParams } = useFilters();

return (
<Breadcrumbs separator=" " aria-label="breadcrumb">
<StyledLink
aria-label="filter-for-successful-tests"
underline="hover"
color={"black"}
onClick={() => setUrlSearchParams({ status: ScenarioStatusFilter.SUCCESS })}
>
<CheckIcon sx={{ mr: 0.5 }} fontSize={"small"} />
{statistic.numSuccessfulScenarios} Successful,
</StyledLink>
<StyledLink
aria-label="filter-for-failed-tests"
underline="hover"
color={"red"}
onClick={() => setUrlSearchParams({ status: ScenarioStatusFilter.FAILED })}
>
<ErrorIcon sx={{ mr: 0.5 }} fontSize={"small"} />
{statistic.numFailedScenarios} failed,
</StyledLink>
<StyledLink
aria-label="filter-for-pending-tests"
underline="hover"
color={"grey"}
onClick={() => setUrlSearchParams({ status: ScenarioStatusFilter.PENDING })}
>
<DoNotDisturbAltIcon sx={{ mr: 0.5 }} fontSize={"small"} />
{statistic.numPendingScenarios} pending,
</StyledLink>
<Typography color="text.primary">{statistic.numScenarios} Total</Typography>
<Typography color={"text.primary"}>
{addRuntimeInSeconds(statistic.durationInNanos)}
</Typography>
</Breadcrumbs>
);
}
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
Loading