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

22 lines
9.7 KiB
JavaScript

// Explicit writes only to a dedicated disposable Development fixture; no native Word automation.
const{chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs');
(async()=>{const w=JSON.parse(fs.readFileSync(process.env.PD_WRITER3_IDENTITY));assert(w.Database==='PlotDirector_Development'&&w.Email.endsWith('@example.invalid'));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(id=>localStorage.setItem('plotdirector.desktop.v1.'+id,JSON.stringify({dismissedAt:Date.now()})),w.UserID);if(pwa)await c.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));const p=await c.newPage(),errors=[];p.on('pageerror',e=>errors.push(e.message));const base='https://dev.plotdirector.com',url=`${base}/Writer/Write?projectId=${w.project}&bookId=${w.book}`;
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()]);
await p.goto(url);const sceneKey='Scene-'+w.scene,goalKey='Goals-'+w.chapter,chapterKey='Chapter-'+w.chapter,workflowKey='Workflow-'+w.scene;const card=k=>p.locator(`[data-key="${k}"]`),edit=async k=>{await card(k).locator('[data-authoring-edit]').click();},save=async k=>{await card(k).locator('[data-authoring-save]').click();await card(k).locator('[data-authoring-status]').filter({hasText:'Saved.'}).waitFor();};await card(sceneKey).waitFor();assert.equal(await p.locator('[data-writer-work]').count(),1);assert((await p.locator('[data-authoring-references]').textContent()).includes('Recorded reference person'));assert((await p.locator('[data-authoring-references]').textContent()).includes('Recorded reference place'));
await edit(sceneKey);await card(sceneKey).locator('[name=ScenePurposeNotes]').fill('Explicit fixture intention — '+ '界'.repeat(4500));await card(sceneKey).locator('[name=SceneOutcomeNotes]').fill('An explicitly recorded outcome');await save(sceneKey);await edit(sceneKey);assert((await card(sceneKey).locator('[name=ScenePurposeNotes]').inputValue()).length>4500);await card(sceneKey).locator('[name=ScenePurposeNotes]').fill('Establish the next development and give the scene a clear direction.');await save(sceneKey);
await p.getByText('Chapter summary and additional intentions',{exact:true}).click();await edit(chapterKey);await card(chapterKey).locator('[name=Summary]').fill('A chapter summary entered through Write');await save(chapterKey);await edit(goalKey);await card(goalKey).locator('[name=GoalSummary]').fill('A chapter goal entered through Write');await card(goalKey).locator('[name=EmotionalGoal]').fill('A recorded feeling intention');await card(goalKey).locator('[name=MustInclude]').fill('An important detail');await save(goalKey);assert((await p.locator('[data-authoring-references]').textContent()).includes('recorded feeling intention'));
await edit('AddNote-0');await card('AddNote-0').locator('[name=NoteTitle]').fill('Disposable inline note');await card('AddNote-0').locator('[name=NoteText]').fill('Remember this saved scene detail');await save('AddNote-0');const note=p.locator('[data-authoring-new-records] [data-kind=Note]').last();await note.locator('[data-authoring-edit]').click();await note.locator('[name=NoteText]').fill('Edited saved 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 saved reminder');await save('AddChecklist-0');const reminder=p.locator('[data-authoring-new-records] [data-kind=Checklist]').last();await reminder.locator('[data-authoring-edit]').click();await reminder.locator('[name=IsCompleted]').check();await reminder.locator('[data-authoring-save]').click();await p.locator('[data-authoring-new-records] [data-kind=Checklist]').last().locator('[data-authoring-status]').filter({hasText:'Saved.'}).waitFor();
await p.getByText('All scene notes, reminders and working details',{exact:true}).click();await edit(workflowKey);await card(workflowKey).locator('[name=Priority]').fill('11');await card(workflowKey).locator('[data-authoring-save]').click();await card(workflowKey).locator('[data-authoring-error]:visible').waitFor();assert.equal(await card(workflowKey).locator('[name=Priority]').inputValue(),'11');await card(workflowKey).locator('[name=Priority]').fill('2');await card(workflowKey).locator('[name=IsBlocked]').check();await card(workflowKey).locator('[name=BlockedReason]').fill('An explicitly recorded blocker');await save(workflowKey);
await p.locator('[data-record-focus]:enabled').waitFor();await p.locator('[data-record-focus]').click();await p.locator('[data-work-current]:visible').waitFor();const readSession=async()=>await(await p.request.get(`${base}/Writer/Work/State?bookId=${w.book}`)).json();const active=(await readSession()).session;await p.locator('[data-work-note]').fill('Return note retained during inline save');await edit(sceneKey);await card(sceneKey).locator('[name=SceneOutcomeNotes]').fill('Outcome edited during a real recording');await save(sceneKey);assert.equal((await readSession()).session.sessionID,active.sessionID);assert.equal((await readSession()).session.chapterID,w.chapter);assert.equal(await p.locator('[data-work-note]').inputValue(),'Return note retained during inline save');await p.locator('[data-work-end]').click();await p.locator('[data-work-current]').waitFor({state:'hidden'});
await edit(sceneKey);await card(sceneKey).locator('[name=SceneOutcomeNotes]').fill('Stale unsaved outcome');const q=await c.newPage();await q.goto(url);const other=q.locator(`[data-key="${sceneKey}"]`);await other.locator('[data-authoring-edit]').click();await other.locator('[name=SceneOutcomeNotes]').fill('A concurrent recorded outcome');await other.locator('[data-authoring-save]').click();await other.locator('[data-authoring-status]').filter({hasText:'Saved.'}).waitFor();await q.close();await card(sceneKey).locator('[data-authoring-save]').click();await card(sceneKey).locator('[data-authoring-reload]:visible').waitFor();assert.equal(await card(sceneKey).locator('[name=SceneOutcomeNotes]').inputValue(),'Stale unsaved outcome');await card(sceneKey).locator('[data-authoring-cancel]').click();await p.reload();await card(sceneKey).waitFor();assert((await card(sceneKey).locator('[data-authoring-display]').textContent()).includes('concurrent recorded outcome'));
const token=await card(sceneKey).locator('[name=__RequestVerificationToken]').inputValue();assert.equal((await p.request.post(base+'/WriterAuthoring/Save',{form:{bookId:String(w.book),chapterId:String(w.chapter),sceneId:String(w.scene),kind:'Scene',entityId:String(w.scene),version:'0'.repeat(64),__RequestVerificationToken:token}})).status(),409);assert.equal((await p.request.post(base+'/WriterAuthoring/Save',{form:{bookId:String(w.book),chapterId:String(w.chapter),sceneId:String(w.scene),kind:'Scene',entityId:String(w.scene)}})).status(),400);assert.equal((await p.request.get(`${base}/WriterAuthoring/Inspect?bookId=${w.other}&chapterId=${w.chapter}&sceneId=${w.scene}`)).status(),404);
if(!pwa&&process.env.PD_WRITER3_SCREENSHOTS){fs.mkdirSync(process.env.PD_WRITER3_SCREENSHOTS,{recursive:true});await p.evaluate(()=>window.PlotDirectorApplyApplicationTheme('modern-dark'));await p.locator('.writer3-main').evaluate(n=>n.scrollTop=0);await p.screenshot({path:process.env.PD_WRITER3_SCREENSHOTS+'/Write-authoring.png',animations:'disabled'});await edit(sceneKey);await card(sceneKey).locator('[data-authoring-form]').scrollIntoViewIfNeeded();await p.screenshot({path:process.env.PD_WRITER3_SCREENSHOTS+'/Write-inline-editor.png',animations:'disabled'});await card(sceneKey).locator('[data-authoring-cancel]').click();}
// Chapter-level focus has goals and scene choices without forcing a scene.
await p.goto(url+'&setup=true');await p.locator('[data-objective-scene]').selectOption('');await Promise.all([p.waitForURL(u=>u.pathname==='/Writer/Write'&&!u.searchParams.has('setup')),p.locator('[data-save-focus]').click()]);await card(goalKey).waitFor();assert.equal(await p.locator(`[data-key="${sceneKey}"]`).count(),0);assert(await p.getByRole('button',{name:'Work on this scene'}).isVisible());await Promise.all([p.waitForURL(u=>u.pathname==='/Writer/Write'&&!u.searchParams.has('setup')),p.getByRole('button',{name:'Work on this scene'}).click()]);await card(sceneKey).waitFor();
if(w.emptyChapter){await p.goto(url+'&setup=true');await p.locator('[data-objective-chapter]').selectOption(String(w.emptyChapter));await Promise.all([p.waitForURL(u=>u.pathname==='/Writer/Write'&&!u.searchParams.has('setup')),p.locator('[data-save-focus]').click()]);await p.getByText('There are no scenes yet.',{exact:false}).waitFor();assert.equal(await p.locator('[data-key="Scene-'+w.scene+'"]').count(),0);await p.goto(url+'&setup=true');await p.locator('[data-objective-chapter]').selectOption(String(w.chapter));await p.locator('[data-objective-scene]').selectOption(String(w.scene));await Promise.all([p.waitForURL(u=>u.pathname==='/Writer/Write'&&!u.searchParams.has('setup')),p.locator('[data-save-focus]').click()]);await card(sceneKey).waitFor();}
assert.deepEqual(errors,[]);await c.close();}
console.log('PASS authenticated Development authoring browser/simulated PWA: actual canonical chapter/scene/goals, long Unicode, note/reminder create/edit, workflow validation, explicit session and note isolation, stale409 retained text, chapter focus/scene selection, scope404 and antiforgery400; explicit disposable fixture edits only.');
}finally{await b.close()}})().catch(e=>{console.error(e.message);process.exitCode=1});