Files
wtr/tests/weather-utils.test.ts
zv bdba3c709c
All checks were successful
CI / Lint, test, typecheck and build (push) Successful in 9m58s
test: add weather logic test suite
2026-06-14 20:44:37 +02:00

30 lines
905 B
TypeScript

import { describe, expect, it } from "vitest";
import {
DEFAULT_WIND_SPEED_UNIT,
formatTemperature,
formatWindSpeed,
isTemperatureUnit,
isWindSpeedUnit,
} from "@/lib/weather-utils";
describe("weather utilities", () => {
it("formats wind speed in km/h by default", () => {
expect(DEFAULT_WIND_SPEED_UNIT).toBe("kmh");
expect(formatWindSpeed(5, "en")).toBe("18 km/h");
});
it("formats selected temperature and wind units", () => {
expect(formatTemperature(10, "en", "f")).toBe("50°F");
expect(formatWindSpeed(4, "en", "mph")).toBe("9 mph");
expect(formatWindSpeed(4, "en", "ms")).toBe("4.0 m/s");
});
it("validates supported presentation units", () => {
expect(isTemperatureUnit("c")).toBe(true);
expect(isTemperatureUnit("kelvin")).toBe(false);
expect(isWindSpeedUnit("kmh")).toBe(true);
expect(isWindSpeedUnit("knots")).toBe(false);
});
});