Skip to content

Commit 25e0c02

Browse files
committed
feat: add test for the testimonials component
1 parent b9cb448 commit 25e0c02

File tree

12 files changed

+49
-63
lines changed

12 files changed

+49
-63
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jest.mock("next/router", () => ({
1010

1111
describe("Communities Section", () => {
1212
it("should render community section", () => {
13-
renderWithRedux(<CommunitiesSection communities={[community]} testId="communitiesSectionId" />);
13+
renderWithRedux(<CommunitiesSection communities={[community]} />);
1414
expect(screen.getByTestId("communitiesSectionId")).toBeInTheDocument();
1515
[community].forEach((community) => {
1616
expect(screen.getByText(community.name)).toBeInTheDocument();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("Main Section", () => {
1515
});
1616

1717
it("should display cards", () => {
18-
renderWithRedux(<MainSection testId="mainSectionId" />);
18+
renderWithRedux(<MainSection />);
1919
cards.forEach((card) => {
2020
expect(screen.getByText(card.title)).toBeInTheDocument();
2121
expect(screen.getByText(card.body)).toBeInTheDocument();

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { renderWithRedux } from "../../../../__mocks__/renderWithRedux";
44
import OpenSource from "@/components/sections/homepage/OpenSource";
55

66
describe("OpenSource", () => {
7-
it("should render Open Source", () => {
8-
renderWithRedux(<OpenSource testId="openSourceId"/>)
9-
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")
13-
})
14-
});
7+
it("should render Open Source", () => {
8+
renderWithRedux(<OpenSource />);
9+
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");
13+
});
14+
});

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,13 @@ import { screen } from "@testing-library/react";
33
import TestimonialsSection from "@/components/sections/homepage/Testimonials";
44
import { renderWithRedux } from "../../../../__mocks__/renderWithRedux";
55

6-
describe("Testimonials Section", () => {
7-
const testimonials = [
8-
{
9-
icon: "/assets/img/testimonials/CED.jpg",
10-
content:
11-
"Dacade helped me to meet people on the same blockchain journey as me and gives access to cool mentors! I like that it rewards you for challenges and helping others.",
12-
},
13-
{
14-
icon: "/assets/img/testimonials/alex.jpg",
15-
content: "Testimonials text",
16-
},
17-
];
18-
19-
it("should render testimonials with correct content", () => {
20-
renderWithRedux(<TestimonialsSection testId="testimonialsId"/>);
21-
const testimonial = screen.getByTestId("testimonialsId");
22-
expect(testimonial).toBeInTheDocument();
23-
24-
testimonials.forEach((testimonial) => {
25-
expect(screen.getByAltText(testimonial.icon)).toBeInTheDocument();
26-
expect(screen.getByText(testimonial.content)).toBeInTheDocument();
27-
});
6+
describe("TestimonialsSection", () => {
7+
it("should render TestimonialsSection with child components", () => {
8+
renderWithRedux(<TestimonialsSection />);
9+
expect(screen.getByTestId("testimonialsSectionId")).toBeInTheDocument();
10+
expect(screen.getByTestId("communityStatsId")).toBeInTheDocument();
11+
expect(screen.getByTestId("testimonialsId")).toBeInTheDocument();
12+
expect(screen.getByTestId("openSourceId")).toBeInTheDocument();
13+
expect(screen.getByTestId("section")).toBeInTheDocument();
2814
});
2915
});

__tests__/components/sections/homepage/_partials/CommunityStats.test.tsx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ import { screen } from "@testing-library/react";
44
import { renderWithRedux } from "../../../../../__mocks__/renderWithRedux";
55

66
describe("CommunityStats", () => {
7-
it("should render Community stats", () => {
8-
renderWithRedux(<CommunityStats testId="communityStatsId"/>)
9-
const communityStat = screen.getByTestId("communityStatsId")
10-
expect(communityStat).toBeInTheDocument()
11-
})
7+
it("should render Community stats", () => {
8+
renderWithRedux(<CommunityStats />);
9+
const communityStat = screen.getByTestId("communityStatsId");
10+
expect(communityStat).toBeInTheDocument();
11+
});
1212

13-
it("should display the stats", () => {
14-
renderWithRedux(<CommunityStats/>)
15-
stats.forEach((stat) => {
16-
expect(screen.getByText(stat.count)).toBeInTheDocument()
17-
expect(screen.getByText(stat.count).textContent).toBe((stat.count).toString())
18-
expect(screen.getByText(stat.title)).toBeInTheDocument()
19-
expect(screen.getByText(stat.title).textContent).toBe((stat.title).toString())
20-
expect(screen.getByText(stat.description)).toBeInTheDocument()
21-
expect(screen.getByText(stat.description).textContent).toBe((stat.title + (" ") + stat.description).toString())
22-
})
23-
})
13+
it("should display the stats", () => {
14+
renderWithRedux(<CommunityStats />);
15+
stats.forEach((stat) => {
16+
expect(screen.getByText(stat.count)).toBeInTheDocument();
17+
expect(screen.getByText(stat.count).textContent).toBe(stat.count.toString());
18+
expect(screen.getByText(stat.title)).toBeInTheDocument();
19+
expect(screen.getByText(stat.title).textContent).toBe(stat.title.toString());
20+
expect(screen.getByText(stat.description)).toBeInTheDocument();
21+
expect(screen.getByText(stat.description).textContent).toBe((stat.title + " " + stat.description).toString());
22+
});
23+
});
2424

25-
it("should display the anchor tag with button", () => {
26-
renderWithRedux(<CommunityStats/>)
27-
expect(screen.getByRole("link")).toHaveAttribute("href");
28-
expect(screen.getByRole("link").getAttribute("href")).toBe("https://discord.gg/U38KQHDtHe");
29-
expect(screen.getByRole("button")).toBeInTheDocument()
30-
expect(screen.getByText("testimonials.community.join")).toBeInTheDocument()
31-
})
32-
})
25+
it("should display the anchor tag with button", () => {
26+
renderWithRedux(<CommunityStats />);
27+
expect(screen.getByRole("link")).toHaveAttribute("href");
28+
expect(screen.getByRole("link").getAttribute("href")).toBe("https://discord.gg/U38KQHDtHe");
29+
expect(screen.getByRole("button")).toBeInTheDocument();
30+
expect(screen.getByText("testimonials.community.join")).toBeInTheDocument();
31+
});
32+
});

__tests__/components/sections/homepage/_partials/Stories.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const fixtureTestimonials = {
1010

1111
describe("Stories", () => {
1212
it("should display the stories", () => {
13-
render(<TestimonialsSection testId="testimonialsId" list={[fixtureTestimonials]} />);
13+
render(<TestimonialsSection list={[fixtureTestimonials]} />);
1414
expect(screen.getByTestId("testimonialsId")).toBeInTheDocument();
1515
const mockGrid = _.chunk([fixtureTestimonials], 5);
1616
mockGrid.forEach((grid) => {

src/components/sections/homepage/Communities.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { Community } from "@/types/community";
1818
* @returns {ReactElement}
1919
*/
2020

21-
export default function CommunitiesSection({ communities, testId }: { communities: Community[], testId?: string }): ReactElement {
21+
export default function CommunitiesSection({ communities, testId = "communitiesSectionId" }: { communities: Community[]; testId?: string }): ReactElement {
2222
const { t } = useTranslation();
2323

2424
return (

src/components/sections/homepage/Main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const cards: { title: string; body: string }[] = [
3434
* @export
3535
* @returns {ReactElement}
3636
*/
37-
export default function MainSection({testId}: {testId?: string}): ReactElement {
37+
export default function MainSection({ testId = "mainSectionId" }: { testId?: string }): ReactElement {
3838
const { t } = useTranslation();
3939

4040
return (

src/components/sections/homepage/OpenSource.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useTranslation } from "next-i18next";
1010
* @returns {ReactElement}
1111
*/
1212

13-
export default function OpenSource({testId}: {testId?: string}) {
13+
export default function OpenSource({ testId = "openSourceId" }: { testId?: string }) {
1414
const { t } = useTranslation();
1515
return (
1616
<div data-testid={testId} className="text-4xl lg:text-5xl pt-24 flex flex-col text-wrap space-y-2">

src/components/sections/homepage/Testimonials.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const stories = (t: TFunction<"translation", undefined, "translation">): Testimo
7575
];
7676
};
7777

78-
export default function TestimonialsSection({testId}: {testId?: string}): ReactElement {
78+
export default function TestimonialsSection({testId="testimonialsSectionId"}: {testId?: string}): ReactElement {
7979
const { t } = useTranslation();
8080
return (
8181
<div data-testid={testId}>

0 commit comments

Comments
 (0)