32 lines
6.7 KiB
JavaScript
32 lines
6.7 KiB
JavaScript
// Normal Development login with an existing dedicated synthetic identity; no owner credentials.
|
|
const {chromium}=require('playwright'),fs=require('node:fs'),assert=require('node:assert/strict');
|
|
const file=process.argv[2];assert(file?.startsWith('/tmp/pd-dev-browser-'));const identity=JSON.parse(fs.readFileSync(file));assert.equal(identity.Database,'PlotDirector_Development');assert(identity.Email.startsWith('pwa-browser-'));
|
|
const base='https://dev.plotdirector.com',out=process.env.DOMAIN_EVIDENCE_DIR||'/tmp/plotdirector-app-domain-browser';fs.mkdirSync(out,{recursive:true});
|
|
(async()=>{const browser=await chromium.launch();const checks=[],errors=[];let page,originalTheme;const login=async()=>{await page.locator('#Email').fill(identity.Email);await page.locator('#Password').fill(identity.Password);await Promise.all([page.waitForNavigation(),page.locator('form button[type=submit]').click()]);};
|
|
try{const context=await browser.newContext({viewport:{width:1440,height:1000}});page=await context.newPage();await page.addInitScript(()=>document.addEventListener('context-connection-ready',()=>window.__qualificationSignalRConnected=true,true));page.on('pageerror',e=>errors.push(e.message));
|
|
await page.goto(base+'/');assert.equal(new URL(page.url()).pathname,'/Account/Login');assert(new URL(page.url()).searchParams.get('ReturnUrl')?.toLowerCase().startsWith('/projects')||new URL(page.url()).searchParams.get('returnUrl')?.toLowerCase().startsWith('/projects'));checks.push('unauthenticated root challenges with Projects return');
|
|
for(const route of ['/Account/Login','/Account/Register','/Account/ForgotPassword','/Account/ResendVerificationEmail','/Account/VerifyEmailConfirmation','/Account/ResetPassword?token=00000000-0000-0000-0000-000000000000','/Account/VerifyEmail?token=00000000-0000-0000-0000-000000000000','/Account/AccessDenied','/Account/Login?companion=true&returnUrl=/word-companion']){
|
|
const r=await page.goto(base+route);assert(r.status()<500,route);assert.equal(await page.locator('html').getAttribute('data-site-theme'),'public',route);assert.equal(await page.locator('html').getAttribute('data-theme'),'light',route);checks.push('branded '+route.split('?')[0]);
|
|
}
|
|
await page.goto(base+'/Projects');await login();assert.equal(new URL(page.url()).pathname,'/Projects');checks.push('normal login returns requested Projects');
|
|
await page.goto(base+'/');assert.equal(new URL(page.url()).pathname,'/Projects');checks.push('authenticated root lands on Projects');
|
|
const projectLink=await page.locator('a[href^="/Projects/Details/"]').first().getAttribute('href');assert(projectLink);const project=Number(projectLink.split('/').pop());
|
|
await page.goto(base+'/Account/Login?returnUrl='+encodeURIComponent(projectLink));assert.equal(new URL(page.url()).pathname,projectLink);checks.push('authenticated sign-in honors safe deep link');
|
|
await page.goto(base+'/Account/Login?returnUrl=https://example.invalid/');assert.equal(new URL(page.url()).pathname,'/Projects');checks.push('external return URL rejected');
|
|
originalTheme=await page.locator('html').getAttribute('data-app-theme');assert(originalTheme);
|
|
const setTheme=async theme=>{const token=await page.locator('[data-appearance-form] input[name="__RequestVerificationToken"]').inputValue();const r=await page.request.post(base+'/Appearance/Theme',{form:{themeKey:theme,__RequestVerificationToken:token}});assert.equal(r.status(),200);await page.reload();assert.equal(await page.locator('html').getAttribute('data-app-theme'),theme);};
|
|
for(const theme of ['plotdirector','warm-light','warm-dark','modern-light','modern-dark','rose-pink','baby-blue']){await setTheme(theme);checks.push('persisted theme '+theme);if(['modern-dark','warm-light'].includes(theme))await page.screenshot({path:out+'/projects-'+theme+'.png',fullPage:true});}
|
|
await setTheme(originalTheme);originalTheme=null;
|
|
await page.goto(base+projectLink);assert((await page.locator('main').innerText()).length>50);checks.push('existing synthetic project');
|
|
const bookLink=await page.locator('a[href^="/Books/Details/"]').first().getAttribute('href');assert(bookLink,'fixture book required');const book=Number(bookLink.split('/').pop());await page.goto(base+bookLink);assert((await page.locator('main').innerText()).length>50);checks.push('existing synthetic book/manuscript workspace');
|
|
const hub=[];page.on('request',r=>{if(r.url().includes('/hubs/'))hub.push(r.url().split('?')[0]);});
|
|
await page.goto(base+`/Writing/Context?projectId=${project}&bookId=${book}`);await page.locator('[data-context-workspace]').waitFor();await page.waitForFunction(()=>window.__qualificationSignalRConnected===true,null,{timeout:20000});await page.screenshot({path:out+'/context-workspace.png',fullPage:true});checks.push('real authenticated Context Workspace');assert(hub.length>0,'real SignalR negotiation');checks.push('real SignalR connection established');
|
|
await page.goto(base+'/word-companion');assert.equal(new URL(page.url()).pathname,'/word-companion');checks.push('Word taskpane route (browser only)');
|
|
await page.goto(base+'/ManageAccount/Subscription');assert.equal(new URL(page.url()).pathname,'/ManageAccount/Subscription');assert((await page.locator('main').innerText()).length>50);checks.push('existing subscription page; no payment initiated');
|
|
const manifest=await (await page.request.get(base+'/site.webmanifest')).json();assert.equal(manifest.start_url,'/Projects');assert.equal(manifest.scope,'/');assert.equal(manifest.id,'/Projects');checks.push('application-owned Projects PWA manifest');
|
|
const logout=page.locator('form[action="/Account/Logout"]').first();await Promise.all([page.waitForNavigation(),logout.evaluate(f=>f.requestSubmit())]);assert.equal(new URL(page.url()).pathname,'/Account/Login');assert.equal(await page.locator('html').getAttribute('data-site-theme'),'public');checks.push('logout returns branded application sign-in');
|
|
await page.goto(base+projectLink);assert.equal(new URL(page.url()).pathname,'/Account/Login');await login();assert.equal(new URL(page.url()).pathname,projectLink);checks.push('unauthenticated deep-link login returns requested project');
|
|
assert.deepEqual(errors,[]);fs.writeFileSync(out+'/results.json',JSON.stringify({passed:true,checks,errors,physicalWordTested:false,externalPaymentsTested:false,realEmailDeliveryTested:false},null,2));console.log(JSON.stringify({passed:true,checks:checks.length,out}));
|
|
}catch(e){fs.writeFileSync(out+'/results.json',JSON.stringify({passed:false,checks,errors,error:String(e)},null,2));throw e;}
|
|
finally{if(originalTheme&&page){try{const token=await page.locator('[data-appearance-form] input[name="__RequestVerificationToken"]').inputValue();await page.request.post(base+'/Appearance/Theme',{form:{themeKey:originalTheme,__RequestVerificationToken:token}});}catch{}}await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;});
|