Files
AtreidesAssetsFree/tests/ui/qr.test.mjs
T

48 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

2026-10-29 11:57:29 +01:00
// Generated, do not edit. sha256:ab76d1a13f8b51c7388dcb1a3adb5921cbdbf5323b484b6f86a9d79addf631f0
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { invoiceQrText, qrMatrix, qrSvg } from '../../client/ui/qr.js';
const ALFABET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l';
const INVOICE = `lnbc210u1p${Array.from({ length: 300 }, (_, i) => ALFABET[(i * 7) % 32]).join('')}`;
function finderOp(m, r0, c0) {
for (let r = 0; r < 7; r++) {
for (let c = 0; c < 7; c++) {
const rand = r === 0 || r === 6 || c === 0 || c === 6;
const midden = r >= 2 && r <= 4 && c >= 2 && c <= 4;
if (m[r0 + r][c0 + c] !== (rand || midden)) return false;
}
}
return true;
}
describe('de QR-code van een invoice', () => {
it('zet de invoice in hoofdletters achter LIGHTNING:', () => {
assert.equal(invoiceQrText('lnbc1abc'), 'LIGHTNING:LNBC1ABC');
});
it('is in hoofdletters duidelijk kleiner dan in kleine letters, want dat is de alfanumerieke modus', () => {
const groot = qrMatrix(`lightning:${INVOICE}`).length;
const klein = qrMatrix(invoiceQrText(INVOICE)).length;
assert.ok(klein < groot, `hoofdletters ${klein} modules, kleine letters ${groot}`);
});
it('is een vierkante matrix met de drie finder-patronen op hun plek', () => {
const m = qrMatrix(invoiceQrText(INVOICE));
const n = m.length;
assert.equal((n - 17) % 4, 0, 'een QR-versie heeft 17 + 4v modules');
assert.ok(m.every(rij => rij.length === n));
assert.ok(finderOp(m, 0, 0) && finderOp(m, 0, n - 7) && finderOp(m, n - 7, 0), 'een finder-patroon ontbreekt');
});
it('tekent de code met een stille zone van vier modules en een vaste maat', () => {
const n = qrMatrix(invoiceQrText(INVOICE)).length;
const svg = qrSvg(invoiceQrText(INVOICE), { label: 'a"b' });
assert.match(svg, new RegExp(`viewBox="0 0 ${n + 8} ${n + 8}"`));
assert.match(svg, /width="240" height="240"/);
assert.match(svg, /aria-label="a&quot;b"/, 'het label is niet geëscaped');
assert.match(svg, /<path d="M4 4h1v1h-1z/, 'de eerste donkere module staat niet op 4,4');
assert.doesNotMatch(svg, /style=/);
});
});