test(frontend): add component tests — TimeEntryForm, WeeklyView, App smoke
- 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>
This commit is contained in:
@@ -1,10 +1,31 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { MemoryRouter } from "react-router-dom";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import App from "../src/App";
|
||||
|
||||
// minimal stub so App renders without network calls
|
||||
vi.mock("../src/lib/api", () => ({
|
||||
api: {
|
||||
users: { list: vi.fn().mockResolvedValue([]) },
|
||||
reports: {
|
||||
weekly: vi.fn().mockResolvedValue({
|
||||
days: [],
|
||||
weekTotalMinutes: 0,
|
||||
weekTotalCostCents: 0,
|
||||
}),
|
||||
},
|
||||
timeEntries: { list: vi.fn().mockResolvedValue([]) },
|
||||
},
|
||||
}));
|
||||
|
||||
describe("App", () => {
|
||||
it("renders a main element", () => {
|
||||
render(<App />);
|
||||
it("renders the top bar and main content area", () => {
|
||||
render(
|
||||
<MemoryRouter initialEntries={["/weekly"]}>
|
||||
<App />
|
||||
</MemoryRouter>,
|
||||
);
|
||||
expect(screen.getByText("TimeTracker")).toBeDefined();
|
||||
expect(screen.getByRole("main")).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user