Files
dj/integration-work/browser-test/verify_composed_frame_ui.cjs
2026-11-13 11:46:25 +08:00

48 lines
3.5 KiB
JavaScript

const {chromium}=require('playwright-core');
const assert=require('node:assert/strict');
const path=require('node:path');
(async()=>{
const browser=await chromium.launch({channel:'chrome',headless:true});
const page=await browser.newPage({viewport:{width:1920,height:1200}});
const errors=[],submissions=[];
try {
page.on('pageerror',e=>errors.push(e.message));page.on('dialog',d=>d.accept());
await page.addInitScript(()=>localStorage.setItem('huobao:tours',JSON.stringify(['episode'])));
await page.route('**/api/v1/tasks',async route=>{
if(route.request().method()!=='POST')return route.continue();
submissions.push(route.request().postDataJSON());
await route.fulfill({status:400,contentType:'application/json',body:JSON.stringify({message:'测试拦截:未提交模型'})});
});
await page.goto('http://127.0.0.1:18970/drama/1/episode/1',{waitUntil:'networkidle'});
const close=page.locator('.driver-popover-close-btn');if(await close.isVisible())await close.click();
await page.getByText('视频制作',{exact:true}).first().click();
await page.locator('.video-task-row').filter({has:page.getByText('#23',{exact:true})}).click();
const model=page.locator('.video-inspector-settings .model-select').filter({hasText:'当前镜头模型'});
await model.getByRole('button').click();
await page.locator('.model-select-option-name').filter({hasText:/LTX-2\.3$/}).click();
const panel=page.getByTestId('composed-first-frame');await panel.waitFor();
assert.match(await panel.innerText(),/15 个绑定素材 · 3 轮融合/);
assert.match(await panel.innerText(),/qwen_image_2_1 · GPU1/);
assert.match(await panel.innerText(),/404宿舍.*Girl.*Lamp/s);
assert.equal(await panel.locator('img').evaluate(img=>img.complete && img.naturalWidth>0),true);
const hint=page.getByTestId('shot-reference-limit');assert.match(await hint.innerText(),/全部 15 个绑定素材/);
assert.match(await hint.innerText(),/超过 6 张/);
await panel.scrollIntoViewIfNeeded();await page.screenshot({path:path.join(process.env.COMPOSE_FIXTURE,'composed-frame-ui.png')});
await page.getByRole('button',{name:'重做首帧并生成视频',exact:true}).click();
await page.waitForFunction(()=>!document.querySelector('.video-inspector-action').disabled);
assert.equal(submissions.length,1);assert.equal(submissions[0].regenerate_first_frame,true);
assert.equal(submissions[0].reference_image_urls.length,15);
// Select an untouched shot and prove Wan's actual outgoing request includes all 4 bindings.
await page.locator('.video-task-row').filter({has:page.getByText('#19',{exact:true})}).click();
await model.getByRole('button').click();await page.locator('.model-select-option-name').filter({hasText:/Wan2\.2-I2V$/}).click();
await page.locator('.video-inspector-action').click();
await page.waitForFunction(()=>!document.querySelector('.video-inspector-action').disabled);
assert.equal(submissions.length,2);assert.equal(submissions[1].model,'Wan2.2-I2V');
assert.equal(submissions[1].reference_image_urls.length,4);assert.equal(submissions[1].regenerate_first_frame,false);
assert.match(submissions[1].prompt,/@404宿舍/);assert.doesNotMatch(submissions[1].prompt,/@图片/);
assert.deepEqual(errors,[]);
console.log('PASS UI: full bindings for LTX/Wan, frame preview and provenance, explicit remake, no real model requests');
}catch(e){await page.screenshot({path:path.join(process.env.COMPOSE_FIXTURE,'ui-failure.png')});throw e}
finally{await browser.close()}
})().catch(e=>{console.error(e.stack);process.exit(1)});