import { render } from "@testing-library/react" import { describe, expect, it, vi } from "vitest" import en from "@/lib/i18n/dictionaries/en.json" const page = (cells: string) => `${cells}` const box = (id: string) => `` // The first edit's result is loaded (the ref has it); the chartXML state // has not caught up yet const BEFORE_FIRST_EDIT = page(box("a")) const AFTER_FIRST_EDIT = page(box("a") + box("b")) vi.mock("@/contexts/diagram-context", () => ({ useDiagram: () => ({ chartXML: BEFORE_FIRST_EDIT, chartXMLRef: { current: AFTER_FIRST_EDIT }, loadDiagram: vi.fn(() => null), }), })) vi.mock("@/hooks/use-dictionary", () => ({ useDictionary: () => en })) import { ChatMessageDisplay } from "@/components/chat-message-display" // jsdom has no layout Element.prototype.scrollIntoView = () => {} describe("the streaming preview of a second edit", () => { it("starts from the first edit's result", () => { const editDiagramOriginalXmlRef = { current: new Map() } const messages = [ { id: "m1", role: "assistant", parts: [ { type: "tool-edit_diagram", toolCallId: "edit-2", state: "input-streaming", input: { operations: [ { operation: "add", cell_id: "c", new_xml: box("c"), }, ], }, }, ], }, ] as any render( {}} setFiles={() => {}} processedToolCallsRef={{ current: new Set() }} editDiagramOriginalXmlRef={editDiagramOriginalXmlRef} status="streaming" />, ) expect(editDiagramOriginalXmlRef.current.get("edit-2")).toBe( AFTER_FIRST_EDIT, ) }) })