62 lines
9.4 KiB
JavaScript
62 lines
9.4 KiB
JavaScript
// Explicit authenticated Development acceptance. Only a disposable account/owned fixture.
|
|
const {chromium}=require('playwright');
|
|
const fs=require('node:fs');
|
|
const assert=require('node:assert/strict');
|
|
let privatePassword='';
|
|
(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);
|
|
const who=JSON.parse(fs.readFileSync(identityPath)),scope=JSON.parse(fs.readFileSync(scopePath));privatePassword=who.Password;
|
|
assert(who.Database==='PlotDirector_Development'&&/^pwa-browser-.*@example\.invalid$/.test(who.Email));
|
|
for(const key of ['project','book','chapter','scene','other','secondChapter'])assert(Number.isSafeInteger(scope[key])&&scope[key]>0);
|
|
const base='https://dev.plotdirector.com',url=book=>`${base}/Writer?projectId=${scope.project}&bookId=${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(),failed=[];
|
|
page.on('response',r=>{if(r.request().isNavigationRequest()&&r.request().frame()===page.mainFrame()&&r.status()>=400)failed.push(r.status()+' '+new URL(r.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(url(scope.book));
|
|
await page.getByRole('button',{name:'Help Me',exact:true}).click();assert.equal(await page.locator('#writer-help-options').isVisible(),true);
|
|
if(!pwa)await page.screenshot({path:output+'/Overview-Help-Live.png',fullPage:true});
|
|
await page.getByRole('link',{name:'Read or start Audio Review',exact:true}).click();await page.waitForURL('**/manuscript/reader?*');assert((await page.locator('#reader-content').textContent()).includes('A small boat crossed the harbour.'));
|
|
await page.getByRole('link',{name:'Return to Writing',exact:true}).click();await page.waitForURL('**/Writer?*');
|
|
if(!pwa && await page.getByRole('link',{name:/Continue an existing manuscript/}).count()){
|
|
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);
|
|
const toolbar=page.locator('[data-writer-work]');
|
|
await toolbar.locator('[name=kind]').selectOption('Reading');await toolbar.locator('[name=chapterId]').selectOption(String(scope.chapter));await toolbar.getByRole('button',{name:'Start session',exact:true}).click();await page.waitForFunction(()=>!document.querySelector('[data-work-current]').hidden);
|
|
await toolbar.locator('[data-work-note]').fill('Review the arrival objective next');await toolbar.locator('[data-work-end]').click();await page.waitForFunction(()=>document.querySelector('[data-work-current]').hidden);
|
|
await toolbar.locator('[name=kind]').selectOption('AudioReview');await toolbar.getByRole('button',{name:'Start Audio Review',exact:true}).click();await page.waitForFunction(()=>!document.querySelector('[data-work-audio]').hidden);
|
|
for(const button of await toolbar.locator('[data-media-command]').all())assert.equal(await button.isDisabled(),true);
|
|
assert((await toolbar.locator('[data-audio-state]').textContent()).includes('Updated Windows Companion'));
|
|
if(!pwa)await page.screenshot({path:output+'/Audio-Unavailable-Live.png',fullPage:true});
|
|
await toolbar.locator('[data-work-note]').fill('Audio controls require Windows qualification');await toolbar.locator('[data-work-end]').click();await page.waitForFunction(()=>document.querySelector('[data-work-current]').hidden);
|
|
const exported=await(await page.request.get(`${base}/Writer/Work/Export?bookId=${scope.book}`)).json();assert(exported.some(x=>x.kind==='Reading'&&x.note==='Review the arrival objective next'));assert(exported.filter(x=>x.kind==='AudioReview').every(x=>x.playbackSeconds===0&&x.uniqueSeconds===0));
|
|
if(!pwa){
|
|
await page.getByRole('link',{name:'Create a writing plan',exact:true}).click();await page.waitForURL('**/Writer/ScheduleSetup?*');assert.equal(await page.locator('[name=GoalType]').inputValue(),'Revision');assert.equal(await page.locator('[name=BookID]').inputValue(),String(scope.book));
|
|
await page.locator('[name=PlanName]').fill('Seventeen-hour revision availability');
|
|
const budget={Monday:240,Tuesday:240,Wednesday:240,Thursday:240,Friday:60};
|
|
for(const row of await page.locator('tbody tr').all()){const day=await row.locator('input[name$=".Day"]').inputValue();await row.locator('input[type=checkbox]').setChecked(Boolean(budget[day]));if(budget[day])await row.locator('select').selectOption(String(budget[day]));}
|
|
await Promise.all([page.waitForURL('**/Writer/PlanActivities?*'),page.getByRole('button',{name:'Review activities',exact:true}).click()]);
|
|
assert.equal(await page.locator('[name$=".Minutes"]').count(),2);await page.locator('[name="Candidates[0].Minutes"]').fill('45');await page.locator('[name="Candidates[1].Minutes"]').fill('90');await page.locator('[name=Confirm][type=checkbox]').check();
|
|
await Promise.all([page.waitForURL('**/Writer/SchedulePreview?*'),page.getByRole('button',{name:'Commit reviewed schedule',exact:true}).click()]);
|
|
assert.equal(await page.getByRole('heading',{name:'Reviewed writing activities',exact:true}).isVisible(),true);assert((await page.locator('body').textContent()).includes('135 planned minutes'));assert.equal(await page.locator('.writer-kpi').count(),0);assert.equal(await page.getByRole('heading',{name:'Schedule Preview Table',exact:true}).count(),0,'No empty legacy table competes with reviewed allocations');
|
|
await page.screenshot({path:output+'/Reviewed-Schedule-Live.png',fullPage:true});
|
|
await page.locator('form[action*="PlanActivities/Complete"] button').first().click();await page.waitForURL('**/Writer/SchedulePreview?*');assert((await page.locator('body').textContent()).includes('Done'));
|
|
await page.goto(url(scope.book));await page.locator('.writer-next-grid').getByRole('link',{name:'The harbour',exact:true}).click();await page.waitForURL(`**/Writer/Chapter/${scope.secondChapter}`);assert((await page.locator('body').textContent()).includes('The harbour'));
|
|
await page.goto(`${base}/Writer/ScheduleSetup?projectId=${scope.project}&bookId=${scope.book}`);await page.locator('[name=BookID]').selectOption('');await page.locator('[name=PlanName]').fill('Project-wide review');await page.getByRole('button',{name:'Review activities',exact:true}).click();await page.waitForURL('**/Writer/PlanActivities?*');assert((await page.locator('body').textContent()).includes('All Books'));await page.locator('[name=Confirm][type=checkbox]').check();await page.getByRole('button',{name:'Commit reviewed schedule',exact:true}).click();await page.waitForURL('**/Writer/SchedulePreview?*');
|
|
}
|
|
await page.goto(`${base}/Writer/Journey?projectId=${scope.project}&bookId=${scope.book}`);assert.equal(await page.locator('.writer-month-grid').count(),1);assert((await page.locator('body').textContent()).includes('Review the arrival objective next'));
|
|
if(!pwa)await page.screenshot({path:output+'/Journey-Live.png',fullPage:true});
|
|
const today=new Date().toISOString().slice(0,10);await page.locator(`.writer-month-grid a[href*="day=${today}"]`).click();assert((await page.locator('body').textContent()).includes('Sessions on this day'));
|
|
await page.goto(url(scope.other));const other=page.locator('[data-writer-work]');await other.locator('[name=kind]').selectOption('Planning');await other.getByRole('button',{name:'Start session',exact:true}).click();await page.waitForFunction(()=>!document.querySelector('[data-work-current]').hidden);await other.locator('[data-work-end]').click();await page.waitForFunction(()=>document.querySelector('[data-work-current]').hidden);await page.reload();assert.equal(await page.getByRole('heading',{name:'Start Here',exact:true}).isVisible(),true);assert.equal(await page.locator('.writer-day-observed').count(),1,'Planning works without any accepted manuscript baseline');
|
|
await page.goto(url(scope.book));assert.equal(await page.getByRole('heading',{name:'Continue Writing',exact:true}).isVisible(),true);
|
|
assert.equal((await page.request.post(base+'/Writer/Work/Command',{form:{bookId:scope.book,sessionId:'00000000-0000-0000-0000-000000000001',command:'play'}})).status(),400,'Media command requires antiforgery');
|
|
assert.deepEqual(failed,[]);console.log(`PASS live intelligent Writer: ${pwa?'simulated PWA':'browser'}; real Help/Reader destination, saved focus, private sessions/notes, unavailable audio, 17-hour revision planning, reviewed chapter/scene tasks, completion, month/day Journey and empty-history planning`);
|
|
await context.close();
|
|
}}finally{await browser.close();}
|
|
})().catch(error=>{const message=error.stack||String(error);console.error(privatePassword?message.replaceAll(privatePassword,'[redacted]'):message);process.exitCode=1;});
|