This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { applyLayout, createDocument, createLayer, deterministicGlyphAngle, layoutDecoratedText, resolveToolTargets, selectCatalogItems, validateDocument } from '../src/index.js';
|
||||
|
||||
test('document and layers validate', () => {
|
||||
const doc=createDocument({layers:[createLayer('text',{text:'hello'})]});
|
||||
assert.equal(validateDocument(doc).valid,true);
|
||||
});
|
||||
test('glyph rotations are deterministic and bounded', () => {
|
||||
const input={documentSeed:'a',layerId:'b',index:3,glyph:'花',maxAngle:8};
|
||||
assert.equal(deterministicGlyphAngle(input),deterministicGlyphAngle(input));
|
||||
assert.ok(Math.abs(deterministicGlyphAngle(input))<=8);
|
||||
});
|
||||
test('decorated background grows with text', () => {
|
||||
const short=layoutDecoratedText('花',()=>20,{fontSize:40,background:{paddingX:10}});
|
||||
const long=layoutDecoratedText('花花花',()=>20,{fontSize:40,background:{paddingX:10}});
|
||||
assert.ok(long.background.width>short.background.width);
|
||||
});
|
||||
test('tag rules and layouts are deterministic', () => {
|
||||
assert.deepEqual(selectCatalogItems([{id:1,tags:['a','b']},{id:2,tags:['a','c']}],{all:['a'],none:['c']}).map(x=>x.id),[1]);
|
||||
assert.equal(applyLayout('two-top-large').length,2);
|
||||
});
|
||||
test('tool bindings target layers by id and dynamic tag', () => {
|
||||
const doc=createDocument({layers:[createLayer('background',{id:'base',tags:['base-user-42']}),createLayer('image',{id:'photo',tags:['photo']})],bindings:{tools:{adjust:{layerIds:['base'],tags:['base-{user.id}']}}}});
|
||||
assert.deepEqual(resolveToolTargets(doc,'adjust',{user:{id:42}}).map(item=>item.id),['base']);
|
||||
});
|
||||
Reference in New Issue
Block a user