Files
dawnline/web/tests/qr.test.ts
T
Aemeath b0d9982796
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions
Dawnline 0.16.3
- Move Dawnline to Services in LuCI and update links and documentation.
- Make activity messages clearer, including device renames and person-specific history.
- Prune redundant frontend tests.
2026-10-31 12:21:53 +03:00

38 lines
1.5 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { denseQr, qrFits, qrSvg, scannable } from '../src/shared/qr';
const LINK = 'https://engage.example.eu:4500/abcdef-ghijkl-mnopqr';
const KEY = `vpn://${'A1b2C3d4'.repeat(180)}`;
/** An AmneziaVPN key on Maximum where the browser cannot compress it: past what version 40-L holds. */
const HUGE = 'A1b2C3d4'.repeat(425);
describe('qr', () => {
it('omits the centre mark on dense codes', () => {
const link = qrSvg(LINK, 3, true, 'night');
// The mark's light tile on a short code, none on a dense one.
expect(link).toContain('<g transform');
expect(denseQr(KEY)).toBe(true);
expect(qrSvg(KEY, 3, true, 'night')).not.toContain('<g transform');
});
it('says a 3.4 KB text does not fit instead of throwing, and keeps it from the camera', () => {
expect(qrFits(HUGE)).toBe(false);
expect(scannable(HUGE)).toBe(false);
// It still fits a code, but too fine to read off a screen.
expect(qrFits(HUGE.slice(0, 2000))).toBe(true);
expect(scannable(HUGE.slice(0, 2000))).toBe(false);
expect(scannable(KEY)).toBe(true);
expect(scannable(LINK)).toBe(true);
});
it('draws the same code after checking it fits, and the next text as itself', () => {
const fresh = qrSvg(KEY, 3, true, 'night');
qrFits(LINK);
const link = qrSvg(LINK, 3, true, 'night');
expect(qrFits(KEY)).toBe(true);
expect(qrSvg(KEY, 3, true, 'night')).toBe(fresh);
expect(qrSvg(LINK, 3, true, 'night')).toBe(link);
expect(link).not.toBe(fresh);
});
});