-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from jgiven/scenario-test-coverage
Scenario test coverage
- Loading branch information
Showing
15 changed files
with
394 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
new/src/components/Scenarios/__test__/Scenario.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
new/src/components/Scenarios/__test__/ScenarioCase.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
new/src/components/Scenarios/__test__/ScenarioHead.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
Oops, something went wrong.