20 lines
12 KiB
JavaScript
20 lines
12 KiB
JavaScript
// Real Development acceptance. Requires a private disposable identity; never run against Production.
|
|
const {chromium}=require('playwright'),fs=require('fs'),assert=require('node:assert/strict');
|
|
const w=JSON.parse(fs.readFileSync(process.env.PD_WRITER2_IDENTITY)),base='https://dev.plotdirector.com',before=process.env.PD_WRITER2_STAGE==='before',out=process.env.PD_WRITER2_SCREENSHOTS;
|
|
(async()=>{const browser=await chromium.launch();try{const context=await browser.newContext({viewport:{width:1440,height:1000}});await context.addInitScript(u=>{Object.defineProperty(navigator,'standalone',{value:true});localStorage.setItem('plotdirector.desktop.v1.'+u,JSON.stringify({dismissedAt:Date.now()}));},w.UserID);const p=await context.newPage(),errors=[];p.on('pageerror',e=>errors.push(e.message));
|
|
await p.goto(base+'/Account/Login');await p.locator('[name=Email]').fill(w.Email);await p.locator('[name=Password]').fill(w.Password);await Promise.all([p.waitForURL('**/Projects'),p.locator('button[type=submit]').click()]);
|
|
const route=(d,b=w.book,project=w.project)=>`${base}/Writer/${d}?projectId=${project}${b?'&bookId='+b:''}`;
|
|
const shot=async n=>{if(!out)return;fs.mkdirSync(out,{recursive:true});await p.mouse.move(2,995);await p.waitForTimeout(200);await p.screenshot({path:out+'/'+n+'.png',animations:'disabled'});};
|
|
for(const [label,book,project] of [['Populated',w.book,w.project],['Minimal',w.otherBook,w.project],['Structured',w.structuredBook,w.project],['No-book',null,w.emptyProject]])for(const d of ['Write','Explore','Plan','Review','Reflect']){const r=await p.goto(route(d,book,project));assert.equal(r.status(),200,label+d);if(!before&&book&&d==='Reflect')await p.locator('.writer-month-grid').waitFor();if(!before&&book&&d==='Explore')await p.locator('[data-investigation-opening] input[name=concern]').first().waitFor();assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2),label+d+' overflow');await shot(label+'-'+d);}
|
|
if(before){console.log('PASS baseline authenticated four-fixture captures');return;}
|
|
await p.goto(route('Write'));const exportSessions=async()=>await(await p.request.get(base+`/Writer/Work/Export?bookId=${w.book}`)).json();const sessionsBefore=await exportSessions();const form=p.locator('[data-focus-wizard]');if(!await form.isVisible())await p.locator('[data-change-focus]').click();await form.locator('[name=Activity]').selectOption('Revising');await form.locator('[data-focus-next]').click();await form.locator('[name=ChapterID]').selectOption(String(w.chapter));await form.locator('[name=SceneID]').selectOption(String(w.scene));await form.locator('[data-focus-next]').click();await form.locator('[name=Intention]').fill('Clarify the turning point');await form.locator('[data-focus-back]').click();assert.equal(await form.locator('[name=ChapterID]').inputValue(),String(w.chapter));await form.locator('[data-focus-next]').click();assert.equal(await form.locator('[name=Intention]').inputValue(),'Clarify the turning point');let saves=0;p.on('request',r=>{if(r.method()==='POST'&&new URL(r.url()).pathname==='/Writer/SaveObjective')saves++;});await form.evaluate(n=>{n.requestSubmit();n.requestSubmit();});await p.locator('[data-focus-summary]').filter({hasText:'Clarify the turning point'}).waitFor();assert.equal(saves,1);assert.deepEqual(await exportSessions(),sessionsBefore,'focus must not create sessions');await shot('Write-established');await p.goto(route('Plan'));assert((await p.locator('.writer3-main').textContent()).includes('Clarify the turning point'));await p.goto(route('Write'));assert((await p.locator('[data-focus-summary]').textContent()).includes('Clarify the turning point'));await p.locator('[data-change-focus]').click();await form.locator('[data-focus-next]').click();await form.locator('[name=ChapterID]').selectOption('');await form.locator('[data-focus-next]').click();await form.locator('[data-save-focus]').click();await p.locator('[data-focus-summary]').filter({hasText:'Across the book'}).waitFor();assert.deepEqual(await exportSessions(),sessionsBefore);
|
|
await p.goto(route('Plan',w.otherBook));await p.locator('[data-change-focus]').click();const next=p.locator('[data-focus-wizard]');await next.locator('[name=Activity]').selectOption('Researching');await next.locator('[data-focus-next]').click();await next.locator('[data-focus-next]').click();await next.locator('[name=Intention]').fill('Consider the next scene without a schedule');await next.locator('[data-save-focus]').click();await p.locator('[data-focus-summary]').filter({hasText:'Consider the next scene without a schedule'}).waitFor();assert(p.url().includes('/Writer/Plan'));
|
|
await p.goto(route('Explore'));await p.locator('[data-discovery-tiles] [data-tile]:visible').first().waitFor();const tile=p.locator('[data-discovery-tiles] [data-tile]:visible').first(),id=await tile.getAttribute('data-tile');await tile.locator('[data-dismiss]').click();assert(await p.locator(`[data-tile="${id}"]`).isHidden());await p.reload();assert(await p.locator(`[data-tile="${id}"]`).isHidden());await p.locator('[data-reconsider]').click();assert(await p.locator(`[data-tile="${id}"]`).isVisible());await p.locator(`[data-tile="${id}"] [data-defer]`).click();assert(await p.locator(`[data-tile="${id}"]`).isHidden());await p.locator('[data-reconsider]').click();await p.locator('[data-investigation-opening] input[name=concern]').first().check();await p.locator('[data-investigation-opening] button[type=submit]').click();await p.waitForURL(/Investigate\?bookId=.*id=/);assert(await p.locator('[data-investigation-answer]').isVisible());await p.goto(route('Explore'));await p.locator('[data-my-investigations] article').first().waitFor();const completed=p.locator('[data-my-investigations] article').filter({hasText:'Original results'}).first();await completed.getByRole('button',{name:'Continue',exact:true}).click();await p.locator('.investigation form[data-guidance-navigation]').first().locator('button').click();await p.locator('[data-investigation-companion] #guidance-finding').waitFor();assert.equal(context.pages().length,1);await p.locator('[data-guidance-pin]').click();await p.goto(route('Explore'));await p.locator('[data-discovery-active] form').first().waitFor();assert((await p.locator('[data-discovery] [data-tile]:visible').count())<=4);assert((await p.locator('[data-discovery-active] [data-tile]:visible').count())<=2);await p.evaluate(()=>PlotLineHelpDrawer.open('writer3.explore'));await p.locator('.help-drawer-article').waitFor();await shot('Explore-both-panels');
|
|
await p.goto(route('Review')+'&chapterId='+w.chapter);await p.locator('[data-review-intentions-slot] [data-review-intentions]').waitFor();assert(await p.locator('.reader-page').isVisible());const paragraph=p.locator('[data-paragraph-id][data-scene-id]').filter({hasText:'recorded first paragraph'}).first();await paragraph.click();await p.locator('[data-review-record]').click();await p.locator('[data-review-form] [name=Observation]').fill('The transition could show a clearer consequence.');await p.locator('[data-review-form] [name=Decision]').fill('Consider this transition when revising in Word.');await p.locator('[data-review-save]').click();await p.locator('[data-review-message]').filter({hasText:'Observation saved.'}).waitFor();await p.locator('[data-review-intentions-slot]').getByText('Disposable review scene',{exact:true}).waitFor();await shot('Review-context');await p.locator('#reader-focus').click();await p.locator('.reader-controls a[rel=next]').click();assert.equal(await p.locator('.manuscript-reader').getAttribute('data-focus'),'true');await shot('Focus-next-chapter');await p.locator('#reader-focus').click();await p.goto(route('Plan'));const reviewReturn=await p.locator('a[href*="/Writer/Review?"]').first().getAttribute('href');await p.goto(new URL(reviewReturn,base).href);assert.equal(await p.locator('.manuscript-reader').getAttribute('data-chapter-id'),String(w.chapter2));await p.goto(route('Review')+'&reading=true&chapterId='+w.chapter);assert.equal(await p.locator('.manuscript-reader').getAttribute('data-reading'),'true');await shot('Reading-mode');
|
|
// An explicit session is a separate action, never a side effect of choosing focus.
|
|
await p.goto(route('Write'));const token=await p.locator('input[name=__RequestVerificationToken]').first().inputValue();const session=require('crypto').randomUUID();assert.equal((await p.request.post(base+'/Writer/Work/Start',{form:{bookId:w.book,kind:'Planning',requestId:session,__RequestVerificationToken:token}})).status(),200);assert.equal((await p.request.post(base+'/Writer/Work/End',{form:{bookId:w.book,sessionId:session,note:'Considered the next writing step',__RequestVerificationToken:token}})).status(),200);
|
|
if(w.planId){await p.goto(`${base}/Writer/PlanActivities?writingPlanId=${w.planId}`);}else{await p.goto(`${base}/Writer/ScheduleSetup?projectId=${w.project}&bookId=${w.book}`);await p.locator('[name=PlanName]').fill('Disposable Phase 2 writing plan');const today=new Date(),end=new Date(Date.now()+28*86400000);await p.locator('[name=StartDate]').fill(today.toISOString().slice(0,10));await p.locator('[name=DeadlineDate]').fill(end.toISOString().slice(0,10));for(const box of await p.locator('input[type=checkbox][name$=".IsAvailable"]').all())await box.check();await p.getByRole('button',{name:'Review activities',exact:true}).click();await p.waitForURL(/PlanActivities|SchedulePreview/);}if(p.url().includes('PlanActivities')){await p.locator('input[type=checkbox][name=Confirm]').check();await p.getByRole('button',{name:'Commit reviewed schedule'}).click();await p.waitForURL(/SchedulePreview/);}const planId=new URL(p.url()).searchParams.get('writingPlanId');assert(planId);await p.goto(route('Plan'));assert((await p.locator('.writer3-main').textContent()).includes('Scheduled writing activities'));await p.goto(`${base}/Writer/EditWritingPlan?writingPlanId=${planId}`);assert(await p.locator('[name=PlanName]').isVisible());await p.locator('[name=PlanName]').fill('Disposable Phase 2 adjusted plan');const saveRibbon=p.locator('[data-ribbon-collapse]');if(await saveRibbon.getAttribute('aria-expanded')==='false')await saveRibbon.click();await p.getByRole('button',{name:'Save Plan',exact:true}).click();await p.waitForURL(/WritingPlans/);assert((await p.locator('body').textContent()).includes('Disposable Phase 2 adjusted plan'));await p.goto(route('Reflect'));await p.locator('.writer-month-grid').waitFor();const month=await p.locator('.writer-section-heading h2').first().textContent();await p.getByRole('link',{name:'Previous month',exact:true}).click();assert(p.url().includes('/Writer/Reflect'));assert.notEqual(await p.locator('.writer-section-heading h2').first().textContent(),month);await p.locator('.writer-month-grid a').first().click();assert(p.url().includes('day='));await shot('Reflect-day');
|
|
for(const d of ['Write','Explore','Plan','Review','Reflect']){await p.goto(route(d));await p.waitForTimeout(150);await shot('Working-'+d);}
|
|
for(const width of [1920,1366,800])for(const d of ['Write','Explore','Plan','Review','Reflect']){await p.setViewportSize({width,height:1000});await p.goto(route(d));await p.waitForFunction(()=>window.PlotDirectorGuidanceSummary?.active===true);const ribbon=p.locator('[data-ribbon-collapse]');if(await ribbon.getAttribute('aria-expanded')==='false')await ribbon.click();if(await p.locator('[data-guidance-open]').isVisible())await p.locator('[data-guidance-open]').click();await p.evaluate(()=>PlotLineHelpDrawer.open('writer3.layout'));await p.locator('.help-drawer-article').waitFor();assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2),d+' '+width);await shot(d+'-'+width+'-panels');const collapse=p.locator('[data-ribbon-collapse]');await collapse.click();assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));if(await p.locator('[data-guidance-collapse]').isVisible())await p.locator('[data-guidance-collapse]').click();await p.locator('[data-help-collapse]').count().then(async n=>{if(n)await p.locator('[data-help-collapse]').click();});await shot(d+'-'+width+'-collapsed');}
|
|
assert.deepEqual(errors,[]);console.log('PASS Phase 2 authenticated four fixtures, AJAX focus and no sessions, discovery preferences, canonical questionnaire, saved guidance, Review/Reading/Focus scene context, Reflect month/day, three widths and panel/ribbon states');await context.close();}finally{await browser.close();}})().catch(e=>{console.error(e.stack);process.exitCode=1});
|