PlotDirector/PlotLine.Tests/Browser/writing-problem-editorial.cjs

13 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs');
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/Editorial/pages-v1.json'));
const base=process.env.SOLVER_BASE_URL||'http://127.0.0.1:5238', indexed=process.env.PD_SOLVER_TEST_INDEXING==='true';
(async()=>{const browser=await chromium.launch();try{const context=await browser.newContext();await context.addCookies([{name:'solver-anonymous',value:'true',url:base}]);const page=await context.newPage();
const discovered=new Set();await page.goto(base+'/writing-problems');assert(await page.locator('a[href="/writing-problems/browse"]').count()>0);await page.goto(base+'/writing-problems/browse');
const areas=await page.locator('.solver-browse-areas a').evaluateAll(es=>es.map(e=>e.getAttribute('href')));assert.equal(areas.length,9);
for(const area of areas){await page.goto(base+area);for(const link of await page.locator('.solver-problem-links a').evaluateAll(es=>es.map(e=>e.getAttribute('href'))))discovered.add(link);}
assert.equal(discovered.size,52);
for(const solution of graph.solutions){const article=catalog.pages.find(p=>p.solution===solution.id),path='/writing-problems/'+solution.slug;assert(discovered.has(path));assert.equal((await page.goto(base+path)).status(),200);assert.equal(await page.locator('h1').innerText(),solution.title);assert((await page.title()).includes(article.title));assert.equal(await page.locator('meta[name=description]').getAttribute('content'),article.description);assert((await page.locator('meta[property="og:title"]').getAttribute('content')).includes(article.title));assert.equal(await page.locator('meta[property="og:description"]').getAttribute('content'),article.description);const canonical=await page.locator('link[rel=canonical]').getAttribute('href');assert.equal(canonical,'https://plotdirector.com'+path);assert.equal(await page.locator('meta[property="og:url"]').getAttribute('content'),canonical);const schema=(await page.locator('script[type="application/ld+json"]').allTextContents()).join('');assert(schema.includes(canonical));assert(!schema.includes('FAQPage'));assert.equal(await page.locator('.solver-result-evidence').count(),0);assert.equal(await page.locator('.solver-permanent-copy').count(),1);assert.equal(await page.locator('.solver-permanent-copy li').count(),3);assert.equal(await page.locator('.solver-related li').count(),article.related.length);assert.equal(await page.locator('.solver-result-cta').count(),1);assert.equal(await page.locator('meta[name=robots]').getAttribute('content'),indexed?'index, follow':'noindex, follow');assert(!(await page.locator('body').innerText()).includes('DEVELOPMENT PREVIEW'));}
for(const width of [390,768,1440,1920]){await page.setViewportSize({width,height:1000});for(const id of ['d01','d16','d21','d28','d30','d34','d43','d49','d50']){const s=graph.solutions.find(s=>s.id===id);await page.goto(base+'/writing-problems/'+s.slug);assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);const canvas=await page.locator('.solver-space').boundingBox();assert(canvas.width>=width-2);const copy=await page.locator('.solver-permanent-copy').boundingBox();assert(copy.width<=898);await page.locator('.solver-start').scrollIntoViewIfNeeded();await page.waitForTimeout(100);const img=page.locator('.solver-result-visual img');if(await img.count())assert(await img.evaluate(e=>e.complete&&e.naturalWidth>0));if(id==='d01'&&process.env.EDITORIAL_CAPTURE_DIR){fs.mkdirSync(process.env.EDITORIAL_CAPTURE_DIR,{recursive:true});await page.screenshot({path:process.env.EDITORIAL_CAPTURE_DIR+'/after-'+width+'.png',fullPage:true});}}}
await context.close();const nojs=await browser.newContext({javaScriptEnabled:false,viewport:{width:390,height:1000}});const np=await nojs.newPage();await np.goto(base+'/writing-problems/'+graph.solutions[0].slug);assert.equal(await np.locator('.solver-permanent-copy').count(),1);assert.equal(await np.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);await nojs.close();console.log('PASS editorial: all 52 metadata/content/direct-entry pages; nine crawlable groups reach all 52; nine families × four widths; no overflow; no-JS; preserved previews.');}finally{await browser.close();}})().catch(e=>{console.error(e);process.exit(1)});