77 lines
2.9 KiB
JavaScript
77 lines
2.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const units_1 = require("../common/utils/units");
|
|
const convert = (q, from, to) => (0, units_1.convertUnit)(q, from, to);
|
|
const normalize = (u) => (0, units_1.normalizeUnit)(u);
|
|
describe('normalizeUnit', () => {
|
|
it('normaliserar aliaser', () => {
|
|
expect(normalize('tesked')).toBe('tsk');
|
|
expect(normalize('matsked')).toBe('msk');
|
|
expect(normalize('gram')).toBe('g');
|
|
expect(normalize('kilogram')).toBe('kg');
|
|
expect(normalize('deciliter')).toBe('dl');
|
|
expect(normalize('milliliter')).toBe('ml');
|
|
});
|
|
it('hanterar gemener och blanksteg', () => {
|
|
expect(normalize(' MSK ')).toBe('msk');
|
|
expect(normalize('G')).toBe('g');
|
|
});
|
|
it('returnerar okänd enhet oförändrad', () => {
|
|
expect(normalize('kopp')).toBe('kopp');
|
|
});
|
|
});
|
|
describe('convertUnit', () => {
|
|
describe('viktkonvertering', () => {
|
|
it('konverterar g → kg', () => {
|
|
expect(convert(500, 'g', 'kg')).toBeCloseTo(0.5);
|
|
});
|
|
it('konverterar kg → g', () => {
|
|
expect(convert(1.5, 'kg', 'g')).toBeCloseTo(1500);
|
|
});
|
|
it('returnerar samma värde för identiska enheter', () => {
|
|
expect(convert(200, 'g', 'g')).toBe(200);
|
|
});
|
|
});
|
|
describe('volymkonvertering', () => {
|
|
it('konverterar dl → ml', () => {
|
|
expect(convert(2, 'dl', 'ml')).toBeCloseTo(200);
|
|
});
|
|
it('konverterar ml → dl', () => {
|
|
expect(convert(150, 'ml', 'dl')).toBeCloseTo(1.5);
|
|
});
|
|
});
|
|
describe('portionskonvertering', () => {
|
|
it('konverterar msk → tsk (1 msk ≈ 3 tsk)', () => {
|
|
expect(convert(2, 'msk', 'tsk')).toBeCloseTo(6);
|
|
});
|
|
it('konverterar tsk → msk', () => {
|
|
expect(convert(3, 'tsk', 'msk')).toBeCloseTo(1);
|
|
});
|
|
});
|
|
describe('normaliserar aliaser vid konvertering', () => {
|
|
it('konverterar "gram" → "kg"', () => {
|
|
expect(convert(1000, 'gram', 'kg')).toBeCloseTo(1);
|
|
});
|
|
it('konverterar "matsked" → "tsk"', () => {
|
|
expect(convert(1, 'matsked', 'tsk')).toBeCloseTo(3);
|
|
});
|
|
});
|
|
describe('felhantering', () => {
|
|
it('kastar fel för inkompatibla enhetstyper', () => {
|
|
expect(() => convert(100, 'g', 'dl')).toThrow();
|
|
});
|
|
it('kastar fel för noll-kvantitet', () => {
|
|
expect(() => convert(0, 'g', 'kg')).toThrow();
|
|
});
|
|
it('kastar fel för negativ kvantitet', () => {
|
|
expect(() => convert(-1, 'g', 'kg')).toThrow();
|
|
});
|
|
it('kastar fel för tom from-enhet', () => {
|
|
expect(() => convert(100, '', 'kg')).toThrow();
|
|
});
|
|
it('kastar fel för okänd enhet', () => {
|
|
expect(() => convert(100, 'kopp', 'dl')).toThrow();
|
|
});
|
|
});
|
|
});
|
|
//# sourceMappingURL=recipes.service.spec.js.map
|