29 lines
995 B
TypeScript
29 lines
995 B
TypeScript
|
|
import { describe, it, expect } from 'vitest';
|
||
|
|
import { unitFamily } from '../../src/lib/server/unit-consolidation';
|
||
|
|
|
||
|
|
describe('unitFamily', () => {
|
||
|
|
it('maps g and kg to weight', () => {
|
||
|
|
expect(unitFamily('g')).toBe('weight');
|
||
|
|
expect(unitFamily('kg')).toBe('weight');
|
||
|
|
});
|
||
|
|
it('maps ml and l to volume', () => {
|
||
|
|
expect(unitFamily('ml')).toBe('volume');
|
||
|
|
expect(unitFamily('l')).toBe('volume');
|
||
|
|
});
|
||
|
|
it('lowercases and trims unknown units', () => {
|
||
|
|
expect(unitFamily(' Bund ')).toBe('bund');
|
||
|
|
expect(unitFamily('TL')).toBe('tl');
|
||
|
|
expect(unitFamily('Stück')).toBe('stück');
|
||
|
|
});
|
||
|
|
it('is case-insensitive for weight/volume', () => {
|
||
|
|
expect(unitFamily('Kg')).toBe('weight');
|
||
|
|
expect(unitFamily('ML')).toBe('volume');
|
||
|
|
});
|
||
|
|
it('returns empty string for null/undefined/empty', () => {
|
||
|
|
expect(unitFamily(null)).toBe('');
|
||
|
|
expect(unitFamily(undefined)).toBe('');
|
||
|
|
expect(unitFamily('')).toBe('');
|
||
|
|
expect(unitFamily(' ')).toBe('');
|
||
|
|
});
|
||
|
|
});
|