Skip to content

Commit ce42343

Browse files
committed
feat: merge branch 'dev' into test/section-community
2 parents b0f50ef + 5947862 commit ce42343

File tree

96 files changed

+2665
-1468
lines changed

Some content is hidden

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

96 files changed

+2665
-1468
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- uses: actions/checkout@v4
1010
- uses: actions/setup-node@v4
1111
with:
12-
node-version: "21.0.0"
12+
node-version: "20.0.0"
1313
cache: "yarn"
1414

1515
- name: Install dependencies

.vscode/settings.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

__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+
};

__mocks__/fixtures/challenge.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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__/fixtures/user.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export const mockUser: User = {
1212
uid: "uuid-uuido-232-dex0232-2331",
1313
joined: "14 days ago",
1414
disabled: false,
15-
reputation: 0,
16-
username: "",
15+
reputation: 2,
16+
username: "Rouven",
1717
lastName: "",
1818
emailVerified: false,
1919
email: "",
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import "@testing-library/jest-dom";
2+
import { render, screen } from "@testing-library/react";
3+
import TeamChallengeCard from "@/components/cards/TeamChallenge";
4+
5+
describe("Team challenge card component", () => {
6+
it("Should render component with default props", () => {
7+
render(<TeamChallengeCard />);
8+
expect(screen.getByText("1")).toBeInTheDocument();
9+
expect(screen.queryAllByAltText('')).not.toBe(null);
10+
});
11+
12+
it("Should render the component with given props", ()=>{
13+
render(<TeamChallengeCard index={5} title="Test title" text="test text"/>)
14+
expect(screen.getByText("5")).toBeInTheDocument()
15+
expect(screen.getByText("Test title")).toBeInTheDocument();
16+
expect(screen.getByText("test text")).toBeInTheDocument();
17+
})
18+
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import UserCard from "@/components/cards/User";
2+
import { renderWithRedux } from "@__mocks__/renderWithRedux";
3+
import { mockUser } from "@__mocks__/fixtures/user";
4+
import { fireEvent, screen } from "@testing-library/react";
5+
import "@testing-library/jest-dom";
6+
7+
jest.mock("next/router", () => ({
8+
useRouter: jest.fn(() => ({
9+
locale: "en",
10+
push: mockPush,
11+
})),
12+
}));
13+
const teamMembers = [mockUser];
14+
const handleClick = jest.fn(() => {});
15+
const mockPush = jest.fn();
16+
17+
describe("User card component", () => {
18+
const timestamp = {
19+
date: new Date(),
20+
text: "",
21+
};
22+
beforeEach(() => {
23+
renderWithRedux(
24+
<UserCard user={mockUser} timestamp={timestamp} teamMembers={teamMembers} onClick={handleClick} link="/testlink">
25+
<div>test link</div>
26+
</UserCard>
27+
);
28+
});
29+
// Mock window.getSelection
30+
window.getSelection = jest.fn().mockReturnValue({
31+
type: "Caret",
32+
});
33+
it("Renders the card component", () => {
34+
expect(screen.getByTestId("userId")).toBeInTheDocument();
35+
expect(screen.getAllByTestId("avatar").length).toEqual(teamMembers.length);
36+
const linkElements = screen.getAllByRole("link");
37+
linkElements.forEach((element, index) => {
38+
if (teamMembers[index]) {
39+
const expectedHref = `/profile/${teamMembers[index].username}`;
40+
expect(element).toHaveAttribute("href", expectedHref);
41+
}
42+
});
43+
});
44+
45+
it("Renders the correct tag and currecy when teamMembers is not empty", () => {
46+
expect(screen.getByTestId("currencyId")).toBeInTheDocument();
47+
expect(screen.getByTestId("tag")).toBeInTheDocument();
48+
});
49+
50+
it("Calls onClick prop when clicked", () => {
51+
fireEvent.click(screen.getByTestId("userId"));
52+
expect(handleClick).toHaveBeenCalled();
53+
});
54+
it("Navigates to the correct link when clicked", () => {
55+
const element = screen.getByText("test link");
56+
fireEvent.click(element);
57+
expect(mockPush).toHaveBeenCalledWith("/testlink");
58+
});
59+
});

0 commit comments

Comments
 (0)