test: add weather logic test suite
All checks were successful
CI / Lint, test, typecheck and build (push) Successful in 9m58s
All checks were successful
CI / Lint, test, typecheck and build (push) Successful in 9m58s
This commit is contained in:
41
tests/forecast-utils.test.ts
Normal file
41
tests/forecast-utils.test.ts
Normal 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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user