11 lines
3.8 KiB
JavaScript
11 lines
3.8 KiB
JavaScript
const{chromium}=require('playwright'),fs=require('node:fs'),assert=require('node:assert/strict');
|
|
const base=process.env.SOLVER_BASE_URL||'http://127.0.0.1:5238';assert(['127.0.0.1:5238','dev.plotdirector.com'].includes(new URL(base).host));
|
|
const graph=JSON.parse(fs.readFileSync('PlotLine/Content/WritingSolver/Candidates/curated-v2-stage1-repair/writing-solver-curated-v2-stage1-repair.json'));
|
|
const catalog=JSON.parse(fs.readFileSync('PlotLine/Content/WritingSolver/Presentation/results-v1.json'));
|
|
(async()=>{const b=await chromium.launch();try{const representatives=[];for(const cap of catalog.capabilities){if(representatives.some(c=>c.captureView===cap.captureView))continue;representatives.push(cap);}assert.equal(representatives.length,11);
|
|
for(const width of [390,768,1440,1920]){const c=await b.newContext({viewport:{width,height:1100}});const p=await c.newPage();for(const cap of representatives){const result=catalog.results.find(r=>r.capability===cap.id);const solution=graph.solutions.find(s=>s.id===result.solution);const images=[];p.on('requestfinished',r=>{if(r.url().includes('/images/writing-solver/'))images.push(r.url());});await p.goto(base+'/problem-solver/'+solution.slug);const img=p.locator('.solver-start .solver-tool-visual img');await img.scrollIntoViewIfNeeded();await img.evaluate(e=>e.decode());assert(await img.evaluate(e=>e.complete&&e.naturalWidth>0));assert.equal(await img.getAttribute('alt'),cap.imageAlt);assert.equal(await p.locator('.solver-visual-placeholder').count(),0);assert.equal(await p.locator('.solver-start .solver-tool-visual picture').count(),1);assert.equal(await p.locator('.solver-start .solver-tool-visual img').count(),1);assert(!(await p.locator('main').innerText()).includes('Development preview'));assert.equal(await p.locator('.solver-space').evaluate(e=>e.getBoundingClientRect().width),width);assert.equal(await p.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);assert.equal(new URL(p.url()).search,'');assert(images.length>=1&&images.length<=2&&new Set(images).size===images.length,'Only one variant per primary/secondary demonstration should download');assert.equal(await p.locator('.solver-start .solver-image-link').getAttribute('target'),null);assert.equal(await p.locator('.solver-start .solver-image-link').getAttribute('aria-haspopup'),'dialog');assert((await p.locator('.solver-content').boundingBox()).width<=1140);p.removeAllListeners('requestfinished');}await c.close();}
|
|
const c=await b.newContext();const p=await c.newPage();for(const solution of graph.solutions){await p.goto(base+'/problem-solver/'+solution.slug);const img=p.locator('.solver-start .solver-tool-visual img');await img.scrollIntoViewIfNeeded();await img.evaluate(e=>e.decode());assert.equal(await img.count(),1);assert(await img.evaluate(e=>e.naturalWidth>0));assert.equal(await p.locator('.solver-visual-placeholder').count(),0);}
|
|
// Test the normal browser fallback when AVIF is unsupported, without changing the application.
|
|
await p.route('**/problem-solver/*',async route=>{const response=await route.fetch();await route.fulfill({response,body:(await response.text()).replace('type="image/avif"','type="image/unsupported"')});});await p.goto(base+'/problem-solver/'+graph.solutions[0].slug);await p.locator('.solver-start .solver-tool-visual img').scrollIntoViewIfNeeded();await p.locator('.solver-start .solver-tool-visual img').evaluate(e=>e.decode());assert((await p.locator('.solver-start .solver-tool-visual img').evaluate(e=>e.currentSrc)).endsWith('.webp'));
|
|
console.log('PASS all 52 real screenshot mappings; 11 view families at 390/768/1440/1920; one responsive variant per primary/secondary demonstration, AVIF/WebP fallback, alt, stable dimensions, clean URLs, full-width canvas, readable column and no overflow.');await c.close();}finally{await b.close();}})().catch(e=>{console.error(e);process.exit(1)});
|