PlotDirector/PlotLine.Tests/Browser/writing-solver-results.cjs

56 lines
6.5 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');
const assert=require('node:assert/strict');
const fs=require('node:fs');
const graph=JSON.parse(fs.readFileSync('PlotLine/Content/WritingSolver/Candidates/curated-v2-stage1/writing-solver-curated-v2-stage1.json'));
const cases=JSON.parse(fs.readFileSync('PlotLine/Content/WritingSolver/Candidates/curated-v2-stage1/acceptance-paths.json')).cases;
const catalog=JSON.parse(fs.readFileSync('PlotLine/Content/WritingSolver/Presentation/results-v1.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));
(async()=>{
const browser=await chromium.launch();
async function journey(page,id){await page.goto(base+'/problem-solver');assert.equal(await page.locator('.solver-library').count(),0);for(const answer of cases.find(c=>c.id===id).answers){assert.equal(await page.locator('input[name=node]').inputValue(),answer.node);assert.equal(await page.locator('.solver-library').count(),0);for(const choice of answer.choices)await page.locator(`input[name=choices][value="${choice}"]`).check();await page.locator('.solver-form button[type=submit]').click();}}
try {
for(const width of [390,1440])for(const javaScriptEnabled of [true,false]){
const context=await browser.newContext({javaScriptEnabled,viewport:{width,height:1100}});
await context.addCookies([{name:'solver-anonymous',value:'true',url:base}]);
const page=await context.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message));
for(const id of [3,25,15,30,47,22,43]){
await journey(page,id);const test=cases.find(c=>c.id===id);const content=catalog.results.find(r=>r.solution===test.expectedPrimary);const tool=catalog.capabilities.find(c=>c.id===content.capability);
assert.equal(await page.locator('.solver-result-panel h1').innerText(),graph.solutions.find(s=>s.id===test.expectedPrimary).title);
assert((await page.locator('.solver-result-evidence').innerText()).length>50);
assert(!/\bd\d{2}\b|observed-|concern-confirmed|threshold|\bscores?\b/i.test(await page.locator('.solver-result-panel').innerText()));
assert.equal(await page.locator('.solver-result-panel .solver-result-cta').count(),1);
assert.equal(await page.locator('.solver-result-cta').getAttribute('href'),tool.tour);
assert((await page.locator('.solver-result-cta').innerText()).startsWith('See how'));
assert.equal(await page.locator('.solver-visual-placeholder').count(),0);assert.equal(await page.locator('.solver-tool-visual img').count(),1);assert(await page.locator('.solver-tool-visual img').evaluate(e=>e.complete&&e.naturalWidth>0));
assert.equal(await page.locator('.solver-also').count(),content.secondary?1:0);
assert.equal(await page.locator('.solver-deeper a').count(),content.articleKey?1:0);
if(content.articleKey){const article=await page.locator('.solver-deeper a').getAttribute('href');assert.equal((await context.request.get(base+article)).status(),200);}
assert.equal(await page.locator('.solver-library').count(),0);assert(!(await page.locator('main').innerText()).includes('A little help, whenever you need it'));
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false,`overflow ${id}/${width}`);
assert.equal(await page.locator('meta[name=robots]').getAttribute('content'),'noindex, follow');
assert.equal(await page.locator('html').getAttribute('data-site-theme'),'public');assert.equal(await page.locator('html').getAttribute('data-app-theme'),null);
if(id===3&&width===1440&&javaScriptEnabled&&base.includes('127.0.0.1'))await page.screenshot({path:'/tmp/solver-results-layout.png'});
await page.goBack();assert.equal(await page.locator('input[name=node]').inputValue(),test.answers.at(-1).node);
await page.goForward();assert.equal(await page.locator('.solver-result-panel').count(),1);
await page.getByRole('link',{name:'Start again',exact:true}).click();assert.equal(await page.locator('input[name=node]').inputValue(),'entry');
}
await page.goto(base+'/problem-solver');for(const [node,choice]of[['entry','unsure'],['rescue-happening','reread-cant-see'],['rescue-confidence','using-tool-concern'],['existing-stage','draft-done'],['existing-barrier','discovery']]){assert.equal(await page.locator('input[name=node]').inputValue(),node);await page.locator(`input[value="${choice}"]`).check();await page.locator('.solver-form button[type=submit]').click();}
assert.equal(await page.locator('.solver-neutral').count(),1);assert.equal(await page.locator('.solver-start,.solver-library,.solver-result-panel').count(),0);
await journey(page,50);assert.equal(await page.locator('.solver-result-panel,.solver-resolution,.solver-library').count(),0);assert((await page.locator('main').innerText()).includes('isn’t enough evidence'));
assert.equal(errors.length,0,errors.join('\n'));await context.close();
}
if(base.includes('127.0.0.1')){
const context=await browser.newContext({viewport:{width:1440,height:1000}});const page=await context.newPage();
await journey(page,3);assert.match(await page.locator('.solver-result-cta').innerText(),/^Open .* in my workspace/);
await page.locator('.solver-result-cta').click();assert.equal(await page.locator('select[name=projectId]').count(),1);
const response=await context.request.get(base+'/problem-solver/workspace/plot?projectId=77',{maxRedirects:0});assert.equal(response.status(),302);assert.equal(response.headers().location,'/PlotLineWorkspace?projectId=77');
await page.goto(base+'/problem-solver/workspace/knowledge?projectId=77');assert.equal(await page.locator('select[name=characterId]').count(),1);
const character=await context.request.get(base+'/problem-solver/workspace/knowledge?projectId=77&characterId=88',{maxRedirects:0});assert.equal(character.status(),302);assert.equal(character.headers().location,'/Dynamics/Knowledge/88?projectId=77');
assert.equal((await context.request.get(base+'/problem-solver/workspace/plot?projectId=999')).status(),404);
await context.close();
}
console.log('PASS result presentation: Plot Lines, timeline/continuity, relationships, scene/chapter, series, knowledge and character arc; evidence variants; optional secondary/article; explicit missing visuals; no article dump; reassurance/insufficient evidence; no-JS; 390/1440px; Back/Forward/Restart; public theme and noindex; signed-out tour CTA'+(base.includes('127.0.0.1')?'; signed-in authorised project/character selector and real workspace redirects.':'.'));
}finally{await browser.close();}
})().catch(e=>{console.error(e);process.exit(1)});