22 lines
5.1 KiB
JavaScript
22 lines
5.1 KiB
JavaScript
// Compiled main Names Razor and shared production scripts; disposable HTTP data only.
|
|
const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs'),os=require('node:os'),path=require('node:path');
|
|
(async()=>{
|
|
const installed=process.argv.includes('--installed'),profile=installed?fs.mkdtempSync(path.join(os.tmpdir(),'pd-names-pwa-')):null;
|
|
const persistent=installed?await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1920,height:1080}}):null;
|
|
const browser=installed?persistent.browser():await chromium.launch(),cdp=installed?await browser.newBrowserCDPSession():null,manifestId='http://127.0.0.1:5238/Projects';
|
|
let page;try{
|
|
if(installed){await persistent.pages()[0].goto('http://127.0.0.1:5238/fixture?page=calendar-test');await cdp.send('PWA.install',{manifestId,installUrlOrBundleUrl:'http://127.0.0.1:5238/fixture?page=calendar-test'});await cdp.send('PWA.changeAppUserSettings',{manifestId,displayMode:'standalone'});const opened=persistent.waitForEvent('page');await cdp.send('PWA.launch',{manifestId,url:'http://127.0.0.1:5238/fixture?page=calendar-test'});page=await opened;await page.waitForLoadState();assert(await page.evaluate(()=>matchMedia('(display-mode: standalone)').matches));}else page=await browser.newPage({viewport:{width:1920,height:1080}});
|
|
const errors=[],calls={search:0,details:0};page.on('pageerror',e=>errors.push(e.message));
|
|
await page.route('**/Names/Results?*',async route=>{calls.search++;const u=new URL(route.request().url());await route.fulfill({response:await page.request.get('http://127.0.0.1:5238/names-workspace-fixture/results?'+u.searchParams)});});
|
|
await page.route('**/Names/Details?*',async route=>{calls.details++;const u=new URL(route.request().url());await route.fulfill({response:await page.request.get('http://127.0.0.1:5238/names-workspace-fixture/details?'+u.searchParams)});});
|
|
await page.route('**/SharedFocus/**',route=>route.fulfill({json:{success:true}}));
|
|
await page.goto('http://127.0.0.1:5238/names-workspace-fixture/page');await page.locator('[data-name-select]').first().waitFor();assert.equal(calls.details,0);
|
|
await page.locator('[name=Search]').fill('George');await page.locator('[data-names-search]').evaluate(f=>f.requestSubmit());await page.waitForFunction(()=>document.querySelector('[data-name-select]')?.dataset.nameSelect==='George 1');
|
|
await page.locator('[data-name-select]').first().click();await page.locator('[data-name-details-fragment]').waitFor();assert.equal(await page.locator('.names-association').count(),2);assert((await page.locator('.names-details').innerText()).includes('Cat'));assert((await page.locator('.names-details').innerText()).includes('Known name / alias'));assert.equal(await page.locator('.names-association a').first().getAttribute('href'),'/Characters/Details/501');
|
|
fs.mkdirSync('/tmp/pd-names-workspace',{recursive:true});const measurements=[];
|
|
for(const width of [1280,1920,2560,3840,768,390]){await page.setViewportSize({width,height:1080});const m=await page.evaluate(()=>({width:innerWidth,overflow:document.documentElement.scrollWidth>innerWidth,workspace:document.querySelector('[data-names-workspace]').getBoundingClientRect().width,rowHeight:document.querySelector('.names-result').getBoundingClientRect().height,details:!!document.querySelector('[data-names-details]').getBoundingClientRect().width}));assert(!m.overflow);assert(m.rowHeight<=65);measurements.push(m);if(width===2560||width===390)await page.screenshot({path:`/tmp/pd-names-workspace/${installed?'pwa':'browser'}-${width}.png`});if(width===390){await page.locator('[data-names-back]').click();assert(await page.locator('[data-names-details]').isHidden());await page.locator('[data-name-select]').first().click();await page.locator('[data-name-details-fragment]').waitFor();assert(await page.locator('[data-names-results-host]').isHidden());}}
|
|
await page.setViewportSize({width:1920,height:1080});for(const theme of ['plotdirector','modern-light','modern-dark','warm-light','warm-dark','rose-pink','baby-blue']){await page.evaluate(theme=>{document.documentElement.dataset.appTheme=theme;document.documentElement.dataset.bsTheme=theme.endsWith('dark')?'dark':'light';document.documentElement.dataset.theme=theme.endsWith('dark')?'dark':'light';},theme);await page.screenshot({path:`/tmp/pd-names-workspace/${installed?'pwa':'browser'}-${theme}.png`});}
|
|
await page.reload();await page.locator('[data-name-details-fragment]').waitFor();assert.equal(await page.locator('[name=Search]').inputValue(),'George');assert.equal(await page.locator('[data-name-select][aria-pressed=true]').count(),1);assert.deepEqual(errors,[]);fs.writeFileSync(`/tmp/pd-names-workspace/${installed?'pwa':'browser'}-measurements.json`,JSON.stringify({measurements,calls},null,2));console.log('PASS Names compact results, deferred canonical details, animal/alias associations, navigation, state, themes, wide/narrow layouts',calls);
|
|
}finally{if(installed){await cdp.send('PWA.uninstall',{manifestId}).catch(()=>{});await persistent.close();fs.rmSync(profile,{recursive:true,force:true});}else await browser.close();}
|
|
})().catch(e=>{console.error(e);process.exitCode=1;});
|