Files
image-workbench-desktop/tests/iwb-tooltip-labels.spec.js
T
qiqi 2cd52d1d4e
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 43s
refactor(promptlib): 收藏入口归插件(宿主不再自带,随插件启停)
按项目所有人要求:提示词库插件负责「管理与收集」的完整能力,宿主只保留基础接口。

宿主侧移除(全部 4 处入口 + 实现):
- 节点气泡星标(app.js 单选气泡的「添加到提示词库」)
- 「选中操作 ▸ 添加到提示词库」、「该节点 ▸ 添加该提示词」
- 提示词节点标题栏星标(src/ui-node-card.js)
- src/runtime-workbench-logic.js 的 addPromptToLibrary(约 45 行)与 ui-canvas-nodes 的 onFavorite 注入

宿主侧保留:promptlib 能力(list/save/insert/copy/notify/onChanged/file*)、prompts 状态与 api('prompts')(备份/迁移)、插件数据通道。

宿主侧补回(此前缺失):右键菜单重新渲染 ctx.commands 注册的插件命令(「插件命令」分区)。

插件 promptlib 1.13.1 → 1.14.0:
- capabilities 增 nodeActions / commands
- nodeActions「收藏为提示词」:仅对 type=prompt 且 text 非空的节点出现(气泡按钮)
- commands「收藏选中的提示词」:右键「插件命令」入口
- 收藏写入插件数据 plugin-data/promptlib.json(以现有数据为基底,保留 cover:{img} 与分组),
  新条目 group:'' 即未分组,并 notify 回执

测试:
- tests/iwb-prompt-collect.spec.js 改为 3 条新契约:插件提供气泡入口 + 宿主无自带入口;
  右键插件命令可用且宿主旧条目已移除;插件停用后两个入口同时消失
- canvas-meta-notice 的旧「点按钮报错回执」用例改为「宿主不得再渲染该入口」
- tests/_helpers/wait.js openDockPanel 加固(等插件宿主初始化,修并行偶发)
- 棘轮下调:app.js 8324 / Workbench 2178

验证:npm run verify:ci 全绿(含 e2e 冒烟 31 条)。
2026-11-27 10:06:03 +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:单选气泡现为 解组/并入分组/放大编辑/改名/复制/替换/粘贴/下载(收藏入口已归 promptlib 插件);
// 「删除」「收藏」只在多选气泡(单选删除走 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)
})