diff --git a/src/components/scoreboard/__snapshots__/scoreboard.test.tsx.snap b/src/components/scoreboard/__snapshots__/scoreboard.test.tsx.snap new file mode 100644 index 00000000..0236c275 --- /dev/null +++ b/src/components/scoreboard/__snapshots__/scoreboard.test.tsx.snap @@ -0,0 +1,47 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Scoreboard test cases Scoreboard renders correctly 1`] = ` + + + + 000 + + + + + beginner + + + intermediate + + + expert + + + + 🙂 + + + + 010 + + + +`; diff --git a/src/components/scoreboard/components/level/level.test.tsx b/src/components/scoreboard/components/level/level.test.tsx index 50432856..e99b3f3e 100644 --- a/src/components/scoreboard/components/level/level.test.tsx +++ b/src/components/scoreboard/components/level/level.test.tsx @@ -12,12 +12,15 @@ describe("Level component test case", function () { expect(asFragment()).toMatchSnapshot(); }); - it("should Select level behaviour", function () { + it("should Select level behaviour", async function () { const onChange = jest.fn(); const levelData = ["beginner", "intermediate", "expert"]; render(); - userEvent.selectOptions(screen.getByRole("select-component"), "intermediate"); + await userEvent.selectOptions(screen.getByRole("select-component"), "intermediate"); expect(screen.getByRole("option", { name: "intermediate" })).toBeEnabled(); + + await Promise.resolve(); + expect(onChange).toHaveBeenCalled(); }); }); diff --git a/src/components/scoreboard/scoreboard.test.tsx b/src/components/scoreboard/scoreboard.test.tsx new file mode 100644 index 00000000..926f4fb7 --- /dev/null +++ b/src/components/scoreboard/scoreboard.test.tsx @@ -0,0 +1,28 @@ +import { ScoreBoard } from "@components/scoreboard/scoreboard"; +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import React from "react"; + +describe("Scoreboard test cases", () => { + const levels = ["beginner", "intermediate", "expert"]; + + it("Scoreboard renders correctly", () => { + const { asFragment } = render( + null} mines="010" onChange={() => null} /> + ); + + expect(asFragment()).toMatchSnapshot(); + }); + it("Scoreboard select level handler check", async () => { + const onChange = jest.fn(); + + render( null} mines="010" onChange={onChange} />); + + await userEvent.selectOptions(screen.getByRole("select-component"), "expert"); + + expect(screen.getByRole("option", { name: "expert" })).toBeEnabled(); + + await Promise.resolve(); + expect(onChange).toHaveBeenCalled(); + }); +});