import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it, vi } from "vitest";
import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
import { ToolLayout } from "../src/ToolCallBlocks/ToolLayout.js";
import { handleToolSummaryActionKeyDown } from "../src/ToolCallBlocks/ToolSummaryRow.js";
describe("ToolLayout", () => {
it("renders force-open details inside collapsible content", () => {
const html = renderToStaticMarkup(
createElement(
ZCodeIntlProvider,
{ initialLocale: "zh-CN" },
createElement(ToolLayout, {
toolId: "tool-layout-spacing",
icon: createElement("span", { "aria-hidden": true }, "icon"),
forceOpen: true,
kindLabel: "已探索",
primaryText: "1 个搜索",
renderContent: () => createElement("div", { className: "tool-detail" }, "detail"),
}),
),
);
expect(html).toContain('data-testid="tool-summary-trigger-tool-layout-spacing"');
expect(html).toMatch(/data-slot="collapsible-content"[^>]*>[\s\S]*?
]*>detail<\/div>/);
});
it("renders force-open content without a collapsible wrapper", () => {
const html = renderToStaticMarkup(
createElement(
ZCodeIntlProvider,
{ initialLocale: "zh-CN" },
createElement(ToolLayout, {
toolId: "tool-layout-force-open-spacing",
icon: createElement("span", { "aria-hidden": true }, "icon"),
canToggle: false,
forceOpen: true,
kindLabel: "已探索",
primaryText: "1 个搜索",
renderContent: () => createElement("div", { className: "tool-detail" }, "detail"),
}),
),
);
expect(html).not.toContain('data-slot="collapsible-content"');
expect(html).toContain('
detail
');
});
it("keeps running tool icons static while animating kind labels", () => {
const html = renderToStaticMarkup(
createElement(
ZCodeIntlProvider,
{ initialLocale: "zh-CN" },
createElement(ToolLayout, {
toolId: "tool-layout-running-label",
icon: createElement("span", { "aria-hidden": true }, "icon"),
canToggle: false,
isRunning: true,
kindLabel: "读取",
primaryText: "mod.rs",
}),
),
);
expect(html).toContain("icon");
expect(html).not.toContain("lucide-loader");
expect(html).not.toContain("animate-spin");
expect(html).toContain("读取");
expect(html).toContain("animated-gradient-text");
});
it("does not reserve a summary content gap when an expanded tool has no summary", () => {
const html = renderToStaticMarkup(
createElement(
ZCodeIntlProvider,
{ initialLocale: "zh-CN" },
createElement(ToolLayout, {
toolId: "tool-layout-empty-expanded-summary",
icon: createElement("span", { "aria-hidden": true }, "icon"),
forceOpen: true,
kindLabel: "终端",
primaryText: null,
renderContent: () => createElement("div", null, "detail"),
}),
),
);
expect(html).not.toContain("tool-summary-content");
expect(html).toMatch(
/tool-summary-kind-label[\s\S]*?终端<\/span>