Files

41 lines
2.8 KiB
JavaScript

const {chromium}=require('playwright-core'),assert=require('node:assert/strict');
(async()=>{
const browser=await chromium.launch({channel:'chrome',headless:true});
try {
const page=await browser.newPage({viewport:{width:1600,height:1100}}),errors=[],writes=[];
let selected=null,english='',status='missing';
page.on('pageerror',e=>errors.push(e.message));
await page.addInitScript(()=>localStorage.setItem('huobao:tours',JSON.stringify(['episode'])));
await page.route('**/api/**',async route=>{
const req=route.request(),url=req.url(),method=req.method();
if(method==='GET'&&/\/episodes\/\d+\/storyboards$/.test(url)){
const response=await route.fetch(),body=await response.json();selected=body.data[0];
Object.assign(selected,{video_prompt_en:english,video_prompt_en_status:status});
return route.fulfill({response,json:body});
}
if(method==='POST'&&url.endsWith('/english-prompt')){
writes.push('translate');english='0-3s: Heavy rain falls on an old dormitory.\n3-9s: Slowly push in toward the dim window. No dialogue or subtitles.';status='ready';
return route.fulfill({status:200,json:{code:200,data:{...selected,video_prompt_en:english,video_prompt_en_status:status}}});
}
if(method==='PUT'&&/\/storyboards\/\d+$/.test(url)){
const body=req.postDataJSON();assert.ok(body.video_prompt_en);assert.equal(body.source_prompt,selected.video_prompt);
english=body.video_prompt_en;writes.push('save-english');return route.fulfill({status:200,json:{code:200,data:{}}});
}
if(!['GET','HEAD'].includes(method))throw Error('Unexpected mutation: '+method+' '+url);
return route.continue();
});
await page.goto('http://127.0.0.1:18938/drama/6/episode/1',{waitUntil:'networkidle'});
await page.getByText('视频制作',{exact:true}).first().click();
const panel=page.locator('.english-video-prompt');await panel.waitFor();await panel.scrollIntoViewIfNeeded();
assert.match(await panel.innerText(),/待生成/);
await panel.getByRole('button',{name:'生成 / 更新英文'}).click();
await panel.locator('.english-state.ready').waitFor();
const input=panel.getByRole('textbox',{name:'英文视频提示词'});assert.match(await input.inputValue(),/Heavy rain/);
await input.fill(english+' Keep the same framing.');await panel.locator('strong').click();
await page.waitForFunction(()=>document.querySelector('.english-actions [role="status"]')?.textContent==='英文修改已保存');
assert.deepEqual(writes,['translate','save-english']);assert.deepEqual(errors,[]);
await panel.scrollIntoViewIfNeeded();await page.screenshot({path:'D:/web/dj/integration-work/english-ui-fixture.png'});
console.log('PASS: English panel, generate/save, Chinese source guard, no real API mutations');
}finally{await browser.close()}
})().catch(e=>{console.error(e.stack);process.exit(1)});