From bd662978b65877071d4484bb09d19fdf275adbde Mon Sep 17 00:00:00 2001 From: acouch Date: Wed, 3 Jul 2024 16:44:07 -0400 Subject: [PATCH] Remove page tests --- frontend/tests/pages/index.test.tsx | 34 ------ .../pages/newsletter/confirmation.test.tsx | 12 -- .../tests/pages/newsletter/index.test.tsx | 111 ------------------ .../pages/newsletter/unsubscribe.test.tsx | 12 -- frontend/tests/pages/process.test.tsx | 24 ---- frontend/tests/pages/research.test.tsx | 23 ---- frontend/tests/pages/search.test.tsx | 96 --------------- 7 files changed, 312 deletions(-) delete mode 100644 frontend/tests/pages/index.test.tsx delete mode 100644 frontend/tests/pages/newsletter/confirmation.test.tsx delete mode 100644 frontend/tests/pages/newsletter/index.test.tsx delete mode 100644 frontend/tests/pages/newsletter/unsubscribe.test.tsx delete mode 100644 frontend/tests/pages/process.test.tsx delete mode 100644 frontend/tests/pages/research.test.tsx delete mode 100644 frontend/tests/pages/search.test.tsx diff --git a/frontend/tests/pages/index.test.tsx b/frontend/tests/pages/index.test.tsx deleted file mode 100644 index 6924cbbd0..000000000 --- a/frontend/tests/pages/index.test.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { waitFor, screen, render } from "tests/react-utils"; - -import { axe } from "jest-axe"; -import Index from "src/app/[locale]/page"; - -describe("Index", () => { - it("renders alert with grants.gov link", () => { - render(); - - const alert = screen.getByTestId("alert"); - const link = screen.getByRole("link", { name: /grants\.gov/i }); - - expect(alert).toBeInTheDocument(); - expect(link).toHaveAttribute("href", "https://www.grants.gov"); - }); - - it("renders the goals section", () => { - render(); - - const goalH2 = screen.getByRole("heading", { - level: 2, - name: /The goal?/i, - }); - - expect(goalH2).toBeInTheDocument(); - }); - - it("passes accessibility scan", async () => { - const { container } = render(); - const results = await waitFor(() => axe(container)); - - expect(results).toHaveNoViolations(); - }); -}); diff --git a/frontend/tests/pages/newsletter/confirmation.test.tsx b/frontend/tests/pages/newsletter/confirmation.test.tsx deleted file mode 100644 index 7324e9c7c..000000000 --- a/frontend/tests/pages/newsletter/confirmation.test.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { render, waitFor } from "tests/react-utils"; -import { axe } from "jest-axe"; -import NewsletterConfirmation from "src/app/[locale]/newsletter/confirmation/page"; - -describe("Newsletter", () => { - it("passes accessibility scan", async () => { - const { container } = render(); - const results = await waitFor(() => axe(container)); - - expect(results).toHaveNoViolations(); - }); -}); diff --git a/frontend/tests/pages/newsletter/index.test.tsx b/frontend/tests/pages/newsletter/index.test.tsx deleted file mode 100644 index 9f430ef2b..000000000 --- a/frontend/tests/pages/newsletter/index.test.tsx +++ /dev/null @@ -1,111 +0,0 @@ -import { fireEvent, render, screen, waitFor } from "tests/react-utils"; - -import userEvent from "@testing-library/user-event"; -import { axe } from "jest-axe"; -import Newsletter from "src/app/[locale]/newsletter/page"; - -import { useRouter } from "next/navigation"; - -jest.mock("next/navigation"); - -describe("Newsletter", () => { - it("renders signup form with a submit button", () => { - render(); - - const sendyform = screen.getByTestId("sendy-form"); - - expect(sendyform).toBeInTheDocument(); - }); - - it("submits the form successfully", async () => { - const mockRouter = { - push: jest.fn(), // the component uses `router.push` only - }; - (useRouter as jest.Mock).mockReturnValue(mockRouter); - render(); - - // Mock the fetch function to return a successful response - global.fetch = jest.fn().mockResolvedValue({ - ok: true, - json: jest.fn().mockResolvedValue({ message: "Success" }), - }); - - // Fill out the form - await userEvent.type(screen.getByLabelText(/First Name/i), "John"); - await userEvent.type(screen.getByLabelText(/Last Name/i), "Doe"); - await userEvent.type( - screen.getByLabelText(/Email/i), - "john.doe@example.com", - ); - - // Submit the form - fireEvent.click(screen.getByRole("button", { name: /subscribe/i })); - - // Wait for the form submission - await waitFor(() => { - expect(mockRouter.push).toHaveBeenCalledWith( - "/newsletter/confirmation/?sendy=Success", - ); - }); - }); - - it("shows alert when recieving an error from Sendy", async () => { - render(); - - // Mock the fetch function to return a successful response - global.fetch = jest.fn().mockResolvedValue({ - ok: false, - json: jest.fn().mockResolvedValue({ error: "Already subscribed." }), - }); - jest.spyOn(global.console, "error"); - - // Fill out the form - await userEvent.type(screen.getByLabelText(/First Name/i), "John"); - await userEvent.type(screen.getByLabelText(/Last Name/i), "Doe"); - await userEvent.type( - screen.getByLabelText(/Email/i), - "john.doe@example.com", - ); - - // Submit the form - fireEvent.click(screen.getByRole("button", { name: /subscribe/i })); - - // Wait for the form submission - await waitFor(() => { - const alert = screen.getByRole("heading", { - level: 3, - name: /You’re already signed up!?/i, - }); - expect(alert).toBeInTheDocument(); - }); - await waitFor(() => { - expect(console.error).toHaveBeenCalledWith( - "client error", - "Already subscribed.", - ); - }); - }); - - it("prevents the form from submitting when incomplete", async () => { - render(); - - // Fill out the form - await userEvent.type(screen.getByLabelText(/First Name/i), "John"); - await userEvent.type(screen.getByLabelText(/Last Name/i), "Doe"); - - // Submit the form - fireEvent.click(screen.getByRole("button", { name: /subscribe/i })); - - // Wait for the form submission - await waitFor(() => { - expect(screen.getByText("Enter your email address.")).toBeInTheDocument(); - }); - }); - - it("passes accessibility scan", async () => { - const { container } = render(); - const results = await waitFor(() => axe(container)); - - expect(results).toHaveNoViolations(); - }); -}); diff --git a/frontend/tests/pages/newsletter/unsubscribe.test.tsx b/frontend/tests/pages/newsletter/unsubscribe.test.tsx deleted file mode 100644 index b544f941f..000000000 --- a/frontend/tests/pages/newsletter/unsubscribe.test.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { render, waitFor } from "tests/react-utils"; -import { axe } from "jest-axe"; -import NewsletterUnsubscribe from "src/app/[locale]/newsletter/unsubscribe/page"; - -describe("Newsletter", () => { - it("passes accessibility scan", async () => { - const { container } = render(); - const results = await waitFor(() => axe(container)); - - expect(results).toHaveNoViolations(); - }); -}); diff --git a/frontend/tests/pages/process.test.tsx b/frontend/tests/pages/process.test.tsx deleted file mode 100644 index bd9d43929..000000000 --- a/frontend/tests/pages/process.test.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { render, screen, waitFor } from "tests/react-utils"; - -import { axe } from "jest-axe"; -import Process from "src/app/[locale]/process/page"; - -describe("Process", () => { - it("renders alert with grants.gov link", () => { - render(); - - const alert = screen.getByTestId("alert"); - // There are multiple links to grants.gov - const link = screen.getAllByText("www.grants.gov")[0]; - - expect(alert).toBeInTheDocument(); - expect(link).toHaveAttribute("href", "https://www.grants.gov"); - }); - - it("passes accessibility scan", async () => { - const { container } = render(); - const results = await waitFor(() => axe(container)); - - expect(results).toHaveNoViolations(); - }); -}); diff --git a/frontend/tests/pages/research.test.tsx b/frontend/tests/pages/research.test.tsx deleted file mode 100644 index c4b55fed6..000000000 --- a/frontend/tests/pages/research.test.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { render, screen, waitFor } from "tests/react-utils"; - -import { axe } from "jest-axe"; -import Research from "src/app/[locale]/research/page"; - -describe("Research", () => { - it("renders alert with grants.gov link", () => { - render(); - - const alert = screen.getByTestId("alert"); - const link = screen.getByRole("link", { name: /www\.grants\.gov/i }); - - expect(alert).toBeInTheDocument(); - expect(link).toHaveAttribute("href", "https://www.grants.gov"); - }); - - it("passes accessibility scan", async () => { - const { container } = render(); - const results = await waitFor(() => axe(container)); - - expect(results).toHaveNoViolations(); - }); -}); diff --git a/frontend/tests/pages/search.test.tsx b/frontend/tests/pages/search.test.tsx deleted file mode 100644 index db4550732..000000000 --- a/frontend/tests/pages/search.test.tsx +++ /dev/null @@ -1,96 +0,0 @@ -/* eslint-disable jest/no-commented-out-tests */ - -import { useFeatureFlags } from "src/hooks/useFeatureFlags"; - -jest.mock("src/hooks/useFeatureFlags"); - -const setFeatureFlag = (flag: string, value: boolean) => { - (useFeatureFlags as jest.Mock).mockReturnValue({ - featureFlagsManager: { - isFeatureEnabled: jest.fn((featureName: string) => - featureName === flag ? value : false, - ), - }, - mounted: true, - }); -}; - -const mockData = [ - { - agency: "firstagency", - category: "firstcategory", - opportunity_title: "firsttitle", - }, - { - agency: "secondagency2", - category: "secondcategory", - opportunity_title: "secondtitle", - }, -]; - -// Mock both search fetchers in case we switch -// Could also switch on a feature flag -jest.mock("../../src/services/search/searchfetcher/APISearchFetcher", () => { - return { - APISearchFetcher: jest.fn().mockImplementation(() => { - return { - fetchOpportunities: jest.fn().mockImplementation(() => { - return Promise.resolve(mockData); - }), - }; - }), - }; -}); - -jest.mock("../../src/services/search/searchfetcher/MockSearchFetcher", () => { - return { - MockSearchFetcher: jest.fn().mockImplementation(() => { - return { - fetchOpportunities: jest.fn().mockImplementation(() => { - return Promise.resolve(mockData); - }), - }; - }), - }; -}); - -describe("Search", () => { - it("should pass", () => { - setFeatureFlag("showSearchV0", true); - expect(1).toBe(1); - }); - // TODO (Issue #1393): Redo tests after converting search to server component. Save below for reference - - // it("passes accessibility scan", async () => { - // setFeatureFlag("showSearchV0", true); - // const { container } = render(); - // const results = await waitFor(() => axe(container)); - // expect(results).toHaveNoViolations(); - // }); - - // describe("Search feature flag", () => { - // it("renders search results when feature flag is on", async () => { - // setFeatureFlag("showSearchV0", true); - // render(); - // fireEvent.click(screen.getByRole("button", { name: /update results/i })); - - // await waitFor(() => { - // expect(screen.getByText(/firstcategory/i)).toBeInTheDocument(); - // }); - // expect(screen.getByText(/secondcategory/i)).toBeInTheDocument(); - // }); - - // it("renders PageNotFound when feature flag is off", async () => { - // setFeatureFlag("showSearchV0", false); - // render(); - - // await waitFor(() => { - // expect( - // screen.getByText( - // /The page you have requested cannot be displayed because it does not exist, has been moved/i, - // ), - // ).toBeInTheDocument(); - // }); - // }); - // }); -});