All checks were successful
CI / Lint, test, typecheck and build (push) Successful in 9m58s
68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { getCountyTerytForLocation, warningMatchesCounty, warningMatchesLocalSelection } from "@/lib/warning-regions";
|
|
import type { WeatherWarning } from "@/types/imgw";
|
|
import type { SelectedLocation } from "@/types/location";
|
|
|
|
function warning(overrides: Partial<WeatherWarning> = {}): WeatherWarning {
|
|
return {
|
|
id: "meteo-1",
|
|
kind: "meteo",
|
|
level: 1,
|
|
title: "Storm",
|
|
description: null,
|
|
comment: null,
|
|
validFrom: null,
|
|
validTo: null,
|
|
publishedAt: null,
|
|
probability: null,
|
|
areas: [],
|
|
terytCodes: [],
|
|
provinces: ["mazowieckie"],
|
|
office: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function location(overrides: Partial<SelectedLocation> = {}): SelectedLocation {
|
|
return {
|
|
name: "Warszawa",
|
|
province: "mazowieckie",
|
|
district: "Warszawa",
|
|
country: "Poland",
|
|
countryCode: "PL",
|
|
admin1: "Mazowieckie",
|
|
admin2: "Warszawa",
|
|
timezone: "Europe/Warsaw",
|
|
region: "PL",
|
|
countyTeryt: "1465",
|
|
latitude: 52.23,
|
|
longitude: 21.01,
|
|
stationId: null,
|
|
stationName: null,
|
|
distanceKm: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("warning region matching", () => {
|
|
it("resolves Mazowieckie county codes from district names", () => {
|
|
expect(getCountyTerytForLocation("mazowieckie", "Warszawa", null)).toBe("1465");
|
|
expect(getCountyTerytForLocation("mazowieckie", "radomski", null)).toBe("1425");
|
|
});
|
|
|
|
it("matches meteorological warnings by county TERYT prefix", () => {
|
|
const warsawWarning = warning({ terytCodes: ["146501"] });
|
|
|
|
expect(warningMatchesCounty(warsawWarning, "1465")).toBe(true);
|
|
expect(warningMatchesCounty(warsawWarning, "1425")).toBe(false);
|
|
});
|
|
|
|
it("uses county filtering before province fallback for selected locations", () => {
|
|
const radomWarning = warning({ terytCodes: ["142501"] });
|
|
|
|
expect(warningMatchesLocalSelection(radomWarning, "mazowieckie", location())).toBe(false);
|
|
expect(warningMatchesLocalSelection(radomWarning, "mazowieckie", location({ countyTeryt: null }))).toBe(true);
|
|
});
|
|
});
|