-
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.
test: 🧪 add basic test for input component
- Loading branch information
1 parent
73afd2a
commit 8196d86
Showing
1 changed file
with
36 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,42 @@ | ||
|
||
import "@testing-library/jest-dom/extend-expect" | ||
import { render } from "@testing-library/react" | ||
import React from "react" | ||
import { render, renderHook } from "@testing-library/react" | ||
import React, { useId, useRef } from "react" | ||
|
||
import { Input } from "./Input" | ||
import { IconCircleX } from "@tabler/icons-react" | ||
|
||
describe("Input component", () => { | ||
test("renders properly", () => {}) | ||
it("should render correctly with default props", () => { | ||
const { container } = render(<Input />) | ||
expect(container.firstChild).toBeInTheDocument() | ||
}) | ||
|
||
it("should handle null or undefined ref gracefully", () => { | ||
const ref = null | ||
const { container } = render(<Input ref={ref} />) | ||
expect(container.firstChild).toBeInTheDocument() | ||
}) | ||
|
||
it("should display cleanable icon when certain conditions are met", () => { | ||
const { container } = render( | ||
<Input cleanable={true} leftIcon={<IconCircleX />} /> | ||
) | ||
const cleanableIconDiv = container.querySelector("div.cursor-pointer") | ||
expect(cleanableIconDiv).toBeInTheDocument() | ||
expect( | ||
cleanableIconDiv && cleanableIconDiv.querySelector("svg") | ||
).toBeInTheDocument() | ||
}) | ||
|
||
it("should not cause memory leaks with useRef and useId hooks", () => { | ||
const { result } = renderHook(() => { | ||
const ref = useRef<HTMLDivElement>(null) | ||
const id = useId() | ||
return { ref, id } | ||
}) | ||
|
||
const { ref, id } = result.current | ||
expect(ref.current).toBeNull() | ||
expect(typeof id).toBe("string") | ||
}) | ||
}) |