78 lines
5.1 KiB
JavaScript
78 lines
5.1 KiB
JavaScript
// 刷新后续跑(用户实测缺陷驱动):
|
||
// 生图进行中刷新页面 → 应出现「上次生成中断」横幅 → 点「▶ 继续生成」应重新发起生成请求(不丢需求)。
|
||
// 根因回归钉子:刷新会取消在途请求 → job 被标记 failed(网络连接中断)→ 启动过滤必须接受
|
||
// failed→recoverable(transitions.failed 含 'recoverable')且状态算 recoverable(非 awaiting-result),
|
||
// 否则 valid 为空 → iwb_web_running 被整体清除 → 需求永久丢失。
|
||
// 运行:npm run build && IWB_E2E_SPECS=tests/iwb-resume-reload.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: 1000 } })
|
||
|
||
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 WS = { workspaces: [{ id: 'ws_p', name: '续跑', nodes: [
|
||
{ id: 'p1', type: 'prompt', x: 420, y: 300, data: { text: '一只猫' } },
|
||
{ id: 'g1', type: 'gen', x: 820, y: 280, data: { provider: 'tuzi', model: 'gpt-image-2', size: '1024x1024', taskVariants: {} } },
|
||
{ id: 'o1', type: 'out', x: 1420, y: 280, data: {} },
|
||
], edges: [{ id: 'e1', from: 'p1', to: 'g1' }, { id: 'e2', from: 'g1', to: 'o1' }], groups: [] }], activeId: 'ws_p', rev: 1 }
|
||
|
||
test('生图中刷新 → 出现续跑横幅 → 点继续生成重新发起请求', async ({ page }) => {
|
||
const errors = []
|
||
page.on('pageerror', (e) => errors.push(String((e && e.message) || e)))
|
||
let reqCount = 0
|
||
await page.route('**/images/generations', async (route) => {
|
||
reqCount++
|
||
if (reqCount === 1) {
|
||
// 首个请求长时间挂起:模拟刷新时仍在生成中(刷新时该请求随页面终止 → job 落为 failed)
|
||
try { await new Promise((r) => setTimeout(r, 20000)); await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [{ url: 'https://example.com/a.png' }] }) }) } catch (e) { /* 页面已刷新,放弃响应 */ }
|
||
return
|
||
}
|
||
try { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [{ url: 'https://example.com/b.png' }] }) }) } catch (e) { /* ignore */ }
|
||
})
|
||
await page.addInitScript((d) => {
|
||
if (localStorage.getItem('iwb_p_init') === '1') return
|
||
localStorage.clear()
|
||
localStorage.setItem('iwb_e2e_initialized', '1')
|
||
localStorage.setItem('iwb_p_init', '1')
|
||
localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws))
|
||
localStorage.setItem('iwb_ws_active', 'ws_p')
|
||
localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg))
|
||
}, { ws: WS, cfg: CFG })
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' })
|
||
await page.waitForTimeout(800)
|
||
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
|
||
await page.waitForTimeout(700)
|
||
|
||
// 发起生成,等首个请求在途(job=running 已持久化)
|
||
await page.locator('[data-node-id="g1"] .iwb-task button:has-text("生成")').first().click()
|
||
await expect.poll(() => reqCount, { timeout: 10000 }).toBe(1)
|
||
|
||
// 生成中刷新
|
||
await page.reload({ waitUntil: 'domcontentloaded' })
|
||
|
||
// ① 续跑横幅必须出现(需求不丢)
|
||
const bar = page.locator('.iwb-resume-bar').filter({ hasText: '上次生成中断' })
|
||
await expect(bar, '刷新后应出现「上次生成中断」续跑横幅').toBeVisible({ timeout: 8000 })
|
||
|
||
// ② 刷新后不得自动重发请求(计费必须由用户手动确认触发):静默期后请求数仍为 1
|
||
expect(reqCount, '刷新后不应自动发起新请求(只提示、不自动重跑)').toBe(1)
|
||
|
||
// ③ 计费警示文案必须可见 + 横幅在视口垂直居中(非底部)
|
||
await expect(bar.locator('.iwb-resume-warning'), '应展示「再次计费」警示').toContainText('再次计费')
|
||
const box = await bar.boundingBox()
|
||
expect(box, '横幅应可见').toBeTruthy()
|
||
expect(Math.abs((box.y + box.height / 2) - 500), '横幅应位于视口垂直居中').toBeLessThan(100)
|
||
|
||
// ③b 视觉层级:不推荐继续(可能重复计费)→ 继续=灰色、取消生成=黑色主色;「忽略」文案已改名
|
||
const continueCls = await bar.locator('button:has-text("继续生成")').getAttribute('class')
|
||
const cancelCls = await bar.locator('button:has-text("取消生成")').getAttribute('class')
|
||
expect(continueCls, '继续生成应为弱化(非主色)按钮').not.toContain('iwb-btn-primary')
|
||
expect(cancelCls, '取消生成应为黑色主色按钮').toContain('iwb-btn-primary')
|
||
expect(await bar.locator('button:has-text("忽略")').count(), '续跑条不应再出现「忽略」').toBe(0)
|
||
|
||
// ④ 点「继续生成」应重新发起请求(不丢生图需求)
|
||
await bar.locator('button:has-text("继续生成")').click()
|
||
await expect.poll(() => reqCount, { timeout: 12000 }).toBe(2)
|
||
|
||
expect(errors).toEqual([])
|
||
})
|