mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-04 02:31:27 +00:00
refactor useLogFilterLogic tests for controlled-hook + backend-query shape
The hook no longer owns filter state or does client-side filtering — it receives filters/setFilters as props and drives filteredLogs from a useQuery over uiSpendLogsCall. Reshape the tests around that contract: introduce a controlled harness that owns filter state, collapse the 10 per-filter assertions into a single it.each over filterKey → API param, and drop the client-side passthrough tests (the .min test file and the "return all logs when no filters" / "empty when logs null" cases) that no longer correspond to any hook behavior.
This commit is contained in:
parent
5ae669ad25
commit
3db143b932
2 changed files with 426 additions and 738 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,62 +0,0 @@
|
|||
import React from "react";
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { useLogFilterLogic } from "../../src/components/view_logs/log_filter_logic";
|
||||
|
||||
// Minimal mocks to avoid real network during hook init
|
||||
vi.mock("../../src/components/key_team_helpers/filter_helpers", () => ({
|
||||
fetchAllKeyAliases: vi.fn().mockResolvedValue([]),
|
||||
fetchAllTeams: vi.fn().mockResolvedValue([]),
|
||||
}));
|
||||
|
||||
const createQueryClient = () =>
|
||||
new QueryClient({
|
||||
defaultOptions: { queries: { retry: false, gcTime: 0 } },
|
||||
});
|
||||
|
||||
function Harness({ logs }: { logs: any }) {
|
||||
const { filteredLogs } = useLogFilterLogic({
|
||||
logs,
|
||||
accessToken: "token",
|
||||
startTime: "2025-01-01 00:00:00",
|
||||
endTime: "2025-01-02 00:00:00",
|
||||
pageSize: 50,
|
||||
isCustomDate: true,
|
||||
setCurrentPage: () => {},
|
||||
userID: "user-1",
|
||||
userRole: "admin",
|
||||
});
|
||||
|
||||
return <div data-testid="count">{filteredLogs.data.length}</div>;
|
||||
}
|
||||
|
||||
describe("useLogFilterLogic (minimal)", () => {
|
||||
it("useLogFilterLogic minimal: updates filteredLogs when logs change", async () => {
|
||||
const qc = createQueryClient();
|
||||
const logsA = { data: [{ request_id: "a" }], total: 1, page: 1, page_size: 50, total_pages: 1 };
|
||||
const logsB = {
|
||||
data: [{ request_id: "a" }, { request_id: "b" }],
|
||||
total: 2,
|
||||
page: 1,
|
||||
page_size: 50,
|
||||
total_pages: 1,
|
||||
};
|
||||
|
||||
const { rerender } = render(
|
||||
<QueryClientProvider client={qc}>
|
||||
<Harness logs={logsA} />
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
|
||||
expect(await screen.findByTestId("count")).toHaveTextContent("1");
|
||||
|
||||
rerender(
|
||||
<QueryClientProvider client={qc}>
|
||||
<Harness logs={logsB} />
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
|
||||
expect(await screen.findByTestId("count")).toHaveTextContent("2");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue