From 80af0f2134b28322d84a268e8b1c80111fe24642 Mon Sep 17 00:00:00 2001 From: Muhammad Zourdy Date: Fri, 5 Aug 2022 08:16:31 +0200 Subject: [PATCH] Add test cases for scoreboard components --- .../level/__snapshots__/level.test.tsx.snap | 26 +++++++++++++++++++ .../components/level/level.test.tsx | 23 ++++++++++++++++ .../scoreboard/components/level/level.tsx | 9 ++++--- .../components/reset/reset.module.scss | 3 ++- .../scoreboard/scoreboard.module.scss | 3 +-- src/components/scoreboard/scoreboard.tsx | 14 +++++++--- src/index.tsx | 6 ----- 7 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 src/components/scoreboard/components/level/__snapshots__/level.test.tsx.snap create mode 100644 src/components/scoreboard/components/level/level.test.tsx diff --git a/src/components/scoreboard/components/level/__snapshots__/level.test.tsx.snap b/src/components/scoreboard/components/level/__snapshots__/level.test.tsx.snap new file mode 100644 index 00000000..7b72fcde --- /dev/null +++ b/src/components/scoreboard/components/level/__snapshots__/level.test.tsx.snap @@ -0,0 +1,26 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Level component test case should render level correctly 1`] = ` + + + +`; diff --git a/src/components/scoreboard/components/level/level.test.tsx b/src/components/scoreboard/components/level/level.test.tsx new file mode 100644 index 00000000..50432856 --- /dev/null +++ b/src/components/scoreboard/components/level/level.test.tsx @@ -0,0 +1,23 @@ +import { Level } from "@components/scoreboard/components"; +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import React from "react"; + +describe("Level component test case", function () { + it("should render level correctly", function () { + const onChange = jest.fn(); + const levelData = ["beginner", "intermediate", "expert"]; + const { asFragment } = render(); + + expect(asFragment()).toMatchSnapshot(); + }); + + it("should Select level behaviour", function () { + const onChange = jest.fn(); + const levelData = ["beginner", "intermediate", "expert"]; + render(); + + userEvent.selectOptions(screen.getByRole("select-component"), "intermediate"); + expect(screen.getByRole("option", { name: "intermediate" })).toBeEnabled(); + }); +}); diff --git a/src/components/scoreboard/components/level/level.tsx b/src/components/scoreboard/components/level/level.tsx index d76f9dfc..fd1f8427 100644 --- a/src/components/scoreboard/components/level/level.tsx +++ b/src/components/scoreboard/components/level/level.tsx @@ -1,9 +1,12 @@ -import React, { FunctionComponent } from "react"; +import React, { ChangeEvent, FunctionComponent } from "react"; import styles from "./level.module.scss"; -export const Level: FunctionComponent<{ levelData: string[] }> = ({ levelData }) => ( - {levelData.map((item: string) => { return (