|
| 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