Files
image-workbench-desktop/tests/iwb-groups-sidebar.spec.js
T

81 lines
3.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 节点组侧栏验收(2026-10-28,P1)
//
// 守 src/ui-groups-sidebar.js(此前 e2e 覆盖仅 2%)。
// 它是资源中心「节点组」tab 的内容:分组管理(新建/重命名/删除)+ 收藏节点组卡片。
//
// 本轮只覆盖**渲染路径**(低风险、稳定):
// ① 打开资源中心 → 节点组 tab → 侧栏正常渲染(空态文案 + 新建分组入口),无 pageerror
// ② 预置一个已收藏的节点组 → 卡片渲染出组名与节点数
//
// ⚠️ 未覆盖:拖拽卡片到画布实例化、分组重命名/删除/排序 ——
// 这些是复合交互(拖拽 + 二次确认),硬写会得到脆弱用例,留作独立任务。
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_grp', name: '节点组', nodes: [], edges: [], groups: [] }],
activeId: 'ws_grp', rev: 1, schemaVersion: 1,
}
// 已收藏的节点组(savedGroups 的存储键 = iwb_web_groups)
const SAVED = [{
id: 'sg1', name: '封面三件套', group: '营销',
nodes: [
{ id: 'n1', type: 'prompt', x: 0, y: 0, data: { text: '标题文案' } },
{ id: 'n2', type: 'gen', x: 240, y: 0, data: { enabled: true, provider: 'tuzi', keyGroup: 'daily', model: 'gpt-image-2', ratio: '1:1', variants: 1 } },
],
edges: [{ id: 'se1', from: 'n1', to: 'n2' }],
}]
async function openGroupsTab(page, saved) {
await page.addInitScript(([ws, sv]) => {
if (localStorage.getItem('__iwb_grp_seeded__') !== '1') {
localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws))
localStorage.setItem('iwb_web_groups', JSON.stringify(sv))
localStorage.setItem('__iwb_grp_seeded__', '1')
}
}, [WS, saved])
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: 15000 })
await page.waitForTimeout(400)
const tab = page.locator('.iwb-res-tab', { hasText: '节点组' }).first()
await expect(tab, '资源中心应有「节点组」tab').toBeVisible()
await tab.click()
await page.waitForTimeout(700)
}
test('① 空态:节点组侧栏渲染出空态文案与「新建分组」入口,无 pageerror', async ({ page }) => {
const errors = []
page.on('pageerror', (e) => errors.push(String(e && e.message || e)))
await openGroupsTab(page, [])
// tab 应已切到「节点组」
const activeTab = await page.evaluate(() => {
const t = Array.from(document.querySelectorAll('.iwb-res-tab')).find((e) => e.className.indexOf('active') >= 0)
return t ? t.innerText : ''
})
expect(activeTab, '「节点组」tab 应处于选中态').toContain('节点组')
const text = await page.locator('.iwb-fullmask, .iwb-fullpanel').first().innerText()
// 空态文案(实测空态下不渲染「新建分组」按钮 —— 那是有分组时才出现的管理入口)
expect(text, '空态应提示暂无收藏节点组').toContain('暂无收藏节点组')
expect(errors, '不应有 pageerror').toEqual([])
})
test('② 有数据:已收藏的节点组渲染出组名与节点数', async ({ page }) => {
const errors = []
page.on('pageerror', (e) => errors.push(String(e && e.message || e)))
await openGroupsTab(page, SAVED)
const panel = await page.locator('.iwb-fullmask, .iwb-fullpanel').first().innerText()
expect(panel, '应显示收藏的节点组名称').toContain('封面三件套')
expect(panel, '应显示该组的分组名').toContain('营销')
expect(errors, '不应有 pageerror').toEqual([])
})