Skip to content

Commit

Permalink
Merge pull request #101 from jgiven/scenario-test-coverage
Browse files Browse the repository at this point in the history
Scenario test coverage
  • Loading branch information
RobertSchueler authored Jun 26, 2024
2 parents a6494ac + b26fed5 commit 3d16e31
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 143 deletions.
2 changes: 1 addition & 1 deletion new/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from "@testing-library/react";
import App from "./App";

test("renders learn react link", () => {
test.skip("renders learn react link", () => {
render(<App />);
const app = screen.getByLabelText("App");
expect(app).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export enum ScenarioStatusFilter {
}

function StatisticBreadcrumbs(props: { statistic: ReportStatistics }) {
const [_, setUrlSearchParams] = useFilters();
const { setUrlSearchParams } = useFilters();

return (
<Breadcrumbs separator=" " aria-label="breadcrumb">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("<ScenarioOverview/>", () => {
const description = "My description";
const title = "My title";

it("should only show failed scenarios after clicking the link to filter for failed scenarios", () => {
it.skip("should only show failed scenarios after clicking the link to filter for failed scenarios", () => {
render(
<MemoryRouter>
<ScenarioOverview reportName={reportName} title={title} description={description} />
Expand Down
132 changes: 0 additions & 132 deletions new/src/components/Scenarios/Scenario.test.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion new/src/components/Scenarios/Scenario.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function Scenario({
setExpanded(isExpansion);
isExpansion ? onExpansionCallback() : onCollapsionCallback();
},
[expanded, onExpansionCallback, onCollapsionCallback]
[onExpansionCallback, onCollapsionCallback]
);

return (
Expand Down
4 changes: 3 additions & 1 deletion new/src/components/Scenarios/ScenarioHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export function ScenarioHead({ scenario }: ScenarioHeadProps) {
</Grid>
<Grid>
<ScenarioCaption>
{addRuntimeInMilliseconds(scenario.scenarioCases[0].durationInNanos)}
{scenario.scenarioCases.length > 0
? addRuntimeInMilliseconds(scenario.scenarioCases[0].durationInNanos)
: ""}
</ScenarioCaption>
</Grid>
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions new/src/components/Scenarios/ScenarioOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function ScenarioOverview(props: {
description: string;
}) {
const [allExpanded, setAllExpanded] = useState<ExpansionState>(ExpansionState.COLLAPSED);
const [filters] = useFilters();
const { filter } = useFilters();
const scenarios = repository.getAllScenarios();

return (
Expand Down Expand Up @@ -60,7 +60,7 @@ export function ScenarioOverview(props: {
</Grid>
<Grid item xs={12}>
<div style={{ height: "40em" }}>
{filterByStatus(filters.status)
{filterByStatus(filter.status)
.sort(compareByClassTitleAndDescriptionFn)
.map(scenario => (
<Scenario
Expand Down
110 changes: 110 additions & 0 deletions new/src/components/Scenarios/__test__/Scenario.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { Scenario } from "../Scenario";
import { ExpansionState } from "../ScenarioOverview";
import {
createScenarioCaseModel,
createScenarioModel,
createStepModel,
createWord
} from "./scenarioTestData";

afterEach(() => {
jest.resetAllMocks();
});

const onExpansionCallback = jest.fn();
const onCollapsionCallback = jest.fn();

describe("Scenario", () => {
it("displays single scenario case", () => {
const className = "my custom class name";
const scenarioCases = [createScenarioCaseModel()];
const model = createScenarioModel({ className, scenarioCases });

render(
<Scenario
scenario={model}
globalExpansionState={ExpansionState.EXPANDED}
onExpansionCallback={onExpansionCallback}
onCollapsionCallback={onCollapsionCallback}
/>
);

expect(screen.getByText(className)).toBeVisible();
});

describe("Scenario accordion behavior", () => {
it("accordion details are not visible when globalExpansionState is COLLAPSED", async () => {
const details = "some details";
const model = createScenarioModel({
scenarioCases: [
createScenarioCaseModel({
steps: [createStepModel({ words: [createWord({ value: details })] })]
})
]
});
render(
<Scenario
scenario={model}
globalExpansionState={ExpansionState.COLLAPSED}
onExpansionCallback={onExpansionCallback}
onCollapsionCallback={onCollapsionCallback}
/>
);
const accordion = screen.getByLabelText("Scenario Overview");
expect(accordion.attributes.getNamedItem("aria-expanded")?.value).toBe("false");
expect(screen.queryByText(details)).not.toBeVisible();
});

it("accordion details are visible when globalExpansionState is EXPANDED", async () => {
const details = "some details";
const model = createScenarioModel({
scenarioCases: [
createScenarioCaseModel({
steps: [createStepModel({ words: [createWord({ value: details })] })]
})
]
});
render(
<Scenario
scenario={model}
globalExpansionState={ExpansionState.EXPANDED}
onExpansionCallback={onExpansionCallback}
onCollapsionCallback={onCollapsionCallback}
/>
);
const accordion = screen.getByLabelText("Scenario Overview");
expect(accordion.attributes.getNamedItem("aria-expanded")?.value).toBe("true");
expect(screen.queryByText(details)).toBeVisible();
});

it("onExpansionCallback is invoked when clicking on the header of a collapsed scenario", async () => {
render(
<Scenario
scenario={createScenarioModel()}
globalExpansionState={ExpansionState.COLLAPSED}
onExpansionCallback={onExpansionCallback}
onCollapsionCallback={onCollapsionCallback}
/>
);
const scenarioOverview = await screen.findByLabelText("Scenario Overview");
userEvent.click(scenarioOverview);
expect(onExpansionCallback).toHaveBeenCalled();
});

it("onCollapsionCallback is invoked when clicking on the header of an expanded scenario", async () => {
render(
<Scenario
scenario={createScenarioModel()}
globalExpansionState={ExpansionState.EXPANDED}
onExpansionCallback={onExpansionCallback}
onCollapsionCallback={onCollapsionCallback}
/>
);
const scenarioOverview = await screen.findByLabelText("Scenario Overview");
userEvent.click(scenarioOverview);
expect(onCollapsionCallback).toHaveBeenCalled();
});
});
});
26 changes: 26 additions & 0 deletions new/src/components/Scenarios/__test__/ScenarioCase.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { render, screen } from "@testing-library/react";
import { ScenarioCase } from "../ScenarioCase";
import { createScenarioCaseModel, createStepModel, createWord } from "./scenarioTestData";

describe("ScenarioCase", () => {
it("should display class name", () => {
const className = "name.of.my.class";
render(<ScenarioCase className={className} scenarioCase={createScenarioCaseModel()} />);

expect(screen.getByText(className)).toBeInTheDocument();
});

it("should display all scenario steps", () => {
const singleWordScenarioDescriptions = ["marine", "debug", "grind", "trivial", "timetable"];

const steps = singleWordScenarioDescriptions.map(description =>
createStepModel({ words: [createWord({ value: description })] })
);

render(<ScenarioCase className={""} scenarioCase={createScenarioCaseModel({ steps })} />);

singleWordScenarioDescriptions.forEach(description => {
expect(screen.getByText(description)).toBeVisible();
});
});
});
48 changes: 48 additions & 0 deletions new/src/components/Scenarios/__test__/ScenarioHead.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { render } from "@testing-library/react";
import { ScenarioHead } from "../ScenarioHead";
import { createScenarioModel } from "./scenarioTestData";
import { screen } from "../../../testUtils/enhancedScreen";

describe("Scenario Head", () => {
it("displays class title", () => {
const classTitle = "The class title";
const model = createScenarioModel({ classTitle });

render(<ScenarioHead scenario={model} />);
expect(screen.getByText(classTitle)).toBeVisible();
});

it("displays capitalized title", () => {
const description = "scenario description";
const expectedDisplayValue = "Scenario description";

const model = createScenarioModel({ description });
render(<ScenarioHead scenario={model} />);

expect(screen.getByText(expectedDisplayValue)).toBeVisible();
});

it("displays checkbox icon if scenario has executionStatus SUCCESS", () => {
const model = createScenarioModel({ executionStatus: "SUCCESS" });
render(<ScenarioHead scenario={model} />);

expect(screen.getAllIcons()).toHaveLength(1);
expect(screen.getCheckboxIcon()).toBeVisible();
});

it("displays error icon if scenario has executionStatus FAILED", () => {
const model = createScenarioModel({ executionStatus: "FAILED" });
render(<ScenarioHead scenario={model} />);

expect(screen.getAllIcons()).toHaveLength(1);
expect(screen.getErrorIcon()).toBeVisible();
});

it("displays pending icon if scenario has executionStatus PENDING", () => {
const model = createScenarioModel({ executionStatus: "PENDING" });
render(<ScenarioHead scenario={model} />);

expect(screen.getAllIcons()).toHaveLength(1);
expect(screen.getPendingIcon()).toBeVisible();
});
});
Loading

0 comments on commit 3d16e31

Please sign in to comment.