You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.7 KiB
39 lines
1.7 KiB
import { describe, expect, it } from "vitest";
|
|
import { formatEstimateTime } from "./format-estimate";
|
|
import ar from "./locales/ar.json";
|
|
import en from "./locales/en.json";
|
|
import fa from "./locales/fa.json";
|
|
|
|
describe("formatEstimateTime", () => {
|
|
it("translates estimates correctly in Arabic", () => {
|
|
expect(formatEstimateTime("2 min", ar)).toBe("2 دقيقة");
|
|
expect(formatEstimateTime("3 min", ar)).toBe("3 دقائق");
|
|
expect(formatEstimateTime("4 min", ar)).toBe("4 دقائق");
|
|
expect(formatEstimateTime("5 min", ar)).toBe("5 دقائق");
|
|
expect(formatEstimateTime("16 min", ar)).toBe("16 دقيقة");
|
|
expect(formatEstimateTime("min", ar)).toBe("دقيقة");
|
|
});
|
|
|
|
it("translates estimates correctly in Persian", () => {
|
|
expect(formatEstimateTime("2 min", fa)).toBe("۲ دقیقه");
|
|
expect(formatEstimateTime("3 min", fa)).toBe("۳ دقیقه");
|
|
expect(formatEstimateTime("4 min", fa)).toBe("۴ دقیقه");
|
|
expect(formatEstimateTime("16 min", fa)).toBe("۱۶ دقیقه");
|
|
expect(formatEstimateTime("min", fa)).toBe("دقیقه");
|
|
});
|
|
|
|
it("handles English locale properly", () => {
|
|
expect(formatEstimateTime("2 min", en)).toBe("2 min");
|
|
expect(formatEstimateTime("3 min", en)).toBe("3 min");
|
|
expect(formatEstimateTime("16 min", en)).toBe("16 min");
|
|
expect(formatEstimateTime("min", en)).toBe("min");
|
|
});
|
|
|
|
it("falls back gracefully for unknown counts or missing keys", () => {
|
|
const mockT = { min: "دقيقة" };
|
|
expect(formatEstimateTime("99 min", mockT)).toBe("99 دقيقة");
|
|
expect(formatEstimateTime("", mockT)).toBe("");
|
|
expect(formatEstimateTime(null, mockT)).toBe("");
|
|
expect(formatEstimateTime("unformatted string", mockT)).toBe("unformatted string");
|
|
});
|
|
});
|