Files

30 lines
3.8 KiB
JavaScript
Raw Permalink Normal View History

// Uses the deployed Foundry ApplicationV2 renderer, with in-memory sample documents.
// Does not log in, install anything, update a world or connect to MA.
import {readFile,writeFile,mkdir} from 'node:fs/promises';
import {resolve} from 'node:path';
import assert from 'node:assert/strict';
const {chromium}=await import(process.env.AM_PLAYWRIGHT_MODULE??'playwright');
const root=resolve(import.meta.dirname,'..'),config=JSON.parse(await readFile('.local/live-environment.json','utf8'));
const browser=await chromium.launch({headless:true,args:['--no-sandbox']});const page=await browser.newPage({viewport:{width:1440,height:1000}});
try{
await page.route(config.foundry+'/adaptive-music-development/**',async route=>{const rel=new URL(route.request().url()).pathname.slice('/adaptive-music-development/'.length),file=resolve(root,rel);if(!file.startsWith(root+'/src/'))return route.abort();try{await route.fulfill({contentType:'text/javascript',body:await readFile(file)});}catch{await route.abort();}});
await page.goto(config.foundry,{waitUntil:'domcontentloaded'});await page.waitForFunction(()=>globalThis.foundry?.applications?.api?.ApplicationV2);
await page.addStyleTag({content:await readFile('styles/adaptive-music.css','utf8')});
const details=await page.evaluate(async()=>{
const {createSetupClass}=await import('/adaptive-music-development/src/foundry/setup.mjs');
const {ReceiverVault}=await import('/adaptive-music-development/src/foundry/receiver-vault.mjs');
const collection=items=>{const m=new Map(items.map(i=>[i.id,i]));m[Symbol.iterator]=function*(){yield*m.values();};return m;};
const fixtureGame={world:{id:'ui-test',title:'UI test'},user:{isGM:true},settings:{get:(ns,key)=>({ownedPlaylistIds:'',musicDefaults:{},enabled:false})[key]},playlists:collection([]),scenes:collection([]),combats:[]};
const connection={status:{state:'disconnected',catalog:0,audioContext:'closed'},test:async()=>{},connect:async()=>{},refresh:async()=>{},resume:async()=>{},disconnect:async()=>{}};
const Setup=createSetupClass({game:fixtureGame,connection,getChoices:async()=>[],start(){},stop(){},setOverrides(){},onError(){}});window.testApplication=new Setup();await window.testApplication.render({force:true});
const scope={campaign:'isolated-ui-test',userId:'isolated-test-gm',maUrl:'https://ma.example.test'};
const vault=new ReceiverVault();await vault.save(scope,{identityStorage:{'sendspin-identity-sk':'A'.repeat(43)},targetName:'Test receiver',catalogKey:'fixture-key',namespace:'test',token:'must-never-be-stored'});
const record=await new ReceiverVault().load(scope);const other=await vault.load({...scope,userId:'other-gm'});await vault.forget(scope);
return {applicationV2:true,version:game.version,receiverVault:{reopened:record.identityStorage['sendspin-identity-sk']==='A'.repeat(43),tokenExcluded:!Object.hasOwn(record,'token'),userIsolation:other===null,forgotten:await vault.load(scope)===null}};
});
assert.ok(Object.values(details.receiverVault).every(Boolean));const sizes=[];
for(const width of [380,640]){await page.evaluate(width=>window.testApplication.setPosition({width}),width);await page.waitForTimeout(100);const fits=await page.locator('#adaptive-music-setup .adaptive-music-setup').evaluate(el=>el.scrollWidth<=el.clientWidth+1);assert.equal(fits,true);sizes.push({width,fits});}
await mkdir('dist/previews',{recursive:true});await page.screenshot({path:'dist/previews/foundry-v14-setup.png'});
const report={at:new Date().toISOString(),scope:'actual deployed Foundry ApplicationV2 before login, in-memory sample documents; no world writes or MA connection',browser:browser.version(),...details,sizes,passed:true};
await writeFile('evidence/foundry-application-v070.json',JSON.stringify(report,null,2)+'\n');console.log(JSON.stringify(report,null,2));
}finally{await browser.close();}