From cdc461b7f14aa78bbfd63f8742f8591a4aca8ec0 Mon Sep 17 00:00:00 2001 From: Aaron Couch Date: Mon, 20 May 2024 19:53:02 -0400 Subject: [PATCH] Add test updates --- .../[locale]/newsletter/confirmation/page.tsx | 1 + frontend/src/app/[locale]/newsletter/page.tsx | 5 ++++- frontend/src/app/[locale]/not-found.tsx | 3 +-- frontend/src/app/[locale]/page.tsx | 3 --- frontend/src/i18n/messages/en/index.ts | 4 ++-- .../pages/newsletter/confirmation.test.tsx | 2 +- frontend/tests/pages/newsletter/index.test.tsx | 18 +++++++++--------- .../pages/newsletter/unsubscribe.test.tsx | 2 +- frontend/tests/pages/process.test.tsx | 3 +-- 9 files changed, 20 insertions(+), 21 deletions(-) diff --git a/frontend/src/app/[locale]/newsletter/confirmation/page.tsx b/frontend/src/app/[locale]/newsletter/confirmation/page.tsx index 8b366e3d6a..b50b0f7986 100644 --- a/frontend/src/app/[locale]/newsletter/confirmation/page.tsx +++ b/frontend/src/app/[locale]/newsletter/confirmation/page.tsx @@ -8,6 +8,7 @@ import PageSEO from "src/components/PageSEO"; import BetaAlert from "src/components/BetaAlert"; import { useTranslations } from "next-intl"; import { Metadata } from "next"; + export function generateMetadata() { // TODO: Enable once [locale] folder created, see: https://next-intl-docs.vercel.app/docs/getting-started/app-router/with-i18n-routing // const t = await getTranslations({ locale: "en" }); diff --git a/frontend/src/app/[locale]/newsletter/page.tsx b/frontend/src/app/[locale]/newsletter/page.tsx index 91808686fe..3830f64d92 100644 --- a/frontend/src/app/[locale]/newsletter/page.tsx +++ b/frontend/src/app/[locale]/newsletter/page.tsx @@ -56,7 +56,10 @@ export default function Newsletter() { })} - + diff --git a/frontend/src/app/[locale]/not-found.tsx b/frontend/src/app/[locale]/not-found.tsx index 43f27237e7..8b72c2223b 100644 --- a/frontend/src/app/[locale]/not-found.tsx +++ b/frontend/src/app/[locale]/not-found.tsx @@ -2,11 +2,10 @@ import BetaAlert from "src/components/BetaAlert"; import { GridContainer } from "@trussworks/react-uswds"; import Link from "next/link"; import { useTranslations } from "next-intl"; -import { unstable_setRequestLocale } from "next-intl/server"; export default function NotFound() { - unstable_setRequestLocale("en"); const t = useTranslations("ErrorPages.page_not_found"); + return ( <> diff --git a/frontend/src/app/[locale]/page.tsx b/frontend/src/app/[locale]/page.tsx index 687e5510ab..29633cfc7d 100644 --- a/frontend/src/app/[locale]/page.tsx +++ b/frontend/src/app/[locale]/page.tsx @@ -5,7 +5,6 @@ import IndexGoalContent from "src/components/content/IndexGoalContent"; import ProcessAndResearchContent from "src/components/content/ProcessAndResearchContent"; import { Metadata } from "next"; import { useTranslations } from "next-intl"; -import { unstable_setRequestLocale } from "next-intl/server"; export function generateMetadata() { // TODO: Enable once [locale] folder created, see: https://next-intl-docs.vercel.app/docs/getting-started/app-router/with-i18n-routing @@ -20,8 +19,6 @@ export function generateMetadata() { return meta; } export default function Home() { - // TODO: Remove when https://github.com/amannn/next-intl/issues/663 lands. - unstable_setRequestLocale("en"); const t = useTranslations("Index"); return ( diff --git a/frontend/src/i18n/messages/en/index.ts b/frontend/src/i18n/messages/en/index.ts index 0f5205f1af..1749e19605 100644 --- a/frontend/src/i18n/messages/en/index.ts +++ b/frontend/src/i18n/messages/en/index.ts @@ -291,9 +291,9 @@ export const messages = { invalid_email: "Enter an email address in the correct format, like name@example.com.", already_subscribed: - "{{email_address}} is already subscribed. If you’re not seeing our emails, check your spam folder and add no-reply@grants.gov to your contacts, address book, or safe senders list. If you continue to not receive our emails, contact simpler@grants.gov.", + " is already subscribed. If you’re not seeing our emails, check your spam folder and add no-reply@grants.gov to your contacts, address book, or safe senders list. If you continue to not receive our emails, contact simpler@grants.gov.", sendy: - "Sorry, an unexpected error in our system occured when trying to save your subscription. If this continues to happen, you may email simpler@grants.gov. Error: {{sendy_error}}", + "Sorry, an unexpected error in our system occured when trying to save your subscription. If this continues to happen, you may email simpler@grants.gov. Error: ", }, }, Newsletter_confirmation: { diff --git a/frontend/tests/pages/newsletter/confirmation.test.tsx b/frontend/tests/pages/newsletter/confirmation.test.tsx index 20edcfdc5c..7324e9c7cc 100644 --- a/frontend/tests/pages/newsletter/confirmation.test.tsx +++ b/frontend/tests/pages/newsletter/confirmation.test.tsx @@ -1,4 +1,4 @@ -import { render, waitFor } from "@testing-library/react"; +import { render, waitFor } from "tests/react-utils"; import { axe } from "jest-axe"; import NewsletterConfirmation from "src/app/[locale]/newsletter/confirmation/page"; diff --git a/frontend/tests/pages/newsletter/index.test.tsx b/frontend/tests/pages/newsletter/index.test.tsx index a39706e22d..5f97a120de 100644 --- a/frontend/tests/pages/newsletter/index.test.tsx +++ b/frontend/tests/pages/newsletter/index.test.tsx @@ -1,13 +1,12 @@ -import { fireEvent, render, screen, waitFor } from "@testing-library/react"; +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/router"; +import { useRouter } from "next/navigation"; -jest.mock("next/router", () => ({ - useRouter: jest.fn(), -})); +jest.mock("next/navigation"); describe("Newsletter", () => { it("renders signup form with a submit button", () => { @@ -44,10 +43,11 @@ describe("Newsletter", () => { // Wait for the form submission await waitFor(() => { - expect(mockRouter.push).toHaveBeenCalledWith({ - pathname: "/newsletter/confirmation/", - query: { sendy: "Success" }, - }); + console.log(mockRouter.push); + + expect(mockRouter.push).toHaveBeenCalledWith( + "/newsletter/confirmation?sendy=User+subscribed+successfully.", + ); }); }); diff --git a/frontend/tests/pages/newsletter/unsubscribe.test.tsx b/frontend/tests/pages/newsletter/unsubscribe.test.tsx index da760f0ef1..8f4d67042d 100644 --- a/frontend/tests/pages/newsletter/unsubscribe.test.tsx +++ b/frontend/tests/pages/newsletter/unsubscribe.test.tsx @@ -1,4 +1,4 @@ -import { render, waitFor } from "@testing-library/react"; +import { render, waitFor } from "tests/react-utils"; import { axe } from "jest-axe"; import NewsletterUnsubscribe from "src/app/[locale]/newsletter/unsubsrcibe/page"; diff --git a/frontend/tests/pages/process.test.tsx b/frontend/tests/pages/process.test.tsx index 6e070dde20..bd9d43929d 100644 --- a/frontend/tests/pages/process.test.tsx +++ b/frontend/tests/pages/process.test.tsx @@ -1,5 +1,4 @@ -import { screen, waitFor } from "tests/react-utils"; -import { render } from "@testing-library/react"; +import { render, screen, waitFor } from "tests/react-utils"; import { axe } from "jest-axe"; import Process from "src/app/[locale]/process/page";