bef6abdd2e
- TimeEntryForm.test.tsx: fills date/project/h:mm, clicks submit, asserts fetch called with correct JSON body (mocked fetch) - WeeklyView.test.tsx: renders with stubbed WeeklyReport fixture, asserts each day's h:mm and the week total display correctly - App.test.tsx: smoke test — renders layout with TopBar and main content Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import { render, screen, waitFor } from "@testing-library/react";
|
|
import { MemoryRouter } from "react-router-dom";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { WeeklyView } from "../src/components/WeeklyView";
|
|
|
|
vi.mock("../src/lib/api", () => ({
|
|
api: {
|
|
reports: {
|
|
weekly: vi.fn().mockResolvedValue({
|
|
days: [
|
|
{ date: "2026-05-11", totalMinutes: 480, totalCostCents: 38400 },
|
|
{ date: "2026-05-12", totalMinutes: 0, totalCostCents: 0 },
|
|
{ date: "2026-05-13", totalMinutes: 0, totalCostCents: 0 },
|
|
{ date: "2026-05-14", totalMinutes: 0, totalCostCents: 0 },
|
|
{ date: "2026-05-15", totalMinutes: 240, totalCostCents: 19200 },
|
|
{ date: "2026-05-16", totalMinutes: 0, totalCostCents: 0 },
|
|
{ date: "2026-05-17", totalMinutes: 0, totalCostCents: 0 },
|
|
],
|
|
weekTotalMinutes: 720,
|
|
weekTotalCostCents: 57600,
|
|
}),
|
|
},
|
|
timeEntries: { list: vi.fn().mockResolvedValue([]) },
|
|
},
|
|
}));
|
|
|
|
vi.mock("../src/state/UserContext", () => ({
|
|
useUser: () => ({
|
|
selectedUserId: 1,
|
|
selectedUser: null,
|
|
users: [],
|
|
setSelectedUserId: vi.fn(),
|
|
}),
|
|
}));
|
|
|
|
describe("WeeklyView", () => {
|
|
it("renders daily totals from report", async () => {
|
|
render(
|
|
<MemoryRouter>
|
|
<WeeklyView />
|
|
</MemoryRouter>,
|
|
);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText("8:00")).toBeInTheDocument(); // 480 min
|
|
expect(screen.getByText("4:00")).toBeInTheDocument(); // 240 min
|
|
});
|
|
});
|
|
|
|
it("renders the week total", async () => {
|
|
render(
|
|
<MemoryRouter>
|
|
<WeeklyView />
|
|
</MemoryRouter>,
|
|
);
|
|
|
|
await waitFor(() => {
|
|
// 720 min = 12:00, rendered as "Week total: 12:00"
|
|
expect(screen.getByText(/Week total.*12:00/)).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|