Files
kochwas/tests/unit/quantity-format.test.ts
hsiegeln 14cf1b1d35
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 2m19s
feat(format): formatQuantity app-weit auf de-DE Komma-Dezimal
Ersetzt Math.round/toFixed-Logik durch q.toLocaleString('de-DE', …).
Dezimaltrennzeichen ist jetzt konsistent ein Komma (0,5 statt 0.5).
Tests aktualisiert; alle 316 Tests + svelte-check grün.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 16:55:29 +02:00

29 lines
865 B
TypeScript

import { describe, it, expect } from 'vitest';
import { formatQuantity } from '../../src/lib/quantity-format';
describe('formatQuantity', () => {
it('renders null as empty string', () => {
expect(formatQuantity(null)).toBe('');
});
it('renders whole numbers as integer', () => {
expect(formatQuantity(400)).toBe('400');
});
it('renders near-integer as integer (epsilon 0.01)', () => {
expect(formatQuantity(400.001)).toBe('400');
expect(formatQuantity(399.999)).toBe('400');
});
it('renders fractional with up to 2 decimals, trailing zeros trimmed', () => {
expect(formatQuantity(0.5)).toBe('0,5');
expect(formatQuantity(0.333333)).toBe('0,33');
expect(formatQuantity(1.1)).toBe('1,1');
expect(formatQuantity(1.1)).toBe('1,1');
});
it('handles zero', () => {
expect(formatQuantity(0)).toBe('0');
});
});