From df82ee4fb83cb3ab70ab48d033357d771a2d4f7b Mon Sep 17 00:00:00 2001 From: Marcus Blais <31868036+blai0264@users.noreply.github.com> Date: Thu, 23 May 2024 13:36:29 -0400 Subject: [PATCH] Fragment component tests (#1021) * Unit testing for ArticleCTA component * Unit testing for BasicTextWithImage component * Unit testing for Button component * fixed typos in ImageWithCollapse.stories.js * Unit testing for ImageWithCollapse component * Unit testing for QuoteVerticalLineContent component * Unit testing for ImageVerticalLineContent component * Unit testing for TextContent component * Unit testing for TextWithImage component * updated alt arg value to match unit test query * fix dcterms metadata to better support AA (#1019) * Font Optimization (#1020) * setup google fonts to be served locally * implement fonts using next/font * apply Lato and Notosans variables directly to Modal * remove duplicate main landmark * fix duplicate main landmarks in error pages * added on click test-case for ImageWithCollapse.test * small update to ImageWithCollapse.test --------- Co-authored-by: Jordan Willis <31868510+will0684@users.noreply.github.com> Co-authored-by: Jordan --- .../fragment_components/ArticleCTA.test.js | 16 +++++++ .../BasicTextWithImage.test.js | 18 ++++++++ .../fragment_components/Button.test.js | 23 ++++++++++ .../ImageVerticalLineContent.test.js | 21 ++++++++++ .../ImageWithCollapse.stories.js | 6 +-- .../ImageWithCollapse.test.js | 42 +++++++++++++++++++ .../QuoteVerticalLineContent.stories.js | 2 +- .../QuoteVerticalLineContent.test.js | 23 ++++++++++ .../fragment_components/TextContent.test.js | 17 ++++++++ .../TextWithImage.stories.js | 4 +- .../fragment_components/TextWithImage.test.js | 29 +++++++++++++ 11 files changed, 195 insertions(+), 6 deletions(-) create mode 100644 components/fragment_renderer/fragment_components/ArticleCTA.test.js create mode 100644 components/fragment_renderer/fragment_components/BasicTextWithImage.test.js create mode 100644 components/fragment_renderer/fragment_components/Button.test.js create mode 100644 components/fragment_renderer/fragment_components/ImageVerticalLineContent.test.js create mode 100644 components/fragment_renderer/fragment_components/ImageWithCollapse.test.js create mode 100644 components/fragment_renderer/fragment_components/QuoteVerticalLineContent.test.js create mode 100644 components/fragment_renderer/fragment_components/TextContent.test.js create mode 100644 components/fragment_renderer/fragment_components/TextWithImage.test.js diff --git a/components/fragment_renderer/fragment_components/ArticleCTA.test.js b/components/fragment_renderer/fragment_components/ArticleCTA.test.js new file mode 100644 index 0000000000..0190c6186c --- /dev/null +++ b/components/fragment_renderer/fragment_components/ArticleCTA.test.js @@ -0,0 +1,16 @@ +import React from "react"; +import { render, screen } from "@testing-library/react"; +import ArticleCTA from "./ArticleCTA"; +import { Default } from "./ArticleCTA.stories.js"; +import { axe, toHaveNoViolations } from "jest-axe"; + +expect.extend(toHaveNoViolations); + +describe("ArticleCTA", () => { + test("renders ArticleCTA component with default props", async () => { + const { container } = render(); + expect(screen.getByText("This is a body")).toBeInTheDocument(); + const results = await axe(container); + expect(results).toHaveNoViolations(); + }); +}); diff --git a/components/fragment_renderer/fragment_components/BasicTextWithImage.test.js b/components/fragment_renderer/fragment_components/BasicTextWithImage.test.js new file mode 100644 index 0000000000..53a2843fd9 --- /dev/null +++ b/components/fragment_renderer/fragment_components/BasicTextWithImage.test.js @@ -0,0 +1,18 @@ +import React from "react"; +import { render, screen } from "@testing-library/react"; +import BasicTextWithImage from "./BasicTextWithImage"; +import { Default } from "./BasicTextWithImage.stories.js"; +import { axe, toHaveNoViolations } from "jest-axe"; + +expect.extend(toHaveNoViolations); + +describe("BasicTextWithImage", () => { + test("renders BasicTextWithImage component with default props", async () => { + const { container } = render(); + expect(screen.getByAltText("image alt text")).toBeInTheDocument(); + expect(screen.getByText((content) => content.startsWith("Every week"))) + .toBeInTheDocument; + const results = await axe(container); + expect(results).toHaveNoViolations(); + }); +}); diff --git a/components/fragment_renderer/fragment_components/Button.test.js b/components/fragment_renderer/fragment_components/Button.test.js new file mode 100644 index 0000000000..e63ae5f9e5 --- /dev/null +++ b/components/fragment_renderer/fragment_components/Button.test.js @@ -0,0 +1,23 @@ +import React from "react"; +import { render, screen } from "@testing-library/react"; +import Button from "./Button"; +import { Primary } from "./Button.stories.js"; +import { Secondary } from "./Button.stories.js"; +import { axe, toHaveNoViolations } from "jest-axe"; + +expect.extend(toHaveNoViolations); + +describe("Button", () => { + test("renders Button component with Primary props", async () => { + const { container } = render(