← back to Quadrille Showroom

scripts/verify-table-view.mjs

58 lines

// verify-table-view.mjs — behavioral test for the newest committed feature (commit 842a1dc):
// "At the Table" view hides the consultation nook (only the centre table shows) and restores
// it on exit; plus the seated set appears and samples can be added. Exit 1 on failure.
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const CANDIDATES = ['playwright',
  '/Users/macstudio3/.claude/skills/hero-readability-auditor/node_modules/playwright/index.js',
  '/Users/macstudio3/.claude/skills/app-demo-video/node_modules/playwright/index.js'];
let chromium=null; for (const c of CANDIDATES){ try{({chromium}=require(c)); if(chromium)break;}catch{} }
if(!chromium){ console.error('playwright not found'); process.exit(2); }

const URL = process.env.URL || 'http://127.0.0.1:7690';
const b = await chromium.launch({ channel:'chrome' });
const ctx = await b.newContext({ httpCredentials:{ username:'admin', password:'DWSecure2024!' } });
const p = await ctx.newPage();
const errs=[]; p.on('console',m=>{if(m.type()==='error')errs.push(m.text())}); p.on('pageerror',e=>errs.push('PE:'+e.message));
await p.goto(URL,{ waitUntil:'load', timeout:20000 });
await p.waitForFunction(()=>window._qhBootSettled===true && !!window._viewmode, { timeout:15000 }).catch(()=>{});
await p.waitForTimeout(2000);

const named = (name) => p.evaluate(n=>{ let f=null; window._scene && window._scene.traverse(o=>{ if(o.name===n) f=o; }); return f? f.visible : 'MISSING'; }, name);
const nookVis = () => p.evaluate(()=> window._qhNookGroup ? window._qhNookGroup.visible : 'MISSING');
const mode = () => p.evaluate(()=> window._viewmode ? window._viewmode.current : '?');

let fail=0; const need=(c,m)=>{ if(!c){console.log('❌ '+m); fail++;} else console.log('✅ '+m); };

// 0) baseline — nook visible before table view
const nook0 = await nookVis();
need(nook0===true, `nook visible before At-the-Table (got ${nook0})`);

// 1) ENTER table view
await p.evaluate(()=> window._viewmode.set('table'));
await p.waitForTimeout(1500);
need(await mode()==='table', 'mode == table after enter');
need(await nookVis()===false, 'consultation nook HIDDEN in At-the-Table view');
need(await named('tableSeatGroup')===true, 'table+chair set visible in table view');
need(await named('seatedAvatarRig')===true, 'seated avatar visible in table view');

// 2) add a sample to the table
const before = await p.evaluate(()=> window._viewmode.sampleCount);
await p.evaluate(()=> window._viewmode.addSample());
await p.waitForTimeout(600);
const after = await p.evaluate(()=> window._viewmode.sampleCount);
need(after>before, `addSample() increments basket (${before} → ${after})`);

// 3) EXIT table view → nook restored
await p.evaluate(()=> window._viewmode.set('walk'));
await p.waitForTimeout(1500);
need(await nookVis()===true, 'consultation nook RESTORED on exit');
need(await named('tableSeatGroup')===false || await named('tableSeatGroup')==='MISSING', 'table set hidden on exit');

need(errs.length===0, `zero console errors (${errs.length})`);
if(errs.length) console.log('  errors:', errs.slice(0,5));

await b.close();
console.log(fail? `\n❌ ${fail} table-view assertion(s) FAILED` : '\n✅ At-the-Table view: nook hides+restores, seated set shows, samples add — all correct');
process.exit(fail?1:0);