From be6dbd4084b1eb80e8fef85f125bdf28fa1269ee Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 17 Apr 2026 19:55:39 +0100 Subject: [PATCH] test: mock chat sidebar markdown --- ui/src/ui/markdown.test.ts | 20 ++++++++++++ ui/src/ui/views/chat.test.ts | 61 ++++++------------------------------ 2 files changed, 30 insertions(+), 51 deletions(-) diff --git a/ui/src/ui/markdown.test.ts b/ui/src/ui/markdown.test.ts index 246bffa6192..9794ca8dd6a 100644 --- a/ui/src/ui/markdown.test.ts +++ b/ui/src/ui/markdown.test.ts @@ -1,5 +1,7 @@ +import { render } from "lit"; import { describe, expect, it, vi } from "vitest"; import { md, toSanitizedMarkdownHtml } from "./markdown.ts"; +import { renderMarkdownSidebar } from "./views/markdown-sidebar.ts"; describe("toSanitizedMarkdownHtml", () => { // ── Original tests from before markdown-it migration ── @@ -510,3 +512,21 @@ describe("toSanitizedMarkdownHtml", () => { }); }); }); + +describe("renderMarkdownSidebar", () => { + it("renders sanitized markdown content", () => { + const container = document.createElement("div"); + + render( + renderMarkdownSidebar({ + content: { kind: "markdown", content: "Hello **world**" }, + error: null, + onClose: () => undefined, + onViewRawText: () => undefined, + }), + container, + ); + + expect(container.querySelector(".sidebar-markdown strong")?.textContent).toBe("world"); + }); +}); diff --git a/ui/src/ui/views/chat.test.ts b/ui/src/ui/views/chat.test.ts index 92812ccf21f..2003f3f532d 100644 --- a/ui/src/ui/views/chat.test.ts +++ b/ui/src/ui/views/chat.test.ts @@ -8,6 +8,16 @@ import { normalizeMessage } from "../chat/message-normalizer.ts"; import type { SessionsListResult } from "../types.ts"; import { renderChat, type ChatProps } from "./chat.ts"; +vi.mock("./markdown-sidebar.ts", async () => { + const { html } = await import("lit"); + return { + renderMarkdownSidebar: (props: { content?: { content?: string; title?: string } | null }) => + html``, + }; +}); + function createSessions(): SessionsListResult { return { ts: 0, @@ -1516,57 +1526,6 @@ describe("chat view", () => { ); }); - it("renders markdown inside tool output sidebar", async () => { - const container = document.createElement("div"); - let sidebarContent: ChatProps["sidebarContent"] = null; - const messages = [ - { - role: "assistant", - content: [ - { type: "toolcall", name: "noop", arguments: {} }, - { type: "toolresult", name: "noop", text: "Hello **world**" }, - ], - timestamp: Date.now(), - }, - ]; - const renderWithSidebar = () => - render( - renderChat( - createProps({ - messages, - sidebarOpen: sidebarContent !== null, - sidebarContent, - sidebarError: null, - onOpenSidebar: (content) => { - sidebarContent = content; - renderWithSidebar(); - }, - onCloseSidebar: () => { - sidebarContent = null; - renderWithSidebar(); - }, - onRequestUpdate: renderWithSidebar, - }), - ), - container, - ); - - renderWithSidebar(); - - const toolSummary = container.querySelector(".chat-tool-msg-summary"); - expect(toolSummary).not.toBeNull(); - toolSummary?.dispatchEvent(new MouseEvent("click", { bubbles: true })); - await flushTasks(); - - const openSidebarButton = container.querySelector(".chat-tool-card__action-btn"); - expect(openSidebarButton).not.toBeNull(); - openSidebarButton?.dispatchEvent(new MouseEvent("click", { bubbles: true })); - await flushTasks(); - - const strongNodes = Array.from(container.querySelectorAll(".sidebar-markdown strong")); - expect(strongNodes.some((node) => node.textContent === "world")).toBe(true); - }); - it("lets a tool call collapse while keeping matching tool output visible", async () => { const container = document.createElement("div");