import { describe, it, expect, afterEach } from "vitest"; import { render, cleanup } from "@testing-library/react"; import { page } from "vitest/browser"; import { drawElevationChart } from "./elevation-chart-draw"; import type { DrawChartParams } from "./elevation-chart-draw"; // 10-point synthetic route: gentle climb from 100m to 200m over 10km const BASE_POINTS = Array.from({ length: 10 }, (_, i) => ({ distance: i * 1000, elevation: 100 + i * 10, lat: 48 + i * 0.01, lon: 11 + i * 0.01, })); const BASE_PARAMS: DrawChartParams = { points: BASE_POINTS, colorMode: "plain", surfaces: [], highways: [], maxspeeds: [], smoothnesses: [], tracktypes: [], cycleways: [], bikeroutes: [], hoverIdx: null, isDragging: false, dragStartX: null, dragCurrentX: null, }; function ChartFixture({ params }: { params: DrawChartParams }) { return ( { if (!canvas) return; const ctx = canvas.getContext("2d"); if (!ctx) return; drawElevationChart(ctx, 600, 100, params); }} /> ); } describe("drawElevationChart visual regression", () => { afterEach(() => cleanup()); it("renders plain color mode", async () => { render(); await expect(page.getByTestId("chart")).toMatchScreenshot("plain.png"); }); it("renders grade color mode", async () => { render(); await expect(page.getByTestId("chart")).toMatchScreenshot("grade.png"); }); it("renders elevation color mode", async () => { render(); await expect(page.getByTestId("chart")).toMatchScreenshot("elevation.png"); }); it("renders surface color mode", async () => { const surfaces = BASE_POINTS.map((_, i) => i < 5 ? "asphalt" : "gravel", ); render(); await expect(page.getByTestId("chart")).toMatchScreenshot("surface.png"); }); it("renders hover crosshair at index 5", async () => { render(); await expect(page.getByTestId("chart")).toMatchScreenshot("hover.png"); }); it("renders drag selection overlay", async () => { render( , ); await expect(page.getByTestId("chart")).toMatchScreenshot("drag-select.png"); }); });