PlotDirector/PlotLine.Tests/Browser/context-spatial-development-pwa.cjs

4 lines
3.3 KiB
JavaScript

// Real installed Chromium PWA on Development; reads only the dedicated synthetic world.
const{chromium}=require('playwright'),fs=require('node:fs'),assert=require('node:assert/strict');const file=process.argv[2];if(!file?.startsWith('/tmp/pd-dev-browser-'))throw Error('Dedicated identity required');const identity=JSON.parse(fs.readFileSync(file));assert.equal(identity.Database,'PlotDirector_Development');assert(identity.Email.startsWith('pwa-browser-'));const f=identity.SpatialFixture;assert(f?.scenes?.length===3);
(async()=>{const base='https://dev.plotdirector.com',profile=fs.mkdtempSync('/tmp/pd-spatial-development-pwa-'),context=await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1600,height:1050}}),cdp=await context.browser().newBrowserCDPSession(),manifestId=base+'/Projects';try{const tab=context.pages()[0];await tab.goto(base+'/Account/Login');await tab.locator('#Email').fill(identity.Email);await tab.locator('#Password').fill(identity.Password);await Promise.all([tab.waitForURL('**/Projects'),tab.locator('form button[type=submit]').click()]);await cdp.send('PWA.install',{manifestId,installUrlOrBundleUrl:base+'/Projects'});await cdp.send('PWA.changeAppUserSettings',{manifestId,displayMode:'standalone'});const opened=context.waitForEvent('page');await cdp.send('PWA.launch',{manifestId,url:base+`/Writing/Context?projectId=${identity.ProjectID}&bookId=${identity.BookID}&sceneId=${f.scenes[1]}&pinned=true`});const page=await opened;await page.waitForLoadState();assert(await page.evaluate(()=>matchMedia('(display-mode: standalone)').matches));const errors=[];page.on('pageerror',e=>errors.push(e.message));const pane=i=>page.locator(`[data-context-pane="${i}"]`);await page.selectOption('[data-context-pane="0"] [data-context-tab]','locations');await pane(0).getByRole('heading',{name:'Bedroom',exact:true}).waitFor();await page.selectOption('[data-context-layout]','columns');await page.selectOption('[data-context-pane="1"] [data-context-tab]','maps');await page.waitForFunction(()=>document.querySelector('iframe')?.contentWindow?.PlotDirectorMapWorkspace?.document.features.length===1);assert.equal(await page.frames().find(frame=>frame.url().includes('/SpatialContext/Map')).locator('.spatial-map-ring').count(),3);await page.screenshot({path:'/tmp/pd-spatial-evidence/development-installed-pwa-maps.png'});await page.selectOption('[data-context-pane="1"] [data-context-tab]','floorplans');await pane(1).locator('.spatial-room-badge').first().waitFor();assert.equal(await pane(1).locator('.spatial-room-badge').count(),3);await page.screenshot({path:'/tmp/pd-spatial-evidence/development-installed-pwa-floorplans.png'});await page.selectOption('[data-context-layout]','rows');await page.screenshot({path:'/tmp/pd-spatial-evidence/development-installed-pwa-stacked.png'});assert.deepEqual(errors,[]);fs.writeFileSync('/tmp/pd-spatial-evidence/development-installed-pwa-results.json',JSON.stringify({passed:true,installed:true,target:'Development',fixturesOnly:true,errors},null,2));console.log('PASS authenticated Development installed Chromium PWA: Locations, Maps, Floor Plans, shared scene highlights, side-by-side/stacked layout, no page errors');}finally{await cdp.send('PWA.uninstall',{manifestId}).catch(()=>{});await context.close();fs.rmSync(profile,{recursive:true,force:true});}})().catch(e=>{console.error(e);process.exitCode=1;});