Skip to content

Commit 3720cd2

Browse files
chore: implement email edit form test
1 parent ce2052c commit 3720cd2

File tree

15 files changed

+1896
-43
lines changed

15 files changed

+1896
-43
lines changed

__mocks__/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function remarkPlugin() { }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { wrapper } from "@/store";
2+
import { ReactNode } from "react";
3+
import { Provider } from "react-redux";
4+
5+
const ReduxProvider = ({ children }: { children: ReactNode }) => {
6+
const { store } = wrapper.useWrappedStore(children);
7+
8+
return <Provider store={store}>{children}</Provider>;
9+
};
10+
11+
export default ReduxProvider;

__mocks__/renderWithRedux.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { RenderOptions, render } from "@testing-library/react";
2+
import { ReactElement } from "react";
3+
import ReduxProvider from "./provider/ReduxProvider";
4+
5+
const customRender = (element: ReactElement, options?: Omit<RenderOptions, "wrapper">) => {
6+
return render(element, { wrapper: ReduxProvider, ...options })
7+
}
8+
9+
export * from "@testing-library/react"
10+
export { customRender as renderWithRedux }

__mocks__/unified.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function unified() { }
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import "@testing-library/jest-dom"
2+
import { renderWithRedux } from "../../../__mocks__/renderWithRedux"
3+
import EmailForm from "@/components/popups/profile-settings/EmailForm";
4+
import { act, 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+
19+
// Mocking the arrow button in order to avoid double work since it was tested in ui tests
20+
jest.mock("../../../src/components/ui/button/Arrow", () => {
21+
return {
22+
__esModule: true,
23+
default: () => {
24+
return <div />;
25+
},
26+
};
27+
});
28+
29+
30+
const handleClose = jest.fn()
31+
32+
const onSubmit = jest.fn()
33+
34+
const renderEmailEditForm = () => {
35+
renderWithRedux(<EmailForm show onClose={handleClose} />)
36+
}
37+
38+
beforeEach(() => {
39+
renderEmailEditForm()
40+
})
41+
42+
afterEach(() => {
43+
onSubmit.mockReset()
44+
})
45+
46+
describe("EmailEditForm", () => {
47+
it('should render the email edit form modal.', () => {
48+
expect(screen.getByTestId('profileModal')).toBeInTheDocument()
49+
})
50+
51+
it('should render a form', () => {
52+
const form = screen.getByTestId('edit-email-form')
53+
expect(form).toBeInTheDocument()
54+
})
55+
56+
it('should contain 2 inputs, and a close button', () => {
57+
const emailInput = screen.getByPlaceholderText('login-page.email.placeholder');
58+
const emailInputConfirm = screen.getByPlaceholderText('profile.settings.edit.email.confirm')
59+
const closeButton = screen.getByTestId('close-button')
60+
61+
expect(emailInput).toBeInTheDocument()
62+
expect(emailInputConfirm).toBeInTheDocument()
63+
expect(closeButton).toBeInTheDocument()
64+
})
65+
66+
it("should not modify the input values of the form", async () => {
67+
const emailInput = screen.getByPlaceholderText('login-page.email.placeholder');
68+
const emailInputConfirm = screen.getByPlaceholderText('profile.settings.edit.email.confirm')
69+
70+
act(() => {
71+
fireEvent.change(emailInput, { target: { value: "[email protected]" } });
72+
fireEvent.change(emailInputConfirm, { target: { value: "[email protected]" } });
73+
fireEvent.submit(screen.getByTestId("edit-email-form"));
74+
})
75+
});
76+
77+
it("it should close the modal when its open", () => {
78+
expect(screen.getByTestId('profileModal')).toBeInTheDocument()
79+
fireEvent.click(screen.getByTestId('close-button'))
80+
expect(handleClose).toHaveBeenCalled()
81+
})
82+
83+
})

check_branch_name.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local_branch_name="$(git rev-parse --abbrev-ref HEAD)"
66
# - ^(dev|main)$)
77
# 2. checking for branch Name starting with fix,ft,ht,chore or doc follwed by a "/" then the "branch name"
88
# - ^((fix|ft|ht|chore|doc)\/[a-zA-Z0-9\-]+)$
9-
valid_branch_regex='^(dev|main)$|^((fix|ft|ht|chore|doc)\/[a-zA-Z0-9\-]+)$'
9+
valid_branch_regex='^(dev|main)$|^((test|fix|ft|ht|chore|doc)\/[a-zA-Z0-9\-]+)$'
1010

1111
green='\033[0;32m'
1212
red='\033[0;31m'

jest.config.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* For a detailed explanation regarding each configuration property, visit:
3+
* https://jestjs.io/docs/configuration
4+
*/
5+
6+
const esModules = ["remark", "rehype", "unist", "github", "query"].join("|");
7+
8+
// eslint-disable-next-line @typescript-eslint/no-var-requires
9+
const nextJest = require("next/jest");
10+
11+
const createJestConfig = nextJest({
12+
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
13+
dir: "./",
14+
});
15+
16+
// Add any custom config to be passed to Jest
17+
const config = {
18+
coverageProvider: "v8",
19+
testEnvironment: "jsdom",
20+
// Add more setup options before each test is run
21+
// setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
22+
moduleNameMapper: {
23+
[`^(${esModules})-.*`]: "<rootDir>/__mocks__/plugin.ts",
24+
unified: "<rootDir>/__mocks__/unified.ts",
25+
},
26+
};
27+
28+
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
29+
module.exports = createJestConfig(config);

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"lint": "eslint --ignore-path .eslintignore \"./**/*.{ts,tsx,js}\"",
1010
"prettier-format": "prettier --config .prettierrc 'src/**/*.{ts,tsx,js,jsx}' --write",
1111
"check-branch-name": "./check_branch_name.sh",
12-
"prepare": "npx husky install && chmod +x .husky/* && chmod +x ./check_branch_name.sh"
12+
"prepare": "npx husky install && chmod +x .husky/* && chmod +x ./check_branch_name.sh",
13+
"test": "jest --silent"
1314
},
1415
"dependencies": {
1516
"@coingecko/cryptoformat": "^0.5.4",
@@ -18,7 +19,11 @@
1819
"@sumsub/websdk": "^1.4.0",
1920
"@tailwindcss/aspect-ratio": "^0.4.2",
2021
"@tailwindcss/line-clamp": "^0.4.2",
22+
"@testing-library/jest-dom": "^6.4.2",
23+
"@testing-library/react": "^15.0.6",
24+
"@testing-library/user-event": "^14.5.2",
2125
"@types/axios": "^0.14.0",
26+
"@types/jest": "^29.5.12",
2227
"@types/react": "18.0.28",
2328
"@types/react-dom": "18.0.11",
2429
"@typescript-eslint/eslint-plugin": "^6.3.0",
@@ -39,6 +44,8 @@
3944
"hex-to-rgba": "^2.0.1",
4045
"highlightjs-solidity": "^2.0.6",
4146
"i18next": "^22.4.13",
47+
"jest": "^29.7.0",
48+
"jest-environment-jsdom": "^29.7.0",
4249
"lodash": "^4.17.21",
4350
"lodash.debounce": "^4.0.8",
4451
"lodash.uniqby": "^4.7.0",
@@ -100,6 +107,7 @@
100107
"lint-staged": "^13.2.0",
101108
"postcss": "^8.4.24",
102109
"prettier": "^2.8.8",
110+
"redux-mock-store": "^1.5.4",
103111
"tailwindcss": "^3.3.2"
104112
},
105113
"lint-staged": {

public/locales/bg/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292
"profile.settings.edit.name.update": "Update your Name",
293293
"profile.settings.edit.email": "Email",
294294
"profile.settings.edit.email.update": "Update your Email",
295+
"profile.settings.edit.email.error": "Имейлите трябва да съвпадат",
295296
"profile.settings.edit.email.confirm": "Confirm email",
296297
"profile.settings.edit.discord": "Discord",
297298
"profile.settings.edit.discord.connect": "connect",

public/locales/en/common.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@
119119
"communities.overview.challenge.certificate": "Certificate",
120120
"communities.overview.challenge.subtitle": "Upon successful completion",
121121
"communities.overview.challenge.expiry": "Challenge expiry date:",
122-
"communities.overview.challenge.take.challenge":"Take the challenge",
122+
"communities.overview.challenge.take.challenge": "Take the challenge",
123123
"communities.overview.challenge.see.challenge": "See the challenge",
124-
"communities.overview.challenge.for.certificate":"for the certificate",
125-
"communities.overview.challenge.for.feedback":"for every feedback",
126-
"communities.overview.challenge.unlock.certificate":"Unlock with Certificate",
127-
"communities.overview.challenge.participate":"Participate in {{token}} hackathons",
124+
"communities.overview.challenge.for.certificate": "for the certificate",
125+
"communities.overview.challenge.for.feedback": "for every feedback",
126+
"communities.overview.challenge.unlock.certificate": "Unlock with Certificate",
127+
"communities.overview.challenge.participate": "Participate in {{token}} hackathons",
128128
"communities.overview.challenge.learning.modules.included": "Learning modules included",
129-
"communities.overview.challenge.no.learning.modules":"No learning modules included",
129+
"communities.overview.challenge.no.learning.modules": "No learning modules included",
130130
"communities.overview.challenge.learning.title": "The following learning materials will equip you with the technical expertise required to successfully address the challenge.",
131131
"communities.overview.challenge.learning.start": "Start now",
132132
"communities.overview.challenge.team.setup.title": "Form your team",
@@ -203,7 +203,7 @@
203203
"course.challenge.reward": "REWARD",
204204
"course.challenge.reward.description": "By completing the challenge in this course you can earn {{amount}} {{token}}",
205205
"course.challenge.reward.stable.description": "By completing the challenge in this course you can earn {{currency}}{{amount}} in {{token}}",
206-
"course.challenge.reward.certificate.description":"Complete the course to achieve the certificate and unlock new opportunities",
206+
"course.challenge.reward.certificate.description": "Complete the course to achieve the certificate and unlock new opportunities",
207207
"course.challenge.certificate": "CERTIFICATE",
208208
"course.challenge.certificate.description": "By completing the challenge in this course you can earn a certificate.",
209209
"course.scoreboard.button": "Load more",
@@ -222,8 +222,8 @@
222222
"testimonials.text": "Dacade is really encouraging, I didn't realize the little that I know would matter. Thank you for making us learn more and to make research too.",
223223
"footer.text": "Dacade is an open-sourced platform and is created in collaboration with multiple contributors. Go to the <a href=\"https://github.com/dacadeorg/dacade-frontend-app\"> repository </a> to start contributing.",
224224
"footer.privacy-policy": "Impressum & Privacy Policy",
225-
"footer.open.source" : "Dacade is an open-sourced platform.",
226-
"footer.open.source.contribute":"Become one of our contributors",
225+
"footer.open.source": "Dacade is an open-sourced platform.",
226+
"footer.open.source.contribute": "Become one of our contributors",
227227
"feedback.bounty": "Feedback bounty",
228228
"feedback.issued": "Issued",
229229
"feedback.ends": "ending in ",
@@ -297,6 +297,7 @@
297297
"profile.settings.edit.email": "Email",
298298
"profile.settings.edit.email.update": "Update your Email",
299299
"profile.settings.edit.email.confirm": "Confirm email",
300+
"profile.settings.edit.email.error": "Emails should match",
300301
"profile.settings.discord.disconnect.confirm": "Do you want to disconnect from Discord?",
301302
"profile.settings.discord.disconnect": "Disconnect",
302303
"profile.settings.edit.discord": "Discord",

0 commit comments

Comments
 (0)