1 parent
7cce0bedb7
commit
79ab798f12
8 files changed
+496
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { render, within } from "@testing-library/react"
|
||||
import { describe, it, expect } from "vitest"
|
||||
import { Breadcrumbs } from "."
|
||||
|
||||
describe("Breadcrumbs", () => {
|
||||
const items = [
|
||||
{ name: "Home", href: "/" },
|
||||
{ name: "About", href: "/about" },
|
||||
{ name: "Team", href: "/about/team" },
|
||||
]
|
||||
|
||||
it("renders breadcrumb items with separators", () => {
|
||||
const { container } = render(<Breadcrumbs items={items} path="/about/team" />)
|
||||
const nav = within(container.querySelector("nav")!)
|
||||
|
||||
expect(nav.getByText("Home")).toBeInTheDocument()
|
||||
expect(nav.getByText("About")).toBeInTheDocument()
|
||||
expect(nav.getByText("Team")).toBeInTheDocument()
|
||||
|
||||
const separators = nav.getAllByText("/")
|
||||
expect(separators).toHaveLength(2)
|
||||
})
|
||||
|
||||
it("disables the button matching the current path", () => {
|
||||
const { container } = render(<Breadcrumbs items={items} path="/about" />)
|
||||
const nav = within(container.querySelector("nav")!)
|
||||
|
||||
const aboutLink = nav.getByText("About").closest("a")!
|
||||
expect(aboutLink.className).toMatch(/disabled/)
|
||||
|
||||
const homeLink = nav.getByText("Home").closest("a")!
|
||||
expect(homeLink.className).not.toMatch(/disabled/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,44 @@
|
||||
import { render, screen } from "@testing-library/react"
|
||||
import { describe, it, expect } from "vitest"
|
||||
import { Box } from "."
|
||||
|
||||
describe("Box", () => {
|
||||
it("renders children", () => {
|
||||
render(<Box>hello</Box>)
|
||||
expect(screen.getByText("hello")).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it("defaults to a div tag", () => {
|
||||
render(<Box>content</Box>)
|
||||
expect(screen.getByText("content").tagName).toBe("DIV")
|
||||
})
|
||||
|
||||
it("renders as a custom tag via the as prop", () => {
|
||||
render(<Box as="section">section content</Box>)
|
||||
expect(screen.getByText("section content").tagName).toBe("SECTION")
|
||||
})
|
||||
|
||||
it("applies vertical class", () => {
|
||||
const { container } = render(<Box vertical>v</Box>)
|
||||
const el = container.firstElementChild!
|
||||
expect(el.className).toMatch(/vertical/)
|
||||
})
|
||||
|
||||
it("applies center class", () => {
|
||||
const { container } = render(<Box center>c</Box>)
|
||||
const el = container.firstElementChild!
|
||||
expect(el.className).toMatch(/center/)
|
||||
})
|
||||
|
||||
it("applies wrap class", () => {
|
||||
const { container } = render(<Box wrap>w</Box>)
|
||||
const el = container.firstElementChild!
|
||||
expect(el.className).toMatch(/wrap/)
|
||||
})
|
||||
|
||||
it("passes gap to inline style", () => {
|
||||
const { container } = render(<Box gap={8}>g</Box>)
|
||||
const el = container.firstElementChild!
|
||||
expect(el).toHaveStyle({ gap: "8px" })
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import { render, screen, fireEvent } from "@testing-library/react"
|
||||
import { describe, it, expect, vi } from "vitest"
|
||||
import { Button } from "."
|
||||
|
||||
describe("Button", () => {
|
||||
it("renders children in a button element", () => {
|
||||
render(<Button>Click me</Button>)
|
||||
const button = screen.getByRole("button", { name: "Click me" })
|
||||
expect(button).toBeInTheDocument()
|
||||
expect(button.tagName).toBe("BUTTON")
|
||||
})
|
||||
|
||||
it("renders as a link when href is provided", () => {
|
||||
render(<Button href="/about">About</Button>)
|
||||
const link = screen.getByRole("link", { name: "About" })
|
||||
expect(link).toBeInTheDocument()
|
||||
expect(link).toHaveAttribute("href", "/about")
|
||||
})
|
||||
|
||||
it("calls onClick with value when clicked", () => {
|
||||
const onClick = vi.fn()
|
||||
render(<Button value="test-value" onClick={onClick}>Click</Button>)
|
||||
fireEvent.click(screen.getByRole("button", { name: "Click" }))
|
||||
expect(onClick).toHaveBeenCalledOnce()
|
||||
expect(onClick).toHaveBeenCalledWith("test-value", expect.anything())
|
||||
})
|
||||
|
||||
it("applies disabled class when disabled is true", () => {
|
||||
const { container } = render(<Button disabled>Disabled</Button>)
|
||||
expect(container.firstElementChild!.className).toMatch(/disabled/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,23 @@
|
||||
import { render } from "@testing-library/react"
|
||||
import { describe, it, expect } from "vitest"
|
||||
import { Panel } from "."
|
||||
|
||||
describe("Panel", () => {
|
||||
it("renders children", () => {
|
||||
const { container } = render(<Panel>hello</Panel>)
|
||||
expect(container).toHaveTextContent("hello")
|
||||
})
|
||||
|
||||
it("applies the default variant class", () => {
|
||||
const { container } = render(<Panel>content</Panel>)
|
||||
const el = container.firstElementChild!
|
||||
expect(el.className).toMatch(/default/)
|
||||
})
|
||||
|
||||
it("applies the ghost variant class when ghost is true", () => {
|
||||
const { container } = render(<Panel ghost>content</Panel>)
|
||||
const el = container.firstElementChild!
|
||||
expect(el.className).toMatch(/ghost/)
|
||||
expect(el.className).not.toMatch(/default/)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user