Skip to content

Commit 27635e1

Browse files
VIA-306 MD: Add missing tests for nhs-app components incl. CardLinkWithDescription
1 parent d8fafdf commit 27635e1

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import CardLink from "@src/app/_components/nhs-app/CardLink";
2+
import { render, screen } from "@testing-library/react";
3+
4+
describe("CardLink", () => {
5+
it("should render component", () => {
6+
render(<CardLink title="Flu" link="/vaccines/flu" />);
7+
8+
const oneOfCards = screen.getByRole("listitem");
9+
10+
expect(oneOfCards).toBeVisible();
11+
});
12+
13+
it("should render link inside of card link", () => {
14+
render(<CardLink title="Flu" link="/vaccines/flu" />);
15+
16+
const cardLinkWithDescription: HTMLElement = screen.getByRole("link", { name: "Flu" });
17+
18+
expect(cardLinkWithDescription).toBeVisible();
19+
});
20+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import CardLinkWithDescription from "@src/app/_components/nhs-app/CardLinkWithDescription";
2+
import { render, screen } from "@testing-library/react";
3+
4+
describe("CardLinkWithDescription", () => {
5+
it("should render component", () => {
6+
render(<CardLinkWithDescription title="Flu" description="Around 12 weeks" link="/vaccines/flu" />);
7+
8+
const oneOfCards = screen.getByRole("listitem");
9+
10+
expect(oneOfCards).toBeVisible();
11+
});
12+
13+
it("should render link inside of card link", () => {
14+
render(<CardLinkWithDescription title="Flu" description="Around 12 weeks" link="/vaccines/flu" />);
15+
16+
const cardLinkWithDescription: HTMLElement = screen.getByRole("link", { name: "Flu" });
17+
18+
expect(cardLinkWithDescription).toBeVisible();
19+
});
20+
21+
it("should render description inside of card link", () => {
22+
render(<CardLinkWithDescription title="Flu" description="Around 12 weeks" link="/vaccines/flu" />);
23+
24+
const content: HTMLElement = screen.getByText("Around 12 weeks");
25+
26+
expect(content).toBeVisible();
27+
});
28+
});

src/app/_components/nhs-app/CardLinkWithDescription.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Link from "next/link";
2+
13
interface CardLinkProps {
24
title: string;
35
description: string;
@@ -9,9 +11,9 @@ const CardLinkWithDescription = ({ title, description, link }: CardLinkProps) =>
911
<li className="nhsapp-card">
1012
<div className="nhsapp-card__container">
1113
<div className="nhsapp-card__content">
12-
<a href={link} className="nhsapp-card__link nhsuk-link--no-visited-state">
14+
<Link prefetch={false} href={link} className="nhsapp-card__link nhsuk-link--no-visited-state">
1315
{title}
14-
</a>
16+
</Link>
1517
<div className="nhsapp-card__below">
1618
<p className="nhsapp-card__description">{description}</p>
1719
</div>

0 commit comments

Comments
 (0)