mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-04 08:47:45 +08:00
- Restored sessions no longer replay the last display_diagram over the saved diagram - Failed or stopped edit_diagram restores the canvas - Message snapshots keep the full multi-page document - "Improve with suggestions" uses the normal send path (headers, xml, retry counters) - Editing a message keeps its file/URL sections; cached example edits work - New chat's first autosave no longer resets the UI - Validation retries counted per user turn; validate-diagram sends the access code - Cached examples only match the example files on an empty canvas - Template sends keep attachments and wait for extraction
78 lines
2.6 KiB
TypeScript
78 lines
2.6 KiB
TypeScript
import { describe, expect, it } from "vitest"
|
|
import {
|
|
CACHED_EXAMPLE_RESPONSES,
|
|
findCachedResponse,
|
|
} from "@/lib/cached-responses"
|
|
|
|
describe("findCachedResponse", () => {
|
|
it("returns cached response for exact match without image", () => {
|
|
const result = findCachedResponse(
|
|
"Give me a **animated connector** diagram of transformer's architecture",
|
|
false,
|
|
)
|
|
expect(result).toBeDefined()
|
|
expect(result?.xml).toContain("Transformer Architecture")
|
|
})
|
|
|
|
it("returns cached response for exact match with the example file", () => {
|
|
const result = findCachedResponse(
|
|
"Replicate this in aws style",
|
|
true,
|
|
"architecture.png",
|
|
)
|
|
expect(result).toBeDefined()
|
|
expect(result?.xml).toContain("AWS")
|
|
})
|
|
|
|
it("returns undefined when the user attached their own file", () => {
|
|
expect(
|
|
findCachedResponse("Replicate this flowchart.", true, "mine.png"),
|
|
).toBeUndefined()
|
|
expect(
|
|
findCachedResponse(
|
|
"Summarize this paper as a diagram",
|
|
true,
|
|
"thesis.pdf",
|
|
),
|
|
).toBeUndefined()
|
|
})
|
|
|
|
it("returns undefined for file examples when the file name is unknown", () => {
|
|
// The server only knows whether a file is attached, not which one
|
|
const result = findCachedResponse("Replicate this in aws style", true)
|
|
expect(result).toBeUndefined()
|
|
})
|
|
|
|
it("returns undefined for non-matching prompt", () => {
|
|
const result = findCachedResponse(
|
|
"random prompt that doesn't exist",
|
|
false,
|
|
)
|
|
expect(result).toBeUndefined()
|
|
})
|
|
|
|
it("returns undefined when hasImage doesn't match", () => {
|
|
// This prompt exists but requires hasImage=true
|
|
const result = findCachedResponse("Replicate this in aws style", false)
|
|
expect(result).toBeUndefined()
|
|
})
|
|
|
|
it("returns undefined for partial match", () => {
|
|
const result = findCachedResponse("Give me a diagram", false)
|
|
expect(result).toBeUndefined()
|
|
})
|
|
|
|
it("returns response for Draw a cat prompt", () => {
|
|
const result = findCachedResponse("Draw a cat for me", false)
|
|
expect(result).toBeDefined()
|
|
expect(result?.xml).toContain("ellipse")
|
|
})
|
|
|
|
it("all cached responses have non-empty xml", () => {
|
|
for (const response of CACHED_EXAMPLE_RESPONSES) {
|
|
expect(response.xml).not.toBe("")
|
|
expect(response.xml.length).toBeGreaterThan(0)
|
|
}
|
|
})
|
|
})
|