mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-26 04:25:46 +02:00
93 lines
2.8 KiB
TypeScript
93 lines
2.8 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import { render, screen } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { Markdown } from "./markdown";
|
|
|
|
vi.mock("@multica/core/config", () => ({
|
|
useConfigStore: (selector: (state: { cdnDomain: string }) => unknown) =>
|
|
selector({ cdnDomain: "" }),
|
|
}));
|
|
|
|
vi.mock("../issues/components/issue-mention-card", () => ({
|
|
IssueMentionCard: ({ issueId }: { issueId: string }) => (
|
|
<span data-testid="issue-mention-card">{issueId}</span>
|
|
),
|
|
}));
|
|
|
|
vi.mock("@multica/core/paths", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("@multica/core/paths")>();
|
|
return {
|
|
...actual,
|
|
useWorkspaceSlug: () => "acme",
|
|
useRequiredWorkspaceSlug: () => "acme",
|
|
useWorkspacePaths: () => ({
|
|
...actual.paths.workspace("acme"),
|
|
projectDetail: (projectId: string) => `/projects/${projectId}`,
|
|
}),
|
|
};
|
|
});
|
|
|
|
vi.mock("../navigation", () => ({
|
|
AppLink: ({
|
|
href,
|
|
children,
|
|
className,
|
|
}: {
|
|
href: string;
|
|
children: ReactNode;
|
|
className?: string;
|
|
}) => (
|
|
<a href={href} className={className}>
|
|
{children}
|
|
</a>
|
|
),
|
|
}));
|
|
|
|
vi.mock("../projects/components/project-chip", () => ({
|
|
ProjectChip: ({ projectId }: { projectId: string }) => (
|
|
<span data-testid="project-chip">{projectId}</span>
|
|
),
|
|
}));
|
|
|
|
const ligatureClasses = [
|
|
"[font-variant-ligatures:none]",
|
|
"[font-feature-settings:'liga'_0]",
|
|
];
|
|
|
|
describe("Markdown", () => {
|
|
it("disables ligatures inside raw code tags", () => {
|
|
render(<Markdown>{"<code>uv run --extra dev pytest -q</code>"}</Markdown>);
|
|
|
|
expect(screen.getByText("uv run --extra dev pytest -q")).toHaveClass(...ligatureClasses);
|
|
});
|
|
|
|
it("disables ligatures inside fenced code blocks", () => {
|
|
render(<Markdown>{"```sh\nuv run --extra dev pytest -q\n```"}</Markdown>);
|
|
|
|
expect(screen.getByText("uv run --extra dev pytest -q")).toHaveClass(...ligatureClasses);
|
|
});
|
|
|
|
it("disables ligatures in terminal-mode code", () => {
|
|
render(<Markdown mode="terminal">{"<code>uv run --extra dev pytest -q</code>"}</Markdown>);
|
|
|
|
expect(screen.getByText("uv run --extra dev pytest -q")).toHaveClass(...ligatureClasses);
|
|
});
|
|
|
|
it("renders slash skill links as slash command pills", () => {
|
|
const { container } = render(
|
|
<Markdown>[/deploy](slash://skill/abc-123)</Markdown>,
|
|
);
|
|
|
|
const pill = container.querySelector(".slash-command");
|
|
expect(pill).not.toBeNull();
|
|
expect(pill?.textContent).toBe("/deploy");
|
|
});
|
|
|
|
it("renders project mention links as project chips", () => {
|
|
render(<Markdown>{"[Roadmap](mention://project/project-123)"}</Markdown>);
|
|
|
|
expect(screen.getByTestId("project-chip")).toHaveTextContent("project-123");
|
|
expect(screen.getByRole("link")).toHaveAttribute("href", "/projects/project-123");
|
|
});
|
|
});
|