82 lines
2.8 KiB
TypeScript
82 lines
2.8 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import "@testing-library/jest-dom";
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import { buildMcpConnectVM, type McpConnectVM } from "@hivegrid/view-models";
|
|
|
|
import { McpConnectDialog } from "./McpConnectDialog";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({ t: (key: string) => key, i18n: { language: "de" } }),
|
|
}));
|
|
|
|
function readyVM(tokens: Parameters<typeof buildMcpConnectVM>[0]["tokens"] = []): McpConnectVM {
|
|
return buildMcpConnectVM({
|
|
connectorUrl: "https://staging-mcp.hivegrid.de",
|
|
tenantName: "Acme",
|
|
appName: "HiveGrid",
|
|
tokens,
|
|
canRevoke: true,
|
|
nowIso: "2026-07-28T12:00:00.000Z",
|
|
});
|
|
}
|
|
|
|
describe("McpConnectDialog", () => {
|
|
it("shows the connector URL a client has to be pointed at", () => {
|
|
render(<McpConnectDialog open vm={readyVM()} onOpenChange={() => {}} onRevoke={() => {}} />);
|
|
|
|
expect(screen.getByText("https://staging-mcp.hivegrid.de")).toBeInTheDocument();
|
|
});
|
|
|
|
it("offers a setup guide per supported client", () => {
|
|
render(<McpConnectDialog open vm={readyVM()} onOpenChange={() => {}} onRevoke={() => {}} />);
|
|
|
|
for (const guide of ["claude-code", "claude-desktop", "chatgpt", "copilot", "codex", "gemini", "editors", "manual"]) {
|
|
expect(document.querySelector(`[data-ui-id="ui.mcp.connect.guide.${guide}"]`)).not.toBeNull();
|
|
}
|
|
});
|
|
|
|
it("explains the empty state instead of showing a bare list", () => {
|
|
render(<McpConnectDialog open vm={readyVM()} onOpenChange={() => {}} onRevoke={() => {}} />);
|
|
|
|
expect(screen.getByText("mcp.connect.connections.empty")).toBeInTheDocument();
|
|
});
|
|
|
|
it("hands the client id to the revoke callback", () => {
|
|
const onRevoke = vi.fn();
|
|
const vm = readyVM([
|
|
{
|
|
clientId: "client-1",
|
|
clientName: "Claude",
|
|
scopes: ["mcp:read"],
|
|
createdAtIso: "2026-07-20T08:00:00.000Z",
|
|
expiresAtIso: "2026-07-28T18:00:00.000Z",
|
|
revoked: false,
|
|
},
|
|
]);
|
|
render(<McpConnectDialog open vm={vm} onOpenChange={() => {}} onRevoke={onRevoke} />);
|
|
|
|
fireEvent.click(screen.getByText("mcp.connect.connections.revoke"));
|
|
|
|
expect(onRevoke).toHaveBeenCalledWith("client-1");
|
|
});
|
|
|
|
it("says what is happening while the data is still loading", () => {
|
|
render(<McpConnectDialog open vm={{ status: "loading" }} onOpenChange={() => {}} onRevoke={() => {}} />);
|
|
|
|
expect(screen.getByText("mcp.connect.loading")).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows plain-text error copy instead of an endless spinner", () => {
|
|
render(
|
|
<McpConnectDialog
|
|
open
|
|
vm={{ status: "error", error: { messageKey: "mcp.connect.error" } }}
|
|
onOpenChange={() => {}}
|
|
onRevoke={() => {}}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByText("mcp.connect.error")).toBeInTheDocument();
|
|
});
|
|
});
|