Add tests to all packages, remove passWithNoTests
Every package now has tests — no more empty test suites: - map-core: 33 tests — maxspeedColor, routeGradeColor, elevationColor, POI categories, getCategoriesForProfile, tile layer configs - db: 5 tests — withDb error handling (503 on DB error, re-throws Response/DataWithResponseInit, logs errors) - ui: 14 tests — Button variants/sizes/disabled, Input label/id/error, Card className forwarding - map: 2 tests — baseLayers/overlayLayers re-export verification Remove passWithNoTests from vitest.shared.ts so missing tests are caught immediately when adding new packages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
daf555dbee
commit
9420201932
9 changed files with 361 additions and 2 deletions
54
packages/map-core/src/colors/elevation.test.ts
Normal file
54
packages/map-core/src/colors/elevation.test.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { routeGradeColor, elevationColor } from "./elevation.ts";
|
||||
|
||||
describe("routeGradeColor", () => {
|
||||
it("returns green for flat terrain", () => {
|
||||
expect(routeGradeColor(0)).toBe("#22c55e");
|
||||
expect(routeGradeColor(2)).toBe("#22c55e");
|
||||
});
|
||||
|
||||
it("returns yellow for moderate grades", () => {
|
||||
expect(routeGradeColor(4)).toBe("#eab308");
|
||||
});
|
||||
|
||||
it("returns orange for steep grades", () => {
|
||||
expect(routeGradeColor(8)).toBe("#f97316");
|
||||
});
|
||||
|
||||
it("returns red for very steep grades", () => {
|
||||
expect(routeGradeColor(12)).toBe("#ef4444");
|
||||
});
|
||||
|
||||
it("returns dark red for extreme grades", () => {
|
||||
expect(routeGradeColor(20)).toBe("#991b1b");
|
||||
});
|
||||
|
||||
it("uses absolute value for negative grades (descents)", () => {
|
||||
expect(routeGradeColor(-4)).toBe("#eab308");
|
||||
expect(routeGradeColor(-12)).toBe("#ef4444");
|
||||
});
|
||||
});
|
||||
|
||||
describe("elevationColor", () => {
|
||||
it("returns green at t=0", () => {
|
||||
expect(elevationColor(0)).toBe("rgb(0, 200, 50)");
|
||||
});
|
||||
|
||||
it("returns yellow at t=0.5", () => {
|
||||
expect(elevationColor(0.5)).toBe("rgb(255, 200, 50)");
|
||||
});
|
||||
|
||||
it("returns red at t=1", () => {
|
||||
expect(elevationColor(1)).toBe("rgb(255, 0, 50)");
|
||||
});
|
||||
|
||||
it("interpolates between green and yellow in lower half", () => {
|
||||
const color = elevationColor(0.25);
|
||||
expect(color).toMatch(/^rgb\(\d+, 200, 50\)$/);
|
||||
});
|
||||
|
||||
it("interpolates between yellow and red in upper half", () => {
|
||||
const color = elevationColor(0.75);
|
||||
expect(color).toMatch(/^rgb\(255, \d+, 50\)$/);
|
||||
});
|
||||
});
|
||||
38
packages/map-core/src/colors/maxspeed.test.ts
Normal file
38
packages/map-core/src/colors/maxspeed.test.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { maxspeedColor } from "./maxspeed.ts";
|
||||
|
||||
describe("maxspeedColor", () => {
|
||||
it("returns green for walking speed", () => {
|
||||
expect(maxspeedColor("walk")).toBe("#22c55e");
|
||||
});
|
||||
|
||||
it("returns dark red for no speed limit", () => {
|
||||
expect(maxspeedColor("none")).toBe("#991b1b");
|
||||
});
|
||||
|
||||
it("returns green for low speeds", () => {
|
||||
expect(maxspeedColor("20")).toBe("#22c55e");
|
||||
expect(maxspeedColor("30")).toBe("#22c55e");
|
||||
});
|
||||
|
||||
it("returns yellow for moderate speeds", () => {
|
||||
expect(maxspeedColor("50")).toBe("#eab308");
|
||||
});
|
||||
|
||||
it("returns orange for higher speeds", () => {
|
||||
expect(maxspeedColor("70")).toBe("#f97316");
|
||||
});
|
||||
|
||||
it("returns red for fast speeds", () => {
|
||||
expect(maxspeedColor("100")).toBe("#ef4444");
|
||||
});
|
||||
|
||||
it("returns dark red for very fast speeds", () => {
|
||||
expect(maxspeedColor("130")).toBe("#991b1b");
|
||||
});
|
||||
|
||||
it("returns gray for unknown values", () => {
|
||||
expect(maxspeedColor("unknown")).toBe("#9ca3af");
|
||||
expect(maxspeedColor("")).toBe("#9ca3af");
|
||||
});
|
||||
});
|
||||
56
packages/map-core/src/poi.test.ts
Normal file
56
packages/map-core/src/poi.test.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { poiCategories, getCategoriesForProfile, profileOverlayDefaults } from "./poi.ts";
|
||||
|
||||
describe("poiCategories", () => {
|
||||
it("has expected categories", () => {
|
||||
const ids = poiCategories.map((c) => c.id);
|
||||
expect(ids).toContain("drinking_water");
|
||||
expect(ids).toContain("camping");
|
||||
expect(ids).toContain("food");
|
||||
expect(ids).toContain("bike_infra");
|
||||
});
|
||||
|
||||
it("every category has required fields", () => {
|
||||
for (const cat of poiCategories) {
|
||||
expect(cat.id).toBeTruthy();
|
||||
expect(cat.name).toBeTruthy();
|
||||
expect(cat.icon).toBeTruthy();
|
||||
expect(cat.color).toMatch(/^#[0-9a-fA-F]{6}$/);
|
||||
expect(cat.query).toBeTruthy();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("getCategoriesForProfile", () => {
|
||||
it("returns trekking-specific categories", () => {
|
||||
const ids = getCategoriesForProfile("trekking");
|
||||
expect(ids).toContain("shelter");
|
||||
expect(ids).toContain("viewpoints");
|
||||
expect(ids).not.toContain("bike_infra");
|
||||
});
|
||||
|
||||
it("returns cycling-specific categories", () => {
|
||||
const ids = getCategoriesForProfile("fastbike");
|
||||
expect(ids).toContain("bike_infra");
|
||||
expect(ids).not.toContain("shelter");
|
||||
});
|
||||
|
||||
it("returns empty array for unknown profile", () => {
|
||||
expect(getCategoriesForProfile("unknown")).toEqual([]);
|
||||
});
|
||||
|
||||
it("returns empty array for profiles with no dedicated categories", () => {
|
||||
// Categories without profiles are available to everyone, not returned here
|
||||
expect(getCategoriesForProfile("")).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("profileOverlayDefaults", () => {
|
||||
it("maps fastbike to cycling routes", () => {
|
||||
expect(profileOverlayDefaults["fastbike"]).toContain("waymarked-cycling");
|
||||
});
|
||||
|
||||
it("maps trekking to hiking routes", () => {
|
||||
expect(profileOverlayDefaults["trekking"]).toContain("waymarked-hiking");
|
||||
});
|
||||
});
|
||||
40
packages/map-core/src/tiles.test.ts
Normal file
40
packages/map-core/src/tiles.test.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { baseLayers, overlayLayers } from "./tiles.ts";
|
||||
|
||||
describe("baseLayers", () => {
|
||||
it("has at least one base layer", () => {
|
||||
expect(baseLayers.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("every layer has a valid URL template", () => {
|
||||
for (const layer of baseLayers) {
|
||||
expect(layer.url).toContain("{z}");
|
||||
expect(layer.url).toContain("{x}");
|
||||
expect(layer.url).toContain("{y}");
|
||||
}
|
||||
});
|
||||
|
||||
it("every layer has a name and attribution", () => {
|
||||
for (const layer of baseLayers) {
|
||||
expect(layer.name).toBeTruthy();
|
||||
expect(layer.attribution).toBeTruthy();
|
||||
}
|
||||
});
|
||||
|
||||
it("includes OpenStreetMap", () => {
|
||||
expect(baseLayers.some((l) => l.name === "OpenStreetMap")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("overlayLayers", () => {
|
||||
it("every overlay has a unique id", () => {
|
||||
const ids = overlayLayers.map((l) => l.id);
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
});
|
||||
|
||||
it("every overlay has a valid URL template", () => {
|
||||
for (const layer of overlayLayers) {
|
||||
expect(layer.url).toContain("{z}");
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue