121 lines
5.7 KiB
JavaScript
121 lines
5.7 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()
|
|
await expect(page.locator('.iwb-node-floatbar')).toBeVisible()
|
|
// 2026-11-09:删除按钮已按用户要求恢复(2026-10-30 曾以「防误删」为由移除)
|
|
await expect(page.locator('.iwb-node-floatbar button[aria-label="删除"]'), '气泡应有删除按钮').toHaveCount(1)
|
|
|
|
for (const label of ['复制', '收藏', '删除']) {
|
|
const btn = page.locator(`.iwb-node-floatbar 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')
|
|
}
|
|
})
|
|
|
|
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)
|
|
})
|