18 lines
4.4 KiB
JavaScript
18 lines
4.4 KiB
JavaScript
// Shared feedback on the real fixed project footer, using only disposable state.
|
|
const {chromium}=require(process.env.PLAYWRIGHT_MODULE_PATH||'playwright');
|
|
const fs=require('node:fs'),http=require('node:http'),assert=require('node:assert/strict');
|
|
(async()=>{const out='../evidence/hel806-toast';fs.mkdirSync(out,{recursive:true});const api=async(p,b,method)=>{const r=await fetch('http://127.0.0.1:8247'+p,{method:method||(b?'POST':'GET'),headers:{'Content-Type':'application/json'},body:b?JSON.stringify(b):undefined});assert(r.ok,await r.clone().text());return r.json()};
|
|
const settings=await api('/api/settings');assert(settings.data_dir.includes('e2e/shots/reference'));
|
|
const project=await api('/api/projects',{title:'HEL806 Toast clearance'});await api(`/api/workbench/projects/${project.id}/stages/storyboard`,{content:{shots:[{id:'s1',scene:'1',shot_size:'远景',description:'隔离的海岸镜头,纸船驶向灯塔。',duration_sec:5}]}},'PATCH');
|
|
const server=http.createServer((req,res)=>{res.setHeader('Content-Type','text/html;charset=utf-8');res.end(fs.readFileSync('../materials/夜片场-多主题交互样本.html'))});await new Promise(r=>server.listen(0,'127.0.0.1',r));const browser=await chromium.launch({args:['--no-sandbox']});const rows=[],errors=[];
|
|
try{const c=await browser.newContext();await c.addInitScript(()=>{localStorage.setItem('aigc-lang','zh');localStorage.setItem('aigc-reduce-motion','0')});const p=await c.newPage(),s=await c.newPage();p.on('pageerror',e=>errors.push(e.message));await p.goto('http://127.0.0.1:5173/workbench/'+project.id+'?stage=storyboard');await p.getByRole('button',{name:'编辑',exact:true}).click();await p.locator('.shot-edit textarea').first().fill('HEL806 Toast 验证:在隔离海岸镜头加入新的纸船描述');await p.locator('[data-testid=stage-save-btn]').click();await p.locator('.toast').last().hover();await p.mouse.move(0,0);await p.locator('.toast .dismiss').last().focus();
|
|
const message=await p.locator('.toast .msg').last().innerText();
|
|
const style=loc=>loc.evaluate(e=>{const r=e.getBoundingClientRect(),s=getComputedStyle(e);return {x:r.x,y:r.y,width:r.width,height:r.height,...Object.fromEntries(['padding','borderRadius','backgroundColor','borderTopColor','boxShadow','fontSize','lineHeight','animationDuration','animationTimingFunction','transitionDuration'].map(k=>[k,s[k]]))}});
|
|
for(const [width,height]of [[1440,900],[1366,768],[1280,720]])for(const theme of ['night','day','grade','bluehour']){
|
|
await p.setViewportSize({width,height});await s.setViewportSize({width,height});await p.evaluate(t=>document.documentElement.dataset.theme=t,theme);await s.goto('http://127.0.0.1:'+server.address().port);await s.evaluate(({theme,message})=>{go('project');document.documentElement.dataset.theme=theme;toast(message)}, {theme,message});await p.waitForTimeout(350);
|
|
const actual=await style(p.locator('.toast').last()),reference=await style(s.locator('.toast').last()),footer=await p.locator('.project-footer').boundingBox();assert(actual.y+actual.height<=footer.y,'toast clears fixed actions');assert.equal(actual.animationDuration,reference.animationDuration);assert.equal(actual.animationTimingFunction,reference.animationTimingFunction);
|
|
await p.screenshot({path:`${out}/project-${theme}-${width}.png`});await p.locator('.toast').last().screenshot({path:`${out}/toast-${theme}-${width}-actual.png`});await s.locator('.toast').last().screenshot({path:`${out}/toast-${theme}-${width}-reference.png`});
|
|
await p.evaluate(()=>document.documentElement.dataset.reduce='1');assert.equal(await p.locator('.toast').last().evaluate(e=>getComputedStyle(e).animationName),'none');await p.evaluate(()=>document.documentElement.dataset.reduce='0');rows.push({theme,width,height,message,actual,reference,footer,gap:footer.y-actual.y-actual.height});}
|
|
await p.locator('.toast .dismiss').last().evaluate(e=>e.blur());await p.mouse.move(0,0);await p.locator('.toast').last().waitFor({state:'detached',timeout:5000});await p.locator('[data-testid=stage-confirm-btn]').click();assert.equal((await api(`/api/workbench/projects/${project.id}`)).stages.find(x=>x.stage_key==='storyboard').status,'confirmed');assert.equal(errors.length,0);console.log('PASS 12 toast style/timing pairs, reduce, footer clearance and real confirmation');
|
|
}finally{fs.writeFileSync(out+'/results.json',JSON.stringify({rows,errors},null,2));await browser.close();await new Promise(r=>server.close(r))}})().catch(e=>{console.error(e);process.exitCode=1});
|