test(style-source): e2e-real 跟上 v1.3.0(按钮改文案定位、总数不写死 310、补样式节点断言)

This commit is contained in:
qiqi committed 2026-11-14 08:38:02 +08:00
1 parent 20118eec0b
commit b136217e2f
1 file changed
+28 -3
+28 -3
View File
@@ -64,7 +64,7 @@ async function main() {
await page.goto(`http://127.0.0.1:${port}/`)
await page.evaluate(() => {
window.__calls = { panels: [], images: [], nodes: [] }
window.__calls = { panels: [], images: [], nodes: [], variants: [] }
window.__nodes = [{ id: 'n1', type: 'prompt', x: 100, y: 100, data: { text: 'x' } }]
window.__sel = { id: 'n1', type: 'prompt', name: 'x' }
window.IWBPluginHost = { register(m, s) { window.__m = m; window.__s = s } }
@@ -77,6 +77,8 @@ async function main() {
settings: { get: (k) => (window.__m.settings[k] || {}).default },
storage: null,
ui: { registerPanel: (p) => window.__calls.panels.push(p) },
// v1.3.0:样式节点变体(宿主能力名 nodeTypes → ctx.nodes)
nodes: { register: (v) => { window.__calls.variants.push(v); return true } },
canvas: {
getNodes: () => window.__nodes,
getSelectedNode: () => window.__sel,
@@ -99,7 +101,8 @@ async function main() {
check('真实网络拉到数据并渲染卡片', Boolean(gotData), 'cards=' + gotData)
const status = await page.locator('#h .iwb-ss-status').innerText().catch(() => '')
check('总数显示 310', /310/.test(status), status.replace(/\n/g, ' '))
// 数量随上游数据增长会变(310 → 367);这里只要求「显示的是三位数总量」
check('总数显示三位数风格条数', /\b[1-9]\d{2}\b/.test(status), status.replace(/\n/g, ' '))
// 真实缩略图必须真的解码出来
const decoded = await poll(async () => {
@@ -114,12 +117,34 @@ async function main() {
// 真实 webp → dataURL
await page.locator('#h .iwb-ss-card').first().click()
await page.waitForTimeout(300)
await page.locator('#h .iwb-ss-dfoot .iwb-ss-btn').first().click()
await page.locator('#h .iwb-ss-dfoot .iwb-ss-btn').filter({ hasText: '插入参考图' }).click()
const img = await poll(() => page.evaluate(() => window.__calls.images[0] || null), 30000)
check('真实图插入画布(createImageNode 被调用)', Boolean(img))
check('dataURL 是真实内容而非空图', Boolean(img) && String(img.dataUrl).length > 5000,
img ? 'len=' + String(img.dataUrl).length + ' head=' + String(img.dataUrl).slice(0, 22) : '')
// v1.3.0:样式节点(真实数据 + 真实模板)
const styleCall = await page.evaluate(async () => {
const v = window.__calls.variants[0]
const btn = [...document.querySelectorAll('#h .iwb-ss-dfoot .iwb-ss-btn')].find((b) => b.textContent === '样式节点')
if (!btn) return { noBtn: true }
window.__calls.nodes.length = 0
btn.click()
await new Promise((r) => setTimeout(r, 60))
return { hasRender: typeof v.render === 'function', ports: v.ports, call: window.__calls.nodes[0] || null }
})
check('详情页有「样式节点」按钮,且变体已注册(render + 只出不入)',
!styleCall.noBtn && styleCall.hasRender === true && styleCall.ports.in === false && styleCall.ports.out === true,
JSON.stringify({ noBtn: styleCall.noBtn, hasRender: styleCall.hasRender, ports: styleCall.ports }))
check('样式节点落的是 plugin:style-source:style,数据带 outKind/promptTpl/varMeta',
Boolean(styleCall.call) && styleCall.call.t === 'plugin:style-source:style' &&
styleCall.call.d.outKind === 'prompt' && typeof styleCall.call.d.promptTpl === 'string' &&
Array.isArray(styleCall.call.d.varMeta),
styleCall.call ? 't=' + styleCall.call.t + ' varMeta=' + (styleCall.call.d.varMeta || []).length : '未调用')
check('未填变量时 text 原样保留 {占位符}(不是被替换成空串)',
Boolean(styleCall.call) && (styleCall.call.d.varMeta.length === 0 || /\{[^{}\n]{1,40}\}/.test(String(styleCall.call.d.text))),
styleCall.call ? 'text=' + String(styleCall.call.d.text).slice(0, 48) : '未调用')
check('无 GitHub 资源请求失败', netFail.length === 0, netFail.slice(0, 2).join(' | '))
check('无页面 JS 异常', errors.length === 0, errors.slice(0, 2).join(' | '))