import { renderHook } from "@testing-library/react" import { describe, expect, it, vi } from "vitest" 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), }), })) import { useDiagramStreaming } from "@/components/chat/use-diagram-streaming" 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 renderHook(() => useDiagramStreaming({ messages, processedToolCallsRef: { current: new Set() }, editDiagramOriginalXmlRef, loadedMessageIdsRef: { current: new Set() }, }), ) expect(editDiagramOriginalXmlRef.current.get("edit-2")).toBe( AFTER_FIRST_EDIT, ) }) })