test: add weather logic test suite
All checks were successful
CI / Lint, test, typecheck and build (push) Successful in 9m58s

This commit is contained in:
zv
2026-06-14 20:44:37 +02:00
parent ee55521803
commit bdba3c709c
11 changed files with 1357 additions and 10 deletions

View File

@@ -0,0 +1,41 @@
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");
});
});