// Dev only; provision/clean the isolated identity using --dev-browser-identity. const {chromium}=require('playwright'); const fs=require('node:fs'); const os=require('node:os'); const path=require('node:path'); const assert=require('node:assert/strict'); const base='https://dev.plotdirector.com'; (async()=>{ const file=process.argv[2];assert(file?.startsWith('/tmp/pd-dev-browser-')); const identity=JSON.parse(fs.readFileSync(file,'utf8'));assert.equal(identity.Database,'PlotDirector_Development');assert(identity.Email.startsWith('pwa-browser-')); const profile=fs.mkdtempSync(path.join(os.tmpdir(),'pd-promotion-dev-')); const context=await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1440,height:1100},reducedMotion:'reduce'}); const cdp=await context.browser().newBrowserCDPSession();const manifestId=base+'/Projects';let installed=false; try{ const page=context.pages()[0]; await page.goto(base+'/Account/Login');await page.locator('[name=Email]').fill(identity.Email);await page.locator('[name=Password]').fill(identity.Password);await page.locator('form button[type=submit]').click();await page.waitForURL(base+'/Projects'); if(!identity.BookID){ if(!identity.ProjectID){await page.goto(base+'/Projects/Create');console.log('Creating project');await page.locator('[name=ProjectName]').fill('Desktop promotion verification');await page.locator('form.edit-panel button[type=submit]').click();await page.waitForURL(/\/Projects\/Details\//); identity.ProjectID=Number(new URL(page.url()).pathname.split('/').at(-1));fs.writeFileSync(file,JSON.stringify(identity),{mode:0o600});console.log('Project fixture created');} const response=await page.goto(base+`/Books/Create?projectId=${identity.ProjectID}`);assert.equal(response.status(),200,'book creation route');assert(await page.locator('[name=BookTitle]').count(),'book fixture form');await page.locator('[name=BookTitle]').fill('Comparison verification');await page.locator('[name=BookNumber]').fill('1');await page.locator('form.edit-panel button[type=submit]').click();await page.waitForURL(/\/Books\/Details\//); identity.BookID=Number(page.url().split('/').at(-1));fs.writeFileSync(file,JSON.stringify(identity),{mode:0o600}); } const url=base+`/Timeline?projectId=${identity.ProjectID}&bookId=${identity.BookID}`; await page.goto(url);await page.locator('dialog.pd-desktop-promotion').waitFor(); await page.waitForFunction(()=>[...document.querySelectorAll('dialog img')].every(i=>i.complete&&i.naturalWidth===1710)); await page.setViewportSize({width:1440,height:900}); await page.locator('dialog').evaluate(d=>{d.querySelector('.pd-desktop-close').focus({preventScroll:true});d.scrollTop=0;}); const scrollBefore=await page.locator('dialog').evaluate(d=>d.scrollTop); const imageBox=await page.locator('.pd-desktop-comparison').boundingBox();assert(imageBox.width>1100); await page.locator('dialog input').focus();await page.keyboard.press('ArrowLeft');assert.equal(await page.inputValue('dialog input'),'67'); await page.locator('dialog').evaluate(d=>{d.querySelector('.pd-desktop-close').focus({preventScroll:true});d.scrollTop=0;}); await page.mouse.move(imageBox.x+imageBox.width*.68,imageBox.y+90);await page.mouse.down();await page.mouse.move(imageBox.x+imageBox.width*.35,imageBox.y+90);await page.mouse.up();assert(Math.abs(Number(await page.inputValue('dialog input'))-35)<2); assert.equal(await page.locator('dialog').evaluate(d=>d.scrollTop),scrollBefore,'divider drag must not scroll the modal'); await page.setViewportSize({width:1440,height:1100}); // Deterministically exercise the non-promptable environment; real installation is checked below through Chromium CDP. await page.evaluate(()=>{window.savedInstallRequest=window.PlotDirectorInstall.request;window.PlotDirectorInstall.request=async()=>'unavailable';}); await page.click('[data-desktop-install]');await page.waitForFunction(()=>document.querySelector('[data-install-status]').textContent.length>10); await page.evaluate(()=>window.PlotDirectorInstall.request=window.savedInstallRequest); for(const theme of ['warm-light','modern-light','modern-dark','warm-dark','rose-pink','baby-blue']){ await page.evaluate(t=>document.documentElement.dataset.appTheme=t,theme);await page.screenshot({path:`/tmp/pd-desktop-promotion-${theme}.png`}); assert(await page.locator('dialog').evaluate(d=>d.scrollWidth<=d.clientWidth+1)); } await page.setViewportSize({width:390,height:844});const actions=await page.locator('dialog footer').boundingBox();assert(actions.y+actions.height<=844,'actions stay visible on narrow screens');await page.screenshot({path:'/tmp/pd-desktop-promotion-mobile.png'});assert(await page.locator('dialog').evaluate(d=>d.scrollWidth<=d.clientWidth+1));await page.setViewportSize({width:1440,height:1100}); await page.click('[data-desktop-continue]');await page.reload();await page.waitForTimeout(2200);assert.equal(await page.locator('dialog[open]').count(),0); await page.click('#accountMenuButton');await page.click('[data-pwa-install]');assert(await page.locator('dialog').isVisible());await page.keyboard.press('Escape'); assert.equal((await page.request.get(base+'/help/workspace/desktop')).status(),200); await cdp.send('PWA.install',{manifestId,installUrlOrBundleUrl:base+'/Projects'});installed=true; await cdp.send('PWA.changeAppUserSettings',{manifestId,displayMode:'standalone'}); const opened=context.waitForEvent('page');await cdp.send('PWA.launch',{manifestId,url});const app=await opened;await app.waitForLoadState(); assert(await app.evaluate(()=>window.PlotDirectorPwa.standalone));await app.waitForTimeout(2200);assert.equal(await app.locator('dialog.pd-desktop-promotion').count(),0);assert(await app.locator('[data-pwa-install-item]').isHidden()); await require('./pwa-first-paint.cjs')(app,page,{url:base+`/StoryBible?projectId=${identity.ProjectID}`}); await app.screenshot({path:'/tmp/pd-desktop-promotion-standalone.png'}); console.log('PASS authenticated Dev: genuine screenshots, divider pointer/keyboard, themes/mobile, install fallback, dismissal persistence/manual reopen, Help, real installed PWA exclusion and first-paint checks.'); }finally{if(installed)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});