diff --git a/PlotLine.Tests/Browser/writer-phase2.cjs b/PlotLine.Tests/Browser/writer-phase2.cjs index d8f90f98..ca37e7f3 100644 --- a/PlotLine.Tests/Browser/writer-phase2.cjs +++ b/PlotLine.Tests/Browser/writer-phase2.cjs @@ -10,7 +10,7 @@ if(before){console.log('PASS baseline authenticated four-fixture captures');retu 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();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 p.locator('#reader-focus').click();await p.goto(route('Plan'));await p.locator('a[href*="/Writer/Review?"]').first().click();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'); +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'));await p.locator('a[href*="/Writer/Review?"]').first().click();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.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'); diff --git a/PlotLine/wwwroot/js/writer-authoring.js b/PlotLine/wwwroot/js/writer-authoring.js index da142056..66b24cdf 100644 --- a/PlotLine/wwwroot/js/writer-authoring.js +++ b/PlotLine/wwwroot/js/writer-authoring.js @@ -38,7 +38,7 @@ async function read(){const response=await fetch(root.dataset.inspectUrl,{cache:'no-store'});if(!response.ok)throw Error('Recorded information is unavailable');const doc=new DOMParser().parseFromString(await response.text(),'text/html');if(!doc.querySelector('[data-authoring-content]'))throw Error('Authorisation or recorded information is unavailable');return doc;} let loadEpoch=0; async function load(){const mine=++loadEpoch;if(!root.dataset.inspectUrl){root.hidden=true;root.replaceChildren();return;}root.hidden=false;try{const doc=await read();if(mine!==loadEpoch)return;root.replaceChildren(...doc.body.childNodes);bind(root);const references=document.querySelector('[data-authoring-references]'),template=root.querySelector('[data-authoring-companion]');if(references&&template)references.replaceChildren(template.content.cloneNode(true));} - catch{root.replaceChildren();const p=document.createElement('p');p.textContent='Recorded information could not load. Your current work and existing editors remain available.';const retry=document.createElement('button');retry.type='button';retry.className='btn btn-outline-secondary';retry.textContent='Try again';retry.addEventListener('click',load);root.append(p,retry);}} + catch{if(mine!==loadEpoch)return;root.replaceChildren();const p=document.createElement('p');p.textContent='Recorded information could not load. Your current work and existing editors remain available.';const retry=document.createElement('button');retry.type='button';retry.className='btn btn-outline-secondary';retry.textContent='Try again';retry.addEventListener('click',load);root.append(p,retry);}} window.addEventListener('beforeunload',e=>{if(dirty()&&!allowLeave){e.preventDefault();e.returnValue='';}}); function guard(e){if(!dirty())return;const target=e.target.closest('a,form,[data-plan-focus]');if(!target||target.matches('[data-authoring-form],[data-work-start]')||target.target==='_blank'||target.hasAttribute('download'))return;if(target.tagName==='A'&&new URL(target.href,location.href).pathname===location.pathname&&new URL(target.href,location.href).search===location.search&&target.hash)return;if(!confirm(root.querySelector('[data-busy="true"]')?'A save is in progress and may finish after you leave. Leave this page?':'Leave without saving your inline edits?')){e.preventDefault();e.stopImmediatePropagation();}else allowLeave=true;} document.addEventListener('click',e=>{if(e.target.closest('a,[data-plan-focus]'))guard(e);},true);document.addEventListener('submit',guard,true);window.addEventListener('pageshow',()=>allowLeave=false); diff --git a/PlotLine/wwwroot/js/writer-objective.js b/PlotLine/wwwroot/js/writer-objective.js index 3b3bb905..3e0463e6 100644 --- a/PlotLine/wwwroot/js/writer-objective.js +++ b/PlotLine/wwwroot/js/writer-objective.js @@ -13,6 +13,6 @@ root.dataset.savedActivity=data.activity;root.dataset.savedChapter=data.chapterI let summary=root.querySelector('[data-focus-summary]');if(!summary){summary=document.createElement('div');host.before(summary);}summary.replaceChildren();const h=document.createElement('h2');h.textContent=data.activity+' · '+data.title;const p=document.createElement('p');p.textContent=data.intention||'Your focus is saved. No recording has started.';const a=document.createElement('a');a.href=data.continueUrl;a.className='btn btn-primary';a.textContent='Continue this work';summary.append(h,p,a);host.hidden=true;const change=root.querySelector('[data-change-focus]');if(change)change.hidden=false;busy=false;button.disabled=false; window.dispatchEvent(new CustomEvent('plotdirector:focus-saved',{detail:data}));summary.tabIndex=-1;summary.focus();}catch{form.querySelector('[data-focus-error]').textContent='Your focus could not be confirmed. Your choices are retained; please try again.';busy=false;button.disabled=false;}}); } - root.querySelector('[data-change-focus]')?.addEventListener('click',async e=>{e.preventDefault();if(loading)return;e.currentTarget.hidden=true;if(host.querySelector('form')){host.hidden=false;return;}loading=true;host.hidden=false;host.textContent='Loading your focus…';try{const r=await fetch(root.dataset.focusUrl);if(!r.ok)throw Error();host.innerHTML=await r.text();initialise();}catch{host.textContent='Focus is temporarily unavailable. Try Change focus again.';}finally{loading=false;}}); + root.querySelector('[data-change-focus]')?.addEventListener('click',async e=>{e.preventDefault();if(loading)return;e.currentTarget.hidden=true;if(host.querySelector('form')){host.hidden=false;return;}loading=true;host.hidden=false;host.textContent='Loading your focus…';try{const r=await fetch(root.dataset.focusUrl);if(!r.ok)throw Error();host.innerHTML=await r.text();initialise();}catch{host.textContent='Focus is temporarily unavailable. Try Change focus again.';const change=root.querySelector('[data-change-focus]');if(change)change.hidden=false;}finally{loading=false;}}); initialise(); })();