feat(shared): para, miktar ve İstanbul günü yardımcıları

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 02:57:58 +03:00
parent 7fda139199
commit eaf80c6bb4
6 changed files with 374 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
import { describe, expect, it } from "vitest";
import { convertQuantity, formatQuantity, parseQuantity } from "./quantity";
describe("parseQuantity", () => {
it.each([
["1,5", 1500],
["1.5", 1500],
["2", 2000],
["0,125", 125],
["5", 5000],
[" 10,25 ", 10250],
])("%s → %i", (input, expected) => {
expect(parseQuantity(input)).toBe(expected);
});
it.each(["", "-1", "1,2345", "1,2,3", "abc", "1e3"])("geçersiz: %s", (input) => {
expect(parseQuantity(input)).toBeNull();
});
});
describe("formatQuantity", () => {
it("gereksiz sıfırları atar, birim ekler", () => {
expect(formatQuantity(1500, "kg")).toBe("1,5 kg");
expect(formatQuantity(5000, "gr")).toBe("5 gr");
expect(formatQuantity(125)).toBe("0,125");
expect(formatQuantity(1234500)).toBe("1.234,5");
expect(formatQuantity(-250)).toBe("-0,25");
});
});
describe("convertQuantity", () => {
it("aynı boyutta dönüştürür", () => {
expect(convertQuantity(1500, "kg", "g")).toBe(1500000); // 1,5 kg = 1500 g
expect(convertQuantity(500000, "g", "kg")).toBe(500); // 500 g = 0,5 kg
expect(convertQuantity(2000, "lt", "ml")).toBe(2000000);
});
it("uyumsuz birimde hata verir", () => {
expect(() => convertQuantity(1000, "kg", "lt")).toThrow(RangeError);
});
});