45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
// @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 }) => <pre data-testid="monaco">{value}</pre> }));
|
|
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(
|
|
<MemoryRouter>
|
|
<ApiSpecs item={item} postmanCollectionUrl={null} />
|
|
</MemoryRouter>
|
|
);
|
|
|
|
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(
|
|
<MemoryRouter>
|
|
<ApiSpecs item={item} postmanCollectionUrl={null} showPostmanCollection={false} />
|
|
</MemoryRouter>
|
|
);
|
|
|
|
expect(screen.queryByText("docs.downloadPostmanCollection")).not.toBeInTheDocument();
|
|
expect(screen.getAllByTestId("monaco")).toHaveLength(1);
|
|
});
|
|
});
|