diff --git a/ui/src/components/routine-page/RoutinePage.test.tsx b/ui/src/components/routine-page/RoutinePage.test.tsx new file mode 100644 index 00000000000..03550f768af --- /dev/null +++ b/ui/src/components/routine-page/RoutinePage.test.tsx @@ -0,0 +1,68 @@ +import type { RoutineDetail } from "@paperclipai/shared"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { renderToStaticMarkup } from "react-dom/server"; +import { MemoryRouter } from "react-router-dom"; +import { describe, expect, it, vi } from "vitest"; +import { RoutinePage, type RoutinePageProject } from "./RoutinePage"; + +vi.mock("@/context/CompanyContext", () => ({ + useCompany: () => ({ selectedCompany: { issuePrefix: "ACME" } }), +})); + +const routine: RoutineDetail = { + id: "routine-1", companyId: "company-1", projectId: "project-1", + title: "Weekly review", description: null, status: "active", priority: "medium", + goalId: null, parentIssueId: null, assigneeAgentId: null, responsibleUserId: null, + concurrencyPolicy: "coalesce_if_active", catchUpPolicy: "skip_missed", + activityGatePolicy: "always", activityGateScope: "company", variables: [], + latestRevisionId: null, latestRevisionNumber: 1, + createdByAgentId: null, createdByUserId: null, updatedByAgentId: null, updatedByUserId: null, + lastTriggeredAt: null, lastEnqueuedAt: null, + createdAt: new Date(0), updatedAt: new Date(0), + project: null, assignee: null, parentIssue: null, activeIssue: null, + triggers: [], recentRuns: [], +}; + +function renderPage(project: RoutinePageProject | null) { + return renderToStaticMarkup( + + + + + , + ); +} + +describe("routine project navigation", () => { + it("keeps the linked project ID when its name and URL key change", () => { + for (const name of ["Operations", "Renamed operations"]) { + const html = renderPage({ id: routine.projectId!, name, urlKey: name.toLowerCase().replaceAll(" ", "-") }); + expect(html).toContain(`href="/ACME/projects/${routine.projectId}"`); + expect(html).toContain(name); + } + }); + + it("keeps same-name projects distinct", () => { + for (const id of ["project-1", "project-2"]) { + const html = renderPage({ id, name: "Operations", urlKey: "operations" }); + expect(html).toContain(`href="/ACME/projects/${id}"`); + } + }); + + it("shows an unassigned routine without a project link", () => { + const html = renderPage(null); + expect(html).toContain("No project"); + expect(html).not.toContain("/projects/"); + }); +}); diff --git a/ui/src/components/routine-page/RoutinePage.tsx b/ui/src/components/routine-page/RoutinePage.tsx index 0f7b2f360af..406558c0613 100644 --- a/ui/src/components/routine-page/RoutinePage.tsx +++ b/ui/src/components/routine-page/RoutinePage.tsx @@ -579,7 +579,7 @@ export function RoutinePage({ {project ? (