diff --git a/new/src/components/Scenarios/ScenarioHead.tsx b/new/src/components/Scenarios/ScenarioHead.tsx index fd4cdf0d..4c53e81c 100644 --- a/new/src/components/Scenarios/ScenarioHead.tsx +++ b/new/src/components/Scenarios/ScenarioHead.tsx @@ -23,7 +23,9 @@ export function ScenarioHead({ scenario }: ScenarioHeadProps) { - {addRuntimeInMilliseconds(scenario.scenarioCases[0].durationInNanos)} + {scenario.scenarioCases.length > 0 + ? addRuntimeInMilliseconds(scenario.scenarioCases[0].durationInNanos) + : ""} diff --git a/new/src/components/Scenarios/__test__/Scenario.test.tsx b/new/src/components/Scenarios/__test__/Scenario.test.tsx index aa288b2f..ceb6f702 100644 --- a/new/src/components/Scenarios/__test__/Scenario.test.tsx +++ b/new/src/components/Scenarios/__test__/Scenario.test.tsx @@ -2,8 +2,12 @@ import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { Scenario } from "../Scenario"; import { ExpansionState } from "../ScenarioOverview"; -import { processWords } from "../../../wordProcessor"; -import { ScenarioModel } from "../../../reportModel"; +import { + createScenarioCaseModel, + createScenarioModel, + createStepModel, + createWord +} from "./scenarioTestData"; afterEach(() => { jest.resetAllMocks(); @@ -12,21 +16,12 @@ afterEach(() => { const onExpansionCallback = jest.fn(); const onCollapsionCallback = jest.fn(); -describe("Scenario accordion behavior", () => { - test("accordion details are not visible when globalExpansionState is COLLAPSED", async () => { - render( - - ); - const accordion = await screen.findByLabelText("Scenario Overview"); - expect(accordion.attributes.getNamedItem("aria-expanded")?.value).toBe("false"); - }); +describe("Scenario", () => { + it("displays capitalized title", () => { + const description = "scenario description"; + const expectedDisplayValue = "Scenario description"; - test("accordion details are visible when globalExpansionState is EXPANDED", async () => { + const model = createScenarioModel({ description }); render( { onCollapsionCallback={onCollapsionCallback} /> ); - const accordion = await screen.findByLabelText("Scenario Overview"); - expect(accordion.attributes.getNamedItem("aria-expanded")?.value).toBe("true"); - }); - test("onExpansionCallback is invoked when clicking on the header of a collapsed scenario", async () => { - render( - - ); - const scenarioOverview = await screen.findByLabelText("Scenario Overview"); - userEvent.click(scenarioOverview); - expect(onExpansionCallback).toHaveBeenCalled(); + expect(screen.getByText(expectedDisplayValue)).toBeVisible(); }); - test("onCollapsionCallback is invoked when clicking on the header of an expanded scenario", async () => { + it("displays single scenario case", () => { + const className = "my custom class name"; + const scenarioCases = [createScenarioCaseModel()]; + const model = createScenarioModel({ className, scenarioCases }); + render( { onCollapsionCallback={onCollapsionCallback} /> ); - const scenarioOverview = await screen.findByLabelText("Scenario Overview"); - userEvent.click(scenarioOverview); - expect(onCollapsionCallback).toHaveBeenCalled(); + + expect(screen.getByText(className)).toBeVisible(); }); -}); -test("Scenario displays steps", async () => { - render( - - ); - const textElement = await screen.findByText( - model.scenarioCases[0].steps[0].words.flatMap(word => word.value).join(" ") - ); - expect(textElement).toBeInTheDocument(); -}); + 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( + + ); + const accordion = screen.getByLabelText("Scenario Overview"); + expect(accordion.attributes.getNamedItem("aria-expanded")?.value).toBe("false"); + expect(screen.queryByText(details)).not.toBeVisible(); + }); -test("Scenario capitalizes title", async () => { - render( - - ); - const textElement = await screen.findByText(processWords(model.description)); - expect(textElement).toBeInTheDocument(); -}); + 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( + + ); + const accordion = screen.getByLabelText("Scenario Overview"); + expect(accordion.attributes.getNamedItem("aria-expanded")?.value).toBe("true"); + expect(screen.queryByText(details)).toBeVisible(); + }); -const model: ScenarioModel = { - classTitle: "classTitle", - executionStatus: "SUCCESS", - tags: [], - className: "testClass", - testMethodName: "testMethod", - description: "this is a description", - extendedDescription: "this is an extended description", - tagIds: ["tag1", "tag2"], - explicitParameters: [], - derivedParameters: [], - scenarioCases: [ - { - caseNr: 1, - description: "case1", - derivedArguments: [], - explicitArguments: [], - durationInNanos: 2001000, - status: "SUCCESS", - steps: [ - { - status: "PASSED", - durationInNanos: 2000000, - name: "Step1", - words: [{ value: "Step1", isIntroWord: true }], - depth: 0, - parentFailed: false - } - ] - } - ], - casesAsTable: false, - durationInNanos: 0 -}; + it("onExpansionCallback is invoked when clicking on the header of a collapsed scenario", async () => { + render( + + ); + 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( + + ); + const scenarioOverview = await screen.findByLabelText("Scenario Overview"); + userEvent.click(scenarioOverview); + expect(onCollapsionCallback).toHaveBeenCalled(); + }); + }); +}); diff --git a/new/src/components/Scenarios/__test__/scenarioTestData.ts b/new/src/components/Scenarios/__test__/scenarioTestData.ts index 6023000f..640baa8a 100644 --- a/new/src/components/Scenarios/__test__/scenarioTestData.ts +++ b/new/src/components/Scenarios/__test__/scenarioTestData.ts @@ -1,4 +1,4 @@ -import { ScenarioCaseModel, StepModel, Word } from "../../../reportModel"; +import { ScenarioCaseModel, ScenarioModel, StepModel, Word } from "../../../reportModel"; export function createWord(props?: Partial): Word { return { @@ -37,3 +37,21 @@ export function createScenarioCaseModel(props?: Partial): Sce description: props?.description }; } + +export function createScenarioModel(props?: Partial): ScenarioModel { + return { + className: props?.className ?? "class name", + classTitle: props?.classTitle ?? "class title", + testMethodName: props?.testMethodName ?? "test method name", + description: props?.description ?? "scenario description", + extendedDescription: props?.extendedDescription, + tagIds: props?.tagIds ?? [], + explicitParameters: props?.explicitParameters ?? [], + derivedParameters: props?.derivedParameters ?? [], + scenarioCases: props?.scenarioCases ?? [], + casesAsTable: props?.casesAsTable ?? false, + durationInNanos: props?.durationInNanos ?? 0, + executionStatus: props?.executionStatus ?? "SUCCESS", + tags: props?.tags ?? [] + }; +}