docs: added tests for components in api-reference project (#14428)
* add tests (WIP) * added test for h2 * finished adding tests * fixes * fixes * fixes
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import React from "react"
|
||||
import { beforeEach, describe, expect, test, vi } from "vitest"
|
||||
import { cleanup, render } from "@testing-library/react"
|
||||
|
||||
// mock hooks
|
||||
const mockUseArea = vi.fn(() => ({
|
||||
area: "store",
|
||||
}))
|
||||
|
||||
// mock components
|
||||
vi.mock("@/providers/area", () => ({
|
||||
useArea: () => mockUseArea(),
|
||||
}))
|
||||
|
||||
import DownloadFull from ".."
|
||||
|
||||
beforeEach(() => {
|
||||
cleanup()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe("render", () => {
|
||||
test("render download link for store area", () => {
|
||||
const { getByTestId } = render(<DownloadFull />)
|
||||
const link = getByTestId("download-full-link")
|
||||
expect(link).toBeInTheDocument()
|
||||
expect(link).toHaveAttribute("href", "/download/store")
|
||||
expect(link).toHaveAttribute("download")
|
||||
expect(link).toHaveAttribute("target", "_blank")
|
||||
})
|
||||
|
||||
test("render download link for admin area", () => {
|
||||
mockUseArea.mockReturnValue({ area: "admin" })
|
||||
const { getByTestId } = render(<DownloadFull />)
|
||||
const link = getByTestId("download-full-link")
|
||||
expect(link).toBeInTheDocument()
|
||||
expect(link).toHaveAttribute("href", "/download/admin")
|
||||
expect(link).toHaveAttribute("download")
|
||||
expect(link).toHaveAttribute("target", "_blank")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user