test(promptlib): 适配两步放置与插入图片流程

This commit is contained in:
qiqi committed 2026-11-23 00:55:41 +08:00
1 parent 06d2a8bc5b
commit d2bef9f348
1 file changed
+19 -4
+19 -4
View File
@@ -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,卡片应出现 <img class=iwb-plp-cover>
@@ -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 }))