Files
wtr/tests/forecast-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

42 lines
1.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { getEffectiveHourlyWeatherCode, getForecastConditionKey, isForecastNight } from "@/lib/forecast-utils";
describe("forecast utilities", () => {
it("promotes dry weather code to rain when precipitation probability is high", () => {
expect(
getEffectiveHourlyWeatherCode({
weatherCode: 0,
precipitation: 0,
precipitationProbability: 100,
}),
).toBe(61);
});
it("keeps clear weather code when there is no precipitation signal", () => {
expect(
getEffectiveHourlyWeatherCode({
weatherCode: 0,
precipitation: 0,
precipitationProbability: 10,
}),
).toBe(0);
});
it("recognizes night hours from sunrise and sunset", () => {
const day = {
sunrise: "2026-06-15T05:00",
sunset: "2026-06-15T21:00",
};
expect(isForecastNight("2026-06-15T03:00", day)).toBe(true);
expect(isForecastNight("2026-06-15T12:00", day)).toBe(false);
expect(isForecastNight("2026-06-15T22:00", day)).toBe(true);
});
it("maps storm and rain weather codes to condition keys", () => {
expect(getForecastConditionKey(61)).toBe("forecast.condition.rain");
expect(getForecastConditionKey(95)).toBe("forecast.condition.thunderstorm");
});
});