139 lines
6.2 KiB
JavaScript
139 lines
6.2 KiB
JavaScript
// Generated, do not edit. sha256:98473478a698610a37641ee7064cdcff85c79c660b5b718e10f48d841ac3bc61
|
|
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { CONFIG, ENUMS } from '../../shared/config.js';
|
|
import { motionMode, nextDelayMs, driftTransform, nextCore, tempoOf, showerMs, bandTile, BAND_LAYERS } from '../../client/ui/aurora.js';
|
|
|
|
const vast = v => () => v;
|
|
|
|
describe('motionMode', () => {
|
|
const glas = { profile: 'glass', glow: 'on' };
|
|
|
|
it('volgt de voorkeur in Glas met de gloed aan', () => {
|
|
assert.equal(motionMode({ ...glas, motion: 'step' }), 'step');
|
|
assert.equal(motionMode({ ...glas, motion: 'always' }), 'always');
|
|
assert.equal(motionMode({ ...glas, motion: 'off' }), 'off');
|
|
});
|
|
|
|
it('staat stil bij minder beweging, een verborgen tabblad, Zakelijk of de gloed uit', () => {
|
|
assert.equal(motionMode({ ...glas, motion: 'always', reducedMotion: true }), 'off');
|
|
assert.equal(motionMode({ ...glas, motion: 'always', hidden: true }), 'off');
|
|
assert.equal(motionMode({ profile: 'business', glow: 'on', motion: 'always' }), 'off');
|
|
assert.equal(motionMode({ profile: 'glass', glow: 'off', motion: 'always' }), 'off');
|
|
});
|
|
|
|
it('valt op stil terug bij een onbekende waarde', () => {
|
|
assert.equal(motionMode({ ...glas, motion: 'wild' }), 'off');
|
|
});
|
|
});
|
|
|
|
describe('nextDelayMs', () => {
|
|
it('is de verplaatsing plus een pauze binnen de grenzen van het tempo', () => {
|
|
for (const key of ENUMS.GLOW_TEMPO) {
|
|
const t = CONFIG.GLOW_TEMPO[key];
|
|
assert.equal(nextDelayMs(t, vast(0)), (t.MOVE_S + t.PAUSE_MIN_S) * 1000, key);
|
|
assert.equal(nextDelayMs(t, vast(0.999999)), Math.round((t.MOVE_S + t.PAUSE_MIN_S + 0.999999 * (t.PAUSE_MAX_S - t.PAUSE_MIN_S)) * 1000), key);
|
|
}
|
|
});
|
|
|
|
it('heeft een tempo voor elke waarde van de voorkeur, en Rustig als terugval', () => {
|
|
assert.deepEqual(Object.keys(CONFIG.GLOW_TEMPO), [...ENUMS.GLOW_TEMPO]);
|
|
assert.equal(tempoOf('onzin'), CONFIG.GLOW_TEMPO.calm);
|
|
assert.deepEqual({ ...CONFIG.GLOW_TEMPO.calm }, { MOVE_S: 24, PAUSE_MIN_S: 45, PAUSE_MAX_S: 90, ALWAYS_MULT: 2 });
|
|
});
|
|
});
|
|
|
|
describe('driftTransform', () => {
|
|
it('blijft binnen het gebied van de bol', () => {
|
|
const gebied = { x: [-45, -5], y: [-40, -5] };
|
|
assert.match(driftTransform(gebied, vast(0)), /^translate\(-45\.0vw,-40\.0vh\) rotate\(-16\.0deg\) scale\(0\.850,0\.850\)$/);
|
|
assert.match(driftTransform(gebied, vast(1)), /^translate\(-5\.0vw,-5\.0vh\) rotate\(16\.0deg\) scale\(1\.200,1\.200\)$/);
|
|
});
|
|
});
|
|
|
|
describe('driftTransform met wegzakken', () => {
|
|
const gebied = { x: [-38, 38], y: [-38, -4], sink: 0.3 };
|
|
|
|
it('zakt weg als de eerste trekking onder de kans valt', () => {
|
|
assert.match(driftTransform(gebied, vast(0.1)), /^translate\(-30\.4vw,80\.0vh\)/);
|
|
});
|
|
|
|
it('blijft binnen zijn gebied als hij niet wegzakt', () => {
|
|
assert.match(driftTransform(gebied, vast(0.5)), /^translate\(0\.0vw,-21\.0vh\)/);
|
|
});
|
|
});
|
|
|
|
describe('nextCore', () => {
|
|
it('maakt van een kern weer een vlek', () => {
|
|
assert.equal(nextCore([true, false, false], 0, vast(0)), false);
|
|
});
|
|
|
|
it('geeft nooit een tweede kern zolang er een is', () => {
|
|
assert.equal(nextCore([false, true, false], 0, vast(0)), false);
|
|
assert.equal(nextCore([false, false, true], 1, vast(0)), false);
|
|
});
|
|
|
|
it('geeft een vlek soms een kern, met de kans uit de config', () => {
|
|
const kans = CONFIG.GLOW_CORE_CHANCE;
|
|
assert.equal(nextCore([false, false, false], 1, vast(kans - 0.01)), true);
|
|
assert.equal(nextCore([false, false, false], 1, vast(kans)), false);
|
|
});
|
|
});
|
|
|
|
describe('showerMs', () => {
|
|
it('is bij een bui twee verplaatsingen lang, en daarna een pauze binnen de grenzen van het tempo', () => {
|
|
const t = CONFIG.GLOW_TEMPO.calm;
|
|
assert.equal(showerMs(t, true, vast(0.5)), t.MOVE_S * 2 * 1000);
|
|
assert.equal(showerMs(t, false, vast(0)), t.PAUSE_MIN_S * 1000);
|
|
assert.equal(showerMs(t, false, vast(1)), t.PAUSE_MAX_S * 1000);
|
|
});
|
|
});
|
|
|
|
describe('bandTile', () => {
|
|
const rects = spec => {
|
|
const svg = decodeURIComponent(bandTile(spec).slice('url("data:image/svg+xml;utf8,'.length, -2));
|
|
return [...svg.matchAll(/<rect x="([\d.-]+)" y="([\d.-]+)" width="([\d.]+)" height="([\d.]+)"/g)]
|
|
.map(m => ({ x: Number(m[1]), y: Number(m[2]), w: Number(m[3]), h: Number(m[4]) }));
|
|
};
|
|
|
|
it('herhaalt naadloos: een baan waarvan de waas over de boven- of onderrand loopt, staat ook aan de andere kant', () => {
|
|
for (const spec of BAND_LAYERS) {
|
|
const all = rects(spec), halo = spec.blur * 3;
|
|
const at = (x, y) => all.some(r => r.x === x && Math.abs(r.y - y) < 0.2);
|
|
for (const r of all.filter(r => r.y >= 0 && r.y < spec.h)) {
|
|
if (r.y + r.h + halo > spec.h) assert.ok(at(r.x, r.y - spec.h), `seed ${spec.seed}: geen kopie boven voor x=${r.x}`);
|
|
if (r.y - halo < 0) assert.ok(at(r.x, r.y + spec.h), `seed ${spec.seed}: geen kopie onder voor x=${r.x}`);
|
|
}
|
|
}
|
|
});
|
|
|
|
it('houdt de waas binnen de zijkanten van de tegel', () => {
|
|
for (const spec of BAND_LAYERS) {
|
|
for (const r of rects(spec)) {
|
|
assert.ok(r.x >= spec.blur * 3 && r.x + r.w <= spec.w - spec.blur * 3, `seed ${spec.seed}: baan op x=${r.x} raakt de zijkant`);
|
|
}
|
|
}
|
|
});
|
|
|
|
it('tekent elke laag bij elke start hetzelfde, met het aantal banen uit de laag', () => {
|
|
for (const spec of BAND_LAYERS) {
|
|
assert.equal(bandTile(spec), bandTile(spec));
|
|
assert.equal(rects(spec).filter(r => r.y >= 0 && r.y < spec.h).length, spec.count);
|
|
}
|
|
});
|
|
|
|
it('heeft geen heldere onderkant: een baan dooft aan beide uiteinden uit', () => {
|
|
const svg = decodeURIComponent(bandTile(BAND_LAYERS[0]));
|
|
assert.match(svg, /<stop offset="0" stop-color="#fff" stop-opacity="0"\/>/);
|
|
assert.match(svg, /<stop offset="1" stop-color="#fff" stop-opacity="0"\/>/);
|
|
});
|
|
|
|
it('valt uit de rechterbovenhoek, en wordt naar voren breder en onscherper', () => {
|
|
for (const spec of BAND_LAYERS) assert.ok(spec.tilt > 0, `seed ${spec.seed} valt niet vanuit rechts`);
|
|
for (let i = 1; i < BAND_LAYERS.length; i++) {
|
|
assert.ok(BAND_LAYERS[i].width[0] > BAND_LAYERS[i - 1].width[1], 'een voorste laag is niet breder');
|
|
assert.ok(BAND_LAYERS[i].blur > BAND_LAYERS[i - 1].blur, 'een voorste laag is niet onscherper');
|
|
}
|
|
});
|
|
});
|