PlotDirector/PlotLine.Tests/Browser/house-theme-seed.cjs

10 lines
2.5 KiB
JavaScript

// Dedicated Development verification account only; never prints credentials or manuscript content.
const {chromium}=require('playwright'),fs=require('node:fs'),assert=require('node:assert/strict');
(async()=>{const file=process.argv[2];assert(file?.startsWith('/tmp/pd-dev-browser-'));const id=JSON.parse(fs.readFileSync(file));assert.equal(id.Database,'PlotDirector_Development');assert(id.Email.startsWith('pwa-browser-'));const b=await chromium.launch();let stage='login';try{const p=await b.newPage();await p.route('**/Appearance/Theme',r=>r.fulfill({json:{themeKey:'warm-light'}}));await p.goto('https://dev.plotdirector.com/Account/Login');await p.locator('[name=Email]').fill(id.Email);await p.locator('[name=Password]').fill(id.Password);await p.locator('form button[type=submit]').click();await p.waitForURL('**/Projects');
async function save(){await Promise.all([p.waitForNavigation(),p.locator('main form button[type=submit]').first().click()]);assert(!await p.locator('.validation-summary-errors').count());}
if(!id.ProjectID){stage='project';await p.goto('https://dev.plotdirector.com/Projects/Create');await p.locator('[name=ProjectName]').fill('House Theme Verification');await save();id.ProjectID=Number(new URL(p.url()).pathname.split('/').at(-1));assert(id.ProjectID>0);fs.writeFileSync(file,JSON.stringify(id),{mode:0o600});}
if(!id.BookID){stage='book';await p.goto('https://dev.plotdirector.com/Books/Create?projectId='+id.ProjectID);await p.locator('[name=BookTitle]').fill('The Glass Harbour');await save();id.BookID=Number(new URL(p.url()).pathname.split('/').at(-1));assert(id.BookID>0);fs.writeFileSync(file,JSON.stringify(id),{mode:0o600});}
if(!id.ChapterID){stage='chapter';await p.goto('https://dev.plotdirector.com/Chapters/Create?bookId='+id.BookID);await p.locator('[name=ChapterTitle]').fill('The Unopened Letter');await save();id.ChapterID=Number(new URL(p.url()).pathname.split('/').at(-1));assert(id.ChapterID>0);fs.writeFileSync(file,JSON.stringify(id),{mode:0o600});}
await p.goto('https://dev.plotdirector.com/Scenes/Create?chapterId='+id.ChapterID);console.log('Fixture project/book/chapter created through Development UI. Scene create controls:',await p.locator('form').evaluateAll(fs=>fs.map(f=>({action:f.getAttribute('action'),fields:[...f.querySelectorAll('input,select,textarea')].map(i=>i.name).filter(n=>!n.includes('Token'))})).filter(f=>f.fields.some(n=>n.includes('Scene')))));
}catch(e){console.error('Failed stage',stage,e.message);process.exitCode=1;}finally{await b.close();}})();