Files
accounted/lib/bokslut/arsredovisning/__tests__/pdf-format.test.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

44 lines
1.6 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { formatPdfKronor } from '../pdf-format'
// Build the special characters from code points so the assertions cannot be
// corrupted by editor/encoding round-trips: U+00A0 is the sv-SE thousands
// separator, U+2212 is the locale minus that WinAnsi Helvetica cannot render.
const NBSP = String.fromCharCode(0x00a0)
const U2212 = String.fromCharCode(0x2212)
describe('formatPdfKronor', () => {
it('formats a loss with an ASCII hyphen-minus, never U+2212', () => {
const out = formatPdfKronor(-4684.24)
expect(out).toBe(`-4${NBSP}684`)
expect(out).not.toContain(U2212)
})
it('keeps sv-SE thousands grouping for positive amounts', () => {
expect(formatPdfKronor(1234567.89)).toBe(`1${NBSP}234${NBSP}568`)
})
it('pins the group separator to U+00A0 regardless of the ICU CLDR choice', () => {
// Newer CLDR data groups sv-SE with U+202F NARROW NO-BREAK SPACE, which
// is also missing from WinAnsi; the formatter must normalize to U+00A0.
const U202F = String.fromCharCode(0x202f)
const out = formatPdfKronor(-9876543)
expect(out).toBe(`-9${NBSP}876${NBSP}543`)
expect(out).not.toContain(U202F)
})
it('rounds to whole kronor and never renders "-0"', () => {
expect(formatPdfKronor(-0.4)).toBe('0')
expect(formatPdfKronor(-0.6)).toBe('-1')
expect(formatPdfKronor(0)).toBe('0')
})
it('always uses ASCII hyphen for negative amounts', () => {
for (const n of [-1, -999, -1000, -4684.24, -1_000_000.5]) {
const out = formatPdfKronor(n)
expect(out).not.toContain(U2212)
expect(out.startsWith('-')).toBe(true)
}
})
})