Skip to content

Commit f42d47f

Browse files
committed
feat: add test for checking the content
1 parent 0666618 commit f42d47f

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

__tests__/components/sections/homepage/Communities.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,13 @@ describe("Communities Section", () => {
1818
});
1919
expect(screen.getByText("page.index.communities.partnering.title")).toBeInTheDocument();
2020
});
21+
it("should handle empty communities list", () => {
22+
renderWithRedux(<CommunitiesSection communities={[]} />);
23+
expect(screen.queryByText(community.name)).not.toBeInTheDocument();
24+
});
25+
26+
it("should render the PartneringCard", () => {
27+
renderWithRedux(<CommunitiesSection communities={[community]} />);
28+
expect(screen.getByText("page.index.communities.partnering.title")).toBeInTheDocument();
29+
});
2130
});

__tests__/components/sections/homepage/Main.test.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ describe("Main Section", () => {
1717
it("should display cards", () => {
1818
renderWithRedux(<MainSection />);
1919
cards.forEach((card) => {
20-
expect(screen.getByText(card.title)).toBeInTheDocument();
21-
expect(screen.getByText(card.body)).toBeInTheDocument();
20+
const cardTitleElement = screen.getByText(card.title);
21+
const cardBodyElement = screen.getByText(card.body);
22+
expect(cardTitleElement).toBeInTheDocument();
23+
expect(cardTitleElement).toHaveTextContent(card.title);
24+
expect(cardBodyElement).toBeInTheDocument();
25+
expect(cardBodyElement).toHaveTextContent(card.body);
2226
});
2327
});
2428
});

__tests__/components/sections/homepage/OpenSource.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ describe("OpenSource", () => {
77
it("should render Open Source", () => {
88
renderWithRedux(<OpenSource />);
99
expect(screen.getByTestId("openSourceId")).toBeInTheDocument();
10-
expect(screen.getByRole("link")).toBeInTheDocument();
11-
expect(screen.getByRole("link").hasAttribute("href")).toBeTruthy();
12-
expect(screen.getByRole("link").getAttribute("href")).toBe("https://github.com/dacadeorg/dacade-frontend-app");
10+
const link = screen.getByRole("link");
11+
expect(link).toBeInTheDocument();
12+
expect(link).toHaveAttribute("href", "https://github.com/dacadeorg/dacade-frontend-app");
1313
});
1414
});
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
import "@testing-library/jest-dom";
22
import TestimonialsSection from "@/components/sections/homepage/_partials/testimonials/Stories";
33
import { render, screen } from "@testing-library/react";
4-
import _ from "lodash";
54

65
const fixtureTestimonials = {
76
content: "testimonials content",
87
icon: "/testimonials-icon",
98
};
109

1110
describe("Stories", () => {
12-
it("should display the stories", () => {
13-
render(<TestimonialsSection list={[fixtureTestimonials]} />);
14-
expect(screen.getByTestId("testimonialsId")).toBeInTheDocument();
15-
const mockGrid = _.chunk([fixtureTestimonials], 5);
16-
mockGrid.forEach((grid) => {
17-
grid.forEach((story) => {
18-
const storyImage = screen.getByRole("img");
19-
expect(storyImage).toBeInTheDocument();
20-
expect(storyImage.hasAttribute("src")).toBeTruthy();
21-
expect(storyImage.getAttribute("src")).toContain(story.icon.replace("/testimonials-icon", "/_next/image?url=%2Ftestimonials-icon&w=96&q=75"));
22-
expect(storyImage.hasAttribute("alt")).toBeTruthy();
23-
});
11+
it("should display each story correctly", () => {
12+
render(<TestimonialsSection list={Array(10).fill(fixtureTestimonials)} />);
13+
const stories = screen.getAllByRole("img");
14+
stories.forEach((storyImage) => {
15+
expect(storyImage).toBeInTheDocument();
16+
expect(storyImage).toHaveAttribute("src", expect.stringContaining(fixtureTestimonials.icon.replace("/testimonials-icon", "/_next/image?url=%2Ftestimonials-icon&w=96&q=75")));
17+
expect(storyImage).toHaveAttribute("alt");
2418
});
2519
});
2620
});

0 commit comments

Comments
 (0)