Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

add unit tests for task management

Khuram Niaz406b091723b2
diff --git a/__mocks__/next-auth-providers.ts b/__mocks__/next-auth-providers.ts
new file mode 100644
index 0000000..289b4e1
--- /dev/null
+++ b/__mocks__/next-auth-providers.ts
@@ -0,0 +1,9 @@
+const Credentials = jest.fn((config: any) => ({
+ id: "credentials",
+ name: "Credentials",
+ type: "credentials",
+ credentials: config?.credentials || {},
+ authorize: config?.authorize || jest.fn(),
+}));
+
+export default Credentials;
diff --git a/__mocks__/next-auth.ts b/__mocks__/next-auth.ts
new file mode 100644
index 0000000..286c937
--- /dev/null
+++ b/__mocks__/next-auth.ts
@@ -0,0 +1,18 @@
+const mockAuth = jest.fn();
+const mockSignIn = jest.fn();
+const mockSignOut = jest.fn();
+const mockHandlers = { GET: jest.fn(), POST: jest.fn() };
+
+const NextAuth = jest.fn(() => ({
+ auth: mockAuth,
+ handlers: mockHandlers,
+ signIn: mockSignIn,
+ signOut: mockSignOut,
+}));
+
+// Export both default and named exports
+export default NextAuth;
+export const auth = mockAuth;
+export const signIn = mockSignIn;
+export const signOut = mockSignOut;
+export const handlers = mockHandlers;
diff --git a/__mocks__/next-auth/index.js b/__mocks__/next-auth/index.js
new file mode 100644
index 0000000..810e667
--- /dev/null
+++ b/__mocks__/next-auth/index.js
@@ -0,0 +1,5 @@
+export const auth = jest.fn();
+
+export default {
+ auth,
+};
diff --git a/__tests__/TaskForm.spec.tsx b/__tests__/TaskForm.spec.tsx
new file mode 100644
index 0000000..59f12ce
--- /dev/null
+++ b/__tests__/TaskForm.spec.tsx
@@ -0,0 +1,445 @@
+import { TaskForm } from "@/components/tasks/TaskForm";
+import "@testing-library/jest-dom";
+import { screen, render, waitFor } from "@testing-library/react";
+import { getCurrentUser } from "@/utils/user.utils";
+import userEvent from "@testing-library/user-event";
+import { createTask, updateTask } from "@/actions/task.actions";
+import { Task } from "@/models/task.model";
+
+jest.mock("@/utils/user.utils", () => ({
+ getCurrentUser: jest.fn(),
+}));
+
+jest.mock("@/actions/task.actions", () => ({
+ createTask: jest.fn().mockResolvedValue({ success: true }),
+ updateTask: jest.fn().mockResolvedValue({ success: true }),
+}));
+
+global.ResizeObserver = jest.fn().mockImplementation(() => ({
+ observe: jest.fn(),
+ unobserve: jest.fn(),
+ disconnect: jest.fn(),
+}));
+
+document.createRange = () => {
+ const range = new Range();
+
+ range.getBoundingClientRect = jest.fn().mockReturnValue({
+ bottom: 0,
+ height: 0,
+ left: 0,
+ right: 0,
+ top: 0,
+ width: 0,
+ });
+
+ range.getClientRects = () => {
+ return {
+ item: () => null,
+ length: 0,
+ [Symbol.iterator]: jest.fn(),
+ };
+ };
+
+ return range;
+};
+
+describe("TaskForm Component", () => {
+ const mockUser = { id: "user-id" };
+ const mockActivityTypes = [
+ {
+ id: "type-1",
+ label: "Development",
+ value: "development",
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ {
+ id: "type-2",
+ label: "Testing",
+ value: "testing",
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ ];
+ const mockResetEditTask = jest.fn();
+ const mockOnTaskSaved = jest.fn();
+ const mockSetDialogOpen = jest.fn();
+ const user = userEvent.setup({ skipHover: true });
+
+ window.HTMLElement.prototype.scrollIntoView = jest.fn();
+ window.HTMLElement.prototype.hasPointerCapture = jest.fn();
+
+ beforeEach(() => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ jest.clearAllMocks();
+ });
+
+ describe("Add Task Mode", () => {
+ beforeEach(() => {
+ render(
+ <TaskForm
+ activityTypes={mockActivityTypes}
+ editTask={null}
+ resetEditTask={mockResetEditTask}
+ onTaskSaved={mockOnTaskSaved}
+ dialogOpen={true}
+ setDialogOpen={mockSetDialogOpen}
+ />
+ );
+ });
+
+ it("should render the dialog with title 'Add Task'", () => {
+ const dialogTitle = screen.getByTestId("task-form-dialog-title");
+ expect(dialogTitle).toBeInTheDocument();
+ expect(dialogTitle).toHaveTextContent("Add Task");
+ });
+
+ it("should show all form fields", () => {
+ expect(screen.getByLabelText(/Title/i)).toBeInTheDocument();
+ expect(screen.getByLabelText(/Activity Type/i)).toBeInTheDocument();
+ expect(screen.getByLabelText(/Status/i)).toBeInTheDocument();
+ expect(screen.getByText(/Priority:/i)).toBeInTheDocument();
+ expect(screen.getByText(/% Complete:/i)).toBeInTheDocument();
+ expect(screen.getByLabelText(/Due Date/i)).toBeInTheDocument();
+ expect(screen.getByText(/Description/i)).toBeInTheDocument();
+ });
+
+ it("should have default values", () => {
+ const titleInput = screen.getByLabelText(/Title/i);
+ expect(titleInput).toHaveValue("");
+
+ const statusSelect = screen.getByLabelText(/Status/i);
+ expect(statusSelect).toHaveTextContent("In Progress");
+
+ expect(screen.getByText(/Priority: 5/i)).toBeInTheDocument();
+ expect(screen.getByText(/% Complete: 0%/i)).toBeInTheDocument();
+ });
+
+ it("should show validation errors when submitting empty form", async () => {
+ const saveBtn = screen.getByTestId("save-task-btn");
+ await user.click(saveBtn);
+
+ await waitFor(() => {
+ expect(
+ screen.getByText("Title must be at least 2 characters.")
+ ).toBeInTheDocument();
+ });
+ });
+
+ it("should successfully submit a new task", async () => {
+ const titleInput = screen.getByLabelText(/Title/i);
+ await user.type(titleInput, "New Test Task");
+
+ const activityTypeCombobox = screen.getByLabelText(/Activity Type/i);
+ await user.click(activityTypeCombobox);
+ const developmentOption = screen.getByRole("option", {
+ name: "Development",
+ });
+ await user.click(developmentOption);
+
+ const saveBtn = screen.getByTestId("save-task-btn");
+ await user.click(saveBtn);
+
+ await waitFor(() => {
+ expect(createTask).toHaveBeenCalledTimes(1);
+ expect(createTask).toHaveBeenCalledWith(
+ expect.objectContaining({
+ title: "New Test Task",
+ activityTypeId: "type-1",
+ status: "in-progress",
+ priority: 5,
+ percentComplete: 0,
+ })
+ );
+ expect(mockOnTaskSaved).toHaveBeenCalledTimes(1);
+ expect(mockSetDialogOpen).toHaveBeenCalledWith(false);
+ expect(mockResetEditTask).toHaveBeenCalledTimes(1);
+ });
+ });
+
+ it("should close the dialog when cancel button is clicked", async () => {
+ const cancelBtn = screen.getByRole("button", { name: /cancel/i });
+ await user.click(cancelBtn);
+
+ expect(mockResetEditTask).toHaveBeenCalledTimes(1);
+ expect(mockSetDialogOpen).toHaveBeenCalledWith(false);
+ });
+
+ it("should display activity types in combobox", async () => {
+ const activityTypeCombobox = screen.getByLabelText(/Activity Type/i);
+ await user.click(activityTypeCombobox);
+
+ const options = screen.getAllByRole("option");
+ expect(options.length).toBeGreaterThan(0);
+ expect(
+ screen.getByRole("option", { name: "Development" })
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("option", { name: "Testing" })
+ ).toBeInTheDocument();
+ });
+
+ it("should display all status options", async () => {
+ const statusSelect = screen.getByLabelText(/Status/i);
+ await user.click(statusSelect);
+
+ expect(
+ screen.getByRole("option", { name: "In Progress" })
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("option", { name: "Complete" })
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("option", { name: "Needs Attention" })
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("option", { name: "Cancelled" })
+ ).toBeInTheDocument();
+ });
+
+ it("should handle title input correctly", async () => {
+ const titleInput = screen.getByLabelText(/Title/i);
+ await user.type(titleInput, "Test Task Title");
+
+ expect(titleInput).toHaveValue("Test Task Title");
+ });
+
+ it("should validate title minimum length", async () => {
+ const titleInput = screen.getByLabelText(/Title/i);
+ await user.type(titleInput, "A");
+
+ const saveBtn = screen.getByTestId("save-task-btn");
+ await user.click(saveBtn);
+
+ await waitFor(() => {
+ expect(
+ screen.getByText("Title must be at least 2 characters.")
+ ).toBeInTheDocument();
+ });
+ });
+
+ it("should validate due date is not in the past", async () => {
+ const titleInput = screen.getByLabelText(/Title/i);
+ await user.type(titleInput, "Valid Title");
+
+ // Note: Due date validation happens at schema level
+ // Testing the form's handling of the validation error
+ const saveBtn = screen.getByTestId("save-task-btn");
+ await user.click(saveBtn);
+
+ await waitFor(() => {
+ expect(createTask).toHaveBeenCalled();
+ });
+ });
+ });
+
+ describe("Edit Task Mode", () => {
+ const mockEditTask: Task = {
+ id: "task-id",
+ userId: "user-id",
+ title: "Existing Task",
+ description: "Existing description",
+ status: "needs-attention",
+ priority: 7,
+ percentComplete: 60,
+ dueDate: new Date("2026-12-31"),
+ activityTypeId: "type-1",
+ activityType: {
+ id: "type-1",
+ label: "Development",
+ value: "development",
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ activity: null,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ };
+
+ beforeEach(() => {
+ render(
+ <TaskForm
+ activityTypes={mockActivityTypes}
+ editTask={mockEditTask}
+ resetEditTask={mockResetEditTask}
+ onTaskSaved={mockOnTaskSaved}
+ dialogOpen={true}
+ setDialogOpen={mockSetDialogOpen}
+ />
+ );
+ });
+
+ it("should render the dialog with title 'Edit Task'", () => {
+ const dialogTitle = screen.getByTestId("task-form-dialog-title");
+ expect(dialogTitle).toBeInTheDocument();
+ expect(dialogTitle).toHaveTextContent("Edit Task");
+ });
+
+ it("should populate form with existing task data", () => {
+ const titleInput = screen.getByLabelText(/Title/i);
+ expect(titleInput).toHaveValue("Existing Task");
+
+ const statusSelect = screen.getByLabelText(/Status/i);
+ expect(statusSelect).toHaveTextContent("Needs Attention");
+
+ expect(screen.getByText(/Priority: 7/i)).toBeInTheDocument();
+ expect(screen.getByText(/% Complete: 60%/i)).toBeInTheDocument();
+ });
+
+ it("should successfully submit updated task", async () => {
+ const titleInput = screen.getByLabelText(/Title/i);
+ await user.clear(titleInput);
+ await user.type(titleInput, "Updated Task Title");
+
+ const saveBtn = screen.getByTestId("save-task-btn");
+ await user.click(saveBtn);
+
+ await waitFor(() => {
+ expect(updateTask).toHaveBeenCalledTimes(1);
+ expect(updateTask).toHaveBeenCalledWith(
+ expect.objectContaining({
+ id: "task-id",
+ title: "Updated Task Title",
+ status: "needs-attention",
+ priority: 7,
+ percentComplete: 60,
+ })
+ );
+ expect(mockOnTaskSaved).toHaveBeenCalledTimes(1);
+ expect(mockSetDialogOpen).toHaveBeenCalledWith(false);
+ expect(mockResetEditTask).toHaveBeenCalledTimes(1);
+ });
+ });
+
+ it("should update status correctly", async () => {
+ const statusSelect = screen.getByLabelText(/Status/i);
+ await user.click(statusSelect);
+
+ const completeOption = screen.getByRole("option", { name: "Complete" });
+ await user.click(completeOption);
+
+ await waitFor(() => {
+ expect(statusSelect).toHaveTextContent("Complete");
+ });
+ });
+
+ it("should handle form reset when cancel is clicked", async () => {
+ const titleInput = screen.getByLabelText(/Title/i);
+ await user.clear(titleInput);
+ await user.type(titleInput, "Changed Title");
+
+ const cancelBtn = screen.getByRole("button", { name: /cancel/i });
+ await user.click(cancelBtn);
+
+ expect(mockResetEditTask).toHaveBeenCalledTimes(1);
+ expect(mockSetDialogOpen).toHaveBeenCalledWith(false);
+ });
+ });
+
+ describe("Error Handling", () => {
+ beforeEach(() => {
+ render(
+ <TaskForm
+ activityTypes={mockActivityTypes}
+ editTask={null}
+ resetEditTask={mockResetEditTask}
+ onTaskSaved={mockOnTaskSaved}
+ dialogOpen={true}
+ setDialogOpen={mockSetDialogOpen}
+ />
+ );
+ });
+
+ it("should handle create task failure", async () => {
+ (createTask as jest.Mock).mockResolvedValue({
+ success: false,
+ message: "Failed to create task",
+ });
+
+ const titleInput = screen.getByLabelText(/Title/i);
+ await user.type(titleInput, "Test Task");
+
+ const saveBtn = screen.getByTestId("save-task-btn");
+ await user.click(saveBtn);
+
+ await waitFor(() => {
+ expect(createTask).toHaveBeenCalled();
+ expect(mockOnTaskSaved).not.toHaveBeenCalled();
+ expect(mockSetDialogOpen).not.toHaveBeenCalledWith(false);
+ });
+ });
+
+ it("should handle update task failure", async () => {
+ const mockEditTask: Task = {
+ id: "task-id",
+ userId: "user-id",
+ title: "Existing Task",
+ description: "",
+ status: "in-progress",
+ priority: 5,
+ percentComplete: 0,
+ dueDate: null,
+ activityTypeId: null,
+ activityType: null,
+ activity: null,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ };
+
+ (updateTask as jest.Mock).mockResolvedValue({
+ success: false,
+ message: "Failed to update task",
+ });
+
+ render(
+ <TaskForm
+ activityTypes={mockActivityTypes}
+ editTask={mockEditTask}
+ resetEditTask={mockResetEditTask}
+ onTaskSaved={mockOnTaskSaved}
+ dialogOpen={true}
+ setDialogOpen={mockSetDialogOpen}
+ />
+ );
+
+ // Just verify that when update fails, onTaskSaved is not called
+ // We verify this through the mock setup, not through interaction
+ expect(mockOnTaskSaved).not.toHaveBeenCalled();
+ });
+ });
+
+ describe("Dialog State Management", () => {
+ it("should not render when dialogOpen is false", () => {
+ render(
+ <TaskForm
+ activityTypes={mockActivityTypes}
+ editTask={null}
+ resetEditTask={mockResetEditTask}
+ onTaskSaved={mockOnTaskSaved}
+ dialogOpen={false}
+ setDialogOpen={mockSetDialogOpen}
+ />
+ );
+
+ const dialogTitle = screen.queryByTestId("task-form-dialog-title");
+ expect(dialogTitle).not.toBeInTheDocument();
+ });
+
+ it("should render when dialogOpen is true", () => {
+ render(
+ <TaskForm
+ activityTypes={mockActivityTypes}
+ editTask={null}
+ resetEditTask={mockResetEditTask}
+ onTaskSaved={mockOnTaskSaved}
+ dialogOpen={true}
+ setDialogOpen={mockSetDialogOpen}
+ />
+ );
+
+ const dialogTitle = screen.getByTestId("task-form-dialog-title");
+ expect(dialogTitle).toBeInTheDocument();
+ });
+ });
+});
diff --git a/__tests__/TasksContainer.spec.tsx b/__tests__/TasksContainer.spec.tsx
new file mode 100644
index 0000000..531846a
--- /dev/null
+++ b/__tests__/TasksContainer.spec.tsx
@@ -0,0 +1,642 @@
+import TasksContainer from "@/components/tasks/TasksContainer";
+import "@testing-library/jest-dom";
+import { screen, render, waitFor } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import {
+ getTasksList,
+ getTaskById,
+ deleteTaskById,
+ updateTaskStatus,
+ startActivityFromTask,
+} from "@/actions/task.actions";
+import { Task } from "@/models/task.model";
+import { useRouter } from "next/navigation";
+
+jest.mock("next-auth", () => {
+ const mockAuth = jest.fn();
+ const mockSignIn = jest.fn();
+ const mockSignOut = jest.fn();
+ const mockHandlers = { GET: jest.fn(), POST: jest.fn() };
+
+ return {
+ __esModule: true,
+ default: jest.fn(() => ({
+ auth: mockAuth,
+ handlers: mockHandlers,
+ signIn: mockSignIn,
+ signOut: mockSignOut,
+ })),
+ auth: mockAuth,
+ signIn: mockSignIn,
+ signOut: mockSignOut,
+ handlers: mockHandlers,
+ };
+});
+
+jest.mock("next-auth/providers/credentials", () => ({
+ __esModule: true,
+ default: jest.fn(() => ({
+ id: "credentials",
+ name: "Credentials",
+ type: "credentials",
+ })),
+}));
+
+jest.mock("@/actions/task.actions", () => ({
+ getTasksList: jest.fn(),
+ getTaskById: jest.fn(),
+ deleteTaskById: jest.fn(),
+ updateTaskStatus: jest.fn(),
+ startActivityFromTask: jest.fn(),
+}));
+
+jest.mock("next/navigation", () => ({
+ useRouter: jest.fn(),
+}));
+
+global.ResizeObserver = jest.fn().mockImplementation(() => ({
+ observe: jest.fn(),
+ unobserve: jest.fn(),
+ disconnect: jest.fn(),
+}));
+
+document.createRange = () => {
+ const range = new Range();
+
+ range.getBoundingClientRect = jest.fn().mockReturnValue({
+ bottom: 0,
+ height: 0,
+ left: 0,
+ right: 0,
+ top: 0,
+ width: 0,
+ });
+
+ range.getClientRects = () => {
+ return {
+ item: () => null,
+ length: 0,
+ [Symbol.iterator]: jest.fn(),
+ };
+ };
+
+ return range;
+};
+
+describe("TasksContainer Component", () => {
+ const mockRouter = {
+ push: jest.fn(),
+ back: jest.fn(),
+ forward: jest.fn(),
+ refresh: jest.fn(),
+ replace: jest.fn(),
+ prefetch: jest.fn(),
+ };
+
+ const mockActivityTypes = [
+ {
+ id: "type-1",
+ label: "Development",
+ value: "development",
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ {
+ id: "type-2",
+ label: "Testing",
+ value: "testing",
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ ];
+
+ const mockTasks: Task[] = [
+ {
+ id: "task-1",
+ userId: "user-id",
+ title: "Task 1",
+ description: "Description 1",
+ status: "in-progress",
+ priority: 5,
+ percentComplete: 50,
+ dueDate: new Date("2026-12-31"),
+ activityTypeId: "type-1",
+ activityType: {
+ id: "type-1",
+ label: "Development",
+ value: "development",
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ activity: null,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ {
+ id: "task-2",
+ userId: "user-id",
+ title: "Task 2",
+ description: "Description 2",
+ status: "needs-attention",
+ priority: 8,
+ percentComplete: 25,
+ dueDate: new Date("2026-11-30"),
+ activityTypeId: "type-2",
+ activityType: {
+ id: "type-2",
+ label: "Testing",
+ value: "testing",
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ activity: null,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ ];
+
+ const user = userEvent.setup({ skipHover: true });
+ window.HTMLElement.prototype.scrollIntoView = jest.fn();
+ window.HTMLElement.prototype.hasPointerCapture = jest.fn();
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ (useRouter as jest.Mock).mockReturnValue(mockRouter);
+ });
+
+ describe("Initial Load", () => {
+ it("should load and display tasks on mount", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(1, 10, undefined, [
+ "in-progress",
+ "needs-attention",
+ ]);
+ });
+
+ await waitFor(() => {
+ expect(screen.getByText("Task 1")).toBeInTheDocument();
+ expect(screen.getByText("Task 2")).toBeInTheDocument();
+ });
+ });
+
+ it("should show loading state while fetching tasks", () => {
+ (getTasksList as jest.Mock).mockImplementation(
+ () => new Promise(() => {}) // Never resolves to keep loading state
+ );
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ expect(screen.getByTestId("loader")).toBeInTheDocument();
+ });
+
+ it("should show empty state when no tasks are found", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: [],
+ total: 0,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(screen.getByText(/No tasks found/i)).toBeInTheDocument();
+ });
+ });
+ });
+
+ describe("Task Actions", () => {
+ beforeEach(async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(screen.queryByTestId("loader")).not.toBeInTheDocument();
+ });
+ });
+
+ it("should open add task dialog when add button is clicked", async () => {
+ const addButton = screen.getByTestId("add-task-btn");
+ await user.click(addButton);
+
+ await waitFor(() => {
+ expect(
+ screen.getByTestId("task-form-dialog-title")
+ ).toBeInTheDocument();
+ expect(screen.getByTestId("task-form-dialog-title")).toHaveTextContent(
+ "Add Task"
+ );
+ });
+ });
+
+ it("should handle task deletion successfully", async () => {
+ (deleteTaskById as jest.Mock).mockResolvedValue({
+ success: true,
+ });
+ (getTasksList as jest.Mock)
+ .mockResolvedValueOnce({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ })
+ .mockResolvedValueOnce({
+ success: true,
+ data: [mockTasks[1]],
+ total: 1,
+ });
+
+ await waitFor(() => {
+ expect(screen.queryByTestId("loader")).not.toBeInTheDocument();
+ });
+
+ // Find and click the actions menu button for the first task
+ const actionButtons = screen.getAllByTestId("task-actions-menu-btn");
+ await user.click(actionButtons[0]);
+
+ // Click the Delete menu item
+ const deleteMenuItem = await screen.findByRole("menuitem", {
+ name: /delete/i,
+ });
+ await user.click(deleteMenuItem);
+
+ // Confirm deletion in the alert dialog
+ const confirmButton = await screen.findByRole("button", {
+ name: /delete/i,
+ });
+ await user.click(confirmButton);
+
+ await waitFor(() => {
+ expect(deleteTaskById).toHaveBeenCalledWith("task-1");
+ });
+ });
+
+ it("should handle task deletion failure", async () => {
+ (deleteTaskById as jest.Mock).mockResolvedValue({
+ success: false,
+ message: "Failed to delete task",
+ });
+
+ await waitFor(() => {
+ expect(screen.queryByTestId("loader")).not.toBeInTheDocument();
+ });
+
+ // Find and click the actions menu button for the first task
+ const actionButtons = screen.getAllByTestId("task-actions-menu-btn");
+ await user.click(actionButtons[0]);
+
+ // Click the Delete menu item
+ const deleteMenuItem = await screen.findByRole("menuitem", {
+ name: /delete/i,
+ });
+ await user.click(deleteMenuItem);
+
+ // Confirm deletion in the alert dialog
+ const confirmButton = await screen.findByRole("button", {
+ name: /delete/i,
+ });
+ await user.click(confirmButton);
+
+ await waitFor(() => {
+ expect(deleteTaskById).toHaveBeenCalled();
+ });
+ });
+
+ it("should open edit task dialog when edit is clicked", async () => {
+ (getTaskById as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks[0],
+ });
+
+ // Find and click the actions menu button for the first task
+ const actionButtons = screen.getAllByTestId("task-actions-menu-btn");
+ await user.click(actionButtons[0]);
+
+ // Click the Edit Task menu item
+ const editMenuItem = await screen.findByRole("menuitem", {
+ name: /edit task/i,
+ });
+ await user.click(editMenuItem);
+
+ await waitFor(() => {
+ expect(getTaskById).toHaveBeenCalledWith("task-1");
+ expect(screen.getByTestId("task-form-dialog-title")).toHaveTextContent(
+ "Edit Task"
+ );
+ });
+ });
+
+ it("should handle edit task failure when task not found", async () => {
+ (getTaskById as jest.Mock).mockResolvedValue({
+ success: false,
+ message: "Task not found",
+ });
+
+ await waitFor(() => {
+ expect(screen.queryByTestId("loader")).not.toBeInTheDocument();
+ });
+
+ // Find and click the actions menu button for the first task
+ const actionButtons = screen.getAllByTestId("task-actions-menu-btn");
+ await user.click(actionButtons[0]);
+
+ // Click the Edit Task menu item
+ const editMenuItem = await screen.findByRole("menuitem", {
+ name: /edit task/i,
+ });
+ await user.click(editMenuItem);
+
+ await waitFor(() => {
+ expect(getTaskById).toHaveBeenCalledWith("task-1");
+ expect(
+ screen.queryByTestId("task-form-dialog-title")
+ ).not.toBeInTheDocument();
+ });
+ });
+
+ it("should update task status successfully", async () => {
+ (updateTaskStatus as jest.Mock).mockResolvedValue({
+ success: true,
+ });
+
+ await waitFor(() => {
+ expect(screen.queryByTestId("loader")).not.toBeInTheDocument();
+ });
+
+ // Find and click the actions menu button for the first task
+ const actionButtons = screen.getAllByTestId("task-actions-menu-btn");
+ await user.click(actionButtons[0]);
+
+ // Hover over Change Status to open submenu
+ const changeStatusMenuItem = await screen.findByRole("menuitem", {
+ name: /change status/i,
+ });
+ await user.hover(changeStatusMenuItem);
+
+ // Click the Complete option in the submenu
+ const completeOption = await screen.findByRole("menuitem", {
+ name: "Complete",
+ });
+ await user.click(completeOption);
+
+ await waitFor(() => {
+ expect(updateTaskStatus).toHaveBeenCalledWith("task-1", "complete");
+ });
+ });
+
+ it("should handle task status update failure", async () => {
+ (updateTaskStatus as jest.Mock).mockResolvedValue({
+ success: false,
+ message: "Failed to update status",
+ });
+
+ await waitFor(() => {
+ expect(screen.queryByTestId("loader")).not.toBeInTheDocument();
+ });
+
+ // Find and click the actions menu button for the first task
+ const actionButtons = screen.getAllByTestId("task-actions-menu-btn");
+ await user.click(actionButtons[0]);
+
+ // Hover over Change Status to open submenu
+ const changeStatusMenuItem = await screen.findByRole("menuitem", {
+ name: /change status/i,
+ });
+ await user.hover(changeStatusMenuItem);
+
+ // Click the Complete option in the submenu
+ const completeOption = await screen.findByRole("menuitem", {
+ name: "Complete",
+ });
+ await user.click(completeOption);
+
+ await waitFor(() => {
+ expect(updateTaskStatus).toHaveBeenCalledWith("task-1", "complete");
+ });
+ });
+
+ it("should start activity from task successfully", async () => {
+ (startActivityFromTask as jest.Mock).mockResolvedValue({
+ success: true,
+ });
+
+ const startActivityButtons = screen.getAllByTestId(/start-activity-/);
+ await user.click(startActivityButtons[0]);
+
+ await waitFor(() => {
+ expect(startActivityFromTask).toHaveBeenCalledWith("task-1");
+ expect(mockRouter.push).toHaveBeenCalledWith("/dashboard/activities");
+ });
+ });
+
+ it("should handle start activity failure", async () => {
+ (startActivityFromTask as jest.Mock).mockResolvedValue({
+ success: false,
+ message: "Failed to start activity",
+ });
+
+ const startActivityButtons = screen.getAllByTestId(/start-activity-/);
+ await user.click(startActivityButtons[0]);
+
+ await waitFor(() => {
+ expect(startActivityFromTask).toHaveBeenCalledWith("task-1");
+ expect(mockRouter.push).not.toHaveBeenCalled();
+ });
+ });
+ });
+
+ describe("Filtering and Grouping", () => {
+ beforeEach(async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ });
+
+ render(
+ <TasksContainer activityTypes={mockActivityTypes} filterKey="type-1" />
+ );
+
+ await waitFor(() => {
+ expect(screen.getByText("Task 1")).toBeInTheDocument();
+ });
+ });
+
+ it("should apply activity type filter", async () => {
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(1, 10, "type-1", [
+ "in-progress",
+ "needs-attention",
+ ]);
+ });
+ });
+
+ it("should toggle status filter", async () => {
+ const filterButton = screen.getByRole("button", { name: /status/i });
+ await user.click(filterButton);
+
+ const inProgressCheckbox = screen.getByRole("menuitemcheckbox", {
+ name: "In Progress",
+ });
+ expect(inProgressCheckbox).toBeChecked();
+
+ await user.click(inProgressCheckbox);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(1, 10, "type-1", [
+ "needs-attention",
+ ]);
+ });
+ });
+
+ it("should change grouping option", async () => {
+ const groupBySelect = screen.getByRole("combobox");
+ await user.click(groupBySelect);
+
+ const dueDateOption = screen.getByRole("option", { name: "Due Date" });
+ await user.click(dueDateOption);
+
+ await waitFor(() => {
+ expect(groupBySelect).toHaveTextContent("Due Date");
+ });
+ });
+ });
+
+ describe("Pagination", () => {
+ it("should show load more button when there are more tasks", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 20,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(screen.getByText("Load More")).toBeInTheDocument();
+ });
+ });
+
+ it("should load more tasks when load more button is clicked", async () => {
+ (getTasksList as jest.Mock)
+ .mockResolvedValueOnce({
+ success: true,
+ data: mockTasks,
+ total: 20,
+ })
+ .mockResolvedValueOnce({
+ success: true,
+ data: [
+ {
+ ...mockTasks[0],
+ id: "task-3",
+ title: "Task 3",
+ },
+ ],
+ total: 20,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(screen.getByText("Load More")).toBeInTheDocument();
+ });
+
+ const loadMoreButton = screen.getByText("Load More");
+ await user.click(loadMoreButton);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(2, 10, undefined, [
+ "in-progress",
+ "needs-attention",
+ ]);
+ });
+ });
+
+ it("should not show load more button when all tasks are loaded", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(screen.queryByText("Load More")).not.toBeInTheDocument();
+ });
+ });
+
+ it("should show correct task count", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 10,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(screen.getByText(/Showing/i)).toBeInTheDocument();
+ expect(
+ screen.getByText("1 to 2", { exact: false })
+ ).toBeInTheDocument();
+ expect(screen.getByText("10", { exact: false })).toBeInTheDocument();
+ });
+ });
+ });
+
+ describe("Error Handling", () => {
+ it("should handle getTasksList error", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: false,
+ message: "Failed to fetch tasks",
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalled();
+ });
+ });
+ });
+
+ describe("Filter Change Callback", () => {
+ it("should call onFilterChange when filter changes", async () => {
+ const mockOnFilterChange = jest.fn();
+
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ });
+
+ render(
+ <TasksContainer
+ activityTypes={mockActivityTypes}
+ filterKey={undefined}
+ onFilterChange={mockOnFilterChange}
+ />
+ );
+
+ await waitFor(() => {
+ expect(screen.getByText("Task 1")).toBeInTheDocument();
+ });
+
+ // Note: onFilterChange would typically be called from parent component
+ // This test verifies the prop is passed correctly
+ expect(mockOnFilterChange).not.toHaveBeenCalled();
+ });
+ });
+});
diff --git a/__tests__/TasksPageClient.spec.tsx b/__tests__/TasksPageClient.spec.tsx
new file mode 100644
index 0000000..a512fa1
--- /dev/null
+++ b/__tests__/TasksPageClient.spec.tsx
@@ -0,0 +1,564 @@
+import TasksPageClient from "@/app/dashboard/tasks/TasksPageClient";
+import "@testing-library/jest-dom";
+import { screen, render, waitFor } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { getTasksList } from "@/actions/task.actions";
+
+jest.mock("next-auth", () => {
+ const mockAuth = jest.fn();
+ const mockSignIn = jest.fn();
+ const mockSignOut = jest.fn();
+ const mockHandlers = { GET: jest.fn(), POST: jest.fn() };
+
+ return {
+ __esModule: true,
+ default: jest.fn(() => ({
+ auth: mockAuth,
+ handlers: mockHandlers,
+ signIn: mockSignIn,
+ signOut: mockSignOut,
+ })),
+ auth: mockAuth,
+ signIn: mockSignIn,
+ signOut: mockSignOut,
+ handlers: mockHandlers,
+ };
+});
+
+jest.mock("next-auth/providers/credentials", () => ({
+ __esModule: true,
+ default: jest.fn(() => ({
+ id: "credentials",
+ name: "Credentials",
+ type: "credentials",
+ })),
+}));
+
+jest.mock("@/actions/task.actions", () => ({
+ getTasksList: jest.fn(),
+}));
+
+jest.mock("next/navigation", () => ({
+ useRouter: jest.fn().mockReturnValue({
+ push: jest.fn(),
+ back: jest.fn(),
+ forward: jest.fn(),
+ refresh: jest.fn(),
+ replace: jest.fn(),
+ prefetch: jest.fn(),
+ }),
+}));
+
+global.ResizeObserver = jest.fn().mockImplementation(() => ({
+ observe: jest.fn(),
+ unobserve: jest.fn(),
+ disconnect: jest.fn(),
+}));
+
+document.createRange = () => {
+ const range = new Range();
+
+ range.getBoundingClientRect = jest.fn().mockReturnValue({
+ bottom: 0,
+ height: 0,
+ left: 0,
+ right: 0,
+ top: 0,
+ width: 0,
+ });
+
+ range.getClientRects = () => {
+ return {
+ item: () => null,
+ length: 0,
+ [Symbol.iterator]: jest.fn(),
+ };
+ };
+
+ return range;
+};
+
+describe("TasksPageClient Component", () => {
+ const mockActivityTypes = [
+ {
+ id: "type-1",
+ label: "Development",
+ value: "development",
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ {
+ id: "type-2",
+ label: "Testing",
+ value: "testing",
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ ];
+
+ const mockActivityTypesWithCounts = [
+ {
+ id: "type-1",
+ label: "Development",
+ value: "development",
+ taskCount: 5,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ {
+ id: "type-2",
+ label: "Testing",
+ value: "testing",
+ taskCount: 3,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ ];
+
+ const user = userEvent.setup({ skipHover: true });
+ window.HTMLElement.prototype.scrollIntoView = jest.fn();
+ window.HTMLElement.prototype.hasPointerCapture = jest.fn();
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: [],
+ total: 0,
+ });
+ });
+
+ describe("Rendering", () => {
+ it("should render TasksSidebar and TasksContainer components", () => {
+ render(
+ <TasksPageClient
+ activityTypes={mockActivityTypes}
+ activityTypesWithCounts={mockActivityTypesWithCounts}
+ totalTasks={8}
+ />
+ );
+
+ // Check if sidebar is rendered
+ expect(screen.getByText("Activity Types")).toBeInTheDocument();
+ expect(screen.getByText("Development")).toBeInTheDocument();
+ expect(screen.getByText("Testing")).toBeInTheDocument();
+
+ // Check if container is rendered
+ expect(screen.getByText("My Tasks")).toBeInTheDocument();
+ });
+
+ it("should display total task count in sidebar", () => {
+ render(
+ <TasksPageClient
+ activityTypes={mockActivityTypes}
+ activityTypesWithCounts={mockActivityTypesWithCounts}
+ totalTasks={8}
+ />
+ );
+
+ expect(screen.getByText("8")).toBeInTheDocument();
+ });
+
+ it("should display task counts for each activity type", () => {
+ render(
+ <TasksPageClient
+ activityTypes={mockActivityTypes}
+ activityTypesWithCounts={mockActivityTypesWithCounts}
+ totalTasks={8}
+ />
+ );
+
+ expect(screen.getByText("5")).toBeInTheDocument(); // Development count
+ expect(screen.getByText("3")).toBeInTheDocument(); // Testing count
+ });
+ });
+
+ describe("Filter Management", () => {
+ it("should start with no filter selected", () => {
+ render(
+ <TasksPageClient
+ activityTypes={mockActivityTypes}
+ activityTypesWithCounts={mockActivityTypesWithCounts}
+ totalTasks={8}
+ />
+ );
+
+ const allButton = screen.getByRole("button", { name: /All/i });
+ expect(allButton).toHaveClass("bg-accent");
+ });
+
+ it("should update filter when activity type is clicked in sidebar", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: [],
+ total: 0,
+ });
+
+ render(
+ <TasksPageClient
+ activityTypes={mockActivityTypes}
+ activityTypesWithCounts={mockActivityTypesWithCounts}
+ totalTasks={8}
+ />
+ );
+
+ const developmentButton = screen.getByRole("button", {
+ name: /Development/i,
+ });
+ await user.click(developmentButton);
+
+ await waitFor(() => {
+ expect(developmentButton).toHaveClass("bg-accent");
+ });
+ });
+
+ it("should reset filter when 'All' is clicked", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: [],
+ total: 0,
+ });
+
+ render(
+ <TasksPageClient
+ activityTypes={mockActivityTypes}
+ activityTypesWithCounts={mockActivityTypesWithCounts}
+ totalTasks={8}
+ />
+ );
+
+ // First click on a filter
+ const developmentButton = screen.getByRole("button", {
+ name: /Development/i,
+ });
+ await user.click(developmentButton);
+
+ await waitFor(() => {
+ expect(developmentButton).toHaveClass("bg-accent");
+ });
+
+ // Then click on All
+ const allButton = screen.getByRole("button", { name: /All/i });
+ await user.click(allButton);
+
+ await waitFor(() => {
+ expect(allButton).toHaveClass("bg-accent");
+ });
+ });
+
+ it("should apply different filters sequentially", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: [],
+ total: 0,
+ });
+
+ render(
+ <TasksPageClient
+ activityTypes={mockActivityTypes}
+ activityTypesWithCounts={mockActivityTypesWithCounts}
+ totalTasks={8}
+ />
+ );
+
+ const developmentButton = screen.getByRole("button", {
+ name: /Development/i,
+ });
+ await user.click(developmentButton);
+
+ await waitFor(() => {
+ expect(developmentButton).toHaveClass("bg-accent");
+ });
+
+ const testingButton = screen.getByRole("button", { name: /Testing/i });
+ await user.click(testingButton);
+
+ await waitFor(() => {
+ expect(testingButton).toHaveClass("bg-accent");
+ });
+ });
+ });
+
+ describe("Empty States", () => {
+ it("should handle empty activity types list", () => {
+ render(
+ <TasksPageClient
+ activityTypes={[]}
+ activityTypesWithCounts={[]}
+ totalTasks={0}
+ />
+ );
+
+ expect(screen.getByText("Activity Types")).toBeInTheDocument();
+ expect(screen.getByText("My Tasks")).toBeInTheDocument();
+ });
+
+ it("should show 0 total tasks when no tasks exist", () => {
+ render(
+ <TasksPageClient
+ activityTypes={mockActivityTypes}
+ activityTypesWithCounts={mockActivityTypesWithCounts.map((type) => ({
+ ...type,
+ taskCount: 0,
+ }))}
+ totalTasks={0}
+ />
+ );
+
+ const zeroElements = screen.queryAllByText("0");
+ expect(zeroElements.length).toBeGreaterThan(0);
+ });
+ });
+
+ describe("Layout", () => {
+ it("should render with correct layout structure", () => {
+ const { container } = render(
+ <TasksPageClient
+ activityTypes={mockActivityTypes}
+ activityTypesWithCounts={mockActivityTypesWithCounts}
+ totalTasks={8}
+ />
+ );
+
+ // Check if main container has correct classes
+ const mainContainer = container.querySelector(".col-span-3.flex.h-full");
+ expect(mainContainer).toBeInTheDocument();
+ });
+
+ it("should render sidebar with correct styling", () => {
+ const { container } = render(
+ <TasksPageClient
+ activityTypes={mockActivityTypes}
+ activityTypesWithCounts={mockActivityTypesWithCounts}
+ totalTasks={8}
+ />
+ );
+
+ const sidebar = container.querySelector(".w-48.border-r.p-4");
+ expect(sidebar).toBeInTheDocument();
+ });
+
+ it("should render container with flex-1 class", () => {
+ const { container } = render(
+ <TasksPageClient
+ activityTypes={mockActivityTypes}
+ activityTypesWithCounts={mockActivityTypesWithCounts}
+ totalTasks={8}
+ />
+ );
+
+ const tasksContainer = container.querySelector(".flex-1");
+ expect(tasksContainer).toBeInTheDocument();
+ });
+ });
+
+ describe("Filter Synchronization", () => {
+ it("should pass filter to TasksContainer", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: [],
+ total: 0,
+ });
+
+ render(
+ <TasksPageClient
+ activityTypes={mockActivityTypes}
+ activityTypesWithCounts={mockActivityTypesWithCounts}
+ totalTasks={8}
+ />
+ );
+
+ const developmentButton = screen.getByRole("button", {
+ name: /Development/i,
+ });
+ await user.click(developmentButton);
+
+ // Wait for the filter to be applied
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 1,
+ 10,
+ "type-1",
+ expect.any(Array)
+ );
+ });
+ });
+
+ it("should clear filter when All is selected", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: [],
+ total: 0,
+ });
+
+ render(
+ <TasksPageClient
+ activityTypes={mockActivityTypes}
+ activityTypesWithCounts={mockActivityTypesWithCounts}
+ totalTasks={8}
+ />
+ );
+
+ // First select a filter
+ const developmentButton = screen.getByRole("button", {
+ name: /Development/i,
+ });
+ await user.click(developmentButton);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 1,
+ 10,
+ "type-1",
+ expect.any(Array)
+ );
+ });
+
+ // Clear mock calls
+ (getTasksList as jest.Mock).mockClear();
+
+ // Then click All
+ const allButton = screen.getByRole("button", { name: /All/i });
+ await user.click(allButton);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 1,
+ 10,
+ undefined,
+ expect.any(Array)
+ );
+ });
+ });
+ });
+
+ describe("Multiple Activity Types", () => {
+ it("should render many activity types correctly", () => {
+ const manyActivityTypes = [
+ {
+ id: "1",
+ label: "Development",
+ value: "development",
+ taskCount: 10,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ {
+ id: "2",
+ label: "Testing",
+ value: "testing",
+ taskCount: 5,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ {
+ id: "3",
+ label: "Code Review",
+ value: "code-review",
+ taskCount: 3,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ {
+ id: "4",
+ label: "Documentation",
+ value: "documentation",
+ taskCount: 2,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ {
+ id: "5",
+ label: "Bug Fixing",
+ value: "bug-fixing",
+ taskCount: 7,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ ];
+
+ render(
+ <TasksPageClient
+ activityTypes={manyActivityTypes}
+ activityTypesWithCounts={manyActivityTypes}
+ totalTasks={27}
+ />
+ );
+
+ expect(screen.getByText("Development")).toBeInTheDocument();
+ expect(screen.getByText("Testing")).toBeInTheDocument();
+ expect(screen.getByText("Code Review")).toBeInTheDocument();
+ expect(screen.getByText("Documentation")).toBeInTheDocument();
+ expect(screen.getByText("Bug Fixing")).toBeInTheDocument();
+ expect(screen.getByText("27")).toBeInTheDocument();
+ });
+
+ it("should handle switching between multiple filters", async () => {
+ const manyActivityTypes = [
+ {
+ id: "1",
+ label: "Development",
+ value: "development",
+ taskCount: 10,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ {
+ id: "2",
+ label: "Testing",
+ value: "testing",
+ taskCount: 5,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ {
+ id: "3",
+ label: "Code Review",
+ value: "code-review",
+ taskCount: 3,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ ];
+
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: [],
+ total: 0,
+ });
+
+ render(
+ <TasksPageClient
+ activityTypes={manyActivityTypes}
+ activityTypesWithCounts={manyActivityTypes}
+ totalTasks={18}
+ />
+ );
+
+ const developmentButton = screen.getByRole("button", {
+ name: /Development/i,
+ });
+ await user.click(developmentButton);
+
+ await waitFor(() => {
+ expect(developmentButton).toHaveClass("bg-accent");
+ });
+
+ const testingButton = screen.getByRole("button", { name: /Testing/i });
+ await user.click(testingButton);
+
+ await waitFor(() => {
+ expect(testingButton).toHaveClass("bg-accent");
+ });
+
+ const codeReviewButton = screen.getByRole("button", {
+ name: /Code Review/i,
+ });
+ await user.click(codeReviewButton);
+
+ await waitFor(() => {
+ expect(codeReviewButton).toHaveClass("bg-accent");
+ });
+ });
+ });
+});
diff --git a/__tests__/task.actions.spec.ts b/__tests__/task.actions.spec.ts
new file mode 100644
index 0000000..02ba723
--- /dev/null
+++ b/__tests__/task.actions.spec.ts
@@ -0,0 +1,819 @@
+import {
+ getTasksList,
+ getTaskById,
+ createTask,
+ updateTask,
+ updateTaskStatus,
+ deleteTaskById,
+ startActivityFromTask,
+ getActivityTypesWithTaskCounts,
+} from "@/actions/task.actions";
+import { getCurrentUser } from "@/utils/user.utils";
+import { PrismaClient } from "@prisma/client";
+
+const prisma = new PrismaClient();
+
+// Mock the Prisma Client
+jest.mock("@prisma/client", () => {
+ const mPrismaClient = {
+ task: {
+ findMany: jest.fn(),
+ findFirst: jest.fn(),
+ count: jest.fn(),
+ create: jest.fn(),
+ update: jest.fn(),
+ delete: jest.fn(),
+ },
+ activity: {
+ findFirst: jest.fn(),
+ create: jest.fn(),
+ },
+ activityType: {
+ findMany: jest.fn(),
+ },
+ };
+ return { PrismaClient: jest.fn(() => mPrismaClient) };
+});
+
+jest.mock("@/utils/user.utils", () => ({
+ getCurrentUser: jest.fn(),
+}));
+
+describe("taskActions", () => {
+ const mockUser = { id: "user-id" };
+ const mockTask = {
+ id: "task-id",
+ userId: mockUser.id,
+ title: "Test Task",
+ description: "Test task description",
+ status: "in-progress" as const,
+ priority: 5,
+ percentComplete: 50,
+ dueDate: new Date("2026-12-31"),
+ activityTypeId: "activity-type-id",
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ activityType: {
+ id: "activity-type-id",
+ label: "Development",
+ value: "development",
+ },
+ activity: null,
+ };
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ describe("getTasksList", () => {
+ it("should return tasks list on successful query with default parameters", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+
+ const mockTasks = [mockTask];
+ (prisma.task.findMany as jest.Mock).mockResolvedValue(mockTasks);
+ (prisma.task.count as jest.Mock).mockResolvedValue(1);
+
+ const result = await getTasksList();
+
+ expect(result).toEqual({
+ success: true,
+ data: mockTasks,
+ total: 1,
+ });
+ expect(prisma.task.findMany).toHaveBeenCalledWith({
+ where: { userId: mockUser.id },
+ include: {
+ activityType: true,
+ activity: {
+ select: { id: true },
+ },
+ },
+ orderBy: [{ dueDate: "asc" }, { createdAt: "desc" }],
+ skip: 0,
+ take: 10,
+ });
+ expect(prisma.task.count).toHaveBeenCalledWith({
+ where: { userId: mockUser.id },
+ });
+ });
+
+ it("should return tasks list with pagination", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+
+ const mockTasks = [mockTask];
+ (prisma.task.findMany as jest.Mock).mockResolvedValue(mockTasks);
+ (prisma.task.count as jest.Mock).mockResolvedValue(25);
+
+ const result = await getTasksList(2, 10);
+
+ expect(result).toEqual({
+ success: true,
+ data: mockTasks,
+ total: 25,
+ });
+ expect(prisma.task.findMany).toHaveBeenCalledWith({
+ where: { userId: mockUser.id },
+ include: {
+ activityType: true,
+ activity: {
+ select: { id: true },
+ },
+ },
+ orderBy: [{ dueDate: "asc" }, { createdAt: "desc" }],
+ skip: 10,
+ take: 10,
+ });
+ });
+
+ it("should return tasks list with activity type filter", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+
+ const mockTasks = [mockTask];
+ (prisma.task.findMany as jest.Mock).mockResolvedValue(mockTasks);
+ (prisma.task.count as jest.Mock).mockResolvedValue(1);
+
+ const result = await getTasksList(1, 10, "activity-type-id");
+
+ expect(result).toEqual({
+ success: true,
+ data: mockTasks,
+ total: 1,
+ });
+ expect(prisma.task.findMany).toHaveBeenCalledWith({
+ where: {
+ userId: mockUser.id,
+ activityTypeId: "activity-type-id",
+ },
+ include: {
+ activityType: true,
+ activity: {
+ select: { id: true },
+ },
+ },
+ orderBy: [{ dueDate: "asc" }, { createdAt: "desc" }],
+ skip: 0,
+ take: 10,
+ });
+ });
+
+ it("should return tasks list with status filter", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+
+ const mockTasks = [mockTask];
+ (prisma.task.findMany as jest.Mock).mockResolvedValue(mockTasks);
+ (prisma.task.count as jest.Mock).mockResolvedValue(1);
+
+ const result = await getTasksList(1, 10, undefined, [
+ "in-progress",
+ "needs-attention",
+ ]);
+
+ expect(result).toEqual({
+ success: true,
+ data: mockTasks,
+ total: 1,
+ });
+ expect(prisma.task.findMany).toHaveBeenCalledWith({
+ where: {
+ userId: mockUser.id,
+ status: { in: ["in-progress", "needs-attention"] },
+ },
+ include: {
+ activityType: true,
+ activity: {
+ select: { id: true },
+ },
+ },
+ orderBy: [{ dueDate: "asc" }, { createdAt: "desc" }],
+ skip: 0,
+ take: 10,
+ });
+ });
+
+ it("should return error when user is not authenticated", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await getTasksList();
+
+ expect(result).toEqual({
+ success: false,
+ message: "Not authenticated",
+ });
+ });
+
+ it("should handle database errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.findMany as jest.Mock).mockRejectedValue(
+ new Error("Database error")
+ );
+
+ const result = await getTasksList();
+
+ expect(result).toEqual({
+ success: false,
+ message: "Database error",
+ });
+ });
+ });
+
+ describe("getTaskById", () => {
+ it("should return task on successful query", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.findFirst as jest.Mock).mockResolvedValue(mockTask);
+
+ const result = await getTaskById("task-id");
+
+ expect(result).toEqual({
+ success: true,
+ data: mockTask,
+ });
+ expect(prisma.task.findFirst).toHaveBeenCalledWith({
+ where: {
+ id: "task-id",
+ userId: mockUser.id,
+ },
+ include: {
+ activityType: true,
+ activity: {
+ select: { id: true },
+ },
+ },
+ });
+ });
+
+ it("should return error when task is not found", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.findFirst as jest.Mock).mockResolvedValue(null);
+
+ const result = await getTaskById("non-existent-id");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Task not found",
+ });
+ });
+
+ it("should return error when user is not authenticated", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await getTaskById("task-id");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Not authenticated",
+ });
+ });
+
+ it("should handle database errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.findFirst as jest.Mock).mockRejectedValue(
+ new Error("Database error")
+ );
+
+ const result = await getTaskById("task-id");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Database error",
+ });
+ });
+ });
+
+ describe("createTask", () => {
+ const taskData = {
+ title: "New Task",
+ description: "New task description",
+ status: "in-progress" as const,
+ priority: 5,
+ percentComplete: 0,
+ dueDate: new Date("2026-12-31"),
+ activityTypeId: "activity-type-id",
+ };
+
+ it("should create a task successfully", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.create as jest.Mock).mockResolvedValue(mockTask);
+
+ const result = await createTask(taskData);
+
+ expect(result).toEqual({
+ success: true,
+ data: mockTask,
+ });
+ expect(prisma.task.create).toHaveBeenCalledWith({
+ data: {
+ title: taskData.title,
+ description: taskData.description,
+ status: taskData.status,
+ priority: taskData.priority,
+ percentComplete: taskData.percentComplete,
+ dueDate: taskData.dueDate,
+ activityTypeId: taskData.activityTypeId,
+ userId: mockUser.id,
+ },
+ include: {
+ activityType: true,
+ },
+ });
+ });
+
+ it("should return error when user is not authenticated", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await createTask(taskData);
+
+ expect(result).toEqual({
+ success: false,
+ message: "Not authenticated",
+ });
+ });
+
+ it("should handle validation errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+
+ const invalidData = {
+ ...taskData,
+ title: "A", // Too short
+ };
+
+ const result = await createTask(invalidData);
+
+ expect(result.success).toBe(false);
+ expect(result.message).toBeTruthy();
+ });
+
+ it("should handle database errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.create as jest.Mock).mockRejectedValue(
+ new Error("Database error")
+ );
+
+ const result = await createTask(taskData);
+
+ expect(result).toEqual({
+ success: false,
+ message: "Database error",
+ });
+ });
+ });
+
+ describe("updateTask", () => {
+ const updateData = {
+ id: "task-id",
+ title: "Updated Task",
+ description: "Updated task description",
+ status: "complete" as const,
+ priority: 8,
+ percentComplete: 100,
+ dueDate: new Date("2026-12-31"),
+ activityTypeId: "activity-type-id",
+ };
+
+ it("should update a task successfully", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ const updatedTask = { ...mockTask, ...updateData };
+ (prisma.task.update as jest.Mock).mockResolvedValue(updatedTask);
+
+ const result = await updateTask(updateData);
+
+ expect(result).toEqual({
+ success: true,
+ data: updatedTask,
+ });
+ expect(prisma.task.update).toHaveBeenCalledWith({
+ where: {
+ id: updateData.id,
+ userId: mockUser.id,
+ },
+ data: {
+ title: updateData.title,
+ description: updateData.description,
+ status: updateData.status,
+ priority: updateData.priority,
+ percentComplete: updateData.percentComplete,
+ dueDate: updateData.dueDate,
+ activityTypeId: updateData.activityTypeId,
+ },
+ include: {
+ activityType: true,
+ },
+ });
+ });
+
+ it("should return error when task ID is missing", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+
+ const dataWithoutId = { ...updateData };
+ delete (dataWithoutId as any).id;
+
+ const result = await updateTask(dataWithoutId);
+
+ expect(result).toEqual({
+ success: false,
+ message: "Task ID is required for update",
+ });
+ });
+
+ it("should return error when user is not authenticated", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await updateTask(updateData);
+
+ expect(result).toEqual({
+ success: false,
+ message: "Not authenticated",
+ });
+ });
+
+ it("should handle database errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.update as jest.Mock).mockRejectedValue(
+ new Error("Database error")
+ );
+
+ const result = await updateTask(updateData);
+
+ expect(result).toEqual({
+ success: false,
+ message: "Database error",
+ });
+ });
+ });
+
+ describe("updateTaskStatus", () => {
+ it("should update task status successfully", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ const updatedTask = { ...mockTask, status: "complete" as const };
+ (prisma.task.update as jest.Mock).mockResolvedValue(updatedTask);
+
+ const result = await updateTaskStatus("task-id", "complete");
+
+ expect(result).toEqual({
+ success: true,
+ data: updatedTask,
+ });
+ expect(prisma.task.update).toHaveBeenCalledWith({
+ where: {
+ id: "task-id",
+ userId: mockUser.id,
+ },
+ data: {
+ status: "complete",
+ },
+ include: {
+ activityType: true,
+ },
+ });
+ });
+
+ it("should return error when user is not authenticated", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await updateTaskStatus("task-id", "complete");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Not authenticated",
+ });
+ });
+
+ it("should handle database errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.update as jest.Mock).mockRejectedValue(
+ new Error("Database error")
+ );
+
+ const result = await updateTaskStatus("task-id", "complete");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Database error",
+ });
+ });
+ });
+
+ describe("deleteTaskById", () => {
+ it("should delete task successfully when no linked activity", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.findFirst as jest.Mock).mockResolvedValue(mockTask);
+ (prisma.task.delete as jest.Mock).mockResolvedValue(mockTask);
+
+ const result = await deleteTaskById("task-id");
+
+ expect(result).toEqual({
+ success: true,
+ });
+ expect(prisma.task.delete).toHaveBeenCalledWith({
+ where: {
+ id: "task-id",
+ userId: mockUser.id,
+ },
+ });
+ });
+
+ it("should return error when task is not found", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.findFirst as jest.Mock).mockResolvedValue(null);
+
+ const result = await deleteTaskById("non-existent-id");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Task not found",
+ });
+ });
+
+ it("should return error when task has linked activity", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ const taskWithActivity = {
+ ...mockTask,
+ activity: { id: "activity-id" },
+ };
+ (prisma.task.findFirst as jest.Mock).mockResolvedValue(taskWithActivity);
+
+ const result = await deleteTaskById("task-id");
+
+ expect(result).toEqual({
+ success: false,
+ message:
+ "Cannot delete task with linked activity. Remove the activity first.",
+ });
+ expect(prisma.task.delete).not.toHaveBeenCalled();
+ });
+
+ it("should return error when user is not authenticated", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await deleteTaskById("task-id");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Not authenticated",
+ });
+ });
+
+ it("should handle database errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.findFirst as jest.Mock).mockRejectedValue(
+ new Error("Database error")
+ );
+
+ const result = await deleteTaskById("task-id");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Database error",
+ });
+ });
+ });
+
+ describe("startActivityFromTask", () => {
+ const mockActivity = {
+ id: "activity-id",
+ activityName: "Test Task",
+ activityTypeId: "activity-type-id",
+ userId: mockUser.id,
+ startTime: expect.any(Date),
+ endTime: null,
+ taskId: "task-id",
+ activityType: {
+ id: "activity-type-id",
+ label: "Development",
+ value: "development",
+ },
+ };
+
+ it("should start activity from task successfully", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.findFirst as jest.Mock).mockResolvedValue(mockTask);
+ (prisma.activity.findFirst as jest.Mock).mockResolvedValue(null);
+ (prisma.activity.create as jest.Mock).mockResolvedValue(mockActivity);
+
+ const result = await startActivityFromTask("task-id");
+
+ expect(result).toEqual({
+ success: true,
+ data: mockActivity,
+ });
+ expect(prisma.activity.create).toHaveBeenCalledWith({
+ data: {
+ activityName: mockTask.title,
+ activityTypeId: mockTask.activityTypeId,
+ userId: mockUser.id,
+ startTime: expect.any(Date),
+ endTime: null,
+ taskId: mockTask.id,
+ },
+ include: {
+ activityType: true,
+ },
+ });
+ });
+
+ it("should return error when task is not found", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.findFirst as jest.Mock).mockResolvedValue(null);
+
+ const result = await startActivityFromTask("non-existent-id");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Task not found",
+ });
+ });
+
+ it("should return error when task already has linked activity", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ const taskWithActivity = {
+ ...mockTask,
+ activity: { id: "activity-id" },
+ };
+ (prisma.task.findFirst as jest.Mock).mockResolvedValue(taskWithActivity);
+
+ const result = await startActivityFromTask("task-id");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Task already has a linked activity.",
+ });
+ });
+
+ it("should return error when task has no activity type", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ const taskWithoutActivityType = {
+ ...mockTask,
+ activityTypeId: null,
+ };
+ (prisma.task.findFirst as jest.Mock).mockResolvedValue(
+ taskWithoutActivityType
+ );
+
+ const result = await startActivityFromTask("task-id");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Task must have an activity type to start an activity.",
+ });
+ });
+
+ it("should return error when task status is complete", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ const completedTask = {
+ ...mockTask,
+ status: "complete" as const,
+ };
+ (prisma.task.findFirst as jest.Mock).mockResolvedValue(completedTask);
+
+ const result = await startActivityFromTask("task-id");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Cannot start an activity from a completed or cancelled task.",
+ });
+ });
+
+ it("should return error when task status is cancelled", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ const cancelledTask = {
+ ...mockTask,
+ status: "cancelled" as const,
+ };
+ (prisma.task.findFirst as jest.Mock).mockResolvedValue(cancelledTask);
+
+ const result = await startActivityFromTask("task-id");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Cannot start an activity from a completed or cancelled task.",
+ });
+ });
+
+ it("should return error when user already has a running activity", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.findFirst as jest.Mock).mockResolvedValue(mockTask);
+ (prisma.activity.findFirst as jest.Mock).mockResolvedValue({
+ id: "existing-activity-id",
+ endTime: null,
+ });
+
+ const result = await startActivityFromTask("task-id");
+
+ expect(result).toEqual({
+ success: false,
+ message:
+ "You already have a running activity. Please stop it before starting a new one.",
+ });
+ });
+
+ it("should return error when user is not authenticated", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await startActivityFromTask("task-id");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Not authenticated",
+ });
+ });
+
+ it("should handle database errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.task.findFirst as jest.Mock).mockRejectedValue(
+ new Error("Database error")
+ );
+
+ const result = await startActivityFromTask("task-id");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Database error",
+ });
+ });
+ });
+
+ describe("getActivityTypesWithTaskCounts", () => {
+ it("should return activity types with task counts successfully", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+
+ const mockActivityTypes = [
+ {
+ id: "type-1",
+ label: "Development",
+ value: "development",
+ createdBy: mockUser.id,
+ _count: { Tasks: 5 },
+ },
+ {
+ id: "type-2",
+ label: "Testing",
+ value: "testing",
+ createdBy: mockUser.id,
+ _count: { Tasks: 3 },
+ },
+ ];
+ (prisma.activityType.findMany as jest.Mock).mockResolvedValue(
+ mockActivityTypes
+ );
+ (prisma.task.count as jest.Mock).mockResolvedValue(8);
+
+ const result = await getActivityTypesWithTaskCounts();
+
+ expect(result).toEqual({
+ success: true,
+ data: [
+ {
+ id: "type-1",
+ label: "Development",
+ value: "development",
+ taskCount: 5,
+ },
+ {
+ id: "type-2",
+ label: "Testing",
+ value: "testing",
+ taskCount: 3,
+ },
+ ],
+ totalTasks: 8,
+ });
+ expect(prisma.activityType.findMany).toHaveBeenCalledWith({
+ where: {
+ createdBy: mockUser.id,
+ },
+ include: {
+ _count: {
+ select: { Tasks: true },
+ },
+ },
+ });
+ expect(prisma.task.count).toHaveBeenCalledWith({
+ where: { userId: mockUser.id },
+ });
+ });
+
+ it("should return error when user is not authenticated", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await getActivityTypesWithTaskCounts();
+
+ expect(result).toEqual({
+ success: false,
+ message: "Not authenticated",
+ });
+ });
+
+ it("should handle database errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.activityType.findMany as jest.Mock).mockRejectedValue(
+ new Error("Database error")
+ );
+
+ const result = await getActivityTypesWithTaskCounts();
+
+ expect(result).toEqual({
+ success: false,
+ message: "Database error",
+ });
+ });
+ });
+});
diff --git a/jest.config.ts b/jest.config.ts
index e678b8a..ae54f59 100644
--- a/jest.config.ts
+++ b/jest.config.ts
@@ -15,6 +15,9 @@ const config: Config = {
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/src/$1",
"^@prisma/client$": "<rootDir>/node_modules/@prisma/client",
+ "^next-auth$": "<rootDir>/__mocks__/next-auth.ts",
+ "^next-auth/providers/credentials$":
+ "<rootDir>/__mocks__/next-auth-providers.ts",
},
setupFiles: ["<rootDir>/jest.polyfills.ts"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
@@ -191,7 +194,9 @@ const config: Config = {
// transform: undefined,
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
- transformIgnorePatterns: ["/node_modules/(?!@prisma)"],
+ transformIgnorePatterns: [
+ "/node_modules/(?!(@prisma|next-auth|@auth|@next|jose))",
+ ],
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
diff --git a/src/components/Loading.tsx b/src/components/Loading.tsx
index 4fa3fcb..4e60a20 100644
--- a/src/components/Loading.tsx
+++ b/src/components/Loading.tsx
@@ -2,7 +2,7 @@ import { Loader } from "lucide-react";
const Loading = () => {
return (
- <div className="flex items-center justify-center">
+ <div className="flex items-center justify-center" data-testid="loader">
<Loader className="animate-spin text-blue-500" size={48} />
</div>
);