Files
next-ai-draw-io/tests/e2e/model-test.spec.ts
T
Dayuan Jiang c513d1a0c2 feat(ui): canvas-first redesign with a self-hosted draw.io (#957)
The canvas now fills the window and the chat floats on its right. draw.io is
served from our own origin (public/drawio, downloaded at build time and
checked against the release's SHA-256), so the app can drive the editor
directly:

- every AI change becomes a version card with a thumbnail; compare, restore
  or undo it, and Ctrl+Z on the canvas takes an AI change back in one step
- shapes the AI just changed are highlighted on the canvas
- selected shapes appear as a chip and are sent to the model
- draw.io's own simple UI: its toolbar, menus (auto layout, Mermaid, CSV
  import) and page tabs; the shape library starts closed
- new start screen, session rename and switcher, open .drawio files
- settings split into Models & keys, Appearance, Advanced and About
- Bedrock in the model settings also takes an API key instead of access keys
- phones switch between canvas and chat
- dark mode uses draw.io's own dark mode, with neutral greys around it

With an external draw.io (NEXT_PUBLIC_DRAWIO_BASE_URL) the features above
that need same origin are off.

The chat logic moved from the 1500-line chat panel into a chat engine plus
small UI components; zustand holds canvas, versions, settings and UI state.
2026-10-08 16:20:15 +09:00

99 lines
3.5 KiB
TypeScript

import { expect, test } from "@playwright/test"
import { getIframe } from "./lib/fixtures"
// One provider with three models; the test endpoint answers each differently
const CONFIG = {
version: 1,
providers: [
{
id: "p1",
provider: "glm",
apiKey: "test-key",
models: [
{ id: "m1", modelId: "model-ok" },
{ id: "m2", modelId: "model-no-tools" },
{ id: "m3", modelId: "model-broken" },
],
},
],
}
test("the Test button checks all models at once and shows each result", async ({
page,
}) => {
await page.addInitScript((config) => {
localStorage.setItem(
"next-ai-draw-io-model-configs",
JSON.stringify(config),
)
}, CONFIG)
const started: string[] = []
await page.route("**/api/validate-model", async (route) => {
const { modelId } = route.request().postDataJSON()
started.push(modelId)
// Answer only once all three requests arrived: they run in parallel
while (started.length < 3) await new Promise((r) => setTimeout(r, 50))
const answers: Record<string, object> = {
"model-ok": { valid: true, responseTime: 1234 },
"model-no-tools": {
valid: true,
responseTime: 800,
warning:
"Connected, but the model answered without calling a tool.",
},
"model-broken": { valid: false, error: "Model not found" },
}
await route.fulfill({ json: answers[modelId] })
})
await page.goto("/", { waitUntil: "networkidle" })
await getIframe(page).waitFor({ state: "visible", timeout: 30000 })
await page.getByTestId("model-selector").click()
await page.getByText("Configure Models...").click()
const dialog = page.locator('[role="dialog"]')
await dialog.getByText("GLM (Zhipu)").first().click()
await dialog.getByRole("button", { name: "Test", exact: true }).click()
await expect(
dialog.getByText("answered without calling a tool"),
).toBeVisible({ timeout: 15000 })
await expect(dialog.getByText("Model not found")).toBeVisible()
await expect(dialog.locator('[title="1.2 s"]')).toBeVisible()
expect(started.sort()).toEqual([
"model-broken",
"model-no-tools",
"model-ok",
])
})
test("the key link and the base URL cleanup", async ({ page }) => {
await page.addInitScript((config) => {
localStorage.setItem(
"next-ai-draw-io-model-configs",
JSON.stringify(config),
)
}, CONFIG)
await page.goto("/", { waitUntil: "networkidle" })
await getIframe(page).waitFor({ state: "visible", timeout: 30000 })
await page.getByTestId("model-selector").click()
await page.getByText("Configure Models...").click()
const dialog = page.locator('[role="dialog"]')
await dialog.getByText("GLM (Zhipu)").first().click()
await expect(
dialog.getByRole("link", { name: "Get API key" }),
).toHaveAttribute(
"href",
"https://open.bigmodel.cn/usercenter/proj-mgmt/apikeys",
)
const baseUrl = dialog.locator("#base-url")
await baseUrl.fill("https://proxy.example.com/v4/chat/completions/")
await baseUrl.blur()
await expect(baseUrl).toHaveValue("https://proxy.example.com/v4")
await expect(
dialog.getByText(
"Requests go to https://proxy.example.com/v4/chat/completions",
),
).toBeVisible()
})