-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uncomment tests to see if errors still exisit
- Loading branch information
1 parent
c288095
commit 80a72b0
Showing
2 changed files
with
140 additions
and
140 deletions.
There are no files selected for viewing
158 changes: 79 additions & 79 deletions
158
packages/openneuro-app/src/scripts/users/__tests__/user-card.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,94 @@ | ||
// import React from "react"; | ||
// import { render, screen } from "@testing-library/react"; | ||
// import { UserCard, User } from "../user-card"; | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { UserCard, User } from "../user-card"; | ||
|
||
// describe("UserCard Component", () => { | ||
// const baseUser: User = { | ||
// name: "John Doe", | ||
// email: "[email protected]", | ||
// orcid: "0000-0001-2345-6789", | ||
// location: "San Francisco, CA", | ||
// institution: "University of California", | ||
// links: ["https://example.com", "https://example.org"], | ||
// github: "johndoe", | ||
// }; | ||
describe("UserCard Component", () => { | ||
const baseUser: User = { | ||
name: "John Doe", | ||
email: "[email protected]", | ||
orcid: "0000-0001-2345-6789", | ||
location: "San Francisco, CA", | ||
institution: "University of California", | ||
links: ["https://example.com", "https://example.org"], | ||
github: "johndoe", | ||
}; | ||
|
||
// it("renders all user details when all data is provided", () => { | ||
it("renders all user details when all data is provided", () => { | ||
|
||
// render(<UserCard user={baseUser} />); | ||
render(<UserCard user={baseUser} />); | ||
|
||
// const orcidLink = screen.getByRole("link", { | ||
// name: "ORCID profile of John Doe", | ||
// }); | ||
// expect(orcidLink).toHaveAttribute("href", "https://orcid.org/0000-0001-2345-6789"); | ||
// expect(screen.getByText("University of California")).toBeInTheDocument(); | ||
// expect(screen.getByText("San Francisco, CA")).toBeInTheDocument(); | ||
const orcidLink = screen.getByRole("link", { | ||
name: "ORCID profile of John Doe", | ||
}); | ||
expect(orcidLink).toHaveAttribute("href", "https://orcid.org/0000-0001-2345-6789"); | ||
expect(screen.getByText("University of California")).toBeInTheDocument(); | ||
expect(screen.getByText("San Francisco, CA")).toBeInTheDocument(); | ||
|
||
// const emailLink = screen.getByRole("link", { name: "[email protected]" }); | ||
// expect(emailLink).toHaveAttribute("href", "mailto:[email protected]"); | ||
const emailLink = screen.getByRole("link", { name: "[email protected]" }); | ||
expect(emailLink).toHaveAttribute("href", "mailto:[email protected]"); | ||
|
||
// const githubLink = screen.getByRole("link", { name: "Github profile of John Doe", }); | ||
// expect(githubLink).toHaveAttribute("href", "https://github.com/johndoe"); | ||
// expect( | ||
// screen.getByRole("link", { name: "https://example.com" }) | ||
// ).toHaveAttribute("href", "https://example.com"); | ||
// expect( | ||
// screen.getByRole("link", { name: "https://example.org" }) | ||
// ).toHaveAttribute("href", "https://example.org"); | ||
// }); | ||
const githubLink = screen.getByRole("link", { name: "Github profile of John Doe", }); | ||
expect(githubLink).toHaveAttribute("href", "https://github.com/johndoe"); | ||
expect( | ||
screen.getByRole("link", { name: "https://example.com" }) | ||
).toHaveAttribute("href", "https://example.com"); | ||
expect( | ||
screen.getByRole("link", { name: "https://example.org" }) | ||
).toHaveAttribute("href", "https://example.org"); | ||
}); | ||
|
||
// it("renders without optional fields", () => { | ||
// const minimalUser: User = { | ||
// name: "Jane Doe", | ||
// email: "[email protected]", | ||
// orcid: "0000-0002-3456-7890", | ||
// links: [], | ||
// }; | ||
it("renders without optional fields", () => { | ||
const minimalUser: User = { | ||
name: "Jane Doe", | ||
email: "[email protected]", | ||
orcid: "0000-0002-3456-7890", | ||
links: [], | ||
}; | ||
|
||
// render(<UserCard user={minimalUser} />); | ||
render(<UserCard user={minimalUser} />); | ||
|
||
// const orcidLink = screen.getByRole("link", { | ||
// name: "ORCID profile of Jane Doe", | ||
// }); | ||
// expect(orcidLink).toHaveAttribute("href", "https://orcid.org/0000-0002-3456-7890"); | ||
// const emailLink = screen.getByRole("link", { name: "[email protected]" }); | ||
// expect(emailLink).toHaveAttribute("href", "mailto:[email protected]"); | ||
// expect(screen.queryByText("University of California")).not.toBeInTheDocument(); | ||
// expect(screen.queryByText("San Francisco, CA")).not.toBeInTheDocument(); | ||
// expect(screen.queryByRole("link", { name: "Github profile of Jane Doe" })).not.toBeInTheDocument(); | ||
// }); | ||
const orcidLink = screen.getByRole("link", { | ||
name: "ORCID profile of Jane Doe", | ||
}); | ||
expect(orcidLink).toHaveAttribute("href", "https://orcid.org/0000-0002-3456-7890"); | ||
const emailLink = screen.getByRole("link", { name: "[email protected]" }); | ||
expect(emailLink).toHaveAttribute("href", "mailto:[email protected]"); | ||
expect(screen.queryByText("University of California")).not.toBeInTheDocument(); | ||
expect(screen.queryByText("San Francisco, CA")).not.toBeInTheDocument(); | ||
expect(screen.queryByRole("link", { name: "Github profile of Jane Doe" })).not.toBeInTheDocument(); | ||
}); | ||
|
||
// it("renders correctly when links are empty", () => { | ||
// const userWithEmptyLinks: User = { | ||
// ...baseUser, | ||
// links: [], | ||
// }; | ||
it("renders correctly when links are empty", () => { | ||
const userWithEmptyLinks: User = { | ||
...baseUser, | ||
links: [], | ||
}; | ||
|
||
// render(<UserCard user={userWithEmptyLinks} />); | ||
render(<UserCard user={userWithEmptyLinks} />); | ||
|
||
// expect(screen.queryByRole("link", { name: "https://example.com" })).not.toBeInTheDocument(); | ||
// expect(screen.queryByRole("link", { name: "https://example.org" })).not.toBeInTheDocument(); | ||
// }); | ||
expect(screen.queryByRole("link", { name: "https://example.com" })).not.toBeInTheDocument(); | ||
expect(screen.queryByRole("link", { name: "https://example.org" })).not.toBeInTheDocument(); | ||
}); | ||
|
||
// it("renders correctly when location and institution are missing", () => { | ||
// const userWithoutLocationAndInstitution: User = { | ||
// name: "Emily Doe", | ||
// email: "[email protected]", | ||
// orcid: "0000-0003-4567-8901", | ||
// links: ["https://example.com"], | ||
// }; | ||
it("renders correctly when location and institution are missing", () => { | ||
const userWithoutLocationAndInstitution: User = { | ||
name: "Emily Doe", | ||
email: "[email protected]", | ||
orcid: "0000-0003-4567-8901", | ||
links: ["https://example.com"], | ||
}; | ||
|
||
// render(<UserCard user={userWithoutLocationAndInstitution} />); | ||
render(<UserCard user={userWithoutLocationAndInstitution} />); | ||
|
||
// const orcidLink = screen.getByRole("link", { | ||
// name: "ORCID profile of Emily Doe", | ||
// }); | ||
// expect(orcidLink).toHaveAttribute("href", "https://orcid.org/0000-0003-4567-8901"); | ||
// const emailLink = screen.getByRole("link", { name: "[email protected]" }); | ||
// expect(emailLink).toHaveAttribute("href", "mailto:[email protected]"); | ||
// const link = screen.getByRole("link", { name: "https://example.com" }); | ||
// expect(link).toHaveAttribute("href", "https://example.com"); | ||
// expect(screen.queryByText("San Francisco, CA")).not.toBeInTheDocument(); | ||
// expect(screen.queryByText("University of California")).not.toBeInTheDocument(); | ||
// }); | ||
// }); | ||
const orcidLink = screen.getByRole("link", { | ||
name: "ORCID profile of Emily Doe", | ||
}); | ||
expect(orcidLink).toHaveAttribute("href", "https://orcid.org/0000-0003-4567-8901"); | ||
const emailLink = screen.getByRole("link", { name: "[email protected]" }); | ||
expect(emailLink).toHaveAttribute("href", "mailto:[email protected]"); | ||
const link = screen.getByRole("link", { name: "https://example.com" }); | ||
expect(link).toHaveAttribute("href", "https://example.com"); | ||
expect(screen.queryByText("San Francisco, CA")).not.toBeInTheDocument(); | ||
expect(screen.queryByText("University of California")).not.toBeInTheDocument(); | ||
}); | ||
}); |
122 changes: 61 additions & 61 deletions
122
packages/openneuro-app/src/scripts/users/__tests__/user-routes.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,71 @@ | ||
// import React from "react"; | ||
// import { render, screen, cleanup } from "@testing-library/react"; | ||
// import { MemoryRouter } from "react-router-dom"; | ||
// import { UserRoutes } from "../user-routes"; | ||
import React from "react"; | ||
import { render, screen, cleanup } from "@testing-library/react"; | ||
import { MemoryRouter } from "react-router-dom"; | ||
import { UserRoutes } from "../user-routes"; | ||
|
||
// export interface User { | ||
// id: string; | ||
// name: string; | ||
// location: string; | ||
// github?: string; | ||
// institution: string; | ||
// email: string; | ||
// avatar: string; | ||
// orcid: string; | ||
// links: string[]; | ||
// } | ||
export interface User { | ||
id: string; | ||
name: string; | ||
location: string; | ||
github?: string; | ||
institution: string; | ||
email: string; | ||
avatar: string; | ||
orcid: string; | ||
links: string[]; | ||
} | ||
|
||
|
||
// const renderWithRouter = (user: User, route: string, hasEdit: boolean) => { | ||
// return render( | ||
// <MemoryRouter initialEntries={[route]}> | ||
// <UserRoutes user={user} hasEdit={hasEdit} /> | ||
// </MemoryRouter> | ||
// ); | ||
// }; | ||
const renderWithRouter = (user: User, route: string, hasEdit: boolean) => { | ||
return render( | ||
<MemoryRouter initialEntries={[route]}> | ||
<UserRoutes user={user} hasEdit={hasEdit} /> | ||
</MemoryRouter> | ||
); | ||
}; | ||
|
||
// describe("UserRoutes Component", () => { | ||
// const user: User = { name: "John Doe" }; | ||
describe("UserRoutes Component", () => { | ||
const user: User = { name: "John Doe" }; | ||
|
||
// it("renders UserDatasetsView for the default route", async () => { | ||
// renderWithRouter(user, "/", true); | ||
// expect(screen.getByText(`${user.name}'s Datasets`)).toBeInTheDocument(); | ||
// const datasetsView = await screen.findByTestId("user-datasets-view"); | ||
// expect(datasetsView).toBeInTheDocument(); | ||
// }); | ||
it("renders UserDatasetsView for the default route", async () => { | ||
renderWithRouter(user, "/", true); | ||
expect(screen.getByText(`${user.name}'s Datasets`)).toBeInTheDocument(); | ||
const datasetsView = await screen.findByTestId("user-datasets-view"); | ||
expect(datasetsView).toBeInTheDocument(); | ||
}); | ||
|
||
// it("renders FourOFourPage for an invalid route", async () => { | ||
// renderWithRouter(user, "/nonexistent-route", true); | ||
// const errorMessage = await screen.findByText( | ||
// /404: The page you are looking for does not exist./i | ||
// ); | ||
// expect(errorMessage).toBeInTheDocument(); | ||
// }); | ||
it("renders FourOFourPage for an invalid route", async () => { | ||
renderWithRouter(user, "/nonexistent-route", true); | ||
const errorMessage = await screen.findByText( | ||
/404: The page you are looking for does not exist./i | ||
); | ||
expect(errorMessage).toBeInTheDocument(); | ||
}); | ||
|
||
// it("renders UserAccountView when hasEdit is true", async () => { | ||
// renderWithRouter(user, "/account", true); | ||
// const accountView = await screen.findByTestId("user-account-view"); | ||
// expect(accountView).toBeInTheDocument(); | ||
// }); | ||
it("renders UserAccountView when hasEdit is true", async () => { | ||
renderWithRouter(user, "/account", true); | ||
const accountView = await screen.findByTestId("user-account-view"); | ||
expect(accountView).toBeInTheDocument(); | ||
}); | ||
|
||
// it("renders UserNotificationsView when hasEdit is true", async () => { | ||
// renderWithRouter(user, "/notifications", true); | ||
// const notificationsView = await screen.findByTestId( | ||
// "user-notifications-view" | ||
// ); | ||
// expect(notificationsView).toBeInTheDocument(); | ||
// }); | ||
it("renders UserNotificationsView when hasEdit is true", async () => { | ||
renderWithRouter(user, "/notifications", true); | ||
const notificationsView = await screen.findByTestId( | ||
"user-notifications-view" | ||
); | ||
expect(notificationsView).toBeInTheDocument(); | ||
}); | ||
|
||
// it("renders FourOThreePage when hasEdit is false for restricted routes", async () => { | ||
// const restrictedRoutes = ["/account", "/notifications"]; | ||
it("renders FourOThreePage when hasEdit is false for restricted routes", async () => { | ||
const restrictedRoutes = ["/account", "/notifications"]; | ||
|
||
// for (const route of restrictedRoutes) { | ||
// cleanup(); | ||
// renderWithRouter(user, route, false); | ||
// const errorMessage = await screen.findByText( | ||
// /403: You do not have access to this page, you may need to sign in./i | ||
// ); | ||
// expect(errorMessage).toBeInTheDocument(); | ||
// } | ||
// }); | ||
// }); | ||
for (const route of restrictedRoutes) { | ||
cleanup(); | ||
renderWithRouter(user, route, false); | ||
const errorMessage = await screen.findByText( | ||
/403: You do not have access to this page, you may need to sign in./i | ||
); | ||
expect(errorMessage).toBeInTheDocument(); | ||
} | ||
}); | ||
}); |