Skip to content

Commit fd743fe

Browse files
refactor: merge branch 'dev' into test/feedback-component
2 parents 023881d + 573215a commit fd743fe

File tree

156 files changed

+2506
-1565
lines changed

Some content is hidden

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

156 files changed

+2506
-1565
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.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ They can also be given class names as shown in the above image.
144144

145145
```javascript
146146
<div
147-
className={classNames("w-1/3", "bg-primary", {
147+
className={classNames("w-1/3", "bg-brand", {
148148
"text-white": type === "default",
149149
underline: hasLink,
150150
})}

__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/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: 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+
});
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import "@testing-library/jest-dom"
2+
import EmailForm from "@/components/popups/profile-settings/EmailForm";
3+
import { act, fireEvent, screen } from "@testing-library/react";
4+
import { renderWithRedux } from "@__mocks__/renderWithRedux";
5+
6+
jest.mock("next/router", () => ({
7+
useRouter: () => ({
8+
push: jest.fn(),
9+
events: {
10+
on: jest.fn(),
11+
off: jest.fn(),
12+
emit: jest.fn(),
13+
},
14+
isFallback: false,
15+
pathname: "mocked-pathname",
16+
}),
17+
}));
18+
19+
const handleClose = jest.fn()
20+
21+
const onSubmit = jest.fn()
22+
23+
const renderEmailEditForm = () => {
24+
renderWithRedux(<EmailForm show onClose={handleClose} />)
25+
}
26+
27+
beforeEach(() => {
28+
renderEmailEditForm()
29+
})
30+
31+
afterEach(() => {
32+
onSubmit.mockReset()
33+
})
34+
35+
describe("EmailEditForm", () => {
36+
it('should render the email edit form modal.', () => {
37+
expect(screen.getByTestId('profileModal')).toBeInTheDocument()
38+
})
39+
40+
it('should render a form', () => {
41+
const form = screen.getByTestId('edit-email-form')
42+
expect(form).toBeInTheDocument()
43+
})
44+
45+
it('should contain 2 inputs, and a close button', () => {
46+
const emailInput = screen.getByPlaceholderText('login-page.email.placeholder');
47+
const emailInputConfirm = screen.getByPlaceholderText('profile.settings.edit.email.confirm')
48+
const closeButton = screen.getByTestId('close-button')
49+
50+
expect(emailInput).toBeInTheDocument()
51+
expect(emailInputConfirm).toBeInTheDocument()
52+
expect(closeButton).toBeInTheDocument()
53+
})
54+
55+
it("should not modify user's input values", async () => {
56+
const emailInput = screen.getByPlaceholderText('login-page.email.placeholder');
57+
const emailInputConfirm = screen.getByPlaceholderText('profile.settings.edit.email.confirm')
58+
59+
act(() => {
60+
fireEvent.change(emailInput, { target: { value: "[email protected]" } });
61+
fireEvent.change(emailInputConfirm, { target: { value: "[email protected]" } });
62+
fireEvent.submit(screen.getByTestId("edit-email-form"));
63+
})
64+
});
65+
66+
it("should not submit the form when emails do not match", async () => {
67+
const emailInput = screen.getByPlaceholderText('login-page.email.placeholder');
68+
const emailInputConfirm = screen.getByPlaceholderText('profile.settings.edit.email.confirm');
69+
const form = screen.getByTestId('edit-email-form');
70+
71+
fireEvent.change(emailInput, { target: { value: "[email protected]" } });
72+
fireEvent.change(emailInputConfirm, { target: { value: "[email protected]" } });
73+
74+
await act(async () => {
75+
fireEvent.submit(form);
76+
});
77+
78+
expect(onSubmit).not.toHaveBeenCalled();
79+
expect(screen.queryByText("Emails should match.")).toBeInTheDocument();
80+
81+
})
82+
83+
it("it should close the modal when its open", () => {
84+
expect(screen.getByTestId('profileModal')).toBeInTheDocument()
85+
fireEvent.click(screen.getByTestId('close-button'))
86+
expect(handleClose).toHaveBeenCalled()
87+
})
88+
})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import "@testing-library/jest-dom"
2+
import { renderWithRedux } from "../../../__mocks__/renderWithRedux"
3+
import EditProfile from "@/components/popups/profile-settings/NamesForm"
4+
import { fireEvent, screen } from "@testing-library/react"
5+
6+
jest.mock("next/router", () => ({
7+
useRouter: () => ({
8+
push: jest.fn(),
9+
events: {
10+
on: jest.fn(),
11+
off: jest.fn(),
12+
emit: jest.fn(),
13+
},
14+
isFallback: false,
15+
pathname: "mocked-pathname",
16+
}),
17+
}));
18+
const handleClose = jest.fn()
19+
beforeEach(() => {
20+
renderWithRedux(<EditProfile show onClose={handleClose} />)
21+
})
22+
describe("NamesForm", () => {
23+
it("should render the names edit form", () => {
24+
const form = screen.getByTestId('names-edit-form')
25+
expect(form).toBeInTheDocument()
26+
})
27+
28+
it("should render the form with 2 inputs", () => {
29+
const form = screen.getByTestId('names-edit-form')
30+
const firstNameInput = form.querySelectorAll("div [data-testid='first-name']")
31+
const lastNameInput = form.querySelectorAll("div [data-testid='last-name']")
32+
expect(firstNameInput).toHaveLength(1)
33+
expect(lastNameInput).toHaveLength(1)
34+
})
35+
36+
it("it should close the modal when its open", () => {
37+
expect(screen.getByTestId('names-edit-form')).toBeInTheDocument()
38+
fireEvent.click(screen.getByTestId('close-button'))
39+
expect(handleClose).toHaveBeenCalled()
40+
})
41+
})

__tests__/components/sections/bounties/Navigation.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "@testing-library/jest-dom";
22
import { screen } from "@testing-library/react";
33
import BountiesNavigation from "@/components/sections/bounties/Navigation";
4-
import { renderWithRedux } from "../../../../__mocks__/renderWithRedux";
4+
import { renderWithRedux } from "@__mocks__/renderWithRedux";
55
import { List } from "@/utilities/CommunityNavigation";
66

77
jest.mock("next/router", () => ({

0 commit comments

Comments
 (0)