Files
image-workbench-desktop/tests/iwb-tooltip-labels.spec.js
T
qiqi 8035c01fb7 fix(canvas): 停靠栏未就绪时不落盘视口(修 6 条 e2e 超时)+ 4 条用例按现 UI 修正
根因(trace 定位,6 条同一原因):
首页视图里启动 fit 早于停靠栏挂载(--iwb-dock-l 首帧为空)⇒ 算出 ins=0 的坏视口
(实测 translate(-92,-84));这份坏值被 useViewportPersistence 落盘,打开画布时又被当作
「用户保存的视口」恢复 ⇒ 节点停在 x=29(压在 318px 左栏下),dblclick 命中浏览器面板的
.iwb-cwv-url / .iwb-cwv-empty,Playwright 重试到 30s 超时。
修法:flushViewport 增加 insetsReady 门槛(--iwb-dock-l 为空串时跳过落盘);
画布打开后 loadWsInto 走 doFit,此时占位就绪,落盘的是正确视口。

4 条用例按现 UI 修正:
- tooltip-labels ②:单选气泡现为 改名/复制/删除/添加到提示词库…(收藏只在多选气泡)
- image-original:收藏入口已收进「选中操作 ▸」子菜单(且需先选中节点)
- resume-scope:运行入口已收进「该节点 ▸」子菜单
- download-cors:同源代理 /api/img 已随网页版删除,桌面走原生 HTTP 另存为 ⇒ 该条标 fixme(需 Tauri 环境)

验证:
- 组 A(typing-perf / storage-incremental / close-flush / history-sweep)6/6 绿
- 组 B(image-original / resize-perf / tooltip-labels / resume-scope / download-cors)12/12 绿
- verify:ci 全绿(facts 数字已 sync)
- 已知红基线 17 → 7 条(只剩 clipboard-audit 3 + image-memory-parity 4,均为环境限制)
2026-11-27 07:01:06 +08:00

124 lines
6.1 KiB
JavaScript

// 图标按钮的功能名提示(2026-10-30)
//
// 用户要求:气泡操作栏 / 底部工具栏 / 节点卡 的图标按钮,hover 时显示**简短功能名**(深色气泡),
// 与插件按钮的提示样式一致;文案统一为 2 字(「提示词」保留 3 字)。
//
// 断言方式:直接读伪元素 `::after` 的 content —— 这是"用户真的会看到什么",不是源码文本。
const { test, expect } = require('./_pw-coverage')
const baseURL = process.env.IWB_BASE_URL || 'http://127.0.0.1:8787'
test.use({ baseURL, viewport: { width: 1440, height: 1000 } })
const WS = {
workspaces: [{
id: 'ws_tip', name: '提示测试', groups: [], edges: [],
nodes: [
{ id: 'p1', type: 'prompt', x: 200, y: 200, data: { text: 'hello' } },
{ id: 'p2', type: 'prompt', x: 560, y: 200, data: { text: 'world' } },
],
}],
activeId: 'ws_tip', rev: 1, schemaVersion: 1,
}
async function boot(page) {
await page.addInitScript((ws) => {
if (localStorage.getItem('__iwb_tip_seeded__') !== '1') {
localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws))
localStorage.setItem('__iwb_tip_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(600)
}
// 读某个元素的 ::after 文案(hover 后才可见,这里同时校验可见性)
async function tipOf(locator) {
await locator.hover()
await locator.page().waitForTimeout(220)
return locator.evaluate((el) => {
const cs = window.getComputedStyle(el, '::after')
return { text: String(cs.content || '').replace(/^"|"$/g, ''), opacity: cs.opacity, visibility: cs.visibility }
})
}
test('① 底部工具栏:图标 hover 显示 2 字功能名', async ({ page }) => {
await boot(page)
const cases = [
['提示词', '提示词'],
['图片', '图片'],
['配置', '配置'],
['输出', '输出'],
['缩小', '缩小'],
['放大', '放大'],
['适应', '适应'],
]
for (const [attr, expectText] of cases) {
const btn = page.locator(`.iwb-toolbar-bottom button[data-tip="${attr}"]`).first()
await expect(btn, `底栏应有 data-tip="${attr}" 的按钮`).toHaveCount(1)
const tip = await tipOf(btn)
expect(tip.text, `底栏「${attr}」提示文案`).toBe(expectText)
expect(tip.opacity, `「${attr}」hover 后提示应可见`).toBe('1')
}
})
test('② 节点气泡:单选时图标显示 2 字功能名(改名/复制)', async ({ page }) => {
await boot(page)
await page.locator('[data-node-id="p1"] .iwb-node-head').click()
const single = page.locator('.iwb-node-floatbar:not(.iwb-node-floatbar-group)')
await expect(single).toBeVisible()
// 2026-11-27:单选气泡现为 解组/并入分组/放大编辑/改名/复制/添加到提示词库/替换/粘贴/下载;
// 「删除」「收藏」只在多选气泡(单选删除走 Delete 键 / 右键菜单)——这里守 2 字提示,也守「不该出现」。
for (const label of ['改名', '复制']) {
const btn = single.locator(`button[aria-label="${label}"]`).first()
await expect(btn, `气泡应有 aria-label="${label}" 的按钮`).toHaveCount(1)
const tip = await tipOf(btn)
expect(tip.text, `气泡「${label}」提示文案`).toBe(label)
expect(tip.opacity, `「${label}」hover 后提示应可见`).toBe('1')
}
await expect(single.locator('button[aria-label="删除"]'), '单选气泡应有删除按钮(2026-11-09 恢复)').toHaveCount(1)
await expect(single.locator('button[aria-label="收藏"]'), '单选气泡不该有收藏(只保留在多选气泡)').toHaveCount(0)
})
test('③ 禁用按钮也能看到提示(多选 2 个节点时「编组」可用;只选 1 个时不可用)', async ({ page }) => {
await boot(page)
// 只选 1 个节点 → 单节点气泡(无编组按钮);选 2 个 → 组气泡,编组可用
await page.locator('[data-node-id="p1"] .iwb-node-head').click()
await page.waitForTimeout(200)
await page.locator('[data-node-id="p2"] .iwb-node-head').click({ modifiers: ['Shift'] })
await expect(page.locator('.iwb-node-floatbar-group')).toBeVisible()
const grp = page.locator('.iwb-node-floatbar-group button[aria-label="编组"]').first()
await expect(grp, '两个节点时「编组」应可用').toBeEnabled()
const tip = await tipOf(grp)
expect(tip.text, '「编组」提示文案').toBe('编组')
expect(tip.opacity, '「编组」hover 后提示应可见').toBe('1')
// 解组按钮此时禁用(这两个节点还没编组)—— 禁用态也必须能出提示(CSS pointer-events:auto 保证)
const ungrp = page.locator('.iwb-node-floatbar-group button[aria-label="解组"]').first()
await expect(ungrp, '未编组时「解组」应禁用').toBeDisabled()
const tip2 = await tipOf(ungrp)
expect(tip2.text, '禁用按钮的提示文案仍应存在').toBe('解组')
})
test('④ 底栏节点图标:提示词=file-text、中继=circle-dot、输出=presentation、组合=server-plus', async ({ page }) => {
await boot(page)
const svgOf = async (tip) => {
const btn = page.locator(`.iwb-toolbar-bottom button[data-tip="${tip}"]`).first()
await expect(btn, `底栏应有「${tip}」按钮`).toHaveCount(1)
return await btn.locator('svg').first().innerHTML()
}
// 每个图标用「独一无二的结构特征」区分(换错了立刻红)
const prompt = await svgOf('提示词')
expect(prompt, '提示词应为 file-text(文件 + 折角)').toContain('M14 2v4a2 2 0 0 0 2 2h4')
const relay = await svgOf('中继')
expect((relay.match(/<circle/g) || []).length, '中继应为 circle-dot(两个同心圆)').toBe(2)
const out = await svgOf('输出')
expect(out, '输出应为 presentation(顶部横杆 + 支架)').toContain('M2 3h20')
const combine = await svgOf('组合')
expect((combine.match(/<rect/g) || []).length, '组合应为 server-plus(两块机箱)').toBe(2)
})