⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
test: add regression coverage for Gantt jump-to-today
reachsanjivbhagat-gifb5d8861c8b79
diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/gantt.test.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/gantt.test.tsxnew file mode 100644index 000000000..ac1f568f5--- /dev/null+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/gantt.test.tsx@@ -0,0 +1,190 @@+import enUS from "@i18n/en-US.json";+import { cleanup, fireEvent, render, screen } from "@testing-library/react";+import type { ComponentType, ReactNode } from "react";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import type Task from "@/types/task";+import { Route } from "./gantt";++// jsdom does not implement either of these; the component relies on both to+// center the timeline on "today".+vi.stubGlobal(+ "ResizeObserver",+ class {+ observe() {}+ unobserve() {}+ disconnect() {}+ },+);+const scrollIntoView = vi.fn();+Element.prototype.scrollIntoView = scrollIntoView;++const navigate = vi.fn();++vi.mock("@tanstack/react-router", () => ({+ createFileRoute: () => (options: unknown) => ({+ ...(options as Record<string, unknown>),+ useParams: () => ({ workspaceId: "workspace-1", projectId: "project-1" }),+ useSearch: () => ({ taskId: undefined }),+ }),+ useNavigate: () => navigate,+}));++const useGetTasks = vi.fn();+vi.mock("@/hooks/queries/task/use-get-tasks", () => ({+ useGetTasks: (projectId: string) => useGetTasks(projectId),+}));++vi.mock("@/hooks/use-mobile", () => ({+ useIsMobile: () => false,+}));++vi.mock("@/store/user-preferences", () => ({+ useUserPreferencesStore: (+ selector: (state: { weekStartsOn: number }) => unknown,+ ) => selector({ weekStartsOn: 0 }),+}));++vi.mock("@/components/common/project-layout", () => ({+ default: ({ children }: { children: ReactNode }) => <div>{children}</div>,+}));++vi.mock("@/components/task/task-details-sheet", () => ({+ default: () => null,+}));++vi.mock("@/components/page-title", () => ({+ default: () => null,+}));++vi.mock("@/components/gantt/gantt-task-bar", () => ({+ GanttTaskBar: ({ task }: { task: { title: string } }) => (+ <div>{task.title}</div>+ ),+}));++// Resolves against the real en-US bundle, so the assertions fail if the+// jumpToToday key (or its interpolated siblings) stops matching what the+// component actually requests.+vi.mock("react-i18next", () => ({+ useTranslation: () => ({+ t: (key: string, options?: Record<string, unknown>) => {+ const [namespace, path] = key.split(":");+ const source = path+ .split(".")+ .reduce<unknown>(+ (accumulator, part) =>+ (accumulator as Record<string, unknown> | undefined)?.[part],+ (enUS as Record<string, unknown>)[namespace],+ );++ if (typeof source !== "string") return key;++ return source.replace(/\{\{(\w+)\}\}/g, (_match, name: string) =>+ String(options?.[name] ?? `{{${name}}}`),+ );+ },+ }),+}));++const GanttRoute = (Route as unknown as { component: ComponentType }).component;++function makeTask(overrides: Partial<Task>): Task {+ return {+ id: "task-1",+ title: "Task",+ number: 1,+ description: null,+ status: "in-progress",+ priority: null,+ startDate: null,+ dueDate: null,+ position: null,+ createdAt: "2026-01-01T00:00:00.000Z",+ userId: null,+ assigneeId: null,+ assigneeName: null,+ projectId: "project-1",+ ...overrides,+ };+}++function mockProjectWithTask(task: Task) {+ useGetTasks.mockReturnValue({+ data: {+ id: "project-1",+ name: "Roadmap",+ slug: "RM",+ columns: [{ id: "col-1", name: "In Progress", tasks: [task] }],+ plannedTasks: [],+ archivedTasks: [],+ },+ });+}++beforeEach(() => {+ // Fixed "today" so the timeline range and isToday() checks are+ // deterministic regardless of when the suite runs.+ vi.useFakeTimers();+ vi.setSystemTime(new Date(2026, 7, 31));+});++afterEach(() => {+ cleanup();+ vi.useRealTimers();+ scrollIntoView.mockClear();+ useGetTasks.mockReset();+});++describe("Gantt jump-to-today", () => {+ it("disables the button and never auto-scrolls when no task falls near today", () => {+ mockProjectWithTask(+ makeTask({+ id: "past-task",+ title: "Old milestone",+ startDate: "2026-05-01",+ dueDate: "2026-05-03",+ }),+ );++ render(<GanttRoute />);++ const button = screen.getByRole("button", { name: "Jump to today" });+ expect(button).toBeDisabled();+ expect(scrollIntoView).not.toHaveBeenCalled();++ fireEvent.click(button);+ expect(scrollIntoView).not.toHaveBeenCalled();+ });++ it("auto-centers on today and re-centers on demand when today is in range", () => {+ mockProjectWithTask(+ makeTask({+ id: "current-task",+ title: "Ongoing work",+ startDate: "2026-08-28",+ dueDate: "2026-09-02",+ }),+ );++ render(<GanttRoute />);++ // The mount-time effect scrolls today's column into view without+ // animating, so it doesn't fight the user for scroll position on load.+ expect(scrollIntoView).toHaveBeenCalledTimes(1);+ expect(scrollIntoView).toHaveBeenLastCalledWith(+ expect.objectContaining({ behavior: "auto", inline: "center" }),+ );++ const button = screen.getByRole("button", { name: "Jump to today" });+ expect(button).not.toBeDisabled();++ fireEvent.click(button);++ // A manual click animates instead, so its intent reads as a deliberate+ // jump rather than the page settling into place.+ expect(scrollIntoView).toHaveBeenCalledTimes(2);+ expect(scrollIntoView).toHaveBeenLastCalledWith(+ expect.objectContaining({ behavior: "smooth", inline: "center" }),+ );+ });+});