test(e2e): 收缩资源中心面板用例,改测停靠栏插件面板(宿主轻量化)

背景:v3.25.82 起「资源中心」全屏浮窗被停靠栏插件面板取代,图库/提示词库改为独立插件。
一批 spec 仍在测已下线的浮窗 UI,长期红且掩盖真回归。按「宿主只守集成契约、面板 UI 归插件仓」收缩:

退役(原因写入 tests/fixtures/e2e-known-red.json 的 retired 段):
- iwb-lib-panel-ux(6 条):浮窗内搜索/快捷键/分类胶囊/插入图标
- iwb-full-window-resize(1 条):浮窗隐形缩放手柄 + 标题栏尺寸数字
- 门禁 spec 数 54 → 52

改写为停靠栏语义:
- iwb-gallery-insert:条目「插入」按钮 → 先选中条目再点工具条「插入」(4 条全绿)
- iwb-canvas-ux 3/4:资源中心 → 图库面板;条目 title 在容器上(4 条中 2 条转绿)
- iwb-stability:图库面板开/关、N 键切换右栏、开面板不移动画布
- iwb-canvas-ops ⑪:图库面板开着时仍能框选
- iwb-plugin-panel-tab-leak:改为「面板切走即卸载、切回只挂一份」(按面板 body 断言)
- _plugin-host-probe 的动态插件面板用例标 fixme:停靠栏面板清单固定为 5 个已知面板,
  动态注册的 panels 能力暂时没有 UI 落点(等宿主补入口再启用)

验证:上述 6 个 spec 由 25 红降到 7 红(剩余为断言类,待逐条判定);gallery-insert / plugin-panel-tab-leak / canvas-ux 复制 / canvas-ops ⑪ 全绿。
This commit is contained in:
qiqi committed 2026-11-27 00:05:48 +08:00
1 parent 8d7ebb298f
commit f6040581eb
10 files changed
+98 -426

No files matched your search

+3 -1
View File
@@ -231,7 +231,9 @@ test('插件节点:启用后可从右键菜单创建、渲染、运行;停
await expect(page.locator('.iwb-ctxmenu .iwb-ctx-item').filter({ hasText: '打招呼节点' })).toHaveCount(0)
})
test('插件面板:启用后出现在资源中心 tab 并可挂载;停用后 tab 消失', async ({ page }) => {
// 2026-11-27:资源中心浮窗下线后,停靠栏面板清单固定为「节点组/浏览器/风格库/提示词库/图库」
// (src/ui-dock-panels.js),动态注册的 panels 能力暂时没有 UI 落点 ⇒ 用例暂挂,等宿主补入口再启用。
test.fixme('插件面板:启用后出现在停靠栏并可挂载;停用后消失(宿主暂无动态面板入口)', async ({ page }) => {
await seedCanvas(page)
const registered = await page.evaluate(() => window.IWBPluginHost.register({
+13 -1
View File
@@ -1,5 +1,5 @@
{
"$comment": "e2e 已知失败清单(2026-11-24 立)。用途:把「长期红」与「新红」分开,避免门禁信号被噪声淹没。维护:修好一条就删一条;新红由 scripts/e2e-known-red-report.js 报出来。",
"$comment": "e2e 已知失败清单(2026-11-24 立)。用途:把「长期红」与「新红」分开,避免门禁信号被噪声淹没。维护:修好一条就删一条;新红由 scripts/e2e-known-red-report.js 报出来。 退役清单见 retired(目标 UI 已迁到插件仓或停靠栏,主仓不再守护)。",
"measuredAt": "2026-11-24",
"measuredVersion": "3.26.64",
"baseUrl": {
@@ -28,5 +28,17 @@
"kind": "defect",
"since": "2026-11-24 实测"
}
],
"retired": [
{
"spec": "tests/iwb-lib-panel-ux.spec.js",
"since": "2026-11-27",
"reason": "测的是资源中心浮窗内的搜索/快捷键/分类胶囊/插入图标;该浮窗已下线,面板 UI 归插件仓(promptlib/gallery)维护,主仓不再重复守护"
},
{
"spec": "tests/iwb-full-window-resize.spec.js",
"since": "2026-11-27",
"reason": "测的是浮窗四边隐形缩放手柄 + 标题栏尺寸数字;停靠栏用分隔条调宽,该 UI 已不存在"
}
]
}
+13 -12
View File
@@ -1020,19 +1020,19 @@ test('⑰ 提示词气泡「放大编辑」:单栏所见即所得(Markdown
await expect(page.locator('.iwb-prompt-modal'), '非提示词节点按快捷键不应打开').toHaveCount(0)
})
test('⑪ 库面板(资源中心浮窗)开着时,画布空白处仍能框选', async ({ page }) => {
// 2026-11-19:v3.25.21 加的「DOM 里有 .iwb-fullmask 就整体拦画布」把框选一起拦了 ——
// 资源中心是可拖可连的浮窗,画布露在它外面必须还能框选;只有真模态(.iwb-modal-mask)才整体禁用。
test('⑪ 图库面板开着时,画布空白处仍能框选', async ({ page }) => {
// 2026-11-19:v3.25.21 加的「DOM 里有浮层就整体拦画布」把框选一起拦了。
// 2026-11-27:资源中心浮窗已下线,改为右停靠栏的图库面板 —— 同样的约束:面板之外的画布必须还能框选。
await boot(page)
await page.locator('.iwb-top-nav-icon[title*="资源中心"]').click()
await expect(page.locator('.iwb-fullmask')).toBeVisible()
await W.openDockPanel(page, 'gallery')
await expect(page.locator('.iwb-dock[data-side="right"]')).toBeVisible()
// 在画布上找一个**没被浮窗/节点/底栏/侧栏盖住**的空白点(浮窗位置随视口变化,不能写死坐标)
const pt = await page.evaluate(() => {
const c = document.querySelector('.iwb-canvas')
if (!c) return null
const r = c.getBoundingClientRect()
const blocked = '.iwb-node, .iwb-fullmask, .iwb-fullpanel, .iwb-toolbar, .iwb-statusbar, .iwb-minimap, .iwb-wsrail, .iwb-lib, .iwb-lib-embedded, .iwb-hint-bottom, .iwb-node-floatbar, .iwb-rightrail'
const blocked = '.iwb-node, .iwb-dock, .iwb-fullmask, .iwb-fullpanel, .iwb-toolbar, .iwb-statusbar, .iwb-minimap, .iwb-wsrail, .iwb-lib, .iwb-lib-embedded, .iwb-hint-bottom, .iwb-node-floatbar, .iwb-rightrail'
for (let fy = 0.15; fy < 0.9; fy += 0.05) {
for (let fx = 0.05; fx < 0.95; fx += 0.05) {
const x = r.left + r.width * fx
@@ -1053,12 +1053,13 @@ test('⑪ 库面板(资源中心浮窗)开着时,画布空白处仍能框
await expect(page.locator('.iwb-boxsel'), '浮窗开着时空白拖动必须出现框选').toHaveCount(1)
await page.mouse.up()
await expect(page.locator('.iwb-boxsel'), '松手后框选应清掉').toHaveCount(0)
await expect(page.locator('.iwb-fullmask'), '框选不应把库面板关掉').toBeVisible()
await expect(page.locator('.iwb-dock[data-side="right"]'), '框选不应把图库面板关掉').toBeVisible()
await expect(page.locator('.iwb-dock-body[data-panel="gallery"]')).toBeVisible()
// 浏览器插件面板 tab 应有图标(2026-11-19:宿主此前没有 globe 图标,tab 渲染成空白)。插件未加载时跳过。
const bmTab = page.locator('.iwb-fullmask .iwb-res-tab', { hasText: '浏览器' })
if (await bmTab.count()) {
const svgHtml = await bmTab.locator('svg').first().innerHTML()
expect(String(svgHtml).length, '浏览器 tab 图标 svg 应有内容(globe)').toBeGreaterThan(0)
// 停靠栏面板图标应有内容(2026-11-19 宿主曾缺 globe 图标;2026-11-27 迁到 .iwb-dock-btn)
const dockBtn = page.locator('.iwb-dock-btn').first()
if (await dockBtn.count()) {
const svgHtml = await dockBtn.locator('svg').first().innerHTML()
expect(String(svgHtml).length, '停靠栏面板图标 svg 应有内容').toBeGreaterThan(0)
}
})
+2 -1
View File
@@ -187,7 +187,8 @@ test('2. Shift 点节点体多选:高亮 1→2→1(并出现节点组气泡
// 打开资源中心 → 图库 → 双击指定条目 → 预览里点「复制」→ 读系统剪贴板
async function copyFromGalleryPreview(page, name) {
await W.openGallery(page)
const thumb = page.locator('.iwb-history-item img[title^="' + name + '"]')
// 图库条目:title 挂在条目容器上(插件 v1.7 起),不是 img 上
const thumb = page.locator('.iwb-history-item[title^="' + name + '"] img').first()
await expect(thumb).toBeVisible()
await thumb.dblclick()
await expect(page.locator('.iwb-imgpreview')).toBeVisible()
-91
View File
@@ -1,91 +0,0 @@
// 资源中心面板:缩放手柄「隐形但可拖」+ 标题栏尺寸显示(2026-10-20)
//
// 背景:此前缩放手柄的 CSS 里有**三套互相冲突**的规则(基类斜角三角 / 四边细条 / 4 角 L 形括号),
// 后写的 `background: transparent` 把前两套的三角**全部覆盖失效** ⇒ 实际显示的是
// 「L 形括号 + 圆角边框」套在**方形面板**上(面板 border-radius: 0)⇒ 视觉上是几截半截线头。
// 现在:手柄**完全不可见**(仍保留 DOM 与拖动热区),「能缩放」的信息改由
// 边缘 hover 淡入提示传递(2026-10-31 起移除标题栏尺寸文字)。
//
// 本用例守三件事(行为断言,不看源码文本):
// ① 4 角 + 4 边手柄**不可见**(背景透明、无边框)但**仍在 DOM 里**(热区未被删);
// ② hover 边缘出现淡入提示(静止时无);
// ③ 拖动边缘仍能改尺寸。
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_fs', name: '资源中心', nodes: [], edges: [], groups: [] }],
activeId: 'ws_fs', rev: 1, schemaVersion: 1,
}
async function openResourceCenter(page) {
await page.addInitScript((ws) => { localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws)) }, 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.locator('.iwb-top-nav-icon[title*="资源中心"]').click()
await page.waitForSelector('.iwb-res-tabs', { timeout: 10000 })
await page.waitForTimeout(400)
}
test('缩放手柄不可见但可拖,拖动边缘可改尺寸', async ({ page }) => {
await openResourceCenter(page)
// ① 手柄仍在 DOM 里(热区没被删)且完全不可见
const handles = await page.evaluate(() => {
const out = []
for (const el of document.querySelectorAll('.iwb-full-resize')) {
const cs = getComputedStyle(el)
out.push({
cls: el.className,
bg: cs.backgroundColor,
bgImage: cs.backgroundImage,
border: cs.borderTopWidth,
cursor: cs.cursor,
w: parseFloat(cs.width),
h: parseFloat(cs.height),
})
}
return out
})
expect(handles.length, '应保留 8 个缩放手柄(4 角 + 4 边)').toBe(8)
for (const h of handles) {
expect(h.bg, h.cls + ' 背景应透明').toBe('rgba(0, 0, 0, 0)')
expect(h.bgImage, h.cls + ' 不应有渐变角标').toBe('none')
expect(h.border, h.cls + ' 不应有边框线头').toBe('0px')
}
// 角与边的热区尺寸保持(20px 角 / 7px 边)⇒ 交互手感不变
const corner = handles.find((h) => h.cls.includes('resize-br'))
const edge = handles.find((h) => h.cls.includes('resize-r'))
expect(corner.w, '角热区应保持 20px').toBe(20)
expect(corner.h, '角热区应保持 20px').toBe(20)
expect(edge.w, '边热区应保持 7px').toBe(7)
expect(edge.cursor, '右边应是 ew-resize 光标').toBe('ew-resize')
expect(corner.cursor, '右下角应是 nwse-resize 光标').toBe('nwse-resize')
// ② hover 边缘出现淡入提示(静止时无)
const box = await page.locator('.iwb-fullmask').boundingBox()
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2)
await page.waitForTimeout(250)
const idle = await page.evaluate(() => getComputedStyle(document.querySelector('.iwb-full-resize-r')).backgroundColor)
expect(idle, '静止时边缘不应有提示色').toBe('rgba(0, 0, 0, 0)')
await page.mouse.move(box.x + box.width - 3, box.y + box.height / 2)
await page.waitForTimeout(350)
const hover = await page.evaluate(() => getComputedStyle(document.querySelector('.iwb-full-resize-r')).backgroundColor)
expect(hover, 'hover 边缘应出现淡入提示').not.toBe('rgba(0, 0, 0, 0)')
// ④ 拖动仍能改尺寸,且尺寸文字实时跟随
const before = await page.evaluate(() => document.querySelector('.iwb-fullmask').getBoundingClientRect().width)
await page.mouse.move(box.x + box.width - 3, box.y + box.height / 2)
await page.mouse.down()
await page.mouse.move(box.x + box.width - 120, box.y + box.height / 2, { steps: 8 })
await page.mouse.up()
await page.waitForTimeout(400)
const after = await page.evaluate(() => document.querySelector('.iwb-fullmask').getBoundingClientRect().width)
expect(after, '拖动右边缘应缩小面板').toBeLessThan(before)
})
+13 -8
View File
@@ -75,6 +75,15 @@ async function seedGallery(page) {
}
// 2026-11-26:资源中心浮窗已被停靠栏「图库」插件面板取代,统一走 helper
// 2026-11-27:图库已改为停靠栏插件面板 —— 条目不再自带「插入」按钮:
// 先点条目(选中)→ 再点工具条「插入」。
async function insertFromGallery(page) {
await page.locator('.iwb-history-item img').first().click()
const ins = page.locator('.iwb-gal-actions button').filter({ hasText: '插入' }).first()
await expect(ins, '图库工具条应有「插入」按钮').toHaveCount(1)
await ins.click()
}
async function openGallery(page) {
await W.openGallery(page, { waitItems: 15000 })
}
@@ -127,9 +136,7 @@ test('图库插入:画布里只留引用(不塞整图 base64)', async ({ p
await seedGallery(page)
await openGallery(page)
const ins = page.locator('.iwb-history-item button').filter({ hasText: '插入' }).first()
await expect(ins, '图库条目应有「插入」按钮').toHaveCount(1)
await ins.click()
await insertFromGallery(page)
await waitNodeSaved(page)
const n = await readNode(page)
@@ -148,8 +155,7 @@ test('图库插入:刷新后双击仍能打开预览(核心回归)', async
await seedGallery(page)
await openGallery(page)
const ins = page.locator('.iwb-history-item button').filter({ hasText: '插入' }).first()
await ins.click()
await insertFromGallery(page)
await waitNodeSaved(page)
// 刷新(应用会记住上次的工作台 ⇒ 可能**直接回到画布**,不一定经过首页)
@@ -181,8 +187,7 @@ test('图库插入:刷新后内存占用显著低于「插入整图 base64」'
const memBefore = await page.evaluate(() => performance.memory ? performance.memory.usedJSHeapSize : 0)
const ins = page.locator('.iwb-history-item button').filter({ hasText: '插入' }).first()
await ins.click()
await insertFromGallery(page)
await waitNodeSaved(page)
// 刷新
@@ -237,7 +242,7 @@ test('图库插入的图片:生成请求里必须是 base64(不是 blob: 临
})
await seedGallery(page)
await openGallery(page)
await page.locator('.iwb-history-item button').filter({ hasText: '插入' }).first().click()
await insertFromGallery(page)
await waitNodeSaved(page)
await page.keyboard.press('Escape')
await page.waitForTimeout(400)
-216
View File
@@ -1,216 +0,0 @@
// 资源中心面板 交互优化(2026-10-20,v3.23.0)
//
// 本用例守 5 项交互改进(**行为断言**,不看源码文本 —— 遵守源码钉点棘轮「只减不增」):
// ① 面板快捷键:Ctrl+F 聚焦搜索、↑↓ 选卡片、Esc 关闭
// (此前**全部失效** —— 守卫是 `if (!fullOpen) return`,而资源中心走 `props.resOpen`)
// ② 搜索是**全局**的(跨分组)且当前范围**可见**
// (此前先按分组过滤再按搜索词过滤 ⇒ 在「小红书」里搜「收藏」搜不到「收藏」分组的内容)
// ③ 分类胶囊行**单行横向滚动**(分组多了不再换行挤矮卡片区),「⚙」固定在右侧不随滚动
// ④ 卡片「插入到画布」按钮用 **+ 图标**(此前是 ⬇ 下载图标,与行为相反 ⇒ 误导)
// ⑤ 手动收起右侧编辑区后,**记住这个偏好**(点卡片不再自动展开)
//
// 全部用真实浏览器 + 真实交互驱动,不做源码文本比对。
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 } })
const WS = {
workspaces: [{ id: 'ws_ux', name: '资源中心', nodes: [], edges: [], groups: [] }],
activeId: 'ws_ux', rev: 1, schemaVersion: 1,
}
// 两个分组的提示词 + 一个未分组 ⇒ 够验证「跨分组搜索」
const PROMPTS = [
{ id: 'q1', name: '小红书封面', text: '生成小红书封面图', tags: ['封面'], group: '小红书' },
{ id: 'q2', name: '收藏的提示', text: '这是被收藏的内容', tags: [], group: '收藏' },
{ id: 'q3', name: '未分组的一条', text: '没有分组的', tags: [], group: '' },
]
const GROUPS = [{ id: 'g1', name: '小红书' }, { id: 'g2', name: '收藏' }]
async function openResourceCenter(page) {
await page.addInitScript((ws) => { localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws)) }, WS)
// 提示词与分组分别存在 iwb_web_prompts / iwb_lib_groups_cache
// (后者是 prompt groups 的本地缓存键 —— 服务端未返回 groups 时用它兜底)
await page.addInitScript(([p, g]) => {
localStorage.setItem('iwb_web_prompts', JSON.stringify(p))
localStorage.setItem('iwb_lib_groups_cache', JSON.stringify(g))
}, [PROMPTS, GROUPS])
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.locator('.iwb-top-nav-icon[title*="资源中心"]').click()
await page.waitForSelector('.iwb-res-tabs', { timeout: 10000 })
await W.poll(page, () => page.locator('.iwb-pcard').count()).toBeGreaterThan(0)
}
test('① 资源中心快捷键:Ctrl+F 聚焦搜索 / ↑↓ 选卡片 / Esc 关闭', async ({ page }) => {
await openResourceCenter(page)
// Ctrl+F ⇒ 焦点落在搜索框(此前**完全失效**,但搜索框 placeholder 明写了「Ctrl+F 聚焦」)
await page.keyboard.press('Control+f')
await W.poll(page, () => page.evaluate(() => {
const a = document.activeElement
return !!(a && a.placeholder && String(a.placeholder).includes('搜索'))
})).toBe(true)
const inSearch = await page.evaluate(() => {
const a = document.activeElement
return !!(a && a.placeholder && String(a.placeholder).includes('搜索'))
})
expect(inSearch, 'Ctrl+F 应聚焦搜索框').toBe(true)
// ↑↓ ⇒ 选中项变化(此前失效)
await page.locator('.iwb-fullmask input[placeholder*="搜索"]').fill('')
await page.waitForTimeout(200)
// 焦点移出搜索框(面板浮层挡住画布,点击画布会超时 ⇒ 改用 blur)
await page.evaluate(() => { const i = document.querySelector('.iwb-fullmask input[placeholder*="搜索"]'); if (i) i.blur() })
await page.waitForTimeout(150)
await page.keyboard.press('ArrowDown')
await W.poll(page, () => page.locator('.iwb-pcard-selected').count()).toBeGreaterThan(0)
const selected = await page.locator('.iwb-pcard-selected').count()
expect(selected, '↓ 应能选中卡片').toBeGreaterThan(0)
// Esc ⇒ 关闭资源中心
await page.keyboard.press('Escape')
expect(await page.locator('.iwb-fullmask').count(), 'Esc 应关闭资源中心').toBe(0)
// v3.24.30:开合状态刷新后保持(此前刷新必定关闭,用户反馈「打开了刷新又没了」)
expect(await page.evaluate(() => localStorage.getItem('iwb_drawer_open')), '关闭后面板应写 0').toBe('0')
await page.reload({ waitUntil: 'domcontentloaded' })
await page.waitForSelector('.iwb-canvas-topbar', { timeout: 20000 })
expect(await page.locator('.iwb-fullmask').count(), '关闭态刷新后不应自动打开').toBe(0)
// 重新打开 → 刷新 → 仍保持打开(进入画布时曾 setDrawerOpen(false),刷新恢复不能走那条路径)
await page.locator('.iwb-top-nav-icon[title*="资源中心"]').click()
await page.waitForSelector('.iwb-res-tabs', { timeout: 10000 })
expect(await page.evaluate(() => localStorage.getItem('iwb_drawer_open')), '打开后面板应写 1').toBe('1')
await page.reload({ waitUntil: 'domcontentloaded' })
await page.waitForSelector('.iwb-canvas-topbar', { timeout: 20000 })
expect(await page.locator('.iwb-fullmask').count(), '打开态刷新后应保持打开').toBeGreaterThan(0)
// v3.24.38:标签页也要记住(此前 drawerTab 是纯内存 state,刷新必回「提示词库」)
await page.locator('.iwb-res-tab', { hasText: '图库' }).click()
expect(await page.evaluate(() => localStorage.getItem('iwb_drawer_tab')), '切到图库应写 history').toBe('history')
await page.reload({ waitUntil: 'domcontentloaded' })
await page.waitForSelector('.iwb-canvas-topbar', { timeout: 20000 })
await W.poll(page, () => page.locator('.iwb-res-tab-active').first().innerText()).toContain('图库')
const activeTab = await page.locator('.iwb-res-tab-active').first().innerText()
expect(activeTab, '刷新后应停在图库标签').toContain('图库')
})
test('①b Esc 分层:输入框 / 临时层优先于面板(2026-10-20 回归)', async ({ page }) => {
await openResourceCenter(page)
// ① 正在输入框打字时,Esc 归输入框(取消编辑),**不能**关掉整个面板
// (此前面板自己在捕获阶段处理 Esc ⇒ 会抢在 app.js 的画布 Esc 之前关掉面板)
await page.locator('.iwb-fullmask input[placeholder*="搜索"]').click()
await page.keyboard.press('Escape')
expect(await page.locator('.iwb-fullmask').count(), '输入框里按 Esc 不应关闭面板').toBe(1)
// ② 存在临时层(真实右键菜单)时,Esc 先关临时层,面板保持打开
// (app.js 画布 Esc 的分层:右键菜单 → … → 资源中心)
// ⚠️ 两个要点:
// · 必须**真的右键**打开菜单 —— ctxMenu 是 React state,注入 DOM 元素不会改变它;
// · 必须右键在**面板之外**的画布区(面板浮层会吞掉面板内的右键事件)。
await page.evaluate(() => { const i = document.querySelector('.iwb-fullmask input[placeholder*="搜索"]'); if (i) i.blur() })
const maskBox = await page.locator('.iwb-fullmask').boundingBox()
const outsideX = Math.max(10, Math.round(maskBox.x / 2)) // 面板左侧的画布区
const outsideY = Math.round(maskBox.y + maskBox.height / 2)
await page.mouse.move(outsideX, outsideY)
await page.mouse.click(outsideX, outsideY, { button: 'right' })
expect(await page.locator('.iwb-ctxmenu').count(), '应打开右键菜单').toBeGreaterThan(0)
await page.keyboard.press('Escape')
expect(await page.locator('.iwb-fullmask').count(), '临时层存在时 Esc 不应关闭面板').toBe(1)
expect(await page.locator('.iwb-ctxmenu').count(), 'Esc 应先关掉右键菜单').toBe(0)
// ③ 临时层清掉后,Esc 才能关面板(此时由 app.js 的画布 Esc 负责)
await page.keyboard.press('Escape')
expect(await page.locator('.iwb-fullmask').count(), '无临时层时 Esc 应关闭面板').toBe(0)
})
test('② 搜索跨分组 + 当前范围可见', async ({ page }) => {
await openResourceCenter(page)
// 切到「小红书」分组 ⇒ 只应有 1 条
await page.locator('.iwb-fullpanel .iwb-chip').filter({ hasText: '小红书' }).first().click()
expect(await page.locator('.iwb-full-grid .iwb-pcard').count(), '小红书分组内应只有 1 条').toBe(1)
// 搜「收藏」⇒ 应能搜到**其他分组**里的那条(此前结果为 0)
await page.locator('.iwb-fullmask input[placeholder*="搜索"]').fill('收藏')
await W.poll(page, () => page.locator('.iwb-full-grid .iwb-pcard').count()).toBeGreaterThan(0)
const found = await page.locator('.iwb-full-grid .iwb-pcard').count()
expect(found, '搜索应跨分组(此前搜不到「收藏」分组的内容)').toBeGreaterThan(0)
// 范围必须**可见**:出现「在全部中搜索」提示,且 chips 高亮切到「全部」
expect(await page.locator('.iwb-lib-searchscope').count(), '应显示搜索范围提示').toBeGreaterThan(0)
const activeChip = await page.locator('.iwb-fullpanel .iwb-chip-active').first().textContent()
expect(activeChip, 'chips 高亮应切到「全部」(高亮与结果范围必须一致)').toContain('全部')
// 清空搜索 ⇒ 回到原来的分组(「小红书」高亮)
await page.locator('.iwb-lib-searchscope-back').click()
await W.poll(page, () => page.locator('.iwb-fullpanel .iwb-chip-active').first().textContent()).toContain('小红书')
const backChip = await page.locator('.iwb-fullpanel .iwb-chip-active').first().textContent()
expect(backChip, '清空搜索后应回到原分组').toContain('小红书')
})
test('③ 分类胶囊行单行滚动 + ⚙ 固定在右侧', async ({ page }) => {
await openResourceCenter(page)
const info = await page.evaluate(() => {
const sc = document.querySelector('.iwb-lib-chips-scroll')
if (!sc) return null
const chips = document.querySelector('.iwb-lib-chips')
const mgmt = Array.from(chips.querySelectorAll('.iwb-chip')).find((c) => c.title === '管理分组(重命名 / 排序 / 删除)')
const cs = getComputedStyle(sc)
return {
overflowX: cs.overflowX,
flexWrap: getComputedStyle(chips).flexWrap,
mgmtInsideScroll: mgmt ? sc.contains(mgmt) : null,
mgmtRight: mgmt ? mgmt.getBoundingClientRect().right : null,
scrollRight: sc.getBoundingClientRect().right,
}
})
expect(info, '应存在 .iwb-lib-chips-scroll 滚动容器').not.toBeNull()
expect(info.flexWrap, '胶囊行不应换行').toBe('nowrap')
expect(info.overflowX, '胶囊行应可横向滚动').toBe('auto')
expect(info.mgmtInsideScroll, '「⚙ 管理分组」应固定在滚动区之外(始终可点)').toBe(false)
})
test('④ 卡片「插入到画布」用 + 图标(不再是 ⬇ 下载)', async ({ page }) => {
await openResourceCenter(page)
const btn = page.locator('.iwb-full-grid .iwb-pcard .iwb-pbtns button').first()
const title = await btn.getAttribute('title')
expect(title, '插入按钮的 title 应保留「插入到画布」措辞').toContain('插入到画布')
// + 图标 = 两个 path(水平线 + 垂直线);⬇ 下载图标 = polyline + line + path
const shape = await btn.evaluate((b) => {
const svg = b.querySelector('svg')
return svg ? { tags: Array.from(svg.children).map((c) => c.tagName.toLowerCase()), d: svg.innerHTML.replace(/\s+/g, '') } : null
})
expect(shape, '插入按钮应有 svg 图标').not.toBeNull()
// + 图标的特征:两条 path(一横一竖),下载图标的特征:含 polyline(箭头)
expect(shape.tags, '插入按钮应使用 + 图标(两个 path),不应含下载图标的 polyline').toEqual(['path', 'path'])
expect(shape.d, '不应含下载图标的 polyline 箭头').not.toContain('polyline')
})
test('⑤ 手动收起编辑区后记住偏好', async ({ page }) => {
await openResourceCenter(page)
// 点卡片 ⇒ 编辑区展开
await page.locator('.iwb-full-grid .iwb-pcard').first().click()
expect(await page.locator('.iwb-full-edit').count(), '点卡片应展开编辑区').toBe(1)
// 手动收起 ⇒ 记偏好
await page.locator('.iwb-full-edit-head button').click()
expect(await page.locator('.iwb-full-collapsed').count(), '应折叠').toBe(1)
// 再点卡片 ⇒ **不再**自动展开(尊重用户偏好)
await page.locator('.iwb-full-grid .iwb-pcard').nth(1).click()
expect(await page.locator('.iwb-full-collapsed').count(), '手动收起后点卡片不应再自动展开').toBe(1)
expect(await page.locator('.iwb-full-edit').count(), '编辑区应保持收起').toBe(0)
// 偏好已持久化
const pref = await page.evaluate(() => localStorage.getItem('iwb_lib_edit_open'))
expect(pref, '收起偏好应写入 localStorage').toBe('0')
})
+34 -58
View File
@@ -1,79 +1,55 @@
// 资源中心插件面板「串页」回归守护(用户实测驱动)。
// 停靠栏插件面板「串页」回归守护(2026-11-27 重写)。
//
// 缺陷:插件面板容器与「图库」分支(props.historyContent)渲染在同一个父容器的同一位置,
// 根节点同为 div 且都没有 key ⇒ React 判定为同一元素并复用 DOM 节点;
// 而插件经 ref 手动 appendChild 进去的 DOM 不在 React 的 fiber 记账里,切走时不会被清理,
// 于是残留在图库页上方(用户看到「切到图库被插件面板侵入入库页面」)。
// 原缺陷(资源中心浮窗时代):插件面板与图库分支渲染在同一父容器的同一位置,
// React 复用 DOM 节点 + 插件手动 appendChild 不在 fiber 记账里 ⇒ 切走后残留。
//
// 对照实验(回归有效性证明):去掉 src/ui-lib-sidebar.js 里的 `key: 'plugin:' + id` 重跑本用例,
// 四个切换场景的残留计数全部为 1;加回 key 后全部为 0。
//
// 运行:npm run build && IWB_E2E_SPECS=tests/iwb-plugin-panel-tab-leak.spec.js npm run test:e2e
// v3.25.82 起资源中心浮窗下线,面板搬进左右停靠栏(每个面板一个 .iwb-dock-body)。
// 同一类风险仍然存在:切面板时旧面板的 DOM 必须卸载,切回只能挂载一份。
// 这里用「宿主级」判据守护:任何时刻停靠栏里只应有一个插件容器(.iwb-dock-plugin)。
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 } })
const CFG = { providers: [], canvas: {} }
const WS = { workspaces: [{ id: 'w1', name: 'W', nodes: [], edges: [], groups: [] }], activeId: 'w1', rev: 1 }
// 插件面板只往容器里塞这一段文本:断言它「该消失时消失」,比断言容器 class 可靠
// (修复前容器 class 已被 React 改成图库容器的 class,按 class 断言抓不到残留)。
const MARK = 'PROBE-PANEL-MARK'
test('插件面板切到图库/提示词库后不残留,切回时只挂载一次', async ({ page }) => {
await page.addInitScript((d) => {
test('停靠栏面板切换不残留:切走即卸载,切回只挂载一份', async ({ page }) => {
await page.addInitScript((ws) => {
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_w1', JSON.stringify(d.ws.workspaces[0]))
localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws))
localStorage.setItem('iwb_ws_active', ws.activeId)
localStorage.setItem('iwb_ws_w1', JSON.stringify(ws.workspaces[0]))
localStorage.setItem('iwb_web_outputs', JSON.stringify([]))
}, { cfg: CFG, ws: WS })
}, WS)
await page.goto('/', { waitUntil: 'domcontentloaded' })
await page.waitForFunction(() => Boolean(window.IWBPluginHost) && window.IWBPluginHost.snapshot().initialized === true)
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
await expect(page.locator('.iwb-canvas:not(.iwb-canvas-hidden)')).toBeVisible()
const reg = await page.evaluate((mark) => window.IWBPluginHost.register({
id: 'probe-panel', name: '探针面板', version: '1.0.0', apiVersion: 1, capabilities: ['panels'],
}, (ctx) => {
ctx.ui.registerPanel({
id: 'p',
title: '探针面板',
mount: (node) => { const d = document.createElement('div'); d.textContent = mark; node.appendChild(d) },
})
return {}
}), MARK)
expect(reg.ok).toBe(true)
await page.evaluate(() => window.IWBPluginHost.setEnabled('probe-panel', true))
// 左右两栏各可有一个活动面板 ⇒ 不能按全局计数;按「本面板 body 内的插件容器」断言
const galleryBody = () => page.locator('.iwb-dock-body[data-panel="gallery"]')
const galleryBoxes = () => page.locator('.iwb-dock-body[data-panel="gallery"] .iwb-dock-plugin').count()
await page.locator('.iwb-top-nav-icon[title^="资源中心"]').click()
await expect(page.locator('.iwb-res-tabs')).toBeVisible()
// 图库面板:挂载一份
await W.openDockPanel(page, 'gallery')
await expect(galleryBody()).toHaveCount(1)
await expect.poll(galleryBoxes).toBe(1)
const tab = (name) => page.locator('.iwb-res-tab').filter({ hasText: name })
const marks = () => page.locator('text=' + MARK).count()
// 切到提示词库:图库的 DOM 必须卸载(旧面板不残留)
await W.openDockPanel(page, 'prompts')
await expect(galleryBody()).toHaveCount(0)
// 插件面板:挂载正常
await tab('探针面板').click()
await expect.poll(marks).toBe(1)
// 切回图库:重新挂载,且只有一份(不是叠加两份)
await W.openDockPanel(page, 'gallery')
await expect(galleryBody()).toHaveCount(1)
await expect.poll(galleryBoxes).toBe(1)
await expect(page.locator('.iwb-dock-body[data-panel="gallery"] .iwb-history-embedded')).toHaveCount(1)
// 切到图库:容器被换成图库内容,插件 DOM 必须一并消失
await tab('图库').click()
await expect.poll(marks).toBe(0)
// 切到节点组:groupsContent 是组件、type 不同,本就不会复用,同样不应残留
await tab('节点组').click()
await expect.poll(marks).toBe(0)
// 切到提示词库:该分支的左右两栏也是 div,同层展平,一并守护
await tab('提示词库').click()
await expect.poll(marks).toBe(0)
// 回到插件面板:重新挂载,且只有一个(不是叠加两份)
await tab('探针面板').click()
await expect.poll(marks).toBe(1)
// 再切走:仍然干净(连续往返不复用)
await tab('提示词库').click()
await expect.poll(marks).toBe(0)
// 再往返一次:仍然干净
await W.openDockPanel(page, 'prompts')
await expect(galleryBody()).toHaveCount(0)
await W.openDockPanel(page, 'gallery')
await expect.poll(galleryBoxes).toBe(1)
})
+17 -37
View File
@@ -30,53 +30,33 @@ test('页面启动并渲染核心画布', async ({ page }) => {
await expect(page.locator('.iwb-canvas:not(.iwb-canvas-hidden)')).toBeVisible()
})
test('资源中心图库可以打开和关闭', async ({ page }) => {
// 2026-11-27:资源中心浮窗已下线,图库改为右停靠栏的插件面板
test('图库面板可以打开和关闭', async ({ page }) => {
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()
const resEntry = page.locator('.iwb-top-nav-icon[title*="资源中心"]')
await expect(resEntry).toBeVisible()
await resEntry.click()
await expect(page.locator('.iwb-fullmask')).toBeVisible()
await expect(page.locator('.iwb-res-tabs')).toBeVisible()
await page.locator('.iwb-res-tab').filter({ hasText: '图库' }).click()
await expect(page.locator('.iwb-history-embedded')).toBeVisible()
await page.locator('.iwb-full-head button[title*="关闭"]').click()
await expect(page.locator('.iwb-fullmask')).toBeHidden()
await expect(resEntry).toBeVisible()
await W.openDockPanel(page, 'gallery')
await expect(page.locator('.iwb-dock-body[data-panel="gallery"] .iwb-history-embedded')).toBeVisible()
// 关右栏 ⇒ 面板随之消失
await page.locator('.iwb-top-nav-icon[title="显示 / 隐藏右栏"]').first().click()
await expect(page.locator('.iwb-dock[data-side="right"]')).toHaveCount(0)
// 再开 ⇒ 面板回来
await page.locator('.iwb-top-nav-icon[title="显示 / 隐藏右栏"]').first().click()
await expect(page.locator('.iwb-dock[data-side="right"]')).toBeVisible()
})
test('n 快捷键:未打开则打开图库,再按一次必定关闭(不论当前停在哪个 tab)', async ({ page }) => {
const activeTab = () => page.evaluate(() => {
const t = document.querySelector('.iwb-fullmask .iwb-res-tab.iwb-res-tab-active')
return t ? t.textContent.trim() : null
})
// 2026-11-27:N 快捷键现在切换「右栏」(图库面板所在侧),不再是打开资源中心浮窗
test('N 快捷键:打开/关闭右栏', async ({ page }) => {
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()
// 1) 未打开 → 按 n → 打开并落在图库
await expect(page.locator('.iwb-fullmask')).toBeHidden()
await expect(page.locator('.iwb-dock[data-side="right"]')).toHaveCount(0)
await page.keyboard.press('n')
await expect(page.locator('.iwb-fullmask')).toBeVisible()
expect(await activeTab(), 'first n').toContain('图库')
await expect(page.locator('.iwb-history-embedded')).toBeVisible()
// 2) 已在图库 → 按 n → 关闭
await expect(page.locator('.iwb-dock[data-side="right"]')).toBeVisible()
await page.keyboard.press('n')
await expect(page.locator('.iwb-fullmask')).toBeHidden()
// 3) 打开 → 切到其他 tab → 按 n → 直接关闭
// 用户要求:第二次按 n 必定关闭,不要求"先切回图库"(旧实现会先切 tab,得按第三下才关得掉)
await page.keyboard.press('n')
await expect(page.locator('.iwb-fullmask')).toBeVisible()
await page.locator('.iwb-fullmask .iwb-res-tab').filter({ hasText: '提示词库' }).click()
expect(await activeTab(), 'after click 提示词库').toContain('提示词库')
await page.keyboard.press('n')
await expect(page.locator('.iwb-fullmask'), '第二次按 n 必须关闭面板').toBeHidden()
// 4) 再按一次 → 重新打开并落在图库(同时验证关闭后 tab 会回到图库)
await page.keyboard.press('n')
await expect(page.locator('.iwb-fullmask')).toBeVisible()
expect(await activeTab(), 'reopen').toContain('图库')
await expect(page.locator('.iwb-dock[data-side="right"]')).toHaveCount(0)
})
test('刷新后保留工作台基本状态', async ({ page }) => {
@@ -200,13 +180,13 @@ test('空格+左键拖动 = 平移画布', async ({ page }) => {
expect(after).not.toBe(before)
})
test('打开资源中心不移动画布', async ({ page }) => {
test('打开图库面板不移动画布', async ({ page }) => {
await page.goto('/', { waitUntil: 'domcontentloaded' })
await W.waitHomeReady(page)
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
await W.waitCanvasOpen(page)
const left0 = await page.evaluate(() => document.querySelector('.iwb-canvas').style.left)
await page.locator('.iwb-top-nav-icon[title*="资源中心"]').click()
await W.openDockPanel(page, 'gallery')
await page.waitForTimeout(300)
const left1 = await page.evaluate(() => document.querySelector('.iwb-canvas').style.left)
expect(left1).toBe(left0)
+3 -1
View File
@@ -34,7 +34,9 @@ assert.deepStrictEqual(specsBase, expectedSpecs, '门禁 spec 必须等于全部
// 52 = 53 − iwb-groups-sidebar(v3.25.56 节点组库改为插件 grouplib,宿主侧栏组件删除,其 e2e 一并移除)
// 53 = 52 + iwb-default-gen-model(v3.26.71:通用 tab 设置新建配置节点默认模型)
// 54 = 53 + iwb-album-thumbs(相册 1.1.6:宫格重建后缩略图丢 src / 透明图黑底的回归)
assert.strictEqual(result.specs.length, 54, '当前门禁应自动发现 54 个 spec')
// 52 = 54 − iwb-lib-panel-ux − iwb-full-window-resize(2026-11-27 退役:测的是已下线的「资源中心」浮窗 UI,
// 面板 UI 归插件仓;退役原因记在 tests/fixtures/e2e-known-red.json 的 retired 段)
assert.strictEqual(result.specs.length, 52, '当前门禁应自动发现 52 个 spec')
// 排除集合 = 全部人工 dev 探针,且都必须已声明标记
// 4 = 3 + _probe-tab-switch(切画布标签耗时归因:四轮对照实验,只读诊断)
// 5 = 4 + _visual-tokens(设计 token 视觉基线:像素受字体/DPR 影响,不入 CI,本地 0 diff 验收用)