import { describe, it, expect } from "vitest"; import { buildHostHtmlTemplate, type HostHtmlTemplateInput } from "../host-html-template.ts"; function createMinimalInput(overrides: Partial = {}): HostHtmlTemplateInput { return { sessionToken: "test-token-123", serverName: "test-server", toolName: "test-tool", toolArgs: { arg1: "value1" }, resource: { uri: "ui://test/widget", html: "

Test Widget

", mimeType: "text/html", meta: {}, }, allowAttribute: "", requireToolConsent: false, cacheToolConsent: true, ...overrides, }; } describe("buildHostHtmlTemplate", () => { describe("structure", () => { it("generates valid HTML document", () => { const html = buildHostHtmlTemplate(createMinimalInput()); expect(html).toContain(""); expect(html).toContain(""); expect(html).toContain(""); }); it("includes title with server and tool name", () => { const html = buildHostHtmlTemplate( createMinimalInput({ serverName: "my-server", toolName: "my-tool" }) ); expect(html).toContain("MCP UI - my-server / my-tool"); }); it("includes header with server and tool info", () => { const html = buildHostHtmlTemplate( createMinimalInput({ serverName: "demo-server", toolName: "widget-tool" }) ); expect(html).toContain('id="server-name"'); expect(html).toContain('id="tool-name"'); expect(html).toContain("Sandboxed"); }); it("includes iframe for app content", () => { const html = buildHostHtmlTemplate(createMinimalInput()); expect(html).toContain('