i18n and tests
This commit is contained in:
1 parent
a797729dd0
commit
0f1500b102
17 files changed
+455
-4
No files matched your search
@@ -27,11 +27,11 @@ describe('Brazilian Portuguese locale', () => {
|
||||
.sort(byCodeUnit)
|
||||
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
|
||||
|
||||
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(342)
|
||||
expect(inherited).toHaveLength(463)
|
||||
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(354)
|
||||
expect(inherited).toHaveLength(475)
|
||||
// If this fails, review the changed keys and wording before accepting a new hash. From
|
||||
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
|
||||
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('cafd0b6fde9f8261563b5040aa6e1278f5b469dc2d6b9c81d7d5554bb6825a05')
|
||||
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('d379a3a509af71a6773017d3374938c2067cc870bbf7bd5bbc0bb8ad853d0781')
|
||||
})
|
||||
|
||||
test('does not leak European Portuguese UI terms', () => {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { normalizeFmt, canRenderFmt } from './qr.js'
|
||||
|
||||
// The QR helpers decide which scanned/typed codes the check-in feature will store: it can read
|
||||
// many symbologies but only redraw QR, so canRenderFmt is the gate, and normalizeFmt is what
|
||||
// folds every spelling mlkit might report into the single token everything else compares on.
|
||||
|
||||
describe('normalizeFmt', () => {
|
||||
it('folds every QR spelling to "qrcode"', () => {
|
||||
// mlkit's BarcodeFormat, the enum-ish casings, and the casual 'qr' all mean the same thing.
|
||||
expect(normalizeFmt('QR_CODE')).toBe('qrcode')
|
||||
expect(normalizeFmt('QrCode')).toBe('qrcode')
|
||||
expect(normalizeFmt('qrcode')).toBe('qrcode')
|
||||
expect(normalizeFmt('qr')).toBe('qrcode')
|
||||
expect(normalizeFmt('QR')).toBe('qrcode')
|
||||
})
|
||||
|
||||
it('lower-cases and strips separators for other formats', () => {
|
||||
expect(normalizeFmt('EAN_13')).toBe('ean13')
|
||||
expect(normalizeFmt('Code128')).toBe('code128')
|
||||
expect(normalizeFmt('CODE_128')).toBe('code128')
|
||||
})
|
||||
|
||||
it('treats empty / nullish as an empty token rather than throwing', () => {
|
||||
expect(normalizeFmt('')).toBe('')
|
||||
expect(normalizeFmt(null)).toBe('')
|
||||
expect(normalizeFmt(undefined)).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('canRenderFmt', () => {
|
||||
it('accepts only QR, in any spelling', () => {
|
||||
expect(canRenderFmt('QR_CODE')).toBe(true)
|
||||
expect(canRenderFmt('QrCode')).toBe(true)
|
||||
expect(canRenderFmt('qr')).toBe(true)
|
||||
})
|
||||
|
||||
it('rejects 1D and other 2D symbologies we cannot faithfully redraw', () => {
|
||||
// These are readable by the scanner but lean-qr can't reproduce them, so a card in one of
|
||||
// these formats must never be stored — it would display as the wrong bars at the turnstile.
|
||||
for (const fmt of ['EAN_13', 'EAN_8', 'CODE_128', 'CODE_39', 'ITF', 'UPC_A', 'PDF_417', 'AZTEC', 'DATA_MATRIX']) {
|
||||
expect(canRenderFmt(fmt)).toBe(false)
|
||||
}
|
||||
})
|
||||
|
||||
it('rejects empty / unknown formats', () => {
|
||||
expect(canRenderFmt('')).toBe(false)
|
||||
expect(canRenderFmt(null)).toBe(false)
|
||||
expect(canRenderFmt('something-else')).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { scanCode, importCodeFromImage } from './scan.js'
|
||||
|
||||
// In the test environment VITE_MOBILE is unset, so MOBILE is false — the same as a web build.
|
||||
// Both capture paths must refuse to run there rather than reach for a native plugin that isn't
|
||||
// present. (The happy-path decoding is exercised on-device; here we pin the guard that keeps the
|
||||
// scanner out of every non-mobile build.)
|
||||
|
||||
describe('scan guards off mobile', () => {
|
||||
it('scanCode rejects when not in the mobile build', async () => {
|
||||
await expect(scanCode()).rejects.toThrow(/only available in the app/)
|
||||
})
|
||||
|
||||
it('importCodeFromImage rejects when not in the mobile build', async () => {
|
||||
const fakeFile = new Blob(['x'], { type: 'image/png' })
|
||||
await expect(importCodeFromImage(fakeFile)).rejects.toThrow(/only available in the app/)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user