From d2bef9f348da0c8aa082324958ffb6bf85dd49b7 Mon Sep 17 00:00:00 2001 From: qiqi Date: Mon, 23 Nov 2026 00:55:41 +0800 Subject: [PATCH] =?UTF-8?q?test(promptlib):=20=E9=80=82=E9=85=8D=E4=B8=A4?= =?UTF-8?q?=E6=AD=A5=E6=94=BE=E7=BD=AE=E4=B8=8E=E6=8F=92=E5=85=A5=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/plugin-promptlib-render-test.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/plugin-promptlib-render-test.js b/tests/plugin-promptlib-render-test.js index 9eb45f4..5ad3664 100644 --- a/tests/plugin-promptlib-render-test.js +++ b/tests/plugin-promptlib-render-test.js @@ -47,6 +47,7 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms)) onChanged: () => () => {}, }, canvasWrite: { + createImageNode: (payload) => { calls.create.push({ type: 'img', payload }); return 'n-img' }, createNode: (type, x, y, data) => { calls.create.push({ type, x, y, data }); return 'n1' }, }, canvas: { @@ -58,6 +59,10 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms)) assert.ok(panel && typeof panel.mount === 'function', '应注册面板') const host = window.document.getElementById('host') + const plCanvas = window.document.createElement('div') + plCanvas.className = 'iwb-canvas' + window.document.body.appendChild(plCanvas) + plCanvas.getBoundingClientRect = () => ({ left: 0, top: 0, right: 800, bottom: 600, width: 800, height: 600 }) panel.mount(host) // 宿主只传一个参数 await wait(60) @@ -133,14 +138,21 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms)) // 插入画布按钮(+ 图标,title 含「插入到画布」) // 再点一次卡片 → 详情弹窗 → 底部「插入画布」 + const allChip = Array.from(host.querySelectorAll('.iwb-chip')).find((c) => c.textContent.indexOf('全部') === 0) + if (allChip) allChip.click() + await wait(30) + assert.ok(cards().length > 0, '应有卡片可点') cards()[0].dispatchEvent(new window.MouseEvent('dblclick', { bubbles: true })) await wait(40) const dlg2 = window.document.querySelector('.iwb-plp-dialog') const insBtn = dlg2 ? Array.from(dlg2.querySelectorAll('.iwb-plp-dfooter button')).find((b) => b.textContent === '插入画布') : null assert.ok(insBtn, '卡片应有「插入到画布」按钮') insBtn.dispatchEvent(new window.MouseEvent('click', { bubbles: true })) - await wait(50) - assert.strictEqual(calls.insert.length, 1, '插入应调用 ctx.promptlib.insert') + await wait(40) + assert.ok(window.document.querySelector('.iwb-plp-placebox'), '插入画布应进入两步放置(出现放置框)') + window.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'Escape' })) + await wait(20) + assert.strictEqual(window.document.querySelector('.iwb-plp-placebox'), null, 'Esc 应取消放置') // ---- v1.4.0 新增覆盖:封面渲染 / 插入封面图片 / 弹窗拖动缩放 ---- // 1) 封面:mock coverUrl 返回一张 dataURL,卡片应出现 @@ -163,9 +175,12 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms)) const imgBtn = dlgA && Array.from(dlgA.querySelectorAll('.iwb-plp-dfooter button')).find((b) => b.textContent === '插入图片') assert.ok(imgBtn, '有封面时详情应有「插入图片」按钮') imgBtn.dispatchEvent(new window.MouseEvent('click', { bubbles: true })) - await wait(60) - assert.strictEqual(inserted.length, 1, '应调用 promptlib.insertImage') + await wait(40) assert.strictEqual(window.document.querySelector('.iwb-plp-dialog'), null, '插入图片后弹窗应关闭') + assert.ok(window.document.querySelector('.iwb-plp-placebox'), '插入图片应进入两步放置') + plCanvas.dispatchEvent(new window.MouseEvent('pointerdown', { bubbles: true, clientX: 300, clientY: 200 })) + await wait(30) + assert.ok(calls.create.some((c) => c.type === 'img'), '点击画布应调用 createImageNode') // 3) 弹窗拖动 + 缩放:标题栏拖动改变 left,右下角拖拽改变 width(且不小于 640) window.document.querySelector('#host .iwb-plp-card').dispatchEvent(new window.MouseEvent('dblclick', { bubbles: true }))