Skip to content

Commit 94d88f2

Browse files
committed
feat: add missing test for the homepage
1 parent 0b62082 commit 94d88f2

File tree

10 files changed

+127
-11
lines changed

10 files changed

+127
-11
lines changed

__mocks__/community.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Community } from "@/types/community";
2+
import { reward } from "./reward";
3+
import { colors } from "./colors";
4+
5+
6+
export const metadata = {
7+
invite_id: "abc123",
8+
submissions: 5,
9+
bestSubmissions: ["submission1", "submission2"],
10+
feedbacks: 10,
11+
name: "Project XYZ",
12+
issuedOn: "2024-01-29T12:00:00Z",
13+
image: "image_url",
14+
title: "Title of the project",
15+
description: "Description of the project",
16+
narrative: "Narrative of the project",
17+
recipientName: "John Doe",
18+
issuerName: "Jane Smith",
19+
comment: "This is a comment",
20+
linkToWork: "link_to_work",
21+
submission: "submission_details",
22+
};
23+
24+
export const community: Community = {
25+
id: "ew-43",
26+
ref: "community/ref",
27+
created_at: new Date("2022-05-01T12:00:00Z"),
28+
updated_at: new Date("2022-05-01T12:00:00Z"),
29+
summary: "this is the summary",
30+
icon: "public/img/communities/aeternity.svg",
31+
name: "aeternity",
32+
image: "public/img/communities/aeternity.svg",
33+
colors: colors,
34+
slug: "ae",
35+
active: true,
36+
description: "this is a aeternity community",
37+
metadata,
38+
timestamp: 182044800000,
39+
rewards: [reward],
40+
reward,
41+
courses: 3,
42+
duration: 4,
43+
can_mint_certificates: true,
44+
challenges: 3
45+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import "@testing-library/jest-dom";
2+
import { screen } from "@testing-library/react";
3+
import { renderWithRedux } from "../../../../__mocks__/renderWithRedux";
4+
import CommunitiesSection from "@/components/sections/homepage/Communities";
5+
import { community } from "../../../../__mocks__/community";
6+
7+
jest.mock("next/router", () => ({
8+
useRouter: jest.fn(),
9+
}));
10+
11+
describe("Communities Section", () => {
12+
it("should render community section", () => {
13+
renderWithRedux(<CommunitiesSection communities={[community]} testId="communitiesSectionId" />);
14+
expect(screen.getByTestId("communitiesSectionId")).toBeInTheDocument();
15+
[community].forEach((community) => {
16+
expect(screen.getByText(community.name)).toBeInTheDocument();
17+
expect(screen.getByText(community.name).textContent).toBe("aeternity");
18+
});
19+
expect(screen.getByText("page.index.communities.partnering.title")).toBeInTheDocument();
20+
});
21+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import "@testing-library/jest-dom";
2+
import { screen } from "@testing-library/react";
3+
import { renderWithRedux } from "../../../../__mocks__/renderWithRedux";
4+
import MainSection, { cards } from "@/components/sections/homepage/Main";
5+
6+
describe("Main Section", () => {
7+
it("should render the main section", () => {
8+
renderWithRedux(<MainSection testId="mainSectionId" />);
9+
expect(screen.getByTestId("mainSectionId")).toBeInTheDocument();
10+
const linkElements = screen.getAllByText("page.index.main.button");
11+
const linkElement = linkElements.find((el) => el.closest("a") !== null);
12+
expect(linkElement?.closest("a")).toHaveAttribute("href", "/communities");
13+
const lastLink = linkElements[linkElements.length - 1];
14+
expect(lastLink.closest("a")).toHaveAttribute("href", "/communities");
15+
});
16+
17+
it("should display cards", () => {
18+
renderWithRedux(<MainSection testId="mainSectionId" />);
19+
cards.forEach((card) => {
20+
expect(screen.getByText(card.title)).toBeInTheDocument();
21+
expect(screen.getByText(card.body)).toBeInTheDocument();
22+
});
23+
});
24+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import "@testing-library/jest-dom";
2+
import { screen } from "@testing-library/react";
3+
import { renderWithRedux } from "../../../../__mocks__/renderWithRedux";
4+
import OpenSource from "@/components/sections/homepage/OpenSource";
5+
6+
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+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import "@testing-library/jest-dom";
2+
import { screen } from "@testing-library/react";
3+
import { renderWithRedux } from "../../../../__mocks__/renderWithRedux";
4+
import TestimonialsSection from "@/components/sections/homepage/Testimonials";
5+
6+
describe("OpenSource", () => {
7+
it("should render Open Source", () => {
8+
renderWithRedux(<TestimonialsSection/>)
9+
expect(screen.getByText("testimonials.community.title")).toBeInTheDocument()
10+
expect(screen.getByText("footer.open.source")).toBeInTheDocument()
11+
})
12+
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import "@testing-library/jest-dom";
33
import { render, screen } from "@testing-library/react";
44
import _ from "lodash";
55

6-
const fixtureTestimonials = {
6+
export const fixtureTestimonials = {
77
content: "testimonials content",
88
icon: "/testimonials-icon",
99
};

src/components/sections/homepage/Communities.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import { Community } from "@/types/community";
1818
* @returns {ReactElement}
1919
*/
2020

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

2424
return (
2525
<Section type="default" padding="pt-20 lg:pb-24 md:pb-24">
26-
<div id="communities" className="md:flex relative items-end">
26+
<div data-testid={testId} id="communities" className="md:flex relative items-end">
2727
<div className="pr-5">
2828
<p className="uppercase font-semibold leading-none text-base">{t("page.index.communities.title")}</p>
2929
</div>

src/components/sections/homepage/Main.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Link from "next/link";
1212
*
1313
* @type {{title: string; body: string}[]}
1414
*/
15-
const cards: { title: string; body: string }[] = [
15+
export const cards: { title: string; body: string }[] = [
1616
{
1717
title: "page.index.main.cards.first.title",
1818
body: "page.index.main.cards.first.body",
@@ -34,12 +34,12 @@ const cards: { title: string; body: string }[] = [
3434
* @export
3535
* @returns {ReactElement}
3636
*/
37-
export default function MainSection(): ReactElement {
37+
export default function MainSection({testId}: {testId?: string}): ReactElement {
3838
const { t } = useTranslation();
3939

4040
return (
4141
<Section type="default" padding="p-0">
42-
<div className="w-full lg:py-24 pt-24 pb-8">
42+
<div data-testid={testId} className="w-full lg:py-24 pt-24 pb-8">
4343
<h1 className="lg:text-8xl md:text-6xl text-5xl leading-none tracking-tighter">{t("page.index.main.title")}</h1>
4444
<p className="lg:text-8xl md:text-6xl text-4.5xl py-2 lg:py-0 md:py-0 sm:py-0 text-gray-400 tracking-tighter leading-none">{t("page.index.main.subtitle")}</p>
4545
</div>

src/components/sections/homepage/OpenSource.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import { useTranslation } from "next-i18next";
1010
* @returns {ReactElement}
1111
*/
1212

13-
export default function OpenSource() {
13+
export default function OpenSource({testId}: {testId?: string}) {
1414
const { t } = useTranslation();
1515
return (
16-
<div className="text-4xl lg:text-5xl pt-24 flex flex-col text-wrap space-y-2">
17-
<p >
16+
<div data-testid={testId} className="text-4xl lg:text-5xl pt-24 flex flex-col text-wrap space-y-2">
17+
<p>
1818
{t("footer.open.source")}
1919
<br className="block md:hidden lg:block" />
2020
<Link href="https://github.com/dacadeorg/dacade-frontend-app" target="_blank" className="text-primary items-center space-x-2">

src/types/community.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export interface Community {
2222
challenges: number;
2323
duration: number;
2424
items?: any[];
25-
challenge: Challenge;
26-
submission: Submission;
25+
challenge?: Challenge;
26+
submission?: Submission;
2727
can_mint_certificates: boolean;
2828
}
2929

0 commit comments

Comments
 (0)