Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/contributors/components/ContributorPage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from "react"
import { describe, expect, test, vi } from "vitest"
import { render, screen } from "@testing-library/react"

// Project member 41 is the person being viewed; their *user* id (7) is a different number
vi.mock("@blitzjs/next", () => ({
useParam: (name: string) => ({ contributorId: 41, projectId: 3 }[name]),
Routes: {
EditContributorPage: ({ projectId, contributorId }: any) =>
`/projects/${projectId}/contributors/${contributorId}/edit`,
},
}))
vi.mock("src/projectprivileges/components/MemberPrivilegesContext", () => ({
useMemberPrivileges: () => ({ privilege: "PROJECT_MANAGER" }),
}))
vi.mock("src/contributors/hooks/useCurrentContributor", () => ({
useCurrentContributor: () => ({ projectMember: { id: 99 } }),
}))
vi.mock("src/contributors/hooks/useContributorData", () => ({
useContributorData: () => ({
contributorUser: { id: 7, firstName: "Ada", lastName: "Lovelace", username: "ada" },
contributorPrivilege: "CONTRIBUTOR",
teamNames: [],
}),
}))
vi.mock("src/core/layouts/Layout", () => ({ default: ({ children }: any) => <>{children}</> }))
vi.mock("src/contributors/components/ContributorInformation", () => ({ default: () => null }))
vi.mock("src/contributors/components/ContributorTeams", () => ({ default: () => null }))
vi.mock("src/contributors/components/DeleteContributor", () => ({ default: () => null }))
vi.mock("src/projectmembers/components/ProjectMemberTaskList", () => ({ default: () => null }))
vi.mock("src/tasklogs/tables/columns/TaskLogProjectMemberColumns", () => ({
TaskLogProjectMemberColumns: [],
}))
vi.mock("react-tooltip", () => ({ Tooltip: () => null }))
vi.mock("next/link", () => ({
default: ({ href, children, ...rest }: any) => (
<a href={href} {...rest}>
{children}
</a>
),
}))

import { ContributorPage } from "src/pages/projects/[projectId]/contributors/[contributorId]"

describe("contributor page", () => {
test("Edit Contributor opens the edit page for this project member, not for their user id", () => {
render(<ContributorPage />)
expect(screen.getByRole("link", { name: "Edit Contributor" }).getAttribute("href")).toBe(
"/projects/3/contributors/41/edit"
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ export const ContributorPage = () => {
{privilege === MemberPrivileges.PROJECT_MANAGER && (
<div className="flex justify-center mt-4 gap-2">
<Link
// the page's contributorId is a project member id; the user's own id is a different number
href={Routes.EditContributorPage({
projectId: projectId!,
contributorId: contributorUser!.id,
contributorId: contributorId!,
})}
className="btn btn-primary"
>
Expand Down
Loading