Skip to content

Commit c4f7664

Browse files
committed
Merge branch 'stage'
2 parents 2b31113 + 0403451 commit c4f7664

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1378
-422
lines changed

__mocks__/fixtures/challenge.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const submission: Submission = {
9696
token: "",
9797
},
9898
reviewed: false,
99-
feedbacks: 0,
99+
feedbacks: 3,
100100
language: "",
101101
evaluation: {
102102
points: 8,
@@ -170,3 +170,11 @@ export const mockFeedback: Feedback = {
170170
ranking: 0,
171171
text: "I am providing a feedback",
172172
};
173+
174+
export const challengeSliceData = {
175+
current: challenge,
176+
list: [challenge],
177+
submission: submission,
178+
loading: false
179+
180+
}

__mocks__/fixtures/colors.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export const colors = {
1+
import { Colors } from "@/types/community";
2+
3+
export const colors: Colors = {
24
textAccent: "--tm-text",
35
text: "--tm-text",
46
accent: "--tm-accent",

__mocks__/fixtures/course.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Course, Format, LearningModule, Material } from "@/types/course";
22
import { mockTrailer } from "./bounty";
3+
import { RatingCriteria } from "@/types/challenge";
34

45

56
export const Introduction = {
@@ -25,7 +26,7 @@ export const Rubric = {
2526
typeSlug: "slug",
2627
};
2728

28-
export const mockRatingCriteria = {
29+
export const mockRatingCriteria: RatingCriteria = {
2930
name: "rating criteria",
3031
order: 4,
3132
rubric: [Rubric],
@@ -131,6 +132,4 @@ export const mockFormat: Format = {
131132
githubLink: true,
132133
text: true,
133134
disclaimer: true,
134-
};
135-
136-
135+
};

__mocks__/referrals.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Referral, UserReferral } from "@/types/community";
2+
import { mockCommunity } from "./community";
3+
import { challenge, mockUser, submission as getMockSubmission } from "./challenge";
4+
5+
6+
const referralSubmission = () => Object.assign(getMockSubmission(), { challengeData: challenge(), link: "referral-link" });
7+
const userReferral: UserReferral = Object.assign(mockUser(), { submissions: [referralSubmission()] });
8+
9+
export const mockReferral = (): Referral => ({
10+
id: "",
11+
name: "",
12+
ref: "",
13+
created_at: new Date("2022-05-01T12:00:00Z"),
14+
updated_at: new Date("2022-05-01T12:00:00Z"),
15+
title: "",
16+
community: mockCommunity,
17+
timestamp: 0,
18+
reward: {
19+
id: "",
20+
ref: "",
21+
created_at: new Date("2022-05-01T12:00:00Z"),
22+
updated_at: new Date("2022-05-01T12:00:00Z"),
23+
challenge: "",
24+
type: "",
25+
community: "",
26+
token: "",
27+
stable: false,
28+
fiatCurrency: undefined,
29+
amount: 0,
30+
timestamp: 0,
31+
distribution: undefined,
32+
},
33+
challenge: challenge(),
34+
submissions: [getMockSubmission()],
35+
rewarded: false,
36+
user: userReferral,
37+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import "@testing-library/jest-dom";
2+
import RewardBadge, { RewardBadgeProps } from "@/components/badges/RewardBadge";
3+
import { screen } from "@testing-library/react";
4+
import { renderWithRedux } from "@__mocks__/renderWithRedux";
5+
6+
const mockRewardBadges: RewardBadgeProps = {
7+
type: "transparent",
8+
reward: {
9+
token: "BTC",
10+
amount: 2,
11+
},
12+
displayAmount: true,
13+
};
14+
jest.mock("../../../src/utilities", () => ({
15+
shortenNumber: (num: number) => `shortened-${num}`,
16+
}));
17+
18+
describe("RewardBadges", () => {
19+
it("should render rewardBadges", () => {
20+
renderWithRedux(<RewardBadge {...mockRewardBadges} />);
21+
const rewardBadge = screen.getByTestId("RewardBadge");
22+
expect(rewardBadge).toBeInTheDocument();
23+
});
24+
it("should render rewardBadges with coin when the token is provide", () => {
25+
renderWithRedux(<RewardBadge reward={{ token: "BTC" }} />);
26+
const rewardBadge = screen.getByTestId("RewardBadge");
27+
const coin = screen.getByTestId("coin");
28+
expect(rewardBadge).toBeInTheDocument();
29+
expect(coin).toBeInTheDocument();
30+
});
31+
32+
it("should render rewardBadges with amount and token", () => {
33+
renderWithRedux(<RewardBadge reward={{ token: "BTC", amount: 1000 }} displayAmount={true} />);
34+
const text = screen.getByText("shortened-1000 BTC");
35+
expect(text).toBeInTheDocument();
36+
});
37+
38+
it('should display "0" when the reward amount is 0 and token is empty', () => {
39+
renderWithRedux(<RewardBadge reward={{ token: "", amount: 0 }} />);
40+
const rewardBadge = screen.getByTestId("RewardBadge");
41+
expect(rewardBadge).toBeInTheDocument();
42+
expect(rewardBadge).toHaveTextContent("0");
43+
});
44+
});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { render, screen, fireEvent } from "@testing-library/react";
2+
import "@testing-library/jest-dom";
3+
import Story from "@/components/cards/Story";
4+
5+
jest.mock("next/image", () => ({
6+
__esModule: true,
7+
default: (props: any) => <img {...props} />,
8+
}));
9+
10+
describe("Story Component", () => {
11+
const mockStory = {
12+
content: "Test story content",
13+
icon: "/test-icon.png",
14+
};
15+
16+
const defaultProps = {
17+
story: mockStory,
18+
position: 0,
19+
gridPosition: 0,
20+
count: 5,
21+
showingBubble: { card: null, grid: null },
22+
onShowBubble: jest.fn(),
23+
onHideBubble: jest.fn(),
24+
};
25+
26+
it("renders the story icon", () => {
27+
render(<Story {...defaultProps} />);
28+
expect(screen.getByTestId("storyId")).toBeInTheDocument();
29+
const icon = screen.getByAltText("story icon");
30+
expect(icon).toBeInTheDocument();
31+
expect(icon).toHaveAttribute("src", "/test-icon.png");
32+
});
33+
34+
it("shows the bubble when clicked", () => {
35+
render(<Story {...defaultProps} />);
36+
fireEvent.click(screen.getByTestId("storyId"));
37+
expect(screen.getByText("Test story content")).toBeInTheDocument();
38+
expect(defaultProps.onShowBubble).toHaveBeenCalled();
39+
});
40+
41+
it("hides the bubble when clicked again", () => {
42+
render(<Story {...defaultProps} />);
43+
fireEvent.click(screen.getByTestId("storyId"));
44+
fireEvent.click(screen.getByTestId("storyId"));
45+
expect(screen.queryByText("Test story content")).not.toBeInTheDocument();
46+
expect(defaultProps.onHideBubble).toHaveBeenCalled();
47+
});
48+
49+
it("shows the bubble initially when showingBubble matches position and gridPosition", () => {
50+
const props = {
51+
...defaultProps,
52+
showingBubble: { card: 0, grid: 0 },
53+
};
54+
render(<Story {...props} />);
55+
expect(screen.getByText("Test story content")).toBeInTheDocument();
56+
});
57+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import "@testing-library/jest-dom";
2+
import { screen } from "@testing-library/react";
3+
import SubmissionCard from "@/components/cards/Submission";
4+
import { useRouter } from "next/router";
5+
import { submission } from "@__mocks__/fixtures/challenge";
6+
import { renderWithRedux } from "@__mocks__/renderWithRedux";
7+
8+
jest.mock("next/router", () => ({
9+
useRouter: jest.fn(),
10+
}));
11+
12+
13+
describe("SubmissionCard", () => {
14+
beforeEach(() => {
15+
(useRouter as jest.Mock).mockReturnValue({
16+
asPath: "/submissions",
17+
push: jest.fn(),
18+
});
19+
});
20+
21+
it("renders the submission card with correct content", () => {
22+
renderWithRedux(
23+
<SubmissionCard submission={submission}>
24+
<div>testing children</div>
25+
</SubmissionCard>
26+
);
27+
expect(screen.getByTestId("submissionId")).toBeInTheDocument();
28+
expect(screen.getByText("Submission")).toBeInTheDocument();
29+
expect(screen.getByText("testing children")).toBeInTheDocument();
30+
});
31+
32+
it("displays evaluation points when available", () => {
33+
renderWithRedux(<SubmissionCard submission={submission} />);
34+
expect(screen.getByTestId("badgeId")).toBeInTheDocument();
35+
expect(screen.getByText("8")).toBeInTheDocument();
36+
expect(screen.getByText("submissions.evaluation.points")).toBeInTheDocument();
37+
});
38+
39+
it("displays feedback count when available", () => {
40+
renderWithRedux(<SubmissionCard submission={submission} />);
41+
expect(screen.getByText("3")).toBeInTheDocument();
42+
expect(screen.getByText("submissions.feedback.feedbacks")).toBeInTheDocument();
43+
});
44+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import Header from "@/components/sections/communities/_partials/Header";
2+
import { render, screen } from "@testing-library/react";
3+
import "@testing-library/jest-dom";
4+
5+
const headerProps = {
6+
description: "Test Description",
7+
title: "Test Title",
8+
subtitle: "Test Subtitle",
9+
isTeamChallenge: true,
10+
isHackathon: true,
11+
};
12+
13+
describe("Header", () => {
14+
it("renders the Header with Props", () => {
15+
render(
16+
<Header
17+
description={headerProps.description}
18+
title={headerProps.title}
19+
subtitle={headerProps.subtitle}
20+
isTeamChallenge={headerProps.isTeamChallenge}
21+
isHackathon={headerProps.isHackathon}
22+
/>
23+
);
24+
expect(screen.getByRole("heading", { name: headerProps.title })).toBeInTheDocument();
25+
expect(screen.getByRole("heading", { name: new RegExp(headerProps.subtitle) })).toBeInTheDocument();
26+
expect(screen.getByTestId("tag")).toBeInTheDocument();
27+
expect(screen.getByText(headerProps.description)).toBeInTheDocument();
28+
});
29+
30+
it("does not render subtitle when not provided", () => {
31+
render(<Header />);
32+
expect(screen.queryByRole("heading", { name: new RegExp(headerProps.subtitle) })).toBe(null);
33+
expect(screen.queryByRole("tag")).toBe(null);
34+
});
35+
36+
it("renders 'TEAM' if isHackathon is false", () => {
37+
render(<Header subtitle={headerProps.subtitle} isTeamChallenge={headerProps.isTeamChallenge} />);
38+
expect(screen.getByText("TEAM")).toBeInTheDocument();
39+
});
40+
41+
it("renders 'Hackathon' if isHackathon is true", () => {
42+
render(<Header subtitle={headerProps.subtitle} isTeamChallenge={headerProps.isTeamChallenge} isHackathon={headerProps.isHackathon} />);
43+
expect(screen.getByText("Hackathon")).toBeInTheDocument();
44+
});
45+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Section from "@/components/sections/communities/_partials/Section";
2+
import "@testing-library/jest-dom";
3+
import { render, screen } from "@testing-library/react";
4+
5+
describe("section", () => {
6+
it("should render section", () => {
7+
render(<Section />);
8+
const communitySection = screen.getByTestId("sectionId");
9+
expect(communitySection).toBeInTheDocument();
10+
});
11+
12+
it("should render section with title and subtitle", () => {
13+
render(<Section title={"section title"} subtitle={"section subtitle"} hideSubtitleOnMobile={false} />);
14+
const communitySectionTitle = screen.getByText("section title");
15+
expect(communitySectionTitle).toBeInTheDocument();
16+
const communitySectionSubTitle = screen.getByText("section subtitle");
17+
expect(communitySectionSubTitle).toBeInTheDocument();
18+
});
19+
20+
it("should render with children", () => {
21+
render(
22+
<Section>
23+
<div>community section child</div>
24+
</Section>
25+
);
26+
expect(screen.getByText("community section child")).toBeInTheDocument();
27+
});
28+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import "@testing-library/jest-dom";
2+
import { screen } from "@testing-library/react";
3+
import { CoursesOverview } from "@/components/sections/communities/overview/Courses";
4+
import { renderWithRedux } from "@__mocks__/renderWithRedux";
5+
import { mockCourse } from "@__mocks__/fixtures/course";
6+
import { mockCommunity } from "@__mocks__/fixtures/community";
7+
8+
9+
jest.mock("next/router", () => ({
10+
useRouter: () => ({
11+
asPath: "next",
12+
}),
13+
}));
14+
15+
describe("CoursesOverview", () => {
16+
it("renders the courses overview section with course cards", () => {
17+
renderWithRedux(<CoursesOverview />, {
18+
courses: { current: mockCourse, list: [mockCourse], content: mockCourse.community, count: 1, menus: [] },
19+
community: { current: mockCommunity, list: [mockCommunity], courses: [mockCourse], status: "succeeded", error: "" },
20+
});
21+
expect(screen.getByText("communities.overview.courses.title")).toBeInTheDocument();
22+
[mockCourse].forEach((course) => {
23+
const courseElement = screen.getByText(course.name);
24+
expect(courseElement).toBeInTheDocument();
25+
expect(courseElement.textContent).toBe(course.name);
26+
});
27+
});
28+
});

0 commit comments

Comments
 (0)