Skip to content

Commit 439c459

Browse files
committed
feat: add test for the section homepage
1 parent b2fa1d3 commit 439c459

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import CommunityStats, { stats } from "@/components/sections/homepage/_partials/testimonials/CommunityStats";
2+
import "@testing-library/jest-dom";
3+
import { screen } from "@testing-library/react";
4+
import { renderWithRedux } from "../../../../../__mocks__/renderWithRedux";
5+
6+
describe("CommunityStats", () => {
7+
it("should render Community stats", () => {
8+
renderWithRedux(<CommunityStats testId="communityStatsId"/>)
9+
const communityStat = screen.getByTestId("communityStatsId")
10+
expect(communityStat).toBeInTheDocument()
11+
})
12+
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+
})
24+
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+
})

src/components/sections/homepage/_partials/testimonials/CommunityStats.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Statistic {
1414
description: string;
1515
count: number;
1616
}
17-
const stats: Statistic[] = [
17+
export const stats: Statistic[] = [
1818
{
1919
title: "testimonials.community.stats.card-1.title",
2020
description: "testimonials.community.stats.card-1.description",
@@ -31,11 +31,11 @@ const stats: Statistic[] = [
3131
count: 6527,
3232
},
3333
];
34-
export default function CommunityStats() {
34+
export default function CommunityStats({testId}: {testId?: string}) {
3535
const { t } = useTranslation();
3636

3737
return (
38-
<div className="p-7 bg-primary rounded-3.5xl mx-auto text-white relative md:absolute md:top-28 lg:top-32 xl:w-1/3 md:w-4/6 z-10 sm:max-w-sm">
38+
<div data-testid={testId} className="p-7 bg-primary rounded-3.5xl mx-auto text-white relative md:absolute md:top-28 lg:top-32 xl:w-1/3 md:w-4/6 z-10 sm:max-w-sm">
3939
<h3 className="m-0 text-4.5xl w-3/4">{t("testimonials.community.title")}</h3>
4040
<div className="relative divide-y divide-white divide-dotted">
4141
{stats.map((stat) => (

0 commit comments

Comments
 (0)