|
| 1 | +/// <reference types="@testing-library/jest-dom" /> |
| 2 | +import React from "react"; |
| 3 | +import { render, screen } from "@testing-library/react"; |
| 4 | +import MimeTabs from "./index"; |
| 5 | + |
| 6 | +// Mock Docusaurus theme-common internals and hooks |
| 7 | +jest.mock("@docusaurus/theme-common/internal", () => ({ |
| 8 | + sanitizeTabsChildren: (children: any) => children, |
| 9 | + useTabs: () => ({ |
| 10 | + selectedValue: "application/json", |
| 11 | + selectValue: jest.fn(), |
| 12 | + tabValues: [ |
| 13 | + { value: "application/json", label: "JSON" }, |
| 14 | + { value: "application/xml", label: "XML" }, |
| 15 | + ], |
| 16 | + }), |
| 17 | + useScrollPositionBlocker: () => ({ |
| 18 | + blockElementScrollPositionUntilNextRender: jest.fn(), |
| 19 | + }), |
| 20 | +})); |
| 21 | +jest.mock("@docusaurus/useIsBrowser", () => () => true); |
| 22 | + |
| 23 | +// Mock theme actions/hooks |
| 24 | +jest.mock("@theme/ApiExplorer/Accept/slice", () => ({ setAccept: jest.fn() })); |
| 25 | +jest.mock("@theme/ApiExplorer/ContentType/slice", () => ({ |
| 26 | + setContentType: jest.fn(), |
| 27 | +})); |
| 28 | +jest.mock("@theme/ApiItem/hooks", () => ({ |
| 29 | + useTypedDispatch: () => jest.fn(), |
| 30 | + useTypedSelector: () => jest.fn(), |
| 31 | +})); |
| 32 | +jest.mock("@theme/ApiItem/store", () => ({})); |
| 33 | + |
| 34 | +// Minimal TabItem mock |
| 35 | +const TabItem = ({ value, label, children }: any) => ( |
| 36 | + <div data-testid={`tab-content-${value}`}>{children}</div> |
| 37 | +); |
| 38 | + |
| 39 | +// Test suite |
| 40 | + |
| 41 | +describe("MimeTabs", () => { |
| 42 | + it("renders mime type tab labels and content", () => { |
| 43 | + render( |
| 44 | + // @ts-ignore |
| 45 | + <MimeTabs schemaType="string"> |
| 46 | + {/* @ts-ignore */} |
| 47 | + <TabItem value="application/json" label="JSON"> |
| 48 | + JSON Content |
| 49 | + </TabItem> |
| 50 | + {/* @ts-ignore */} |
| 51 | + <TabItem value="application/xml" label="XML"> |
| 52 | + XML Content |
| 53 | + </TabItem> |
| 54 | + </MimeTabs> |
| 55 | + ); |
| 56 | + expect(screen.getByText("JSON")).toBeInTheDocument(); |
| 57 | + expect(screen.getByText("XML")).toBeInTheDocument(); |
| 58 | + expect(screen.getByText("JSON Content")).toBeInTheDocument(); |
| 59 | + }); |
| 60 | +}); |
0 commit comments