-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
392 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import "@testing-library/jest-dom" | ||
import { fireEvent, render, screen } from "@testing-library/react" | ||
|
||
import BlockButton from "~/components/base/Button/BlockButton" | ||
|
||
describe("BlockButton", (): void => { | ||
test("renders with children", (): void => { | ||
render(<BlockButton>Click me</BlockButton>) | ||
expect(screen.getByText("Click me")).toBeInTheDocument() | ||
}) | ||
|
||
test("calls onClick handler when clickable and button is clicked", (): void => { | ||
const handleClick: jest.Mock = jest.fn() | ||
render( | ||
<BlockButton | ||
clickable | ||
onClick={handleClick} | ||
> | ||
Click me | ||
</BlockButton>, | ||
) | ||
|
||
fireEvent.click(screen.getByText("Click me")) | ||
expect(handleClick).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
test("does not call onClick handler when not clickable", (): void => { | ||
const handleClick: jest.Mock = jest.fn() | ||
render( | ||
<BlockButton | ||
clickable={false} | ||
onClick={handleClick} | ||
> | ||
Click me | ||
</BlockButton>, | ||
) | ||
|
||
fireEvent.click(screen.getByText("Click me")) | ||
expect(handleClick).not.toHaveBeenCalled() | ||
}) | ||
|
||
test("applies width and height correctly", (): void => { | ||
const { container } = render( | ||
<BlockButton | ||
btnWidth={"100px"} | ||
btnHeight={"50px"} | ||
> | ||
Click me | ||
</BlockButton>, | ||
) | ||
const button: HTMLButtonElement = container.querySelector("button") | ||
|
||
expect(button).toHaveStyle("width: 100px") | ||
expect(button).toHaveStyle("height: 50px") | ||
}) | ||
|
||
test("renders with title attribute", (): void => { | ||
render(<BlockButton title="This is a button">Click me</BlockButton>) | ||
expect(screen.getByTitle("This is a button")).toBeInTheDocument() | ||
}) | ||
}) |
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,37 @@ | ||
import "@testing-library/jest-dom" | ||
import { fireEvent, render, screen } from "@testing-library/react" | ||
|
||
import RoundButton from "~/components/base/Button/RoundButton" | ||
|
||
describe("RoundButton", (): void => { | ||
it("renders with children", (): void => { | ||
render(<RoundButton title="Test Button">Click Me</RoundButton>) | ||
expect(screen.getByText("Click Me")).toBeInTheDocument() | ||
}) | ||
|
||
it("handles click event", (): void => { | ||
const handleClick: jest.Mock = jest.fn() | ||
render(<RoundButton onClick={handleClick}>Click Me</RoundButton>) | ||
fireEvent.click(screen.getByText("Click Me")) | ||
expect(handleClick).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it("does not call onClick when clickable is false", (): void => { | ||
const handleClick: jest.Mock = jest.fn() | ||
render( | ||
<RoundButton | ||
onClick={handleClick} | ||
clickable={false} | ||
> | ||
Click Me | ||
</RoundButton>, | ||
) | ||
fireEvent.click(screen.getByText("Click Me")) | ||
expect(handleClick).not.toHaveBeenCalled() | ||
}) | ||
|
||
it("renders with the correct title attribute", (): void => { | ||
render(<RoundButton title="Test Button">Click Me</RoundButton>) | ||
expect(screen.getByTitle("Test Button")).toBeInTheDocument() | ||
}) | ||
}) |
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 "@testing-library/jest-dom" | ||
import { render } from "@testing-library/react" | ||
import "jest-styled-components" | ||
|
||
import IconFont from "~/components/base/IconFont" | ||
|
||
describe("IconFont", (): void => { | ||
it("renders with the correct icon content", (): void => { | ||
const { container } = render(<IconFont icon="users" />) | ||
expect(container.firstChild).toHaveStyle({ | ||
"font-family": "iconfont", | ||
}) | ||
expect(container.firstChild).toHaveStyleRule("content", '"\\e658"', { | ||
modifier: "::before", | ||
}) | ||
}) | ||
|
||
it("renders with the correct block property", (): void => { | ||
const { container } = render( | ||
<IconFont | ||
icon="views" | ||
block | ||
/>, | ||
) | ||
expect(container.firstChild).toHaveStyle({ | ||
display: "block", | ||
}) | ||
}) | ||
|
||
it("renders with the correct size", (): void => { | ||
const { container } = render( | ||
<IconFont | ||
icon="heart" | ||
size="2em" | ||
/>, | ||
) | ||
expect(container.firstChild).toHaveStyle({ | ||
"font-size": "2em", | ||
}) | ||
}) | ||
|
||
it("renders with the correct default size", (): void => { | ||
const { container } = render(<IconFont icon="like" />) | ||
expect(container.firstChild).toHaveStyle({ | ||
"font-size": "1.3em", | ||
}) | ||
}) | ||
}) |
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,34 @@ | ||
import "@testing-library/jest-dom" | ||
import { render } from "@testing-library/react" | ||
import "jest-styled-components" | ||
|
||
import Main from "~/components/base/Main" | ||
|
||
describe("Main", (): void => { | ||
it("renders with children", (): void => { | ||
const { getByText } = render( | ||
<Main className="custom-class"> | ||
<div>Test Child</div> | ||
</Main>, | ||
) | ||
expect(getByText("Test Child")).toBeInTheDocument() | ||
}) | ||
|
||
it("applies the passed className", (): void => { | ||
const { container } = render( | ||
<Main className="custom-class"> | ||
<div>Test Child</div> | ||
</Main>, | ||
) | ||
expect(container.firstChild).toHaveClass("custom-class") | ||
}) | ||
|
||
it("has the main class from style module", (): void => { | ||
const { container } = render( | ||
<Main className="custom-class"> | ||
<div>Test Child</div> | ||
</Main>, | ||
) | ||
expect(container.firstChild).toHaveClass("main") | ||
}) | ||
}) |
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,33 @@ | ||
import "@testing-library/jest-dom" | ||
import { render } from "@testing-library/react" | ||
|
||
import Row from "~/components/base/Row" | ||
|
||
describe("Row", (): void => { | ||
it("renders with title and text", (): void => { | ||
const { getByTitle, getByText } = render( | ||
<Row | ||
title="Test Title" | ||
text="Test Text" | ||
> | ||
<div>Child Element</div> | ||
</Row>, | ||
) | ||
|
||
expect(getByTitle("Test Title")).toBeInTheDocument() | ||
expect(getByText("Test Text")).toBeInTheDocument() | ||
}) | ||
|
||
it("renders with children", (): void => { | ||
const { getByText } = render( | ||
<Row | ||
title="Test Title" | ||
text="Test Text" | ||
> | ||
<div>Child Element</div> | ||
</Row>, | ||
) | ||
|
||
expect(getByText("Child Element")).toBeInTheDocument() | ||
}) | ||
}) |
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,38 @@ | ||
import "@testing-library/jest-dom" | ||
import { fireEvent, render } from "@testing-library/react" | ||
|
||
import Switch from "~/components/base/Switch" | ||
|
||
describe("Switch", (): void => { | ||
it("should render correctly", (): void => { | ||
const handleChange: jest.Mock = jest.fn() | ||
const { getByRole } = render( | ||
<Switch | ||
id="test-switch" | ||
checked={false} | ||
onChange={handleChange} | ||
/>, | ||
) | ||
|
||
const input: HTMLElement = getByRole("checkbox") | ||
expect(input).toBeInTheDocument() | ||
expect(input).toHaveAttribute("id", "test-switch") | ||
expect(input).not.toBeChecked() | ||
}) | ||
|
||
it("should handle check state changes", (): void => { | ||
const handleChange: jest.Mock = jest.fn() | ||
const { getByRole } = render( | ||
<Switch | ||
id="test-switch" | ||
checked={false} | ||
onChange={handleChange} | ||
/>, | ||
) | ||
|
||
const input: HTMLElement = getByRole("checkbox") | ||
fireEvent.click(input) | ||
|
||
expect(handleChange).toHaveBeenCalled() | ||
}) | ||
}) |
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,17 @@ | ||
import "@testing-library/jest-dom" | ||
import { render, screen } from "@testing-library/react" | ||
|
||
import View from "~/components/base/View" | ||
|
||
describe("View", (): void => { | ||
it("should render children correctly", (): void => { | ||
render( | ||
<View> | ||
<span>Child Content</span> | ||
</View>, | ||
) | ||
|
||
const childContent: HTMLElement = screen.getByText("Child Content") | ||
expect(childContent).toBeInTheDocument() | ||
}) | ||
}) |
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
Oops, something went wrong.