102 lines
5.7 KiB
JavaScript
102 lines
5.7 KiB
JavaScript
// 提示词 / 文本节点的「上游继承文本」(用户报障驱动,2026-11-14)。
|
|
//
|
|
// 用户看到的现象:样式节点连到这两个节点后框里是空的,判断「接收文本 / 二次编辑没做」。
|
|
// 实际上数据层一直通(生成时用上游文本),缺的是**节点体不回显**,且一打字就是整段替换。
|
|
// 这条 spec 钉的是 DOM 行为(纯函数侧见 tests/inherit-text-test.js):
|
|
// ① 自己没写字 ⇒ 框里直接显示上游文本,状态条「继承 · 来自 X」;
|
|
// ② 改一个字 ⇒ 接管,状态条变「已固定」并出现「恢复跟随」;
|
|
// ③ 点「恢复跟随」⇒ 回到跟随上游;
|
|
// ④ 未接管时上游改动会跟着变(这是「能接收」的实际含义)。
|
|
//
|
|
// 不带插件:用内置「提示词 → 中继 → 提示词」「提示词 → 文本」两条链,等价于样式节点那条路
|
|
//(宿主只看 data.outKind / 节点产出文本,不区分是不是插件)。
|
|
// 运行:npm run build && IWB_E2E_SPECS=tests/iwb-inherit-text.spec.js npm run test:e2e
|
|
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: 900 } })
|
|
|
|
const CFG = { providers: [{ id: 'tuzi', name: '探针', baseUrl: 'https://probe.test/v1', fallbacks: [], genPath: '/images/generations', editPath: '/images/edits', keys: [{ id: 'k1', name: 'k', source: 'literal', value: 'sk-test' }], models: [{ name: 'gpt-image-2', visible: true, default: true }], defaultModel: 'gpt-image-2' }] }
|
|
const SRC_TEXT = '一只戴墨镜的柴犬,胶片颗粒,冷调高对比'
|
|
const WS = {
|
|
workspaces: [{
|
|
id: 'ws_i', name: '继承文本', groups: [],
|
|
nodes: [
|
|
{ id: 'p1', type: 'prompt', x: 140, y: 160, w: 300, h: 200, data: { text: SRC_TEXT } },
|
|
{ id: 'r1', type: 'relay', x: 520, y: 210, data: {} },
|
|
{ id: 'p2', type: 'prompt', x: 700, y: 160, w: 300, h: 200, data: {} },
|
|
{ id: 'p3', type: 'prompt', x: 140, y: 470, w: 300, h: 200, data: { text: '原本文案:夏日海边短片脚本' } },
|
|
{ id: 't1', type: 'textout', x: 700, y: 470, w: 300, h: 200, data: {} },
|
|
],
|
|
edges: [
|
|
{ id: 'e1', from: 'p1', to: 'r1' },
|
|
{ id: 'e2', from: 'r1', to: 'p2' },
|
|
{ id: 'e3', from: 'p3', to: 't1' },
|
|
],
|
|
}],
|
|
activeId: 'ws_i', rev: 1,
|
|
}
|
|
|
|
const box = (page, id) => page.locator('[data-node-id="' + id + '"]')
|
|
|
|
// 往受控 textarea 里输入(React 只认原生 setter + input 事件;直接改 value 会被吞)
|
|
async function typeInto(page, id, text) {
|
|
await page.evaluate(async (args) => {
|
|
const el = document.querySelector('[data-node-id="' + args.id + '"] textarea')
|
|
el.focus()
|
|
await new Promise((r) => setTimeout(r, 60))
|
|
const setter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value').set
|
|
setter.call(el, args.text)
|
|
el.dispatchEvent(new Event('input', { bubbles: true }))
|
|
el.blur()
|
|
}, { id, text })
|
|
}
|
|
|
|
test('提示词与文本节点显示上游继承文本,改字即接管、可恢复跟随', async ({ page }) => {
|
|
const errors = []
|
|
page.on('pageerror', (e) => errors.push(String((e && e.message) || e)))
|
|
await page.addInitScript((d) => {
|
|
if (localStorage.getItem('iwb_inherit_init') === '1') return
|
|
localStorage.clear()
|
|
localStorage.setItem('iwb_inherit_init', '1')
|
|
localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws))
|
|
localStorage.setItem('iwb_ws_active', 'ws_i')
|
|
localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg))
|
|
}, { ws: WS, cfg: CFG })
|
|
|
|
await page.goto('/', { waitUntil: 'domcontentloaded' })
|
|
await page.waitForTimeout(700)
|
|
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
|
|
await page.waitForTimeout(900)
|
|
|
|
// ① 提示词节点(经中继):显示上游文本 + 继承状态条
|
|
await expect(box(page, 'p2').locator('textarea'), '提示词节点应显示上游文本,而不是空框').toHaveValue(SRC_TEXT)
|
|
await expect(box(page, 'p2').locator('.iwb-inherit-tag'), '状态条应标「继承」').toHaveText('继承')
|
|
await expect(box(page, 'p2').locator('textarea')).toHaveClass(/is-inherited/)
|
|
|
|
// ② 文本节点:同样显示
|
|
await expect(box(page, 't1').locator('textarea')).toHaveValue('原本文案:夏日海边短片脚本')
|
|
await expect(box(page, 't1').locator('.iwb-inherit-tag')).toHaveText('继承')
|
|
|
|
// ③ 未接管时跟随上游:改上游,文本节点跟着变
|
|
await typeInto(page, 'p3', '上游改过的文案')
|
|
await expect(box(page, 't1').locator('textarea'), '未接管时应实时跟随上游').toHaveValue('上游改过的文案')
|
|
|
|
// ④ 在文本节点上改一个字 ⇒ 接管
|
|
await typeInto(page, 't1', '上游改过的文案(我加了夜景)')
|
|
await expect(box(page, 't1').locator('textarea')).toHaveValue('上游改过的文案(我加了夜景)')
|
|
await expect(box(page, 't1').locator('.iwb-inherit-tag'), '接管后状态条应变「已固定」').toHaveText('已固定')
|
|
await expect(box(page, 't1').locator('textarea')).not.toHaveClass(/is-inherited/)
|
|
|
|
// ⑤ 接管后再改上游,不再覆盖自己的版本
|
|
await typeInto(page, 'p3', '上游又改了一次')
|
|
await expect(box(page, 't1').locator('textarea'), '已接管的节点不该被上游覆盖').toHaveValue('上游改过的文案(我加了夜景)')
|
|
|
|
// ⑥ 恢复跟随:清空自己的文案,回到上游
|
|
await box(page, 't1').locator('.iwb-inherit-reset').click()
|
|
await expect(box(page, 't1').locator('textarea')).toHaveValue('上游又改了一次')
|
|
await expect(box(page, 't1').locator('.iwb-inherit-tag')).toHaveText('继承')
|
|
await expect(box(page, 't1').locator('.iwb-inherit-reset')).toHaveCount(0)
|
|
|
|
expect(errors, '全程不应有页面 JS 异常').toEqual([])
|
|
})
|