|
| 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 | +}); |
0 commit comments