Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Fix for 404 and e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
acouch committed May 21, 2024
1 parent e05df40 commit 50bb9df
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 52 deletions.
13 changes: 6 additions & 7 deletions frontend/src/app/[locale]/newsletter/confirmation/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ import PageSEO from "src/components/PageSEO";
import BetaAlert from "src/components/BetaAlert";
import { useTranslations } from "next-intl";
import { Metadata } from "next";
import { getTranslations } 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
// const t = await getTranslations({ locale: "en" });
export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
const meta: Metadata = {
// title: t("Newsletter.page_title"),
title: "Newsletter Confirmation | Simpler.Grants.gov",
description:
"A one‑stop shop for all federal discretionary funding to make it easy for you to discover, understand, and apply for opportunities.",
title: t("Newsletter.page_title"),
description: t("Index.meta_description"),
};

return meta;
}

export default function NewsletterConfirmation() {
const t = useTranslations("Newsletter_confirmation");

Expand Down
12 changes: 5 additions & 7 deletions frontend/src/app/[locale]/newsletter/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ import PageSEO from "src/components/PageSEO";
import BetaAlert from "src/components/BetaAlert";
import NewsletterForm from "src/app/[locale]/newsletter/NewsletterForm";
import { Metadata } from "next";
import { getTranslations } from "next-intl/server";
import {
useTranslations,
useMessages,
NextIntlClientProvider,
} from "next-intl";

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" });
export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
const meta: Metadata = {
// title: t("Newsletter.page_title"),
title: "Newsletter | Simpler.Grants.gov",
description:
"A one‑stop shop for all federal discretionary funding to make it easy for you to discover, understand, and apply for opportunities.",
title: t("Newsletter.page_title"),
description: t("Index.meta_description"),
};

return meta;
Expand Down
12 changes: 5 additions & 7 deletions frontend/src/app/[locale]/newsletter/unsubscribe/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import PageSEO from "src/components/PageSEO";
import BetaAlert from "src/components/BetaAlert";
import { useTranslations } from "next-intl";
import { Metadata } from "next";
import { getTranslations } 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
// const t = await getTranslations({ locale: "en" });
export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
const meta: Metadata = {
// title: t("Newsletter.page_title"),
title: "Newsletter | Simpler.Grants.gov",
description:
"A one‑stop shop for all federal discretionary funding to make it easy for you to discover, understand, and apply for opportunities.",
title: t("Newsletter.page_title"),
description: t("Index.meta_description"),
};

return meta;
Expand Down
14 changes: 6 additions & 8 deletions frontend/src/app/[locale]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ import IndexGoalContent from "src/components/content/IndexGoalContent";
import ProcessAndResearchContent from "src/components/content/ProcessAndResearchContent";
import { Metadata } from "next";
import { useTranslations } from "next-intl";
import { getTranslations } 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
// const t = await getTranslations({ locale: "en" });
export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
const meta: Metadata = {
// title: t("Research.page_title"),
title: "Simpler.Grants.gov",
description:
"A one‑stop shop for all federal discretionary funding to make it easy for you to discover, understand, and apply for opportunities.",
title: t("Index.page_title"),
description: t("Index.meta_description"),
};

return meta;
}

export default function Home() {
const t = useTranslations("Index");

Expand Down
13 changes: 5 additions & 8 deletions frontend/src/app/[locale]/process/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ import ProcessIntro from "src/app/[locale]/process/ProcessIntro";
import ProcessInvolved from "src/app/[locale]/process/ProcessInvolved";
import ProcessMilestones from "src/app/[locale]/process/ProcessMilestones";
import { useTranslations } from "next-intl";
import { getTranslations } 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
// const t = await getTranslations({ locale: "en" });
export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
const meta: Metadata = {
// title: t("Process.page_title"),
title: "Process | Simpler.Grants.gov",
description:
"A one‑stop shop for all federal discretionary funding to make it easy for you to discover, understand, and apply for opportunities.",
title: t("Process.page_title"),
description: t("Process.meta_description"),
};

return meta;
}

Expand Down
14 changes: 6 additions & 8 deletions frontend/src/app/[locale]/research/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ import ResearchMethodology from "src/app/[locale]/research/ResearchMethodology";
import ResearchThemes from "src/app/[locale]/research/ResearchThemes";
import { Metadata } from "next";
import { useTranslations } from "next-intl";
import { getTranslations } 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
// const t = await getTranslations({ locale: "en" });
export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
const meta: Metadata = {
// title: t("Research.page_title"),
title: "Research | Simpler.Grants.gov",
description:
"A one‑stop shop for all federal discretionary funding to make it easy for you to discover, understand, and apply for opportunities.",
title: t("Research.page_title"),
description: t("Research.meta_description"),
};

return meta;
}

export default function Research() {
const t = useTranslations("Research");

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/[locale]/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
const meta: Metadata = {
title: t("Search.title"),
description: t("Index.meta_description"),
};

return meta;
}

async function Search({ searchParams }: ServerPageProps) {
const convertedSearchParams = convertSearchParamsToProperTypes(searchParams);
const initialSearchResults = await searchFetcher.fetchOpportunities(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "src/styles/styles.scss";
import { GoogleAnalytics } from "@next/third-parties/google";
import { PUBLIC_ENV } from "../../constants/environments";
import { PUBLIC_ENV } from "src/constants/environments";

import Layout from "src/components/Layout";
import { unstable_setRequestLocale } from "next-intl/server";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@ import BetaAlert from "src/components/BetaAlert";
import { GridContainer } from "@trussworks/react-uswds";
import Link from "next/link";
import { useTranslations } from "next-intl";
import { getTranslations, unstable_setRequestLocale } from "next-intl/server";
import { Metadata } from "next";

export async function generateMetadata() {
const t = await getTranslations({ locale: "en" });
const meta: Metadata = {
title: t("ErrorPages.page_not_found.title"),
description: t("Index.meta_description"),
};
return meta;
}

export default function NotFound() {
unstable_setRequestLocale("en");
const t = useTranslations("ErrorPages.page_not_found");

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useEffect } from "react";
import { sendGAEvent } from "@next/third-parties/google";
import { PUBLIC_ENV } from "../../constants/environments";
import { PUBLIC_ENV } from "src/constants/environments";

export default function Template({ children }: { children: React.ReactNode }) {
const isProd = process.env.NODE_ENV === "production";
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/messages/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export const messages = {
"The Simpler.Grants.gov newsletter is powered by the Sendy data service. Personal information is not stored within Simpler.Grants.gov. ",
},
ErrorPages: {
page_title: "Page Not Found | Simpler.Grants.gov",
page_not_found: {
title: "Oops! Page Not Found",
message_content_1:
Expand Down
2 changes: 1 addition & 1 deletion frontend/stories/pages/404.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meta } from "@storybook/react";
import PageNotFound from "src/app/[locale]/not-found";
import PageNotFound from "src/app/not-found";

const meta: Meta<typeof PageNotFound> = {
title: "Pages/404",
Expand Down
20 changes: 20 additions & 0 deletions frontend/tests/e2e/404.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable testing-library/prefer-screen-queries */
import { test, expect } from "@playwright/test";

test.beforeEach(async ({ page }) => {
await page.goto("/imnothere");
});

test.afterEach(async ({ context }) => {
await context.close();
});

test("has title", async ({ page }) => {
await expect(page).toHaveTitle("Oops! Page Not Found");
});

test("can view the home button", async ({ page }) => {
await expect(page.getByRole("link", { name: "Return Home" })).toHaveText(
"Return Home",
);
});
6 changes: 3 additions & 3 deletions frontend/tests/pages/404.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { screen, waitFor, render } from "tests/react-utils";
// import { render } from "@testing-library/react";
import { screen, waitFor } from "tests/react-utils";
import { render } from "@testing-library/react";

import { axe } from "jest-axe";
import PageNotFound from "src/app/[locale]/not-found";
import PageNotFound from "src/app/not-found";

describe("PageNotFound", () => {
it("renders alert with grants.gov link", () => {
Expand Down

0 comments on commit 50bb9df

Please sign in to comment.