PlotDirector/PlotLine.Tests/Browser/maps-appearance-engine.cjs

13 lines
1.5 KiB
JavaScript

const assert=require('node:assert/strict'),E=require('../../PlotLine/wwwroot/js/maps-appearance-engine.js');
for(const preset of ['light','paper','dark','custom']){
const map={appearanceJson:JSON.stringify({preset,backgroundColor:'#123456',landColor:'#efefef'})},before=JSON.stringify(map),p=E.palette(map);assert.match(p.backgroundColor,/^#[0-9a-f]{6}$/);assert.equal(JSON.stringify(map),before);assert.equal(p.story.length,3);
if(preset!=='custom')assert.deepEqual([p.backgroundColor,p.landColor],[E.presets[preset].backgroundColor,E.presets[preset].landColor]);else assert.equal(p.backgroundColor,'#123456');
}
assert.equal(E.palette({}).backgroundColor,'#c9dfdf','Existing maps retain their working canvas independently of UI theme');
const view={x:-600,y:-400,w:1200,h:800},image={imageID:'asset',width:1600,height:900},r=E.fit(image,view,45);
assert.equal(r.isLocked,true);assert.equal(r.opacity,.35);const boundsW=r.width*Math.SQRT1_2+r.height*Math.SQRT1_2;assert(boundsW<=view.w*.8+1e-8);
assert.deepEqual(E.transform(r,'move',[0,0],[20,30]),{...r,x:r.x+20,y:r.y+30});
assert.equal(E.transform({...r,rotation:0},'rotate',[1,0],[0,1]).rotation,90);const scaled=E.transform(r,'scale',[r.x+10,r.y],[r.x+20,r.y]);assert.equal(scaled.width,r.width*2);assert.equal(scaled.height,r.height*2);
assert.equal(E.reference({referenceJson:'{}'}),null);assert.equal(E.reference({referenceJson:JSON.stringify(r)}).imageID,'asset');
console.log('PASS Maps appearance presets/custom isolation, immutable palette, reference transforms and locked fit defaults');