// 画布操作验收:复制/删除节点、文本与组合文本渲染(2026-10-28,P1) // // 守两条此前 e2e 几乎没覆盖的路径: // ① `src/canvas-actions.js` 的 `duplicateGraph`(app.js 里 Ctrl+D / 节点复制按钮共用的唯一实现) // —— 此前覆盖 9%。它算错就是"复制节点丢连线/重叠/组归属错"。 // ② `src/canvas-text.js` 的文本派生(文本节点展示来源文本、组合节点拼接多来源) // —— 此前覆盖 8%。它算错就是"文案串台/丢来源"。 // // 全部行为级断言(不看源码文本,遵守源码钉点棘轮「只减不增」)。 const { test, expect } = require('./_pw-coverage') const W = require('./_helpers/wait') const baseURL = process.env.IWB_BASE_URL || 'http://127.0.0.1:8787' test.use({ baseURL, viewport: { width: 1440, height: 1000 } }) // 预置一张小画布:prompt(p1) → textout(t1),prompt(p1) → combine(c1) // 这样文本派生路径在首次渲染时就会跑(canvas-text 的 batchSrcText / combineInputTexts 等) const WS = { workspaces: [{ id: 'ws_ops', name: '画布操作', groups: [], nodes: [ { id: 'p1', type: 'prompt', x: 120, y: 120, data: { text: '来源文案甲' } }, { id: 't1', type: 'textout', x: 420, y: 120, data: {} }, { id: 'c1', type: 'combine', x: 420, y: 320, data: {} }, ], edges: [ { id: 'e1', from: 'p1', to: 't1' }, { id: 'e2', from: 'p1', to: 'c1' }, ], }], activeId: 'ws_ops', rev: 1, schemaVersion: 1, } async function boot(page) { await page.addInitScript((ws) => { if (localStorage.getItem('__iwb_ops_seeded__') !== '1') { localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws)) localStorage.setItem('__iwb_ops_seeded__', '1') } }, WS) await page.goto('/', { waitUntil: 'domcontentloaded' }) await page.waitForSelector('.iwb-home-card:not(.iwb-home-new)', { timeout: 20000 }) await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick() await page.waitForSelector('.iwb-canvas-topbar', { timeout: 20000 }) await page.waitForTimeout(700) } const nodeCount = (page) => page.locator('.iwb-node').count() const edgeCount = (page) => page.locator('.iwb-edge, path.iwb-edge, .iwb-edge-hit').count() test('① 预置画布渲染:文本节点与组合节点都显示来源文案(canvas-text 派生路径)', async ({ page }) => { const errors = [] page.on('pageerror', (e) => errors.push(String(e && e.message || e))) await boot(page) expect(await nodeCount(page), '应渲染 3 个节点').toBe(3) // 文本/组合节点把来源文案显示在各自文本框里(不是 innerText)⇒ 直接读 textarea 的 value const vals = await page.evaluate(() => Array.from(document.querySelectorAll('.iwb-node textarea')).map((t) => t.value)) const hit = vals.filter((v) => String(v).includes('来源文案甲')).length expect(hit, '下游文本/组合节点应至少 1 处展示来源文案(canvas-text 派生路径)').toBeGreaterThanOrEqual(1) // 2026-10-30:组合节点的「分隔符」下拉恢复到「组合(N)」同一行右侧(不再独占一行) const cmb = page.locator('[data-node-id="c1"]') await expect(cmb, '组合节点应渲染').toHaveCount(1) await expect(cmb.locator('.iwb-gen-head .iwb-combine-sep'), '分隔符下拉应在标题行内').toHaveCount(1) await expect(cmb.locator('.iwb-combine-row'), '不应再独占一行').toHaveCount(0) expect(errors, '不应有 pageerror').toEqual([]) }) test('② Ctrl+D 复制节点:节点 +1 且原连线保留(canvas-actions.duplicateGraph)', async ({ page }) => { await boot(page) const n0 = await nodeCount(page) const e0 = await edgeCount(page) await page.locator('[data-node-id="p1"] .iwb-node-head').click() await expect(page.locator('.iwb-node-selected')).toHaveCount(1) await page.keyboard.press('Control+d') await W.waitNodeCount(page, n0 + 1) // Ctrl+D 后节点应 +1 expect(await nodeCount(page), 'Ctrl+D 后节点应 +1').toBe(n0 + 1) expect(await edgeCount(page), '复制单个节点不应改变连线数').toBe(e0) // 复制结果不得与原节点重叠(v3.24.43 起:placeBeside 右侧/下方就近让位,**含源节点**参与避让) // 旧断言只查"left/top 完全相同",56px 对角错位的实现照样通过 —— 但 480 宽的节点被压住 88%, // 原节点只剩一条细边可点(用户反馈"复制完贴在一起、选不中")。这里改成真实矩形判交 + 必须完全在侧边。 const dup = await page.evaluate(() => { const seeded = ['p1', 't1', 'c1'] const a = document.querySelector('[data-node-id="p1"]').getBoundingClientRect() const copies = Array.from(document.querySelectorAll('.iwb-node')) .filter((e) => !seeded.includes(e.getAttribute('data-node-id'))) .map((e) => e.getBoundingClientRect()) return copies.map((r) => ({ overlap: r.left < a.right && r.right > a.left && r.top < a.bottom && r.bottom > a.top, clear: r.left >= a.right - 1 || r.top >= a.bottom - 1, })) }) expect(dup.length, '应恰好新增 1 个节点').toBe(1) expect(dup[0].overlap, '复制出的节点不得与原节点重叠:' + JSON.stringify(dup)).toBe(false) expect(dup[0].clear, '复制体应整体落在原节点右侧或下方(不骑在边上)').toBe(true) }) test('③ Delete 删除选中节点:节点 −1 且相关连线被清理', async ({ page }) => { await boot(page) const n0 = await nodeCount(page) const e0 = await edgeCount(page) await page.locator('[data-node-id="t1"] .iwb-node-head').click() await expect(page.locator('.iwb-node-selected')).toHaveCount(1) await page.keyboard.press('Delete') await W.waitNodeCount(page, n0 - 1) // 删除后节点应 −1 expect(await nodeCount(page), '删除后节点应 −1').toBe(n0 - 1) expect(await edgeCount(page), '删除节点后其连线应一并清理').toBeLessThan(e0) }) test('④ 文本节点编辑后立即生效(canvas-text 的输入→展示链路)', async ({ page }) => { await boot(page) // 文字类节点默认**只读**,双击进入编辑后才可输入(见 ui-node-card 的 onDoubleClick) const ta = page.locator('[data-node-id="p1"] textarea.iwb-textarea').first() await expect(ta, 'prompt 节点应有文本框').toBeVisible() // 2026-11-27:locator.dblclick() 会因「双击后进入编辑态重渲染」被 Playwright 反复重试到超时; // 用坐标双击绕开动作可操作性检查(被测行为不变)。 const tb = await ta.boundingBox() await page.mouse.dblclick(tb.x + tb.width / 2, tb.y + tb.height / 2) await page.waitForTimeout(300) await ta.fill('改后的文案乙') await page.waitForTimeout(800) const vals = await page.evaluate(() => Array.from(document.querySelectorAll('.iwb-node textarea')).map((t) => t.value)) expect(vals.filter((v) => String(v).includes('改后的文案乙')).length, '下游文本/组合节点应同步显示新文案').toBeGreaterThanOrEqual(1) }) test('⑤ 气泡删除按钮(2026-11-09 恢复,hover 红、静态灰);右键菜单 / Delete 键仍在', async ({ page }) => { // 历史:2026-10-30 用户要求移除气泡上的 × 删除按钮(防误删);2026-11-09 用户确认恢复。 // 本测试守三件事:①按钮回来了 ②静态态与普通按钮一致、只有 hover 才红(方案 B)③另两条删除入口没被弄没。 await boot(page) await page.locator('[data-node-id="t1"] .iwb-node-head').click() await page.waitForTimeout(250) const fb = page.locator('.iwb-node-floatbar') await expect(fb, '选中后应出现气泡').toBeVisible() const fbDel = fb.locator('button[aria-label="删除"]') await expect(fbDel, '气泡上应有删除按钮').toHaveCount(1) // 按功能命名(iwb-fb-del),不复用 2026-10-30 那个按颜色命名的旧类 —— 颜色会变,语义不变 await expect(fbDel, '删除按钮应挂语义化类名 iwb-fb-del').toHaveClass(/iwb-fb-del/) await expect(fb.locator('.iwb-node-floatbar-danger'), '不得复用已废弃的旧类 iwb-node-floatbar-danger').toHaveCount(0) // 复制按钮仍在(气泡功能没被削掉) await expect(fb.locator('[aria-label="复制"]')).toHaveCount(1) // 删除入口①:气泡按钮(2026-11-09 新增) const n0 = await nodeCount(page) await fbDel.click() // 不写固定等待:紧接的两条断言都是条件等待,会自动重试到超时 await expect(page.locator('[data-node-id="t1"]'), '气泡删除应真删掉该节点').toHaveCount(0) expect(await nodeCount(page), '气泡删除应让节点数 -1').toBe(n0 - 1) // 删除入口②:右键菜单(2026-11-19 收进「该节点▸」二级:一级只剩 添加节点/选中操作/该节点) const n1 = await nodeCount(page) const box = await page.locator('[data-node-id="p1"]').boundingBox() await page.mouse.click(box.x + box.width / 2, box.y + 60, { button: 'right' }) await page.waitForTimeout(250) await page.locator('.iwb-ctxmenu:not(.iwb-ctx-sub)').locator('.iwb-ctx-item', { hasText: /^该节点/ }).hover() const delItem = page.locator('.iwb-ctxmenu.iwb-ctx-sub .iwb-ctx-danger').filter({ hasText: '删除该节点' }) await expect(delItem, '「该节点▸」二级菜单应保留「删除」').toBeVisible() await delItem.click() expect(await nodeCount(page), '右键删除应生效').toBe(n1 - 1) // 删除入口③:Delete 键 await page.locator('[data-node-id="c1"] .iwb-node-head').click() await page.waitForTimeout(150) await page.keyboard.press('Delete') expect(await nodeCount(page), 'Delete 键删除应生效').toBeLessThan(n1 - 1) }) test('⑥ 气泡压在标题带上(与标题同距),气泡上的「改名」可用', async ({ page }) => { // 2026-10-30:气泡下沉到与标题底边齐平(会遮住标题)⇒ 改名入口移到气泡按钮 + 右键菜单。 // 这条同时守住「几何关系」与「遮挡下仍能改名」。 await boot(page) // 把节点拖到屏幕中部,保证气泡有空间向上弹(否则会翻到节点下方) const nb = await page.locator('[data-node-id="t1"]').boundingBox() await page.mouse.move(nb.x + nb.width / 2, nb.y + 80) await page.mouse.down() await page.mouse.move(nb.x + nb.width / 2, nb.y + 300, { steps: 8 }) await page.mouse.up() await page.waitForTimeout(300) await page.locator('[data-node-id="t1"] .iwb-node-head').click() await page.waitForTimeout(350) const g = await page.evaluate(() => { const node = document.querySelector('[data-node-id="t1"]') const head = node.querySelector('.iwb-node-head') const fb = document.querySelector('.iwb-node-floatbar') const n = node.getBoundingClientRect(), h = head.getBoundingClientRect(), f = fb.getBoundingClientRect() return { gapHead: Math.round(n.top - h.bottom), gapFb: Math.round(n.top - f.bottom), below: fb.className.indexOf('below') >= 0 } }) expect(g.below, '上方有空间时气泡应在节点上方').toBe(false) expect(Math.abs(g.gapFb - g.gapHead), `气泡底边应与标题底边同距(气泡 ${g.gapFb}px / 标题 ${g.gapHead}px)`).toBeLessThanOrEqual(1) // 遮挡下仍可改名:气泡上的铅笔 await page.locator('.iwb-node-floatbar button[aria-label="改名"]').click() await expect(page.locator('.iwb-rename-modal')).toBeVisible() await page.locator('.iwb-rename-input').fill('新名字甲') await page.locator('.iwb-rename-modal .iwb-btn-primary').click() await expect(page.locator('[data-node-id="t1"] .iwb-node-title')).toHaveText('新名字甲') }) test('⑦ 右键菜单「重命名节点」也能改名(备用入口)', async ({ page }) => { await boot(page) const nb = await page.locator('[data-node-id="t1"]').boundingBox() await page.mouse.click(nb.x + nb.width / 2, nb.y + 80, { button: 'right' }) await expect(page.locator('.iwb-ctxmenu:not(.iwb-ctx-sub)')).toBeVisible() // 2026-11-19:重命名收进「该节点▸」二级菜单 await page.locator('.iwb-ctxmenu:not(.iwb-ctx-sub)').locator('.iwb-ctx-item', { hasText: /^该节点/ }).hover() await page.locator('.iwb-ctxmenu.iwb-ctx-sub .iwb-ctx-item', { hasText: '重命名节点' }).click() await expect(page.locator('.iwb-rename-modal')).toBeVisible() await page.locator('.iwb-rename-input').fill('新名字乙') await page.locator('.iwb-rename-modal .iwb-btn-primary').click() await expect(page.locator('[data-node-id="t1"] .iwb-node-title')).toHaveText('新名字乙') }) test('⑧ 图库插入的参考图(url 是引用对象)不能让配置节点报渲染错误', async ({ page }) => { // 2026-10-30 用户实测:图库「插入到画布」的图片,其 data.url 是 {__blob}/{__cache} **引用对象**(既有设计)。 // 直接接进 组合 → 配置 后,refArgsOf 里 d.url.trim() 抛错 ⇒ 配置节点整块显示 // 「渲染错误:o.url.trim is not a function」;同时参考图的 URL 输入框显示 "[object Object]"。 const IMG = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFAAH/q842iQAAAABJRU5ErkJggg==' const wsRef = { workspaces: [{ id: 'ws_refbug', name: '图库插入', groups: [], nodes: [ // 引用对象形式的 url(图库插入产生)+ 一张正常 data 图 { id: 'rObj', type: 'ref', x: 80, y: 80, data: { url: { __cache: { u: 'https://example.test/a.png' } }, data: null, name: '图库图.png' } }, { id: 'rOk', type: 'ref', x: 80, y: 360, data: { url: '', data: IMG, name: '正常图.png' } }, { id: 'cb', type: 'combine', x: 460, y: 180, data: {} }, { id: 'g1', type: 'gen', x: 900, y: 180, w: 480, data: { model: 'gpt-image-2', provider: 'p-a', keyGroup: 'a-1', size: '1024x1024', ratio: '1:1', res: '1K' } }, ], edges: [ { id: 'e1', from: 'rObj', to: 'cb' }, { id: 'e2', from: 'rOk', to: 'cb' }, { id: 'e3', from: 'cb', to: 'g1' }, ], }], activeId: 'ws_refbug', rev: 1, schemaVersion: 1, } await page.addInitScript((d) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg)) localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws)) localStorage.setItem('iwb_ws_active', d.ws.activeId) localStorage.setItem('iwb_ws_ws_refbug', JSON.stringify(d.ws.workspaces[0])) }, { cfg: { providers: [{ id: 'p-a', name: 'A', baseUrl: 'https://a.example/v1', keys: [{ id: 'a-1', name: 'k' }], models: [{ name: 'gpt-image-2', visible: true }] }], canvas: {} }, ws: wsRef }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await W.waitHomeReady(page) await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick() await expect(page.locator('.iwb-canvas:not(.iwb-canvas-hidden)')).toBeVisible() await page.waitForTimeout(500) // ① 配置节点不能出现渲染错误,且能正常建任务 const gen = page.locator('[data-node-id="g1"]') await expect(gen, '配置节点不应出现渲染错误').not.toContainText('渲染错误') await expect(gen.locator('.iwb-tasks'), '配置节点应正常渲染任务区').toHaveCount(1) // ② 参考图节点的 URL 输入框不能显示 "[object Object]" const urlVal = await page.locator('[data-node-id="rObj"] .iwb-ref-url-input').inputValue() expect(urlVal, 'URL 输入框不应显示 [object Object]').toBe('') }) test('⑨ F2 重命名:单选生效;未选中 / 多选 / 正在输入时都不触发(第 3 个改名入口)', async ({ page }) => { // 2026-10-31:改名此前只有两个入口(气泡铅笔 ⑥、右键菜单 ⑦),补 F2 快捷键。 // 断言的正是「分派条件」:sel.length === 1 才弹窗;多选不猜哪个;输入框内不抢键。 await boot(page) // ① 未选中:按 F2 不应弹窗(否则会对着"上一次选中"或空节点弹出来) await page.locator('.iwb-canvas').click({ position: { x: 12, y: 12 } }) await expect(page.locator('.iwb-node-selected')).toHaveCount(0) await page.keyboard.press('F2') await expect(page.locator('.iwb-rename-modal'), '未选中节点时 F2 不应弹窗').toHaveCount(0) // ② 正在输入框里打字(提示词 textarea 聚焦):F2 不应抢键 // ⚠️ 不要试图把「单击输入框就聚焦」当成 bug 修(2026-10-31 用户确认是**有意设计**): // 这一版的语义是 **单击 = 选中节点并进入拖动**,**再点一次 = 聚焦输入框开始打字**。 // 若改成单击即聚焦,节点就会被输入框吃掉点击,再也没法「点一下选中并拖动」。 // Playwright 的 click() 落点在这套语义下拿不到焦点(它连点的间隔与真人不同), // 所以这里用显式 focus() 来验证「焦点在输入框时 F2 不抢键」这条守卫—— // 否则断言会走到「F2 本来该弹窗」的分支上,变成假阳性。 const ta = page.locator('[data-node-id="p1"] textarea').first() await ta.focus() await expect(ta, '提示词输入框应已获得焦点(F2 守卫的前提)').toBeFocused() await page.keyboard.press('F2') await expect(page.locator('.iwb-rename-modal'), '输入框内按 F2 不应弹窗').toHaveCount(0) // ③ 单选:F2 弹出改名弹窗,预填当前标题,回车提交后标题生效 await page.locator('[data-node-id="t1"] .iwb-node-head').click() await page.waitForTimeout(250) await page.keyboard.press('F2') await expect(page.locator('.iwb-rename-modal'), '单选时 F2 应弹出改名弹窗').toBeVisible() await expect(page.locator('.iwb-rename-modal .iwb-modal-head'), '弹窗标题应是「重命名节点」').toContainText('重命名节点') expect(await page.locator('.iwb-rename-input').inputValue(), '应预填当前标题(非空)').toBeTruthy() await page.locator('.iwb-rename-input').fill('F2 改的名字') await page.keyboard.press('Enter') await expect(page.locator('[data-node-id="t1"] .iwb-node-title'), 'F2 改名应写回节点标题').toHaveText('F2 改的名字') await expect(page.locator('.iwb-rename-modal'), '提交后弹窗应关闭').toHaveCount(0) // ④ 多选:不弹窗(不猜用户想改哪一个) await page.locator('[data-node-id="t1"] .iwb-node-head').click() await page.locator('[data-node-id="p1"] .iwb-node-head').click({ modifiers: ['Control'] }) await page.waitForTimeout(250) await page.keyboard.press('F2') await expect(page.locator('.iwb-rename-modal'), '多选时 F2 不应弹窗').toHaveCount(0) }) test('⑩ 抓手工具:空白拖动=平移(不框选);V/Esc 切回选择', async ({ page }) => { // 2026-10-31:底栏最左新增互斥工具组「选择 / 抓手」。抓手 = 空格+左键的固化版(不用按住空格), // 只接管画布**空白处**的左键拖;这一条守「拖空白 = 平移、且不再框选」。 await boot(page) // 2026-11-27:平移改的是 .iwb-world;.iwb-grid 的 transform 是静态点阵偏移,不随平移变化 const gridPos = () => page.evaluate(() => { const w = document.querySelector('.iwb-world'); return w ? w.style.transform : '' }) const nodeT = () => page.locator('[data-node-id="p1"]').evaluate((el) => el.style.transform) const beforePos = await gridPos() const beforeNode = await nodeT() await page.locator('.iwb-toolbar-bottom button[data-tool="pan"]').click() await expect(page.locator('.iwb-toolbar-bottom button[data-tool="pan"]'), '抓手按钮应进入选中态').toHaveAttribute('aria-pressed', 'true') await expect(page.locator('.iwb-canvas'), '抓手态应挂上 iwb-tool-pan(grab 光标)').toHaveClass(/iwb-tool-pan/) // 空白处拖动(画布 60% 宽 / 25% 高处,避开节点与底栏) await page.waitForTimeout(250) // 等工具态落到画布(2026-11-27:偶发首帧仍按选择工具处理) // 运行时找一处真正的画布空白(避开节点/停靠栏/工具条)——写死比例会随取景变化落到节点上 const pt = await page.evaluate(() => { const blocked = '.iwb-node, .iwb-dock, .iwb-toolbar, .iwb-minimap, .iwb-statusbar, .iwb-hint-bottom, .iwb-canvas-topbar' for (let fy = 0.35; fy < 0.85; fy += 0.05) { for (let fx = 0.45; fx < 0.9; fx += 0.05) { const x = window.innerWidth * fx, y = window.innerHeight * fy const el = document.elementFromPoint(x, y) if (!el || !el.closest || !el.closest('.iwb-canvas')) continue if (el.closest(blocked)) continue return { x, y } } } return null }) expect(pt, '应能找到画布空白点').toBeTruthy() await page.mouse.move(pt.x, pt.y) await page.mouse.down() await page.mouse.move(pt.x + 70, pt.y + 45, { steps: 10 }) await expect(page.locator('.iwb-boxsel'), '抓手拖动不应产生框选').toHaveCount(0) await page.mouse.up() await expect.poll(gridPos, { timeout: 5000 }).not.toBe(beforePos) expect(await nodeT(), '平移画布不应移动节点').toBe(beforeNode) // V 切回选择工具 await page.keyboard.press('v') await expect(page.locator('.iwb-toolbar-bottom button[data-tool="select"]'), 'V 应切回选择工具').toHaveAttribute('aria-pressed', 'true') await expect(page.locator('.iwb-canvas'), '选择态不应再挂 iwb-tool-pan').not.toHaveClass(/iwb-tool-pan/) // H 进抓手,Esc 退出 await page.keyboard.press('h') await expect(page.locator('.iwb-toolbar-bottom button[data-tool="pan"]'), 'H 应切到抓手').toHaveAttribute('aria-pressed', 'true') await page.keyboard.press('Escape') await expect(page.locator('.iwb-toolbar-bottom button[data-tool="select"]'), 'Esc 应退回选择工具').toHaveAttribute('aria-pressed', 'true') }) test('⑪ 抓手工具:拖节点仍移动节点(视口不平移)', async ({ page }) => { // 抓手「只接管空白处」——节点自己 stopPropagation,事件到不了画布 ⇒ 拖动仍是移动节点。 await boot(page) const grid = page.locator('.iwb-grid') const gridPos = async () => (await grid.getAttribute('style')) || '' const nodeT = () => page.locator('[data-node-id="p1"]').evaluate((el) => el.style.transform) await page.locator('.iwb-toolbar-bottom button[data-tool="pan"]').click() const beforePos = await gridPos() const beforeNode = await nodeT() const head = await page.locator('[data-node-id="p1"] .iwb-node-head').boundingBox() await page.mouse.move(head.x + 30, head.y + head.height / 2) await page.mouse.down() await page.mouse.move(head.x + 30 + 90, head.y + head.height / 2 + 60, { steps: 8 }) await page.mouse.up() expect(await nodeT(), '抓手态下拖节点应移动该节点').not.toBe(beforeNode) expect(await gridPos(), '抓手态下拖节点不应平移画布').toBe(beforePos) }) test('⑨ 节点背景色:气泡色板可选色、刷新后保留、可撤销;右键菜单同入口', async ({ page }) => { // 2026-11-01 新增:所有节点支持背景色(6 预设 + 无)。 // 性能契约:纯静态 CSS,不改色时零开销;改色只让该节点重渲染(节点卡 memo + 引用比较)。 const CFG = { providers: [], canvas: {} } const WS = { workspaces: [{ id: 'ws_bg', name: '背景色', groups: [], nodes: [ { id: 'n1', type: 'prompt', x: 200, y: 200, data: { text: '你做什么' } }, { id: 'n2', type: 'prompt', x: 640, y: 200, data: { text: '第二个节点' } }, ], edges: [] }], activeId: 'ws_bg', rev: 1, schemaVersion: 1 } await page.addInitScript((d) => { if (localStorage.getItem('iwb_ws_ws_bg')) return localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg)) localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws)) localStorage.setItem('iwb_ws_active', 'ws_bg') localStorage.setItem('iwb_ws_ws_bg', JSON.stringify(d.ws.workspaces[0])) }, { cfg: CFG, ws: WS }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await W.waitHomeReady(page) await page.locator('.iwb-home-card').filter({ hasText: '背景色' }).first().dblclick() await expect(page.locator('[data-node-id="n1"]')).toBeVisible({ timeout: 15000 }) const bgOf = (id) => page.locator('[data-node-id="' + id + '"]').evaluate((n) => getComputedStyle(n).backgroundColor) // ① 单选气泡里的「背景色」按钮 → 色板 6 格(无 / 白 / 青 / 紫 / 橙 / 黄) await page.locator('[data-node-id="n1"]').click() const bgBtn = page.locator('.iwb-node-floatbar button[aria-label="背景色"]') await expect(bgBtn, '气泡应有「背景色」按钮').toHaveCount(1) // 2026-11-01:按钮上直接显示**当前背景色**,鼠标移上去就自动展开色板(不用先点一下) const dot = bgBtn.locator('.iwb-bg-dot') await expect(dot, '按钮应显示当前背景色的小色块').toHaveCount(1) expect(await dot.getAttribute('data-bg'), '未上色时色块应标记为 none').toBe('none') await expect(page.locator('.iwb-bg-palette'), 'hover 之前不应展开').toHaveCount(0) await bgBtn.hover() await expect(page.locator('.iwb-pop.iwb-bg-palette'), 'hover 应自动弹出色板(省一次点击)').toBeVisible({ timeout: 5000 }) await expect(page.locator('.iwb-bg-palette .iwb-bg-swatch'), '应有 8 个预设色(无/白/青/紫/粉红/橙/黄/浅绿)').toHaveCount(8) // ①-b 悬停即预览换色(不写数据),移开不点 ⇒ 自动还原;点击才算确认 const bgPlain = await bgOf('n1') const cyanSwatchBg = await page.locator('.iwb-bg-palette .iwb-bg-swatch').nth(2).evaluate((e) => getComputedStyle(e).backgroundColor) await page.locator('.iwb-bg-palette .iwb-bg-swatch').nth(2).hover() await expect.poll(() => bgOf('n1'), { timeout: 5000, message: '悬停色块应立即预览换色' }).toBe(cyanSwatchBg) await page.mouse.move(10, 10) await expect.poll(() => bgOf('n1'), { timeout: 8000, message: '移开未确认应还原原色' }).toBe(bgPlain) // ② 点「青」⇒ 该节点背景 = 色块对应的颜色(与色块自身计算色对比,不写死 hex) const before2 = await bgOf('n2') await bgBtn.hover() await expect(page.locator('.iwb-pop.iwb-bg-palette')).toBeVisible({ timeout: 5000 }) await page.locator('.iwb-bg-palette .iwb-bg-swatch').nth(2).hover() await page.locator('.iwb-bg-palette .iwb-bg-swatch').nth(2).click() await expect.poll(() => bgOf('n1'), { timeout: 5000, message: '节点背景应变青' }).toBe(cyanSwatchBg) expect(await bgOf('n2'), '未选中的节点不应受影响').toBe(before2) // ③ 撤销回默认(撤销栈只在内存里 ⇒ 必须在刷新前测) await page.waitForTimeout(600) // 等历史入栈(debounce) await page.locator('[data-node-id="n1"]').click() await page.waitForTimeout(200) await page.keyboard.press('Control+z') await expect.poll(() => bgOf('n1'), { timeout: 8000, message: '撤销应回默认背景' }).not.toBe(cyanSwatchBg) // ④ 再选一次「青」,刷新后应保留 await page.locator('[data-node-id="n1"]').click() await page.locator('.iwb-node-floatbar button[aria-label="背景色"]').click() await page.locator('.iwb-bg-palette .iwb-bg-swatch').nth(2).hover() await page.locator('.iwb-bg-palette .iwb-bg-swatch').nth(2).click() await expect.poll(() => bgOf('n1'), { timeout: 5000 }).toBe(cyanSwatchBg) await page.waitForTimeout(800) await page.reload({ waitUntil: 'domcontentloaded' }) await expect(page.locator('[data-node-id="n1"]')).toBeVisible({ timeout: 15000 }) expect(await bgOf('n1'), '刷新后背景色应保留').toBe(cyanSwatchBg) // ⑤ 右键菜单同一入口(2026-11-19:背景色收进「该节点▸」二级菜单) await page.locator('[data-node-id="n2"]').click({ button: 'right' }) await page.locator('.iwb-ctxmenu:not(.iwb-ctx-sub)').locator('.iwb-ctx-item', { hasText: /^该节点/ }).hover() const ctxBg = page.locator('.iwb-ctxmenu.iwb-ctx-sub .iwb-ctx-item').filter({ hasText: '背景色' }) await expect(ctxBg, '「该节点▸」二级菜单应有「背景色」').toBeVisible() await ctxBg.click() await expect(page.locator('.iwb-pop.iwb-bg-palette'), '右键应打开同一套色板').toBeVisible() const purpleSwatchBg = await page.locator('.iwb-bg-palette .iwb-bg-swatch').nth(3).evaluate((e) => getComputedStyle(e).backgroundColor) await page.locator('.iwb-bg-palette .iwb-bg-swatch').nth(3).hover() await page.locator('.iwb-bg-palette .iwb-bg-swatch').nth(3).click() await expect.poll(() => bgOf('n2'), { timeout: 5000, message: '右键选色也应生效' }).toBe(purpleSwatchBg) }) test('⑩ 节点背景色:多选批量上色(同一套色板,一次改多个)', async ({ page }) => { // ⚠️ 两个坑(都实测过): // ① Ctrl 多选只挂在**标题栏**按下(app.js onHeaderDown)上,点节点体不会进多选 // ② macOS 上 Ctrl+点击 = 右键 ⇒ 会先弹右键菜单把气泡盖住;必须用 **Meta(Cmd)** const WS2 = { workspaces: [{ id: 'ws_bg2', name: '背景色多选', groups: [], nodes: [ { id: 'm1', type: 'prompt', x: 200, y: 200, data: { text: '甲' } }, { id: 'm2', type: 'prompt', x: 640, y: 200, data: { text: '乙' } }, ], edges: [] }], activeId: 'ws_bg2', rev: 1, schemaVersion: 1 } await page.addInitScript((d) => { if (localStorage.getItem('iwb_ws_ws_bg2')) return localStorage.setItem('iwb_web_cfg', JSON.stringify({ providers: [], canvas: {} })) localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws)) localStorage.setItem('iwb_ws_active', 'ws_bg2') localStorage.setItem('iwb_ws_ws_bg2', JSON.stringify(d.ws.workspaces[0])) }, { ws: WS2 }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await W.waitHomeReady(page) await page.locator('.iwb-home-card').filter({ hasText: '背景色多选' }).first().dblclick() await expect(page.locator('[data-node-id="m1"]')).toBeVisible({ timeout: 15000 }) const bgOf = (id) => page.locator('[data-node-id="' + id + '"]').evaluate((n) => getComputedStyle(n).backgroundColor) await page.locator('[data-node-id="m1"] .iwb-node-head').click() await page.locator('[data-node-id="m2"] .iwb-node-head').click({ modifiers: ['Meta'] }) const multiBg = page.locator('.iwb-node-floatbar-group button[aria-label="背景色"]') await expect(multiBg, '多选气泡应有「背景色」').toHaveCount(1, { timeout: 8000 }) await multiBg.click() await expect(page.locator('.iwb-pop.iwb-bg-palette'), '应弹出色板').toBeVisible() const orangeSwatchBg = await page.locator('.iwb-bg-palette .iwb-bg-swatch').nth(5).evaluate((e) => getComputedStyle(e).backgroundColor) // 0无 1白 2青 3紫 4粉红 5橙 await page.locator('.iwb-bg-palette .iwb-bg-swatch').nth(5).hover() await page.locator('.iwb-bg-palette .iwb-bg-swatch').nth(5).click() await expect.poll(() => bgOf('m1'), { timeout: 6000, message: '批量上色应作用于 m1' }).toBe(orangeSwatchBg) await expect.poll(() => bgOf('m2'), { timeout: 6000, message: '批量上色应作用于 m2' }).toBe(orangeSwatchBg) }) test('⑪ 自定义背景色节点的内层元素走同色系派生;未上色节点保持原样', async ({ page }) => { // 2026-11-01:节点设了背景色后,内部的下拉框 / 组合来源行 / 配置任务卡改用「比节点底亮一档」的同色系派生色 // (color-mix 静态计算,不改色时零开销)。未上色的节点必须**完全不变**,避免影响既有观感。 const CFG = { providers: [{ id: 'p-a', name: 'A', baseUrl: 'https://a.example/v1', keys: [{ id: 'a-1', name: 'k', value: 'sk-test' }], models: [{ name: 'gpt-image-2.5', visible: true }] }], canvas: {} } const genData = (bg) => ({ model: 'gpt-image-2.5', provider: 'p-a', keyGroup: 'a-1', size: '1024x1024', ratio: '1:1', res: '1K', ...(bg ? { bg } : {}) }) // bg 用令牌(yellow) const ws = { workspaces: [{ id: 'ws_tint', name: '同色系', groups: [], nodes: [ { id: 'q1', type: 'prompt', x: 100, y: 60, data: { text: '甲段', bg: 'green' } }, { id: 'q2', type: 'prompt', x: 100, y: 520, data: { text: '乙段' } }, { id: 'gc', type: 'gen', x: 620, y: 60, w: 460, data: genData('yellow') }, { id: 'gp', type: 'gen', x: 620, y: 520, w: 460, data: genData('') }, ], edges: [{ id: 'a1', from: 'q1', to: 'gc' }, { id: 'a2', from: 'q2', to: 'gp' }] }], activeId: 'ws_tint', rev: 1, schemaVersion: 1 } await page.addInitScript((d) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg)) localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws)) localStorage.setItem('iwb_ws_active', 'ws_tint') localStorage.setItem('iwb_ws_ws_tint', JSON.stringify(d.ws.workspaces[0])) }, { cfg: CFG, ws }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await W.waitHomeReady(page) await page.locator('.iwb-home-card').filter({ hasText: '同色系' }).first().dblclick() await expect(page.locator('[data-node-id="gc"] .iwb-task').first()).toBeVisible({ timeout: 15000 }) const bgOf = (id, sel) => page.locator('[data-node-id="' + id + '"] ' + sel).first().evaluate((e) => getComputedStyle(e).backgroundColor) const taskColored = await bgOf('gc', '.iwb-task') const taskPlain = await bgOf('gp', '.iwb-task') const pickColored = await bgOf('gc', '.iwb-pick') const pickPlain = await bgOf('gp', '.iwb-pick') // ① 未上色节点:内层保持默认令牌(2026-11-27:--iwb-field 现为 #ffffff,不再硬编码旧值) const tokenColors = await page.evaluate(() => { const probe = (name) => { const d = document.createElement('div'); d.style.color = 'var(' + name + ')'; document.body.appendChild(d); const c = getComputedStyle(d).color; d.remove(); return c } return { field: probe('--iwb-field'), surface: probe('--iwb-bg-surface') } }) expect(taskPlain, '未上色节点的任务卡应等于 --iwb-field(默认底色)').toBe(tokenColors.field) expect(pickPlain, '未上色节点的下拉应保持纯白').toBe('rgb(255, 255, 255)') // ② 上色节点:内层不再是纯白/浅灰,而是同色系派生(黄底 ⇒ 偏黄) expect(taskColored, '上色节点的任务卡应改为同色系').not.toBe(taskPlain) expect(pickColored, '上色节点的下拉应改为同色系').not.toBe(pickPlain) expect(taskColored.indexOf('255, 255, 255'), '不应仍是纯白').toBeLessThan(0) // ②-b 下拉类控件在自定义底色节点上**无描边**(用户反馈:多一圈框不好看);未上色节点保持原样 const pickBorderColored = await page.locator('[data-node-id="gc"] .iwb-pick').first().evaluate((e) => getComputedStyle(e).borderTopColor) const pickBorderPlain = await page.locator('[data-node-id="gp"] .iwb-pick').first().evaluate((e) => getComputedStyle(e).borderTopColor) expect(pickBorderColored, '上色节点的下拉应无描边').toBe('rgba(0, 0, 0, 0)') expect(pickBorderPlain, '未上色节点的下拉仍保留描边').not.toBe('rgba(0, 0, 0, 0)') // 箭头统一向下(原来模型/尺寸用「⌃」向上,与原生 select 不一致) await expect(page.locator('[data-node-id="gc"] .iwb-pick-caret svg').first(), '下拉箭头应为向下的 chevron 图标').toHaveCount(1) // 任务卡不再有左侧 3px 装饰条(统一 1px 描边) const taskLeft = await page.locator('[data-node-id="gc"] .iwb-task').first().evaluate((e) => getComputedStyle(e).borderLeftWidth) expect(taskLeft, '任务卡左侧装饰条应已移除(1px 常规描边)').toBe('1px') // 批量管理行的复选框与任务卡复选框在同一条竖线上 const cbX = await page.evaluate(() => { const bulk = document.querySelector('[data-node-id="gc"] .iwb-task-bulkbar .iwb-task-check input') const task = document.querySelector('[data-node-id="gc"] .iwb-task .iwb-task-check input') return { bulk: bulk ? Math.round(bulk.getBoundingClientRect().x) : null, task: task ? Math.round(task.getBoundingClientRect().x) : null } }) expect(Math.abs(cbX.bulk - cbX.task), '批量管理与任务复选框应对齐(允许 1px 取整误差)').toBeLessThanOrEqual(1) // ③ 提示词/文本节点的**正文输入区**与节点背景同色(透明),不再单独区分 const taBg = await page.locator('[data-node-id="q1"] .iwb-textarea').first().evaluate((e) => getComputedStyle(e).backgroundColor) expect(taBg, '上色节点的正文输入区应透明(与节点背景同色)').toBe('rgba(0, 0, 0, 0)') // 未上色节点的正文输入区本来就是透明的(.iwb-textarea-plain)⇒ 上色后也必须保持一致 const taBgPlain = await page.locator('[data-node-id="q2"] .iwb-textarea').first().evaluate((e) => getComputedStyle(e).backgroundColor) expect(taBgPlain, '未上色节点的正文输入区同样透明').toBe('rgba(0, 0, 0, 0)') // ④ 节点类名标记(CSS 派生的开关) await expect(page.locator('[data-node-id="gc"]'), '上色节点应带 iwb-node-bg-custom').toHaveClass(/iwb-node-bg-custom/) await expect(page.locator('[data-node-id="gp"]'), '未上色节点不应带该类').not.toHaveClass(/iwb-node-bg-custom/) }) test('⑫ 暗色主题下自定义背景色仍能看清深色文字(对比度 ≥ 7)', async ({ page }) => { // 2026-11-01 用户实测:暗色令牌第一版给成 #26~#3a,近黑文字看不清。 // 本项目暗色是「中灰底 + 近黑文字」(--iwb-text #111) ⇒ 令牌必须是中灰调。 // 这里用 WCAG 对比度(≥7 = AAA)守住,避免以后再把暗色令牌调深。 const WS = { workspaces: [{ id: 'ws_dark', name: '暗色可读', groups: [], nodes: [ { id: 'k1', type: 'prompt', x: 160, y: 160, data: { text: '黑字应清晰', bg: 'yellow' } }, { id: 'k2', type: 'prompt', x: 620, y: 160, data: { text: '黑字应清晰', bg: 'cyan' } }, ], edges: [] }], activeId: 'ws_dark', rev: 1, schemaVersion: 1 } await page.addInitScript((d) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify({ providers: [], canvas: {} })) localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws)) localStorage.setItem('iwb_ws_active', 'ws_dark') localStorage.setItem('iwb_ws_ws_dark', JSON.stringify(d.ws.workspaces[0])) }, { ws: WS }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await W.waitHomeReady(page) await page.locator('.iwb-home-card').filter({ hasText: '暗色可读' }).first().dblclick() await expect(page.locator('[data-node-id="k1"]')).toBeVisible({ timeout: 15000 }) await page.locator('.iwb-navrail .iwb-nav-item[title="切换主题"]').click() // → 暗色 await expect(page.locator('html')).toHaveClass(/theme-dark/, { timeout: 5000 }) await page.waitForTimeout(300) const res = await page.evaluate(() => { const lumOf = (v) => { const s0 = String(v).trim() const c = s0.charAt(0) === '#' ? [parseInt(s0.slice(1, 3), 16), parseInt(s0.slice(3, 5), 16), parseInt(s0.slice(5, 7), 16)] : String(s0).match(/[\d.]+/g).slice(0, 3).map(Number) const lin = c.map((v) => { const s = v / 255; return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4) }) return 0.2126 * lin[0] + 0.7152 * lin[1] + 0.0722 * lin[2] } // 2026-11-27:用节点**实际**文字色(自定义底色在暗色下会改 --iwb-node-text 为近黑) return ['k1', 'k2'].map((id) => { const n = document.querySelector('[data-node-id="' + id + '"]') const cs = getComputedStyle(n) const bg = cs.backgroundColor const fg = cs.color const L = lumOf(bg), Lt = lumOf(fg) return { id, bg, fg, contrast: Math.round(((Math.max(L, Lt) + 0.05) / (Math.min(L, Lt) + 0.05)) * 10) / 10 } }) }) for (const r of res) { expect(r.contrast, `暗色下「${r.id}」背景 ${r.bg} / 文字 ${r.fg} 对比度应 ≥ 7(实际 ${r.contrast})`).toBeGreaterThanOrEqual(7) } }) test('⑫-b 跟随系统:系统切暗后内联 token 必须一起变(D1)', async ({ page }) => { // 2026-11-23 修 D1(token 三写入者):mq 回调原来只 toggle(theme-dark),不重算 上的内联 token, // 于是「跟随系统 + 日落自动转暗」会得到壳层暗、画布与节点还是亮色的混色半成品。 // 守三件事:class 变了 + --iwb-bg 跟着变 + 变暗(不是换成另一个亮色)。 await page.emulateMedia({ colorScheme: 'light' }) const WS = { workspaces: [{ id: 'ws_sys', name: '跟随系统', groups: [], nodes: [], edges: [] }], activeId: 'ws_sys', rev: 1, schemaVersion: 1 } await page.addInitScript((d) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify({ providers: [], canvas: {} })) localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws)) localStorage.setItem('iwb_ws_active', 'ws_sys') localStorage.setItem('iwb_theme', 'system') }, { ws: WS }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await W.waitHomeReady(page) const bgVar = () => page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--iwb-bg').trim()) const lumOf = (v) => { const s0 = String(v).trim() const c = s0.charAt(0) === '#' ? [1, 3, 5].map((i) => parseInt(s0.slice(i, i + 2), 16)) : String(s0).match(/[\d.]+/g).slice(0, 3).map(Number) const lin = c.map((x) => { const s = x / 255; return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4) }) return 0.2126 * lin[0] + 0.7152 * lin[1] + 0.0722 * lin[2] } const before = await bgVar() await page.emulateMedia({ colorScheme: 'dark' }) await expect(page.locator('html')).toHaveClass(/theme-dark/, { timeout: 5000 }) await expect.poll(bgVar, { timeout: 5000 }).not.toBe(before) expect(lumOf(await bgVar()), '暗色的 --iwb-bg 必须比亮色更暗(否则就是没重算)').toBeLessThan(lumOf(before)) }) test('⑬ 连接节点来源行与组合节点一致;中继节点改色只染圆环、中间透明', async ({ page }) => { // 2026-11-01 用户要求: // ① 连接(batch)节点的来源行样式与组合(combine)节点**靠齐**(原来 batch 用品牌色淡染,视觉上不一样) // ② 中继(relay)改背景色时应该是**圆环变色**、中间透明(原来整块实心圆) const CFG = { providers: [], canvas: {} } const ws = { workspaces: [{ id: 'ws_rl', name: '中继圆环', groups: [], nodes: [ { id: 'bb', type: 'batch', x: 100, y: 100, data: { bg: 'green' } }, { id: 'cc', type: 'combine', x: 560, y: 100, data: { bg: 'green' } }, { id: 'r1', type: 'relay', x: 1000, y: 140, data: { bg: 'cyan' } }, { id: 'r2', type: 'relay', x: 1000, y: 400, data: {} }, { id: 's1', type: 'prompt', x: 100, y: 480, data: { text: '来源甲' } }, { id: 's2', type: 'prompt', x: 560, y: 480, data: { text: '来源乙' } }, ], edges: [{ id: 'x1', from: 's1', to: 'bb' }, { id: 'x2', from: 's2', to: 'cc' }, { id: 'x3', from: 'bb', to: 'r1' }] }], activeId: 'ws_rl', rev: 1, schemaVersion: 1 } await page.addInitScript((d) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg)) localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws)) localStorage.setItem('iwb_ws_active', 'ws_rl') localStorage.setItem('iwb_ws_ws_rl', JSON.stringify(d.ws.workspaces[0])) }, { cfg: CFG, ws }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await W.waitHomeReady(page) await page.locator('.iwb-home-card').filter({ hasText: '中继圆环' }).first().dblclick() await expect(page.locator('[data-node-id="bb"] .iwb-batch-src').first()).toBeVisible({ timeout: 15000 }) // ① 来源行样式一致(同色系派生色相同、边框色相同) const styleOf = (sel, prop) => page.locator(sel).first().evaluate((e, p) => getComputedStyle(e)[p], prop) const batchBg = await styleOf('[data-node-id="bb"] .iwb-batch-src', 'backgroundColor') const combineBg = await styleOf('[data-node-id="cc"] .iwb-combine-src', 'backgroundColor') expect(batchBg, '连接来源行底色应与组合来源行一致').toBe(combineBg) const batchBorder = await styleOf('[data-node-id="bb"] .iwb-batch-src', 'borderTopColor') const combineBorder = await styleOf('[data-node-id="cc"] .iwb-combine-src', 'borderTopColor') expect(batchBorder, '连接来源行描边应与组合来源行一致').toBe(combineBorder) // ② 中继:节点本体透明、圆环取色 const relayBg = await styleOf('[data-node-id="r1"]', 'backgroundColor') expect(relayBg, '中继节点本体应透明(不再整块填充)').toBe('rgba(0, 0, 0, 0)') const ringBorder = await styleOf('[data-node-id="r1"] .iwb-relay-ring', 'borderTopColor') const cyanToken = await page.locator('[data-node-id="r1"]').evaluate((n) => getComputedStyle(n).getPropertyValue('--iwb-node-color').trim()) const rgbOf = (hex) => 'rgb(' + [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16)).join(', ') + ')' expect(ringBorder, '圆环颜色应等于所选背景色').toBe(rgbOf(cyanToken)) // 未上色的中继:圆环跟随主题的节点底色(不再硬编码白色) const ring2 = await styleOf('[data-node-id="r2"] .iwb-relay-ring', 'borderTopColor') const nodeBgVar = await page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--iwb-node-bg').trim()) const hexToRgb = (hex) => 'rgb(' + [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16)).join(', ') + ')' expect(ring2, '未上色的中继圆环应等于 --iwb-node-bg(亮色主题)').toBe(hexToRgb(nodeBgVar)) // ②-b 暗色主题:圆环同样是「节点底色」而不是亮白圈(用户实测问题) await page.locator('.iwb-navrail .iwb-nav-item[title="切换主题"]').click() await expect(page.locator('html')).toHaveClass(/theme-dark/, { timeout: 5000 }) await page.waitForTimeout(300) const ringDark = await styleOf('[data-node-id="r2"] .iwb-relay-ring', 'borderTopColor') const nodeBgDark = await page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--iwb-node-bg').trim()) expect(ringDark, '暗色下中继圆环应等于暗色的 --iwb-node-bg(不再是亮白圈)').toBe(hexToRgb(nodeBgDark)) expect(ringDark, '暗色下圆环不应是纯白').not.toBe('rgb(255, 255, 255)') // ②-c 暗色下:引用行/任务卡/节点本体都不再多一圈深色描边(中灰底上会显得"到处是框") const srcBorderDark = await styleOf('[data-node-id="cc"] .iwb-combine-src', 'borderTopColor') expect(srcBorderDark, '暗色下组合引用行描边应透明').toBe('rgba(0, 0, 0, 0)') const nodeSides = await page.evaluate(() => { const n = document.querySelector('[data-node-id="cc"]') const cs = getComputedStyle(n) return { l: cs.borderLeftColor, r: cs.borderRightColor, b: cs.borderBottomColor } }) expect(nodeSides.l, '暗色下节点左边描边应透明').toBe('rgba(0, 0, 0, 0)') expect(nodeSides.r, '暗色下节点右边描边应透明').toBe('rgba(0, 0, 0, 0)') expect(nodeSides.b, '暗色下节点下边描边应透明').toBe('rgba(0, 0, 0, 0)') // ③ 暗色下顶部标签:选中态必须与未选中态有可见差异(用户反馈难区分) const tabs = await page.evaluate(() => { const all = Array.from(document.querySelectorAll('.iwb-tabstrip .iwb-tab')) const act = all.find((t) => t.classList.contains('iwb-tab-active')) const inact = all.find((t) => !t.classList.contains('iwb-tab-active')) return { active: act ? getComputedStyle(act).backgroundColor : null, inactive: inact ? getComputedStyle(inact).backgroundColor : null } }) expect(tabs.active, '暗色下应有选中标签').not.toBeNull() expect(tabs.active, '选中标签底色应不同于未选中').not.toBe(tabs.inactive) }) test('⑭ 端口加号提示:hover / 选中未连线显示 +,已连线不显示;点 + 直接弹推荐菜单', async ({ page }) => { // 2026-11-01 用户要求(参照参考图):鼠标靠近端点或选中未连线节点时端点变「+」; // 已连线的端点不显示加号;点击「+」直接弹推荐菜单(输出=引用该节点生成 / 输入=为它添加来源)。 const WS = { workspaces: [{ id: 'ws_port', name: '端口加号', groups: [], nodes: [ { id: 'a1', type: 'prompt', x: 160, y: 160, data: { text: '甲' } }, { id: 'b1', type: 'gen', x: 760, y: 160, w: 460, data: { model: 'x', provider: 'p-a', keyGroup: 'a-1', size: '1024x1024', ratio: '1:1', res: '1K' } }, { id: 'c1', type: 'prompt', x: 160, y: 520, data: { text: '未连线' } }, ], edges: [{ id: 'e1', from: 'a1', to: 'b1' }] }], activeId: 'ws_port', rev: 1, schemaVersion: 1 } await page.addInitScript((d) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify({ providers: [], canvas: {} })) localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws)) localStorage.setItem('iwb_ws_active', 'ws_port') localStorage.setItem('iwb_ws_ws_port', JSON.stringify(d.ws.workspaces[0])) }, { ws: WS }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await W.waitHomeReady(page) await page.locator('.iwb-home-card').filter({ hasText: '端口加号' }).first().dblclick() await expect(page.locator('[data-node-id="a1"]')).toBeVisible({ timeout: 15000 }) const plusOpacity = (sel) => page.locator(sel).first().evaluate((e) => getComputedStyle(e, '::before').opacity) // ① 已连线端口:带 iwb-port-linked;**hover 时也显示加号**(节点可多连,2026-11-01 用户要求) await expect(page.locator('[data-node-id="a1"] .iwb-port-out').first(), '已连线的输出端口应带 linked 标记').toHaveClass(/iwb-port-linked/) await expect(page.locator('[data-node-id="b1"] .iwb-port-in').first(), '已连线的输入端口应带 linked 标记').toHaveClass(/iwb-port-linked/) // 选中但未 hover ⇒ 已连线端口不显示加号 await page.locator('[data-node-id="a1"] .iwb-node-head').click() await page.mouse.move(20, 20) expect(await plusOpacity('[data-node-id="a1"] .iwb-port-out'), '已连线端口在选中但未 hover 时不显示加号').toBe('0') // hover ⇒ 显示加号(尺寸再放大一档) const aOut = await page.locator('[data-node-id="a1"] .iwb-port-out').first().boundingBox() await page.mouse.move(aOut.x + aOut.width / 2, aOut.y + aOut.height / 2) // hover 后样式需要一帧才生效:用轮询代替固定等待(2026-11-06 e2e 去固定等待) await expect.poll(() => plusOpacity('[data-node-id="a1"] .iwb-port-out'), { timeout: 5000 }).toBe('1') const hoverW = await page.locator('[data-node-id="a1"] .iwb-port-out').first().evaluate((e) => Math.round(e.getBoundingClientRect().width)) // 2026-11-27:24px 是**世界坐标**尺寸;getBoundingClientRect 含画布缩放,需按 zoom 归一后比较 const zoom = await page.evaluate(() => { const w = document.querySelector('.iwb-world'); const m = /scale\(([\d.]+)\)/.exec((w && w.style.transform) || ''); return m ? parseFloat(m[1]) : 1 }) expect(hoverW, 'hover 时端口应为 24px(世界坐标 @ zoom ' + zoom + ')').toBe(Math.round(24 * zoom)) // ② hover 未连线端口 ⇒ 显示加号 const cOut = await page.locator('[data-node-id="c1"] .iwb-port-out').first().boundingBox() await page.mouse.move(cOut.x + cOut.width / 2, cOut.y + cOut.height / 2) await expect.poll(() => plusOpacity('[data-node-id="c1"] .iwb-port-out'), { timeout: 5000 }).toBe('1') // ③ 选中未连线节点 ⇒ 不 hover 也显示加号(触屏可用) await page.mouse.move(20, 20) await page.waitForTimeout(200) await page.locator('[data-node-id="c1"] .iwb-node-head').click() await expect.poll(() => plusOpacity('[data-node-id="c1"] .iwb-port-out'), { timeout: 5000 }).toBe('1') const selW = await page.locator('[data-node-id="c1"] .iwb-port-out').first().evaluate((e) => Math.round(e.getBoundingClientRect().width)) expect(selW, '选中时端口应为 22px(世界坐标 @ zoom ' + zoom + ')').toBe(Math.round(22 * zoom)) // ④ 点击「+」直接弹菜单(输出口 ⇒ 引用该节点生成;输入口 ⇒ 为它添加来源) await page.locator('[data-node-id="c1"] .iwb-port-out').first().click() await expect(page.locator('.iwb-connect-menu'), '点输出口 + 应弹菜单').toHaveCount(1, { timeout: 8000 }) await expect(page.locator('.iwb-connect-menu .iwb-ctx-title')).toHaveText('引用该节点生成') await page.keyboard.press('Escape') await page.waitForTimeout(300) await page.locator('[data-node-id="c1"] .iwb-port-in').first().click() await expect(page.locator('.iwb-connect-menu'), '点输入口 + 应弹菜单').toHaveCount(1, { timeout: 8000 }) await expect(page.locator('.iwb-connect-menu .iwb-ctx-title')).toHaveText('为它添加来源') }) test('⑮ 工具栏新增节点落在当前视口中心(空画布 / 平移缩放后都一样)', async ({ page }) => { // 2026-11-01 用户反馈:从工具栏加节点会跑到左上角,有时被工具栏挡住选不中。 // 根因:findSpot 用了 canvasSize(未测到 = {0,0} → 回落 800x600),中心与视口边界都算错。 // 修法:工具栏加节点时用 **.iwb-world 的实时变换 + 画布实际尺寸** 算视口中心,作为找位的种子点。 const seed = { workspaces: [{ id: 'ws_spot', name: '落点', groups: [], nodes: [], edges: [] }], activeId: 'ws_spot', rev: 1, schemaVersion: 1 } await page.addInitScript((d) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify({ providers: [], canvas: {} })) localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws)) localStorage.setItem('iwb_ws_active', 'ws_spot') localStorage.setItem('iwb_ws_ws_spot', JSON.stringify(d.ws.workspaces[0])) }, { ws: seed }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await W.waitHomeReady(page) await page.locator('.iwb-home-card').filter({ hasText: '落点' }).first().dblclick() await expect(page.locator('.iwb-canvas')).toBeVisible({ timeout: 15000 }) await page.waitForTimeout(400) const lastNodeVsCenter = () => page.evaluate(() => { const ns = Array.from(document.querySelectorAll('.iwb-node')) const last = ns[ns.length - 1] if (!last) return null const b = last.getBoundingClientRect() const c = document.querySelector('.iwb-canvas').getBoundingClientRect() return { dx: Math.round(b.x + b.width / 2 - (c.x + c.width / 2)), dy: Math.round(b.y + b.height / 2 - (c.y + c.height / 2)), inside: b.x >= c.x - 1 && b.y >= c.y - 1 && b.x + b.width <= c.x + c.width + 1 && b.y + b.height <= c.y + c.height + 1, } }) // ① 空画布:应正落在中心(±40px) await page.locator('button[data-tip="提示词"]').first().click() await page.waitForTimeout(600) const d1 = await lastNodeVsCenter() expect(Math.abs(d1.dx), '空画布新增应水平居中,实际 ' + d1.dx).toBeLessThanOrEqual(40) expect(Math.abs(d1.dy), '空画布新增应垂直居中,实际 ' + d1.dy).toBeLessThanOrEqual(40) // ② 平移到空白区域 + 缩放后:仍应落在**当前视口**中心 // (先平移把上一步的节点移出视口,否则中心被占,找位逻辑会自然地挪到旁边的空位) // 平移用**中键拖拽**(左键在空白处是框选,不会移动视口) await page.mouse.move(1250, 300) await page.mouse.down({ button: 'middle' }) await page.mouse.move(560, 700, { steps: 10 }) await page.mouse.up({ button: 'middle' }) await page.mouse.wheel(0, -240) await page.waitForTimeout(500) await page.locator('button[data-tip="文本"]').first().click() await page.waitForTimeout(600) const d2 = await lastNodeVsCenter() expect(Math.abs(d2.dx), '平移缩放后新增应水平居中,实际 ' + d2.dx).toBeLessThanOrEqual(60) expect(Math.abs(d2.dy), '平移缩放后新增应垂直居中,实际 ' + d2.dy).toBeLessThanOrEqual(60) // ③ 连续新增:中心被占时也要落在视口内(不能跑到左上角/视口外) await page.locator('button[data-tip="图片"]').first().click() await page.waitForTimeout(600) const d3 = await lastNodeVsCenter() expect(d3.inside, '连续新增的节点必须完整落在当前视口内').toBe(true) }) test('⑯ 未编组节点可一键「并入分组」(并进它相连的那个组)', async ({ page }) => { // 2026-11-01 用户需求:单独的节点气泡上给一个「并入分组」,快速并进它相连的分组。 const WS = { workspaces: [{ id: 'ws_join', name: '并入分组', groups: [{ id: 'g1', name: '分组甲', memberIds: ['a1', 'a2'] }], nodes: [ { id: 'a1', type: 'prompt', x: 160, y: 160, data: { text: '甲' } }, { id: 'a2', type: 'prompt', x: 160, y: 420, data: { text: '乙' } }, { id: 'b1', type: 'textout', x: 700, y: 300, data: {} }, { id: 'c1', type: 'prompt', x: 1200, y: 300, data: { text: '孤立节点' } }, ], edges: [{ id: 'e1', from: 'a2', to: 'b1' }] }], activeId: 'ws_join', rev: 1, schemaVersion: 1 } await page.addInitScript((d) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify({ providers: [], canvas: {} })) localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws)) localStorage.setItem('iwb_ws_active', 'ws_join') localStorage.setItem('iwb_ws_ws_join', JSON.stringify(d.ws.workspaces[0])) }, { ws: WS }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await W.waitHomeReady(page) await page.locator('.iwb-home-card').filter({ hasText: '并入分组' }).first().dblclick() await expect(page.locator('[data-node-id="b1"]')).toBeVisible({ timeout: 15000 }) const joinBtn = page.locator('.iwb-node-floatbar button[aria-label="并入分组"]') // ① 孤立节点(没有相连分组)不该出现这个按钮 await page.locator('[data-node-id="c1"]').click() await expect(joinBtn, '没有相连分组时不应显示「并入分组」').toHaveCount(0) // ② 与分组相连的未编组节点:出现按钮,点一下并入 await page.locator('[data-node-id="b1"]').click() await expect(joinBtn, '与分组相连的未编组节点应显示「并入分组」').toHaveCount(1) await expect(page.locator('.iwb-group-bar')).toContainText('2 节点') await joinBtn.click() await expect(page.locator('.iwb-group-bar'), '并入后组内应变成 3 个节点').toContainText('3 节点') // ③ 已在组内 ⇒ 按钮消失 await page.locator('[data-node-id="b1"]').click() await expect(joinBtn, '已在组内时不应再显示「并入分组」').toHaveCount(0) }) test('⑰ 提示词气泡「放大编辑」:单栏所见即所得(Markdown 实时渲染),关闭写回纯文本', async ({ page }) => { // 2026-11-01 用户需求:气泡上加放大按钮;浮层要**单栏内直接渲染**(标题/列表/粗斜体/删除线/分割线), // 不要左右分栏、不要标题栏和边框;保存时转回纯文本 Markdown(数据仍是纯文本,不污染提示词)。 const MD = '# 角色设定\n## 场景\n**赛博朋克** 霓虹街景,*冷色调*\n- 主体:橘猫\n---\n普通段落 ~~删除~~ 结束' const WS = { workspaces: [{ id: 'ws_exp', name: '放大编辑', groups: [], nodes: [ { id: 'p1', type: 'prompt', x: 260, y: 220, data: { text: MD } }, { id: 't1', type: 'textout', x: 260, y: 620, data: {} }, ], edges: [] }], activeId: 'ws_exp', rev: 1, schemaVersion: 1 } await page.addInitScript((d) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify({ providers: [], canvas: {} })) localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws)) localStorage.setItem('iwb_ws_active', 'ws_exp') localStorage.setItem('iwb_ws_ws_exp', JSON.stringify(d.ws.workspaces[0])) }, { ws: WS }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await W.waitHomeReady(page) await page.locator('.iwb-home-card').filter({ hasText: '放大编辑' }).first().dblclick() await expect(page.locator('[data-node-id="p1"]')).toBeVisible({ timeout: 15000 }) const expandBtn = page.locator('.iwb-node-floatbar button[aria-label="放大编辑"]') await page.locator('[data-node-id="p1"]').click() await expect(expandBtn, '提示词节点气泡应有「放大编辑」').toHaveCount(1) await expandBtn.click() await expect(page.locator('.iwb-prompt-modal'), '应弹出放大编辑浮层').toHaveCount(1, { timeout: 5000 }) // ① 外观:无标题、无边框、**单栏**(没有左右预览栏) await expect(page.locator('.iwb-prompt-modal .iwb-modal-head'), '不应有「放大编辑」标题').toHaveCount(0) expect(await page.locator('.iwb-prompt-modal').evaluate((e) => getComputedStyle(e).borderTopWidth), '浮层不应有可见边框').toBe('0px') await expect(page.locator('.iwb-prompt-preview'), '不应有左右分栏的预览栏').toHaveCount(0) // ② 工具条:H1/H2/H3/列表/有序/分割线/加粗/斜体/删除线/清除格式 + 复制(图标)= 11 个 // 2026-11-03 用户反馈:原来「—/B/I/S」单个符号认不出功能 ⇒ 后半段改中文标签; // 复制按钮从「挨着关闭」移到格式按钮之后;补齐「有序」(此前只有内部命令、没有入口)。 await expect(page.locator('.iwb-prompt-tool'), '工具条应有 11 个按钮(含图标复制)').toHaveCount(11) await expect(page.locator('.iwb-prompt-copy svg'), '复制按钮应是图标').toHaveCount(1) await expect(page.locator('.iwb-prompt-tool', { hasText: '表格' }), '表格按钮应已移除').toHaveCount(0) await expect(page.locator('.iwb-prompt-tool', { hasText: '链接' }), '链接按钮应已移除').toHaveCount(0) for (const label of ['H1', 'H2', 'H3', '列表', '有序', '分割线', '加粗', '斜体', '删除线', '清除格式']) { await expect(page.locator('.iwb-prompt-tool', { hasText: label }).first(), '工具条应有「' + label + '」').toHaveCount(1) } // 标签本身写字形:加粗按钮粗体、斜体按钮斜体、删除线按钮带删除线(此前 .iwb-md-* 没有 CSS,等于没有) expect(await page.locator('.iwb-prompt-tool.iwb-md-b').evaluate((e) => getComputedStyle(e).fontWeight), '「加粗」标签本身应是粗体').toBe('700') expect(await page.locator('.iwb-prompt-tool.iwb-md-i').evaluate((e) => getComputedStyle(e).fontStyle), '「斜体」标签本身应是斜体').toBe('italic') expect(await page.locator('.iwb-prompt-tool.iwb-md-s').evaluate((e) => getComputedStyle(e).textDecorationLine), '「删除线」标签本身应带删除线').toContain('line-through') // 复制紧跟在格式按钮之后,且与关闭之间留出弹性空白 const copyBox = await page.locator('.iwb-prompt-copy').boundingBox() const delBox = await page.locator('.iwb-prompt-tool', { hasText: '删除线' }).boundingBox() const closeBox = await page.locator('.iwb-prompt-x').boundingBox() expect(copyBox.x, '复制应在格式按钮右侧').toBeGreaterThan(delBox.x) expect(copyBox.x + copyBox.width, '复制不应与关闭挤在一起(中间应有留白)').toBeLessThan(closeBox.x - 40) // ③ 实时渲染:Markdown 已在编辑器内渲染成真实样式 const ed = page.locator('.iwb-md-editor') await expect(ed.locator('h1'), 'H1 应渲染').toHaveCount(1) await expect(ed.locator('h2'), 'H2 应渲染').toHaveCount(1) await expect(ed.locator('b'), '加粗应渲染').toHaveCount(1) await expect(ed.locator('i'), '斜体应渲染').toHaveCount(1) await expect(ed.locator('s'), '删除线应渲染').toHaveCount(1) await expect(ed.locator('li'), '列表应渲染').toHaveCount(1) await expect(ed.locator('hr'), '分割线应渲染').toHaveCount(1) // ④ 工具条可用:选中一段 → 点「加粗」⇒ 变粗体;复制给出反馈 await ed.evaluate((r) => { const rg = document.createRange(); rg.selectNodeContents(r.querySelector('div') || r); const sl = window.getSelection(); sl.removeAllRanges(); sl.addRange(rg) }) await page.locator('.iwb-prompt-tool', { hasText: '加粗' }).first().click() await page.waitForTimeout(200) await page.locator('.iwb-prompt-copy').click() await expect(page.locator('.iwb-prompt-copied'), '复制后应出现「已复制」反馈').toHaveCount(1) // ④-b 「清除格式」:标题/加粗/斜体/列表全部清掉,且**顺序不变** await ed.click() await page.locator('.iwb-prompt-tool', { hasText: '清除格式' }).first().click() await expect(ed.locator('h1'), '清除后不应再有标题').toHaveCount(0) await expect(ed.locator('b'), '清除后不应再有加粗').toHaveCount(0) await expect(ed.locator('li'), '清除后不应再有列表').toHaveCount(0) await expect(ed, '清除后文字顺序应保持').toContainText('角色设定') // ④-c 行距回归(2026-11-03 用户报障):空行在 DOM 里是