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:
Shahed Nasser
2026-01-05 10:56:56 +02:00
committed by GitHub
parent fb772f0f6a
commit 4d632e7a5d
102 changed files with 8278 additions and 127 deletions

View File

@@ -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")
})
})

View File

@@ -1,7 +1,8 @@
"use client"
import React from "react"
import { Button } from "docs-ui"
import { useArea } from "../../providers/area"
import { useArea } from "@/providers/area"
import Link from "next/link"
const DownloadFull = () => {
@@ -9,7 +10,12 @@ const DownloadFull = () => {
return (
<Button variant="secondary">
<Link href={`/download/${area}`} download target="_blank">
<Link
href={`/download/${area}`}
download
target="_blank"
data-testid="download-full-link"
>
Download OpenApi Specs Collection
</Link>
</Button>