287 lines
15 KiB
JavaScript
287 lines
15 KiB
JavaScript
// 「模型设置」面板的真实浏览器验收(2026-10-30 改造)
|
||
//
|
||
// 背景:原来 服务商 / 分组 / 模型 三个控件挤在节点参数行(`.iwb-gen-row` 不换行),
|
||
// 节点只能靠 480px 宽硬撑。改造后三者收进「模型设置」面板,节点行只剩「模型 + 尺寸」。
|
||
//
|
||
// 覆盖:
|
||
// ① 面板结构(标题「模型设置」、服务商/分组 两个下拉、模型网格、无 pageerror)
|
||
// ② 模型名**单行显示且不省略**;标签流式排列(按内容宽度、排满自动换行)
|
||
// ③ 切服务商 ⇒ 分组重置为该服务商第一个 key,模型网格随之刷新
|
||
// ④ 点模型 ⇒ 面板关闭 + 节点触发器显示新模型 + 高亮打勾
|
||
// ⑤ 无 Key 分组时下拉禁用并显示「无分组」;「服务商 · 分组」显示在节点气泡上
|
||
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 LONG_MODEL = 'gemini-3.1-flash-image-preview' // 30 字符:真实场景里最长的模型名
|
||
|
||
const WS = {
|
||
workspaces: [{
|
||
id: 'w_pick', name: 'W',
|
||
nodes: [{
|
||
id: 'g1', type: 'gen', x: 80, y: 80, w: 330,
|
||
data: { model: 'gpt-image-2', provider: 'p-a', keyGroup: 'a-1', size: '1024x1024', ratio: '1:1', res: '1K', quality: 'auto' },
|
||
}],
|
||
edges: [], groups: [],
|
||
}],
|
||
activeId: 'w_pick', rev: 1, schemaVersion: 1,
|
||
}
|
||
|
||
const CFG = {
|
||
providers: [
|
||
{
|
||
id: 'p-a', name: '服务商 A', baseUrl: 'https://a.example/v1',
|
||
keys: [{ id: 'a-1', name: 'A 第一个 key' }, { id: 'a-2', name: 'A 第二个 key' }],
|
||
models: [{ name: 'gpt-image-2', visible: true }, { name: 'gpt-image-2.5', visible: true }, { name: LONG_MODEL, visible: true }],
|
||
},
|
||
{ id: 'p-b', name: '服务商 B', baseUrl: 'https://b.example/v1', keys: [{ id: 'b-1', name: 'B 第一个 key' }], models: [{ name: 'model-b', visible: true }] },
|
||
{ id: 'p-c', name: '无 Key 服务商', baseUrl: 'https://c.example/v1', keys: [], models: [] },
|
||
],
|
||
canvas: { snap: true },
|
||
}
|
||
|
||
async function seed(page) {
|
||
await page.addInitScript((d) => {
|
||
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_w_pick', JSON.stringify(d.ws.workspaces[0]))
|
||
}, { cfg: CFG, ws: WS })
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' })
|
||
await page.waitForTimeout(600)
|
||
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
|
||
await expect(page.locator('.iwb-canvas:not(.iwb-canvas-hidden)')).toBeVisible()
|
||
await page.waitForTimeout(300)
|
||
}
|
||
|
||
const modelBtn = (page) => page.locator('[data-node-id="g1"] .iwb-pick-genmodel')
|
||
const panel = (page) => page.locator('.iwb-gen-config')
|
||
// 「服务商 · 分组」2026-10-30 移到节点气泡上(节点本体不再常显,避免信息太杂)
|
||
const fbLabel = (page) => page.locator('.iwb-node-floatbar .iwb-node-floatbar-title')
|
||
const selectNode = async (page) => {
|
||
await page.locator('[data-node-id="g1"] .iwb-node-head').click()
|
||
await page.waitForTimeout(250)
|
||
}
|
||
|
||
async function openPanel(page) {
|
||
await modelBtn(page).click()
|
||
await expect(panel(page)).toBeVisible({ timeout: 8000 })
|
||
}
|
||
|
||
test('① 面板结构:标题「模型设置」+ 服务商/分组 两个下拉 + 模型网格,无 pageerror', async ({ page }) => {
|
||
const errors = []
|
||
page.on('pageerror', (e) => errors.push(String((e && e.message) || e)))
|
||
await seed(page)
|
||
|
||
// 节点参数行只剩「模型」(服务商/分组已移走)
|
||
const cells = page.locator('[data-node-id="g1"] .iwb-gen-cell')
|
||
await expect(cells, '参数行应只剩 1 个格子(模型)').toHaveCount(1)
|
||
await expect(cells.first()).toHaveAttribute('title', '模型')
|
||
|
||
await openPanel(page)
|
||
await expect(panel(page).locator('.iwb-pop-title')).toHaveText('模型设置')
|
||
await expect(panel(page).locator('.iwb-gc-select')).toHaveCount(2)
|
||
await expect(panel(page).locator('.iwb-gc-item')).toHaveCount(3)
|
||
const provOpts = await panel(page).locator('.iwb-gc-select').first().locator('option').allTextContents()
|
||
expect(provOpts).toEqual(['服务商 A', '服务商 B', '无 Key 服务商'])
|
||
expect(errors, '不应有 pageerror').toEqual([])
|
||
})
|
||
|
||
test('② 模型名单行不省略;标签流式排列(按内容宽度,排满自动换行)', async ({ page }) => {
|
||
await seed(page)
|
||
await openPanel(page)
|
||
|
||
const items = panel(page).locator('.iwb-gc-item')
|
||
await expect(items).toHaveCount(3)
|
||
const gridBox = await panel(page).locator('.iwb-gc-grid').boundingBox()
|
||
|
||
const info = await items.evaluateAll((els) => els.map((el) => {
|
||
const name = el.querySelector('.iwb-gc-name')
|
||
const cs = window.getComputedStyle(name)
|
||
const r = el.getBoundingClientRect()
|
||
return {
|
||
text: (name.textContent || '').trim(),
|
||
whiteSpace: cs.whiteSpace,
|
||
textOverflow: cs.textOverflow,
|
||
truncated: name.scrollWidth > name.clientWidth + 1, // 内容被裁 ⇒ 说明省略了
|
||
w: r.width, y: Math.round(r.top),
|
||
}
|
||
}))
|
||
|
||
for (const it of info) {
|
||
expect(it.whiteSpace, `「${it.text}」必须单行显示(nowrap)`).toBe('nowrap')
|
||
expect(it.textOverflow, `「${it.text}」不得使用省略号`).not.toBe('ellipsis')
|
||
expect(it.truncated, `「${it.text}」不得被截断`).toBe(false)
|
||
}
|
||
expect(info.map((x) => x.text).sort()).toEqual(['gpt-image-2', 'gpt-image-2.5', LONG_MODEL].sort())
|
||
|
||
// 标签流式:每个按内容宽度;能并排就并排(同一行可多个),排满自动折行
|
||
const rows = new Set(info.map((x) => x.y))
|
||
expect(rows.size, '应有折行(不是每个都独占一行)').toBeLessThan(info.length)
|
||
const shortOne = info.find((x) => x.text === 'gpt-image-2')
|
||
const longOne = info.find((x) => x.text === LONG_MODEL)
|
||
expect(shortOne.w, '短名按内容宽度(不拉满整行)').toBeLessThan(gridBox.width * 0.7)
|
||
expect(longOne.w, '长名应比短名宽').toBeGreaterThan(shortOne.w)
|
||
for (const it of info) expect(it.w, `「${it.text}」不应超出面板`).toBeLessThanOrEqual(gridBox.width + 1)
|
||
})
|
||
|
||
test('③ 切服务商 ⇒ 分组重置为该服务商第一个 key,模型网格刷新', async ({ page }) => {
|
||
await seed(page)
|
||
await openPanel(page)
|
||
|
||
await panel(page).locator('.iwb-gc-select').first().selectOption('p-b')
|
||
await expect(panel(page).locator('.iwb-gc-select').nth(1), '分组应重置为 B 的第一个 key').toHaveValue('b-1')
|
||
await expect(panel(page).locator('.iwb-gc-item')).toHaveCount(1)
|
||
await expect(panel(page).locator('.iwb-gc-item').first()).toContainText('model-b')
|
||
await selectNode(page)
|
||
await expect(fbLabel(page), '气泡上应显示新的服务商').toContainText('服务商 B')
|
||
})
|
||
|
||
test('④ 点模型 ⇒ 面板关闭 + 触发器更新 + 高亮打勾', async ({ page }) => {
|
||
await seed(page)
|
||
await openPanel(page)
|
||
await panel(page).locator('.iwb-gc-item').filter({ hasText: LONG_MODEL }).first().click()
|
||
await expect(panel(page)).toHaveCount(0)
|
||
await expect(modelBtn(page)).toContainText(LONG_MODEL)
|
||
await openPanel(page)
|
||
const on = panel(page).locator('.iwb-gc-item-on')
|
||
await expect(on).toContainText(LONG_MODEL)
|
||
await expect(on).toContainText('✓')
|
||
})
|
||
|
||
test('⑤ 无 Key 分组:下拉禁用并显示「无分组」;「服务商 · 分组」显示在节点气泡上', async ({ page }) => {
|
||
await seed(page)
|
||
await selectNode(page)
|
||
await expect(fbLabel(page), '气泡上应显示「服务商 · 分组」').toContainText('服务商 A · A 第一个 key')
|
||
// 不选中也能查:模型按钮的悬停提示里也带
|
||
await expect(modelBtn(page)).toHaveAttribute('title', /服务商:服务商 A/)
|
||
await expect(modelBtn(page)).toHaveAttribute('title', /分组:A 第一个 key/)
|
||
|
||
await openPanel(page)
|
||
await panel(page).locator('.iwb-gc-select').first().selectOption('p-c')
|
||
await page.waitForTimeout(250)
|
||
const grp = panel(page).locator('.iwb-gc-select').nth(1)
|
||
await expect(grp).toBeDisabled()
|
||
await expect(grp.locator('option').first()).toHaveText('无分组')
|
||
await expect(fbLabel(page), '无分组时气泡显示「无分组」').toContainText('无分组')
|
||
})
|
||
|
||
test('⑥ 旧画布里的分层节点仍正常渲染(隐藏的只是新建入口)', async ({ page }) => {
|
||
// 分层(layer)默认隐藏新建入口,但已存在的节点必须照常渲染与运行 —— 这是"零删除"的验收点
|
||
const wsLayer = {
|
||
workspaces: [{
|
||
id: 'w_pick', name: 'W',
|
||
nodes: [
|
||
{ id: 'g1', type: 'gen', x: 80, y: 80, w: 330, data: { model: 'gpt-image-2', provider: 'p-a', keyGroup: 'a-1', size: '1024x1024', ratio: '1:1', res: '1K' } },
|
||
{ id: 'l1', type: 'layer', x: 80, y: 560, w: 520, data: { model: 'seedream-layer', provider: 'p-a', keyGroup: 'a-1' } },
|
||
],
|
||
edges: [], groups: [],
|
||
}],
|
||
activeId: 'w_pick', rev: 1, schemaVersion: 1,
|
||
}
|
||
const cfgLayer = JSON.parse(JSON.stringify(CFG))
|
||
cfgLayer.providers[0].layerModels = [{ name: 'seedream-layer', visible: true }]
|
||
await page.addInitScript((d) => {
|
||
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_w_pick', JSON.stringify(d.ws.workspaces[0]))
|
||
}, { cfg: cfgLayer, ws: wsLayer })
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' })
|
||
await page.waitForTimeout(600)
|
||
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
|
||
await expect(page.locator('.iwb-canvas:not(.iwb-canvas-hidden)')).toBeVisible()
|
||
await page.waitForTimeout(400)
|
||
|
||
const layer = page.locator('[data-node-id="l1"]')
|
||
await expect(layer, '分层节点必须照常渲染').toHaveCount(1)
|
||
// 分层节点同样复用参数区(模型触发器在),并显示分层模型
|
||
await expect(layer.locator('.iwb-pick-genmodel')).toHaveCount(1)
|
||
await expect(layer.locator('.iwb-pick-genmodel')).toContainText('seedream-layer')
|
||
// 但底栏/右键菜单不再提供「分层」入口
|
||
await expect(page.locator('.iwb-toolbar-bottom .iwb-btn[data-tip="分层"]')).toHaveCount(0)
|
||
})
|
||
|
||
test('⑦ 当前模型已从服务商清单移除 ⇒ 触发器红框提示 + 面板内该项标红', async ({ page }) => {
|
||
// 覆盖 modelAvailable === false 的错误态(原来只在源码层断言,没有真实渲染覆盖)
|
||
const wsBad = JSON.parse(JSON.stringify(WS))
|
||
wsBad.workspaces[0].nodes[0].data.model = 'removed-model-x'
|
||
await page.addInitScript((d) => {
|
||
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_w_pick', JSON.stringify(d.ws.workspaces[0]))
|
||
}, { cfg: CFG, ws: wsBad })
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' })
|
||
await page.waitForTimeout(600)
|
||
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
|
||
await expect(page.locator('.iwb-canvas:not(.iwb-canvas-hidden)')).toBeVisible()
|
||
|
||
await expect(modelBtn(page), '已删除的模型仍显示在原处(不静默改值)').toContainText('removed-model-x')
|
||
await expect(modelBtn(page), '触发器应有红框错误态').toHaveClass(/iwb-input-err/)
|
||
await openPanel(page)
|
||
const errItem = panel(page).locator('.iwb-gc-item-on')
|
||
await expect(errItem, '面板内当前项应标红').toHaveClass(/iwb-gc-item-err/)
|
||
})
|
||
|
||
test('⑧ 面板挂 body(不撑开节点)+ 始终完整落在视口内(会自动上下翻转)', async ({ page }) => {
|
||
await seed(page)
|
||
const nodeBoxBefore = await page.locator('[data-node-id="g1"]').boundingBox()
|
||
await openPanel(page)
|
||
|
||
// ① 必须是 body 下的浮层:不在节点内部 ⇒ 不会参与节点布局把节点撑开
|
||
const mount = await panel(page).evaluate((el) => {
|
||
const anchor = el.closest('.iwb-pop-anchor') || el
|
||
const cs = window.getComputedStyle(anchor)
|
||
return {
|
||
parentIsBody: anchor.parentElement === document.body,
|
||
insideNode: !!el.closest('.iwb-node'),
|
||
fixed: cs.position === 'fixed',
|
||
z: Number(cs.zIndex) || 0,
|
||
}
|
||
})
|
||
expect(mount.parentIsBody, '面板必须 portal 到 document.body(挂在 .iwb-pop-anchor 下)').toBe(true)
|
||
expect(mount.fixed, '面板外壳必须是 position: fixed(否则会落在文档流里、位置错乱)').toBe(true)
|
||
expect(mount.z, '面板 z-index 必须高于应用层(否则点不动)').toBeGreaterThan(1000)
|
||
expect(mount.insideNode, '面板不得渲染在节点内部(会撑开节点/被 transform 裁切)').toBe(false)
|
||
|
||
// ② 打开面板不得改变节点尺寸
|
||
const nodeBoxAfter = await page.locator('[data-node-id="g1"]').boundingBox()
|
||
expect(Math.round(nodeBoxAfter.width), '节点宽度不应被面板撑开').toBe(Math.round(nodeBoxBefore.width))
|
||
expect(Math.round(nodeBoxAfter.height), '节点高度不应被面板撑开').toBe(Math.round(nodeBoxBefore.height))
|
||
|
||
// ③ 完整落在视口内(空间不足时向上/向下翻转,不得被裁切)
|
||
const vh = page.viewportSize().height
|
||
const box = await panel(page).boundingBox()
|
||
expect(box.y, '面板顶部不得越出视口').toBeGreaterThanOrEqual(0)
|
||
expect(box.y + box.height, '面板底部不得越出视口(不得被裁切)').toBeLessThanOrEqual(vh + 1)
|
||
|
||
// ④ 把视口压到很矮:面板仍须在视口内(高度封顶 + 内部滚动)
|
||
await page.setViewportSize({ width: 1200, height: 420 })
|
||
await page.waitForTimeout(250)
|
||
const box2 = await panel(page).boundingBox()
|
||
expect(box2.y, '矮视口下面板顶部仍在视口内').toBeGreaterThanOrEqual(0)
|
||
expect(box2.y + box2.height, '矮视口下面板底部仍在视口内').toBeLessThanOrEqual(421)
|
||
})
|
||
|
||
test('⑨ 两个浮层互斥:开「图像设置」会自动关掉「模型设置」(反之亦然)', async ({ page }) => {
|
||
// 2026-10-31 用户实测:先开模型设置,再点图像设置,模型设置面板不消失,两个浮层叠在一起。
|
||
await seed(page)
|
||
await openPanel(page)
|
||
await expect(page.locator('.iwb-gen-config'), '模型设置应打开').toHaveCount(1)
|
||
|
||
// 开图像设置 ⇒ 模型设置自动关闭
|
||
await page.locator('.iwb-gen-summary').first().click()
|
||
await expect(page.locator('.iwb-image-settings'), '图像设置应打开').toHaveCount(1)
|
||
await expect(page.locator('.iwb-gen-config'), '模型设置应自动关闭').toHaveCount(0)
|
||
|
||
// 再开模型设置 ⇒ 图像设置自动关闭
|
||
await page.locator('.iwb-pick-genmodel').first().click()
|
||
await expect(page.locator('.iwb-gen-config'), '模型设置应重新打开').toHaveCount(1)
|
||
await expect(page.locator('.iwb-image-settings'), '图像设置应自动关闭').toHaveCount(0)
|
||
})
|