Skip to content

Commit be5c80b

Browse files
committed
test-deck component
1 parent e10fda8 commit be5c80b

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/components/Deck/Deck.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import cardsData from "@/data/fakeCards.json";
44

55
const Deck = (props) => {
66
return (
7-
<div className="deck">
7+
<div className="deck" data-testid="info cards">
88
{cardsData.map((city, index) => (
99
<Card
1010
key={index}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Deck from "../Deck";
2+
import { render, screen } from "@testing-library/react";
3+
4+
test(" info cards should be displayed on the page for each city (Glasgow, Manchester, London).", () => {
5+
render(<Deck />);
6+
const cardcomponent = screen.getAllByTestId("info cards");
7+
const manchester = cardcomponent.filter((card) =>
8+
card.textContent.toLowerCase().includes("manchester")
9+
);
10+
const glasgow = cardcomponent.filter((card) =>
11+
card.textContent.toLowerCase().includes("glasgow")
12+
);
13+
const london = cardcomponent.filter((card) =>
14+
card.textContent.toLowerCase().includes("london")
15+
);
16+
expect(manchester.length).toBeGreaterThan(0);
17+
expect(glasgow.length).toBeGreaterThan(0);
18+
expect(london.length).toBeGreaterThan(0);
19+
});
20+
test("Each card should link to the correct website.", () => {
21+
render(<Deck />);
22+
const cardcomponent = screen.getAllByTestId("info cards");
23+
cardcomponent.forEach((card) => {
24+
const linkElement = card.querySelector("a");
25+
expect(linkElement).toBeInTheDocument();
26+
expect(linkElement).toHaveAttribute("href");
27+
});
28+
});
29+
test("Each card should link to the correct image.", () => {
30+
render(<Deck />);
31+
const cardcomponent = screen.getAllByTestId("info cards");
32+
cardcomponent.forEach((card) => {
33+
const imageElement = card.querySelector("img");
34+
expect(imageElement).toBeInTheDocument();
35+
expect(imageElement).toHaveAttribute("src");
36+
});
37+
});

0 commit comments

Comments
 (0)