diff --git a/ui/src/ui/views/chat.browser.test.ts b/ui/src/ui/views/chat.browser.test.ts deleted file mode 100644 index 51b2d78c24a..00000000000 --- a/ui/src/ui/views/chat.browser.test.ts +++ /dev/null @@ -1,123 +0,0 @@ -import { render } from "lit"; -import { afterEach, describe, expect, it } from "vitest"; -import "../../test-helpers/load-styles.ts"; -import { renderChat, type ChatProps } from "./chat.ts"; - -const contextNoticeSessions: ChatProps["sessions"] = { - ts: 0, - path: "", - count: 1, - defaults: { modelProvider: "openai", model: "gpt-5", contextTokens: null }, - sessions: [ - { - key: "main", - kind: "direct", - updatedAt: null, - totalTokens: 3_800, - inputTokens: 3_800, - contextTokens: 4_000, - }, - ], -}; - -function createProps(overrides: Partial = {}): ChatProps { - return { - sessionKey: "main", - onSessionKeyChange: () => undefined, - thinkingLevel: null, - showThinking: false, - showToolCalls: true, - loading: false, - sending: false, - canAbort: false, - compactionStatus: null, - fallbackStatus: null, - messages: [], - toolMessages: [], - streamSegments: [], - stream: null, - streamStartedAt: null, - assistantAvatarUrl: null, - draft: "", - queue: [], - connected: true, - canSend: true, - disabledReason: null, - error: null, - sessions: { - ts: 0, - path: "", - count: 1, - defaults: { modelProvider: "openai", model: "gpt-5", contextTokens: null }, - sessions: [ - { - key: "main", - kind: "direct", - updatedAt: null, - inputTokens: 3_800, - contextTokens: 4_000, - }, - ], - }, - focusMode: false, - assistantName: "OpenClaw", - assistantAvatar: null, - onRefresh: () => undefined, - onToggleFocusMode: () => undefined, - onDraftChange: () => undefined, - onSend: () => undefined, - onQueueRemove: () => undefined, - onNewSession: () => undefined, - agentsList: null, - currentAgentId: "", - onAgentChange: () => undefined, - ...overrides, - }; -} - -async function renderContextNoticeChat() { - const container = document.createElement("div"); - document.body.append(container); - render( - renderChat( - createProps({ - sessions: contextNoticeSessions, - }), - ), - container, - ); - await new Promise((resolve) => requestAnimationFrame(() => resolve())); - return container; -} - -describe("chat context notice", () => { - afterEach(() => { - document.body.innerHTML = ""; - document.documentElement.style.removeProperty("--warn"); - document.documentElement.style.removeProperty("--danger"); - }); - - it("renders robust notice colors and badge-sized warning icon", async () => { - document.documentElement.style.setProperty("--warn", "rgb(1, 2, 3)"); - document.documentElement.style.setProperty("--danger", "tomato"); - const container = await renderContextNoticeChat(); - - const notice = container.querySelector(".context-notice"); - expect(notice).not.toBeNull(); - expect(notice?.style.getPropertyValue("--ctx-color")).toContain("rgb("); - expect(notice?.style.getPropertyValue("--ctx-color")).not.toContain("NaN"); - expect(notice?.style.getPropertyValue("--ctx-bg")).not.toContain("NaN"); - - const icon = container.querySelector(".context-notice__icon"); - expect(icon).not.toBeNull(); - if (!icon) { - return; - } - - expect(icon.tagName.toLowerCase()).toBe("svg"); - expect(icon.classList.contains("context-notice__icon")).toBe(true); - expect(icon.getAttribute("width")).toBe("16"); - expect(icon.getAttribute("height")).toBe("16"); - expect(icon.querySelector("path")).not.toBeNull(); - }); -}); diff --git a/ui/src/ui/views/chat.test.ts b/ui/src/ui/views/chat.test.ts index 31a0d58d9ed..5268b3a746a 100644 --- a/ui/src/ui/views/chat.test.ts +++ b/ui/src/ui/views/chat.test.ts @@ -143,6 +143,8 @@ describe("chat view", () => { it("renders the context notice only for fresh high current usage", () => { const container = document.createElement("div"); + document.documentElement.style.setProperty("--warn", "rgb(1, 2, 3)"); + document.documentElement.style.setProperty("--danger", "tomato"); const renderWithSession = (session: NonNullable["sessions"][number]) => render( @@ -182,6 +184,22 @@ describe("chat view", () => { expect(container.textContent).toContain("95% context used"); expect(container.textContent).toContain("190k / 200k"); expect(container.textContent).not.toContain("757.3k / 200k"); + const notice = container.querySelector(".context-notice"); + expect(notice).not.toBeNull(); + expect(notice?.style.getPropertyValue("--ctx-color")).toContain("rgb("); + expect(notice?.style.getPropertyValue("--ctx-color")).not.toContain("NaN"); + expect(notice?.style.getPropertyValue("--ctx-bg")).not.toContain("NaN"); + + const icon = container.querySelector(".context-notice__icon"); + expect(icon).not.toBeNull(); + expect(icon?.tagName.toLowerCase()).toBe("svg"); + expect(icon?.classList.contains("context-notice__icon")).toBe(true); + expect(icon?.getAttribute("width")).toBe("16"); + expect(icon?.getAttribute("height")).toBe("16"); + expect(icon?.querySelector("path")).not.toBeNull(); + + document.documentElement.style.removeProperty("--warn"); + document.documentElement.style.removeProperty("--danger"); renderWithSession({ key: "main",