Refactor useHistory hook: replace HistoryQuery with explicit parameters and add documentation

- Split useHistory interface to accept explicit parameters (page, pageSize, range, origin, jail, ip, source) instead of HistoryQuery object
- Add comprehensive JSDoc for useHistory function
- Update HistoryPage and tests to use new parameter structure
- Move TaskList documentation from Tasks.md to Web-Development.md
- Improve type safety with explicit TimeRange and BanOriginFilter types

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-04-23 09:51:16 +02:00
parent 8904e180d1
commit 9c5757eeb0
5 changed files with 119 additions and 93 deletions

View File

@@ -3,10 +3,10 @@ import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { FluentProvider, webLightTheme } from "@fluentui/react-components";
let lastQuery: Record<string, unknown> | null = null;
const mockUseHistory = vi.fn((query: Record<string, unknown>) => {
console.log("mockUseHistory called", query);
lastQuery = query;
let lastCallArgs: unknown[] | null = null;
const mockUseHistory = vi.fn((...args: unknown[]) => {
console.log("mockUseHistory called with args:", args);
lastCallArgs = args;
return {
items: [],
total: 0,
@@ -19,7 +19,7 @@ const mockUseHistory = vi.fn((query: Record<string, unknown>) => {
});
vi.mock("../../hooks/useHistory", () => ({
useHistory: (query: Record<string, unknown>) => mockUseHistory(query),
useHistory: (...args: unknown[]) => mockUseHistory(...args),
useIpHistory: () => ({ detail: null, loading: false, error: null, refresh: vi.fn() }),
}));
@@ -47,17 +47,18 @@ describe("HistoryPage", () => {
</FluentProvider>,
);
// Initial load should include the auto-applied default query.
// Initial load should have default parameters: page, pageSize, range, origin, jail, ip, source
// Arguments: (page: 1, pageSize: 50, range: "7d", origin: undefined, jail: undefined, ip: undefined, source: "archive")
await waitFor(() => {
expect(lastQuery).toEqual({
range: "7d",
source: "archive",
origin: undefined,
jail: undefined,
ip: undefined,
page: 1,
page_size: 50,
});
expect(lastCallArgs).toEqual([
1, // page
50, // pageSize
"7d", // range
undefined, // origin
undefined, // jail
undefined, // ip
"archive", // source
]);
});
expect(screen.queryByRole("button", { name: /apply/i })).toBeNull();
@@ -66,12 +67,12 @@ describe("HistoryPage", () => {
// Time-range and origin updates should be applied automatically.
await user.click(screen.getByRole("button", { name: /Last 7 days/i }));
await waitFor(() => {
expect(lastQuery).toMatchObject({ range: "7d" });
expect(lastCallArgs?.[2]).toBe("7d"); // range is at index 2
});
await user.click(screen.getByRole("button", { name: /Blocklist/i }));
await waitFor(() => {
expect(lastQuery).toMatchObject({ origin: "blocklist" });
expect(lastCallArgs?.[3]).toBe("blocklist"); // origin is at index 3
});
});
@@ -83,9 +84,9 @@ describe("HistoryPage", () => {
);
await waitFor(() => {
expect(lastQuery?.range).toBe("7d");
expect(lastCallArgs?.[2]).toBe("7d"); // range is at index 2
});
expect(mockUseHistory.mock.calls.every((call) => call[0].range === "7d")).toBe(true);
expect(mockUseHistory.mock.calls.every((call) => call[2] === "7d")).toBe(true);
});
});