Remove production test scaffolding from useMapData and update MapPage tests

This commit is contained in:
2026-04-19 18:47:29 +02:00
parent e7582c4bae
commit b6303cff72
2 changed files with 27 additions and 42 deletions

View File

@@ -100,20 +100,3 @@ export function useMapData(
}; };
} }
/**
* Test helper: returns arguments most recently used to call `useMapData`.
*
* This helper is only intended for test use with a mock implementation.
*/
export function getLastArgs(): { range: string; origin: string } {
throw new Error("getLastArgs is only available in tests with a mocked useMapData");
}
/**
* Test helper: mutates mocked map data state.
*
* This helper is only intended for test use with a mock implementation.
*/
export function setMapData(_: Partial<UseMapDataResult>): void {
throw new Error("setMapData is only available in tests with a mocked useMapData");
}

View File

@@ -2,35 +2,37 @@ import { describe, expect, it, vi } from "vitest";
import { render, screen } from "@testing-library/react"; import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event"; import userEvent from "@testing-library/user-event";
import { FluentProvider, webLightTheme } from "@fluentui/react-components"; import { FluentProvider, webLightTheme } from "@fluentui/react-components";
import { getLastArgs, setMapData } from "../../hooks/useMapData";
import { MapPage } from "../MapPage"; import { MapPage } from "../MapPage";
import type { UseMapDataResult } from "../../hooks/useMapData";
vi.mock("../../hooks/useMapData", () => { let lastArgs: { range: string; origin: string } = { range: "", origin: "" };
let lastArgs: { range: string; origin: string } = { range: "", origin: "" }; let dataState: UseMapDataResult = {
let dataState = { countries: {},
countries: {}, countryNames: {},
countryNames: {}, bans: [],
bans: [], total: 0,
total: 0, loading: false,
loading: false, error: null,
error: null, refresh: () => {},
refresh: () => {}, };
};
return { function getLastArgs(): { range: string; origin: string } {
useMapData: (range: string, origin: string) => { return lastArgs;
lastArgs = { range, origin }; }
return { ...dataState };
}, function setMapData(newState: Partial<typeof dataState>): void {
setMapData: (newState: Partial<typeof dataState>) => { dataState = { ...dataState, ...newState };
dataState = { ...dataState, ...newState }; }
},
getLastArgs: () => lastArgs, vi.mock("../../hooks/useMapData", () => ({
}; useMapData: (range: string, origin: string) => {
}); lastArgs = { range, origin };
return { ...dataState };
},
}));
vi.mock("../../api/config", () => ({ vi.mock("../../api/config", () => ({
fetchMapColorThresholds: vi.fn(async () => ({ fetchMapColorThresholds: vi.fn(() => ({
threshold_low: 10, threshold_low: 10,
threshold_medium: 50, threshold_medium: 50,
threshold_high: 100, threshold_high: 100,
@@ -65,7 +67,7 @@ describe("MapPage", () => {
const user = userEvent.setup(); const user = userEvent.setup();
const bans: import("../../types/map").MapBanItem[] = Array.from({ length: 120 }, (_, index) => ({ const bans: import("../../types/map").MapBanItem[] = Array.from({ length: 120 }, (_, index) => ({
ip: `192.0.2.${index}`, ip: "192.0.2." + String(index),
jail: "ssh", jail: "ssh",
banned_at: new Date(Date.now() - index * 1000).toISOString(), banned_at: new Date(Date.now() - index * 1000).toISOString(),
service: null, service: null,