52 lines
4.6 KiB
JavaScript
52 lines
4.6 KiB
JavaScript
const {chromium}=require('playwright');
|
|
const assert=require('node:assert/strict');
|
|
const 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 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 indexed=process.env.PD_SOLVER_TEST_INDEXING==='true';
|
|
(async()=>{const browser=await chromium.launch();try{
|
|
for(const width of [1440,390])for(const javaScriptEnabled of [true,false]){
|
|
const context=await browser.newContext({viewport:{width,height:1000},javaScriptEnabled});
|
|
await context.addCookies([{name:'solver-anonymous',value:'true',url:base}]);
|
|
const page=await context.newPage();
|
|
async function choose(choice){await page.locator(`input[name=choices][value="${choice}"]`).check();await page.locator('.solver-form button[type=submit]').click();}
|
|
await page.goto(base+'/problem-solver');
|
|
for(const c of ['story-not-working','too-many','lost'])await choose(c);
|
|
assert.equal(await page.locator('meta[name=robots]').getAttribute('content'),'noindex, follow');
|
|
await choose('unwanted');
|
|
const slug=graph.solutions.find(s=>s.id==='d01').slug;
|
|
assert.equal(page.url(),base+'/problem-solver/'+slug);
|
|
assert((await page.locator('.solver-result-evidence li').count())>0);
|
|
const personal=await page.locator('.solver-result-evidence').innerText();
|
|
await page.reload();assert.equal(await page.locator('.solver-result-evidence').innerText(),personal);
|
|
const fresh=await browser.newContext();const direct=await fresh.newPage();await direct.goto(page.url());
|
|
assert.equal(await direct.locator('.solver-result-panel').count(),1);
|
|
assert.equal(await direct.locator('.solver-result-evidence').count(),0);assert.equal(await direct.locator('.solver-permanent-copy').count(),1);
|
|
assert.equal(await direct.locator('nav[aria-label="Areas discussed"]').count(),0);
|
|
assert.equal(await direct.locator('.solver-result-cta').count(),1);
|
|
await fresh.close();
|
|
await page.goBack();assert.equal(await page.locator('input[name=node]').inputValue(),'intent-threads');
|
|
await page.goForward();assert.equal(page.url(),base+'/problem-solver/'+slug);
|
|
// Explicit Back preserves the prior accepted answers independently of browser caching.
|
|
await page.getByRole('link',{name:'← Back',exact:true}).click();
|
|
await page.getByRole('link',{name:'← Back',exact:true}).click();
|
|
await page.getByRole('link',{name:'← Back',exact:true}).click();
|
|
await choose('dont-connect');await choose('gap');await choose('unwanted');
|
|
assert.equal(page.url(),base+'/problem-solver/'+graph.solutions.find(s=>s.id==='d02').slug);
|
|
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);
|
|
const canonical=await page.locator('link[rel=canonical]').getAttribute('href');
|
|
assert.equal(new URL(canonical).pathname,new URL(page.url()).pathname);assert(!canonical.includes('?'));
|
|
assert.equal(await page.locator('meta[property="og:url"]').getAttribute('content'),canonical);
|
|
assert((await page.locator('script[type="application/ld+json"]').allTextContents()).join('').includes(canonical));
|
|
assert.equal(await page.locator('meta[name=robots]').getAttribute('content'),indexed?'index, follow':'noindex, follow');
|
|
await context.close();
|
|
}
|
|
const context=await browser.newContext();const page=await context.newPage();
|
|
for(const solution of graph.solutions){const response=await page.goto(base+'/problem-solver/'+solution.slug);assert.equal(response.status(),200);assert.equal(await page.locator('h1').innerText(),solution.title);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.equal(new URL(await page.locator('link[rel=canonical]').getAttribute('href')).pathname,'/problem-solver/'+solution.slug);assert((await page.locator('meta[name=description]').getAttribute('content')).length>10);assert(await page.locator('a[href^=\"/features/\"]').count()>0);}
|
|
const sitemap=await (await context.request.get(base+'/sitemap.xml')).text();assert(!sitemap.includes('state='));
|
|
if(indexed)for(const solution of graph.solutions)assert(sitemap.includes('/problem-solver/'+solution.slug));
|
|
console.log('PASS clean URLs: 52 direct pages; private evidence/refresh/fresh sharing; Back/Forward; revised diagnosis; 390/1440; JS/no-JS; canonical/OG/structured data; robots; sitemap'+(indexed?' all 52 indexable':' Development noindex'));
|
|
await context.close();
|
|
}finally{await browser.close();}})().catch(e=>{console.error(e);process.exit(1)});
|