// Explicit Development acceptance only. Requires a disposable author and owned fixture. // Credentials remain in a private file and are never logged. const {chromium}=require('playwright'); const fs=require('node:fs'); const assert=require('node:assert/strict'); (async()=>{ const identityPath=process.env.PD_WRITER_IDENTITY,scopePath=process.env.PD_WRITER_SCOPE,output=process.env.PD_WRITER_SCREENSHOTS; assert(identityPath?.startsWith('/tmp/pd-dev-browser-writer2-')&&scopePath&&output,'Dedicated fixture files required'); const who=JSON.parse(fs.readFileSync(identityPath)),scope=JSON.parse(fs.readFileSync(scopePath)); assert(who.Database==='PlotDirector_Development'&&/^pwa-browser-.*@example\.invalid$/.test(who.Email)); for(const key of ['project','book','chapter','scene','other'])assert(Number.isSafeInteger(scope[key])&&scope[key]>0); const base='https://dev.plotdirector.com',writer=`${base}/Writer?projectId=${scope.project}&bookId=${scope.book}`; const browser=await chromium.launch(); try{for(const pwa of [false,true]){ const context=await browser.newContext({viewport:{width:1440,height:1000}}); if(pwa)await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true})); const page=await context.newPage(); const failures=[]; page.on('response', response=>{if(response.request().isNavigationRequest()&&response.request().frame()===page.mainFrame()&&response.status()>=400)failures.push(response.status()+' '+new URL(response.url()).pathname);}); await page.goto(base+'/Account/Login');await page.locator('[name=Email]').fill(who.Email);await page.locator('[name=Password]').fill(who.Password); await Promise.all([page.waitForURL('**/Projects'),page.locator('button[type=submit]').click()]); await page.goto(writer); if(!pwa){ assert.equal(await page.getByRole('heading',{name:'Start Here',exact:true}).isVisible(),true); await page.screenshot({path:output+'/Overview-Initial.png',fullPage:true}); await page.getByRole('link',{name:/Explore your manuscript/}).click();await page.waitForURL(`**/Books/Details/${scope.book}#chapters`); assert.equal(await page.locator('#chapters').isVisible(),true);assert.equal(await page.getByRole('link',{name:'The crossing',exact:true}).count(),1); await page.getByRole('link',{name:'The crossing',exact:true}).click(); await page.waitForURL(`**/Chapters/Details/${scope.chapter}`);assert((await page.locator('body').textContent()).includes('Arrival')); await page.goto(writer);await page.getByRole('link',{name:/Continue an existing manuscript/}).click(); await page.locator('[name=Activity]').selectOption('Revising');await page.locator('[data-objective-chapter]').selectOption(String(scope.chapter));await page.locator('[data-objective-scene]').selectOption(String(scope.scene)); await Promise.all([page.waitForURL(`**/Writer?bookId=${scope.book}`),page.getByRole('button',{name:'Save objective · start without a schedule'}).click()]); } assert.equal(await page.getByRole('heading',{name:'Continue Writing',exact:true}).isVisible(),true); assert((await page.locator('.writer-current').textContent()).includes('Revising')); if(!pwa)await page.screenshot({path:output+'/Overview-Objective.png',fullPage:true}); await page.getByRole('link',{name:'Continue Writing',exact:true}).click();await page.waitForURL(`**/Scenes/Edit/${scope.scene}`); assert((await page.locator('body').textContent()).includes('Arrival')); await page.goto(writer);await page.getByRole('link',{name:'Open Chapters',exact:true}).click();await page.waitForURL(`**/Books/Details/${scope.book}#chapters`);assert.equal(await page.locator('#chapters').isVisible(),true); await page.goto(writer);await page.getByRole('link',{name:'Create a writing plan',exact:true}).click();await page.waitForURL('**/Writer/ScheduleSetup?*'); assert.equal(await page.locator('[name=BookID]').inputValue(),String(scope.book));assert.equal(await page.locator('[name=ProjectID]').inputValue(),String(scope.project)); assert((await page.locator('[name=BookID]').textContent()).includes('All Books')); await page.getByRole('link',{name:'Skip scheduling · return to Writer'}).click();assert.equal(await page.getByRole('heading',{name:'Continue Writing',exact:true}).isVisible(),true); if(!pwa){ for(const allBooks of [false,true]){ await page.goto(`${base}/Writer/ScheduleSetup?projectId=${scope.project}&bookId=${scope.book}`); await page.locator('[name=PlanName]').fill(allBooks?'Synthetic project-wide plan':'Synthetic book plan'); if(allBooks)await page.locator('[name=BookID]').selectOption(''); await Promise.all([page.waitForURL('**/Writer/PlanActivities?writingPlanId=*'),page.getByRole('button',{name:'Review activities',exact:true}).click()]); await page.locator('[name=Confirm][type=checkbox]').check(); await Promise.all([page.waitForURL('**/Writer/SchedulePreview?writingPlanId=*'),page.getByRole('button',{name:'Commit reviewed schedule',exact:true}).click()]); await page.getByRole('link',{name:'Edit Plan',exact:true}).click();await page.waitForURL('**/Writer/EditWritingPlan?writingPlanId=*'); assert.equal(await page.locator('input[readonly]').nth(1).inputValue(),allBooks?'All Books':'Writer verification book'); await page.locator('[name=PlanName]').fill(allBooks?'Updated project-wide plan':'Updated book plan'); await Promise.all([page.waitForURL('**/Writer/WritingPlans?*'),page.getByRole('button',{name:'Save Plan',exact:true}).click()]); assert((await page.locator('body').textContent()).includes(allBooks?'Updated project-wide plan':'Updated book plan')); } await page.goto(`${base}/Writer/WritingPlans?projectId=${scope.project}&bookId=${scope.book}`); assert((await page.locator('body').textContent()).includes('Updated project-wide plan')); assert((await page.locator('body').textContent()).includes('Updated book plan')); } for(const title of ['Writing Journey','Writing Plan','Workspaces','Reports']){ await page.goto(writer);const link=page.locator('#ribbon-panel-writer').getByRole('link',{name:title,exact:true}); assert.equal(await link.count(),1);await link.click();await page.waitForLoadState();assert.equal(await page.locator('h1').count(),1);assert(!(await page.locator('body').textContent()).includes('An error occurred')); assert(new URL(page.url()).searchParams.get('bookId')===String(scope.book),`${title} retains book`); } await page.goto(`${base}/Writer?projectId=${scope.project}&bookId=${scope.other}`);assert.equal(await page.getByRole('heading',{name:'Start Here',exact:true}).isVisible(),true); await page.goto(writer);assert.equal(await page.getByRole('heading',{name:'Continue Writing',exact:true}).isVisible(),true); await page.getByRole('link',{name:'Change objective'}).click();assert.equal(await page.locator('[name=Activity]').inputValue(),'Revising');assert.equal(await page.locator('[data-objective-scene]').inputValue(),String(scope.scene)); assert.deepEqual(failures,[]); console.log(`PASS live Writer author journey: ${pwa?'simulated PWA':'browser'}; real chapter/scene destinations, saved objective, optional scheduling, ribbon and book isolation`); await context.close(); }}finally{await browser.close();} })().catch(error=>{console.error(error.stack);process.exitCode=1;});