PlotDirector/PlotLine.Tests/Browser/writer3-authoring.cjs

24 lines
9.2 KiB
JavaScript

const{chromium}=require('playwright'),assert=require('node:assert/strict');
(async()=>{const b=await chromium.launch();try{for(const pwa of[false,true]){
const c=await b.newContext({viewport:{width:1440,height:1000}});await c.addInitScript(()=>localStorage.setItem('plotdirector.desktop.v1.4',JSON.stringify({dismissedAt:Date.now()})));if(pwa)await c.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));await c.route('**/Writer/Work/State?*',r=>r.fulfill({json:{session:null,defaultPauseOnEdit:true}}));
const p=await c.newPage(),errors=[];let posts=0;p.on('request',r=>{if(r.method()==='POST'&&new URL(r.url()).pathname==='/WriterAuthoring/Save')posts++;});p.on('pageerror',e=>errors.push(e.message));const url='http://127.0.0.1:5238/Writer/Write?projectId=7&bookId=12&objective=true';await p.goto(url);await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus);await p.evaluate(()=>window.PlotDirectorNarrativeFocus.set({chapterID:21,sceneID:31}));await p.locator('[data-key="Scene-31"]').waitFor();assert((await p.locator('[data-authoring-references]').textContent()).includes('Fixture character'));
const help=p.locator('[data-help-key="writer3.authoring"] button');await help.click();await p.locator('.plotline-help-popover').waitFor();assert((await p.locator('.plotline-help-popover').textContent()).includes('More...'));await p.locator('.plotline-help-more').click();await p.locator('[data-help-content] .help-drawer-article').waitFor();assert((await p.locator('[data-help-content]').textContent()).includes('Cancel'));await p.locator('[data-help-close]').click();
const card=k=>p.locator(`[data-key="${k}"]`),edit=async k=>{await card(k).getByRole('button',{name:/^Edit|^Add/}).first().click();},save=async k=>{const before=posts;await card(k).locator('[data-authoring-form]').evaluate(n=>{n.requestSubmit();n.requestSubmit();});await card(k).locator('[data-authoring-status]').filter({hasText:'Saved.'}).waitFor();assert.equal(posts,before+1,'duplicate submit is ignored');};
await edit('Scene-31');await card('Scene-31').locator('[name=ScenePurposeNotes]').fill('Unsaved cancellation');await card('Scene-31').locator('[data-authoring-cancel]').click();assert(!(await card('Scene-31').textContent()).includes('Unsaved cancellation'));
await edit('Scene-31');await card('Scene-31').locator('[name=ScenePurposeNotes]').fill('Unicode intention — 界 <script>text only</script>');await card('Scene-31').locator('[name=SceneOutcomeNotes]').fill('A different ending');
await p.getByText('Chapter summary and additional intentions',{exact:true}).click();await edit('Goals-21');await card('Goals-21').locator('[name=GoalSummary]').fill('Keep unrelated unsaved goal');await save('Scene-31');assert.equal(await card('Goals-21').locator('[name=GoalSummary]').inputValue(),'Keep unrelated unsaved goal');assert(await card('Goals-21').locator('[data-authoring-form]').isVisible());assert((await card('Scene-31').locator('[data-authoring-display]').textContent()).includes('<script>text only</script>'));await save('Goals-21');
await edit('Chapter-21');await card('Chapter-21').locator('[name=Summary]').fill('Chapter summary inline');await card('Chapter-21').locator('[name=ChapterPurposeID]').selectOption('1');await save('Chapter-21');
await edit('AddNote-0');await card('AddNote-0').locator('[name=NoteText]').fill('Remember the recorded detail');await card('AddNote-0').locator('[name=NoteTitle]').fill('Inline note');await save('AddNote-0');const note=p.locator('[data-authoring-new-records] [data-kind=Note]').last();await note.getByRole('button',{name:/^Edit/}).click();await note.locator('[name=NoteText]').fill('Edited note');await note.locator('[data-authoring-save]').click();await p.locator('[data-authoring-new-records] [data-kind=Note]').last().locator('[data-authoring-status]').filter({hasText:'Saved.'}).waitFor();
await edit('AddChecklist-0');await card('AddChecklist-0').locator('[name=ItemText]').fill('A reminder');await save('AddChecklist-0');
await p.getByText('Scene notes, reminders and working details',{exact:true}).click();await edit('Workflow-31');await card('Workflow-31').locator('[name=Priority]').fill('11');await card('Workflow-31').locator('[data-authoring-save]').click();await card('Workflow-31').locator('[data-authoring-error]:visible').waitFor();assert.equal(await card('Workflow-31').locator('[name=Priority]').inputValue(),'11');await card('Workflow-31').locator('[name=Priority]').fill('2');await card('Workflow-31').locator('[name=IsBlocked]').check();await save('Workflow-31');
await edit('Scene-31');await card('Scene-31').locator('[name=ScenePurposeNotes]').fill('Retain after network failure');await p.route('**/WriterAuthoring/Save',r=>r.fulfill({status:503,body:'temporarily unavailable'}));await card('Scene-31').locator('[data-authoring-save]').click();await card('Scene-31').locator('[data-authoring-error]:visible').waitFor();assert.equal(await card('Scene-31').locator('[name=ScenePurposeNotes]').inputValue(),'Retain after network failure');await p.unroute('**/WriterAuthoring/Save');await card('Scene-31').locator('[data-authoring-cancel]').click();
// A second page commits first; the original editor must retain its stale unsaved text with409.
await edit('Scene-31');await card('Scene-31').locator('[name=ScenePurposeNotes]').fill('Stale unsaved intention');const q=await c.newPage();await q.goto(url);const other=q.locator('[data-key="Scene-31"]');await other.locator('[data-authoring-edit]').click();await other.locator('[name=ScenePurposeNotes]').fill('Concurrent author change');await other.locator('[data-authoring-save]').click();await other.locator('[data-authoring-status]').filter({hasText:'Saved.'}).waitFor();await q.close();await card('Scene-31').locator('[data-authoring-save]').click();await card('Scene-31').locator('[data-authoring-reload]:visible').waitFor();assert.equal(await card('Scene-31').locator('[name=ScenePurposeNotes]').inputValue(),'Stale unsaved intention');
p.once('dialog',d=>d.dismiss());await p.locator('#ribbon-panel-writer').getByRole('link',{name:'Explore',exact:true}).click();assert(new URL(p.url()).pathname==='/Writer/Write');await card('Scene-31').locator('[data-authoring-cancel]').click();
const session={sessionID:'33333333-3333-3333-3333-333333333333',kind:'AudioReview',bookID:12,chapterID:22,chapterTitle:'Bound audio chapter',startedUtc:new Date().toISOString(),engagedSeconds:60,playbackSeconds:20,uniqueSeconds:10,pauseOnEdit:true,live:true,playbackState:'playing',capabilities:'play,pause,back15,forward15',sequence:1};await p.route('**/Writer/Work/State?*',r=>r.fulfill({json:{session}}));await p.goto(url);await p.locator('[data-work-audio]:visible').waitFor();await card('Scene-31').waitFor();assert(await p.locator('.writer3-session-block').evaluate(n=>n.nextElementSibling?.matches('[data-writer-authoring]')),'active controls remain above authoring');const work=await p.locator('[data-writer-work]').elementHandle();await p.locator('[data-work-note]').fill('Unsaved audio return note');await edit('Scene-31');await card('Scene-31').locator('[name=SceneOutcomeNotes]').fill('An explicit outcome during audio review');await save('Scene-31');assert(await work.evaluate(n=>n===document.querySelector('[data-writer-work]')));assert.equal(await p.locator('[data-work-note]').inputValue(),'Unsaved audio return note');assert((await p.locator('[data-work-bound]').textContent()).includes('Bound audio chapter'));assert.equal(await p.locator('[data-work-start] select').count(),2,'Windows baseline retains independent recording activity and chapter controls');
await p.setViewportSize({width:390,height:844});const companionToggle=p.locator('[data-writer-companion-toggle]');for(const menu of await companionToggle.locator('xpath=ancestor::details').all()){if(!await menu.evaluate(n=>n.open))await menu.locator(':scope > summary').click();}await companionToggle.click();assert(await p.locator('[data-authoring-references]').isVisible());await p.keyboard.press('Escape');assert(await p.locator('.writer3-reference').isHidden());assert(await p.locator('[data-authoring-content]').isVisible());
await p.goto(url+'&chapterOnly=true');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus);await p.evaluate(()=>window.PlotDirectorNarrativeFocus.set({chapterID:21}));await p.locator('[data-key="Goals-21"]').waitFor();assert.equal(await p.locator('[data-key="Scene-31"]').count(),0);assert(await p.getByRole('button',{name:'Go to scene'}).isVisible());
await p.goto('http://127.0.0.1:5238/Writer/Write?projectId=7&bookId=13');assert(await p.locator('[data-writer-authoring]').isHidden(),'book switching hides unavailable support fields');assert.equal(await p.locator('[data-writer-authoring] [data-authoring-form]').count(),0,'book switching cannot keep old support fields');assert.equal((await p.request.get('http://127.0.0.1:5238/WriterAuthoring/Inspect?bookId=13&chapterId=21&sceneId=31')).status(),404);assert.deepEqual(errors,[]);await c.close();}
console.log('PASS Writer3 authoring browser/simulated PWA: scene/chapter/goal editing, Cancel, escaped Unicode, unrelated dirty fields, note/reminder creation/edit, workflow validation, stale409 retention, navigation guard, chapter-only focus, scope and companion overlay.');
}finally{await b.close()}})().catch(e=>{console.error(e.stack);process.exitCode=1});