Skip to content

Commit ac011f3

Browse files
thinknoacknellh
authored andcommitted
adding confributor spec for app component
1 parent a8ca622 commit ac011f3

File tree

2 files changed

+81
-10
lines changed

2 files changed

+81
-10
lines changed

packages/openneuro-app/src/scripts/dataset/__tests__/__snapshots__/snapshot-container.spec.tsx.snap

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -795,16 +795,6 @@ OCI-1131441 (R. Poldrack, PI) in any publications.
795795
</h2>
796796
N/A
797797
</div>
798-
<div
799-
class="dataset-meta-block dmb-inline-list"
800-
>
801-
<h2
802-
class="dmb-heading"
803-
>
804-
Authors
805-
</h2>
806-
J. Doe, J. Doe, J. Doe
807-
</div>
808798
<div
809799
class="dataset-meta-block dmb-modalities"
810800
>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import React from "react"
2+
import { render, screen } from "@testing-library/react"
3+
import { MemoryRouter } from "react-router-dom"
4+
import { MockedProvider } from "@apollo/client/testing"
5+
import { vi } from "vitest"
6+
import { SingleContributorDisplay } from "../contributor"
7+
8+
// --- Mock Dependencies ---
9+
vi.mock("../../queries/user", () => ({
10+
useUser: vi.fn(() => ({
11+
user: null,
12+
loading: false,
13+
error: undefined,
14+
})),
15+
}))
16+
17+
import { useUser } from "../../queries/user"
18+
19+
vi.mock("../../assets/ORCIDiD_iconvector.svg", () => ({
20+
default: "mock-orcid-logo.svg",
21+
}))
22+
23+
describe("SingleContributorDisplay - Basic Loading", () => {
24+
const renderComponent = (props: {
25+
contributor: { name?: string; orcid?: string | null }
26+
isLast?: boolean
27+
separator?: React.ReactNode
28+
}) => {
29+
return render(
30+
<MemoryRouter>
31+
<MockedProvider>
32+
<SingleContributorDisplay
33+
contributor={props.contributor}
34+
isLast={props.isLast ?? true}
35+
separator={props.separator ?? null}
36+
/>
37+
</MockedProvider>
38+
</MemoryRouter>,
39+
)
40+
}
41+
42+
beforeEach(() => {
43+
vi.clearAllMocks()
44+
vi.mocked(useUser).mockImplementation((userId) => {
45+
if (userId) {
46+
return {
47+
user: { id: userId, name: `Mock User ${userId}` },
48+
loading: false,
49+
error: undefined,
50+
}
51+
}
52+
return { user: null, loading: false, error: undefined }
53+
})
54+
})
55+
56+
it("renders the component and displays the contributor name", async () => {
57+
const contributor = { name: "Jane Doe", orcid: null }
58+
renderComponent({ contributor })
59+
expect(screen.getByText("Jane Doe")).toBeInTheDocument()
60+
})
61+
62+
it("renders 'Unknown Contributor' if the contributor name is missing", async () => {
63+
const contributor = { name: undefined, orcid: null }
64+
renderComponent({ contributor })
65+
expect(screen.getByText("Unknown Contributor")).toBeInTheDocument()
66+
})
67+
68+
it("renders the component and displays the ORCID link if an ID is provided", async () => {
69+
const testOrcid = "0000-0000-0000-0000"
70+
const contributor = { name: "Author With ORCID", orcid: testOrcid }
71+
renderComponent({ contributor })
72+
const orcidLink = screen.getByLabelText(
73+
`ORCID profile for ${contributor.name}`,
74+
)
75+
expect(orcidLink).toBeInTheDocument()
76+
expect(orcidLink).toHaveAttribute(
77+
"href",
78+
expect.stringContaining(testOrcid),
79+
)
80+
})
81+
})

0 commit comments

Comments
 (0)