Skip to content

Commit a51aacf

Browse files
committed
test(today): add tests for TodayViewContent component
- Introduce tests for TodayViewContent to ensure proper rendering and functionality - Verify layout includes tasks and calendar sections - Check for today's date display and task addition functionality - Mock dependencies for isolated testing of component behavior
1 parent 527499b commit a51aacf

2 files changed

Lines changed: 94 additions & 15 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import React from "react";
2+
import { act } from "react";
3+
import "@testing-library/jest-dom";
4+
import { render, screen } from "@testing-library/react";
5+
import userEvent from "@testing-library/user-event";
6+
import { TodayViewContent } from "./TodayViewContent";
7+
import { TaskProvider } from "./context/TaskProvider";
8+
9+
// Mock the CalendarAgenda component
10+
jest.mock("./components/CalendarAgenda", () => ({
11+
CalendarAgenda: () => (
12+
<div className="h-96 bg-gray-100">Calendar Content</div>
13+
),
14+
}));
15+
16+
// Mock the keyboard shortcuts hook
17+
jest.mock("./hooks/useKeyboardShortcuts", () => ({
18+
useKeyboardShortcuts: jest.fn(),
19+
}));
20+
21+
const renderWithProvider = (component: React.ReactElement) => {
22+
return render(<TaskProvider>{component}</TaskProvider>);
23+
};
24+
25+
describe("TodayViewContent", () => {
26+
beforeEach(() => {
27+
localStorage.clear();
28+
});
29+
30+
it("should render the main layout with tasks and calendar sections", () => {
31+
renderWithProvider(<TodayViewContent />);
32+
33+
// Verify the main components are present
34+
expect(screen.getByText("Add task")).toBeInTheDocument();
35+
expect(screen.getByText("Calendar Content")).toBeInTheDocument();
36+
});
37+
38+
it("should display today's date in the tasks section", () => {
39+
renderWithProvider(<TodayViewContent />);
40+
41+
// Check that today's date is displayed
42+
const todayHeading = new Date().toLocaleDateString("en-US", {
43+
weekday: "long",
44+
month: "long",
45+
day: "numeric",
46+
});
47+
expect(screen.getByText(todayHeading)).toBeInTheDocument();
48+
});
49+
50+
it("should allow users to add new tasks", async () => {
51+
const user = userEvent.setup();
52+
renderWithProvider(<TodayViewContent />);
53+
54+
// Click the add task button
55+
const addTaskButton = screen.getByText("Add task");
56+
await act(() => user.click(addTaskButton));
57+
58+
// Verify input field appears
59+
expect(
60+
screen.getByPlaceholderText("Enter task title..."),
61+
).toBeInTheDocument();
62+
});
63+
64+
it("should maintain a fixed height layout that fills the viewport", () => {
65+
renderWithProvider(<TodayViewContent />);
66+
67+
// The layout should be present and functional
68+
expect(screen.getByText("Add task")).toBeInTheDocument();
69+
expect(screen.getByText("Calendar Content")).toBeInTheDocument();
70+
});
71+
72+
it("should display add task button", () => {
73+
renderWithProvider(<TodayViewContent />);
74+
75+
// The tasks section should be present and functional
76+
expect(screen.getByText("Add task")).toBeInTheDocument();
77+
78+
// Users should be able to interact with the tasks section
79+
expect(screen.getByText("Add task")).toBeEnabled();
80+
});
81+
});

packages/web/src/views/Today/TodayViewContent.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,20 @@ export const TodayViewContent = () => {
9090
});
9191

9292
return (
93-
<div className=" flex min-h-screen justify-center bg-darkBlue-400 px-6 py-8">
94-
<div className="flex w-full max-witems-stretch gap-8">
95-
{/* Tasks Panel */}
96-
<div className="flex w-96 text-white flex-shrink-0">
97-
<TaskList
98-
onTaskFocus={setFocusedTaskId}
99-
focusedTaskId={focusedTaskId}
100-
onSelectTask={setSelectedTaskIndex}
101-
selectedTaskIndex={selectedTaskIndex}
102-
/>
103-
</div>
93+
<div className="bg-red-400 flex w-full max-w-items-stretch gap-8 px-6 py-8 overflow-hidden h-screen">
94+
{/* Tasks Panel */}
95+
<div className="flex w-96 text-white flex-shrink-0 overflow-y-auto">
96+
<TaskList
97+
onTaskFocus={setFocusedTaskId}
98+
focusedTaskId={focusedTaskId}
99+
onSelectTask={setSelectedTaskIndex}
100+
selectedTaskIndex={selectedTaskIndex}
101+
/>
102+
</div>
104103

105-
{/* Calendar Panel */}
106-
<div className="flex flex-1 min-w-0">
107-
<CalendarAgenda />
108-
</div>
104+
{/* Calendar Panel */}
105+
<div className="flex flex-1 min-w-0 overflow-y-auto">
106+
<CalendarAgenda />
109107
</div>
110108
</div>
111109
);

0 commit comments

Comments
 (0)