// @vitest-environment jsdom import "@testing-library/jest-dom"; import { render, screen } from "@testing-library/react"; import { MemoryRouter } from "react-router"; import { describe, expect, it, vi } from "vitest"; import type { ApiSpecsDto } from "../services/ApiSpecsService"; import ApiSpecs from "./ApiSpecs"; vi.mock("~/components/editors/MonacoEditor", () => ({ default: ({ value }: { value: string }) =>
{value}
})); vi.mock("~/components/ui/icons/ExternalLinkEmptyIcon", () => ({ default: () => null })); vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string) => key }) })); const item = { openApi: { openapi: "3.1.0" }, postmanCollection: { info: { name: "API" }, item: [] }, apiDocsUrl: "https://api.example.com/v1/docs", } as unknown as ApiSpecsDto; describe("ApiSpecs", () => { it("can hide the admin-only Postman download while still rendering the collection preview", () => { render( ); expect(screen.getByText("docs.openApi")).toBeInTheDocument(); expect(screen.queryByText("docs.downloadPostmanCollection")).not.toBeInTheDocument(); expect(screen.queryByRole("link", { name: /postman/i })).not.toBeInTheDocument(); expect(screen.getAllByTestId("monaco")).toHaveLength(2); }); it("can hide the full Postman collection preview on tenant-facing docs", () => { render( ); expect(screen.queryByText("docs.downloadPostmanCollection")).not.toBeInTheDocument(); expect(screen.getAllByTestId("monaco")).toHaveLength(1); }); });