fix(canvas): 提示词编辑 - 修复小视口溢出与窗口调整手柄失效

Refs #507
This commit is contained in:
ddCat
2026-09-18 13:19:57 +08:00
parent 10f2aa302c
commit 4eaa28b807
4 changed files with 72 additions and 27 deletions

View File

@@ -0,0 +1,22 @@
import { describe, expect, test } from "bun:test";
import { clampPromptEditorModalSize } from "../src/lib/canvas/canvas-prompt-editor-size";
describe("prompt editor window bounds", () => {
test("keeps desktop minimums and leaves a viewport margin", () => {
const viewport = { width: 1440, height: 900 };
expect(clampPromptEditorModalSize({ width: 100, height: 100 }, viewport)).toEqual({ width: 560, height: 320 });
expect(clampPromptEditorModalSize({ width: 2000, height: 2000 }, viewport)).toEqual({ width: 1416, height: 876 });
});
test("a narrow or short viewport takes precedence over desktop minimums", () => {
expect(clampPromptEditorModalSize({ width: 1200, height: 800 }, { width: 390, height: 844 })).toEqual({ width: 366, height: 800 });
expect(clampPromptEditorModalSize({ width: 1200, height: 800 }, { width: 844, height: 300 })).toEqual({ width: 820, height: 276 });
});
test("reconstrains a previously resized window after viewport shrink", () => {
const desktop = clampPromptEditorModalSize({ width: 1200, height: 800 }, { width: 1440, height: 900 });
const mobile = clampPromptEditorModalSize(desktop, { width: 390, height: 300 });
expect(mobile).toEqual({ width: 366, height: 276 });
expect(clampPromptEditorModalSize(mobile, { width: 390, height: 300 })).toEqual(mobile);
});
});