// 图标按钮的功能名提示(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(/