From 80a72b07d4f2a5aa327fbece20673c2f1c88b16d Mon Sep 17 00:00:00 2001 From: Gregory Noack Date: Mon, 16 Dec 2024 13:55:55 -0800 Subject: [PATCH] uncomment tests to see if errors still exisit --- .../users/__tests__/user-card.test.tsx | 158 +++++++++--------- .../users/__tests__/user-routes.test.tsx | 122 +++++++------- 2 files changed, 140 insertions(+), 140 deletions(-) diff --git a/packages/openneuro-app/src/scripts/users/__tests__/user-card.test.tsx b/packages/openneuro-app/src/scripts/users/__tests__/user-card.test.tsx index 076778696..4333f9c98 100644 --- a/packages/openneuro-app/src/scripts/users/__tests__/user-card.test.tsx +++ b/packages/openneuro-app/src/scripts/users/__tests__/user-card.test.tsx @@ -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: "johndoe@example.com", -// 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: "johndoe@example.com", + 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(); + render(); -// 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: "johndoe@example.com" }); -// expect(emailLink).toHaveAttribute("href", "mailto:johndoe@example.com"); + const emailLink = screen.getByRole("link", { name: "johndoe@example.com" }); + expect(emailLink).toHaveAttribute("href", "mailto:johndoe@example.com"); -// 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: "janedoe@example.com", -// orcid: "0000-0002-3456-7890", -// links: [], -// }; + it("renders without optional fields", () => { + const minimalUser: User = { + name: "Jane Doe", + email: "janedoe@example.com", + orcid: "0000-0002-3456-7890", + links: [], + }; -// render(); + render(); -// 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: "janedoe@example.com" }); -// expect(emailLink).toHaveAttribute("href", "mailto:janedoe@example.com"); -// 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: "janedoe@example.com" }); + expect(emailLink).toHaveAttribute("href", "mailto:janedoe@example.com"); + 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(); + render(); -// 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: "emilydoe@example.com", -// 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: "emilydoe@example.com", + orcid: "0000-0003-4567-8901", + links: ["https://example.com"], + }; -// render(); + render(); -// 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: "emilydoe@example.com" }); -// expect(emailLink).toHaveAttribute("href", "mailto:emilydoe@example.com"); -// 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: "emilydoe@example.com" }); + expect(emailLink).toHaveAttribute("href", "mailto:emilydoe@example.com"); + 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(); + }); +}); diff --git a/packages/openneuro-app/src/scripts/users/__tests__/user-routes.test.tsx b/packages/openneuro-app/src/scripts/users/__tests__/user-routes.test.tsx index b357a2794..c9ca65879 100644 --- a/packages/openneuro-app/src/scripts/users/__tests__/user-routes.test.tsx +++ b/packages/openneuro-app/src/scripts/users/__tests__/user-routes.test.tsx @@ -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( -// -// -// -// ); -// }; +const renderWithRouter = (user: User, route: string, hasEdit: boolean) => { + return render( + + + + ); +}; -// 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(); + } + }); +});