import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import {
ScanErrorDetailsModal,
type ScanErrorDetailsState,
} from "./scan-error-details-modal";
vi.mock("@/components/shadcn/code-snippet/code-snippet", () => ({
CodeSnippet: ({
value,
formatter,
ariaLabel,
}: {
value: string;
formatter?: (value: string) => string;
ariaLabel?: string;
}) => (
<>
{formatter ? formatter(value) : value}
>
),
}));
const loadedState: ScanErrorDetailsState = {
kind: "loaded",
details: {
type: "ValidationError",
messages: ["Missing cloud credentials", "Retry scan setup"],
module: "scan.runner",
copyValue:
"ErrorType: ValidationError\nError: Missing cloud credentials\nRetry scan setup",
},
};
describe("ScanErrorDetailsModal", () => {
it("renders nothing visible when closed", () => {
render(
,
);
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});
it("shows the loading placeholder while state is loading", () => {
render(
,
);
expect(screen.getByText(/loading error details/i)).toBeInTheDocument();
});
it("renders the error message when state is error", () => {
render(
,
);
expect(screen.getByText("Task not found")).toBeInTheDocument();
});
it("renders error type, module and messages when loaded", () => {
render(
,
);
expect(screen.getByText("ValidationError")).toBeInTheDocument();
expect(screen.getByText("scan.runner")).toBeInTheDocument();
expect(screen.getByText(/Missing cloud credentials/)).toBeInTheDocument();
expect(screen.getByText(/Retry scan setup/)).toBeInTheDocument();
});
it("shows the copy action only when state is loaded", () => {
const { rerender } = render(
,
);
expect(
screen.queryByRole("button", { name: /copy error details/i }),
).not.toBeInTheDocument();
rerender(
,
);
expect(
screen.getByRole("button", { name: /copy error details/i }),
).toBeInTheDocument();
});
});