Skip to content

Commit c43efdb

Browse files
chore: test edit profile names form
1 parent 85f4875 commit c43efdb

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

__mocks__/colors.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Colors } from "@/types/community";
2+
3+
export const mockColors = (): Colors => ({
4+
textAccent: "#bada55",
5+
text: "#bada55",
6+
accent: "#bada55",
7+
primary: "#bada55",
8+
secondary: "#bada55",
9+
highlight: "#bada55",
10+
muted: "#bada55",
11+
cover: {
12+
text: "#bada55",
13+
accent: "#bada55",
14+
primary: "#bada55",
15+
background: "#bada55",
16+
}
17+
})

__tests__/components/popus/NamesForm.test.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "@testing-library/jest-dom"
22
import { renderWithRedux } from "../../../__mocks__/renderWithRedux"
33
import EditProfile from "@/components/popups/profile-settings/NamesForm"
4-
import { screen } from "@testing-library/react"
4+
import { fireEvent, screen } from "@testing-library/react"
55

66
jest.mock("next/router", () => ({
77
useRouter: () => ({
@@ -16,10 +16,33 @@ jest.mock("next/router", () => ({
1616
}),
1717
}));
1818
const handleClose = jest.fn()
19+
jest.mock("../../../src/components/ui/button/Arrow", () => {
20+
return {
21+
__esModule: true,
22+
default: () => {
23+
return <div />;
24+
},
25+
};
26+
});
27+
beforeEach(() => {
28+
renderWithRedux(<EditProfile show onClose={handleClose} />)
29+
})
1930
describe("NamesForm", () => {
2031
it("should render the names edit form", () => {
21-
renderWithRedux(<EditProfile show onClose={handleClose} />)
2232
const form = screen.getByTestId('names-edit-form')
2333
expect(form).toBeInTheDocument()
2434
})
35+
36+
it("should render the form with 2 inputs", () => {
37+
const form = screen.getByTestId('names-edit-form')
38+
const firstNameInput = form.querySelectorAll("div [data-testid='first-name']")
39+
const lastNameInput = form.querySelectorAll("div [data-testid='last-name']")
40+
expect(firstNameInput).toHaveLength(1)
41+
expect(lastNameInput).toHaveLength(1)
42+
})
43+
it("it should close the modal when its open", () => {
44+
expect(screen.getByTestId('names-edit-form')).toBeInTheDocument()
45+
fireEvent.click(screen.getByTestId('close-button'))
46+
expect(handleClose).toHaveBeenCalled()
47+
})
2548
})

src/components/popups/profile-settings/NamesForm.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export default function EditProfile({ show, onClose }: EditProfileProps): ReactE
7070
<form onSubmit={handleSubmit(onSave)} data-testid="names-edit-form">
7171
<div className="mb-2.5">
7272
<Input
73+
testId="first-name"
7374
label={`${t("profile.edit.label.fist-name")}`}
7475
error={errors.firstName?.message}
7576
type="firstName"
@@ -85,6 +86,7 @@ export default function EditProfile({ show, onClose }: EditProfileProps): ReactE
8586
</div>
8687
<div className="mb-8">
8788
<Input
89+
testId="last-name"
8890
label={`${t("profile.edit.label.last-name")}`}
8991
error={errors.lastName?.message}
9092
type="lastName"
@@ -98,7 +100,7 @@ export default function EditProfile({ show, onClose }: EditProfileProps): ReactE
98100
/>
99101
</div>
100102
<div className="flex pb-2 items-center justify-between">
101-
<span className="cursor-pointer text-sm font-medium text-primary" onClick={onClose}>
103+
<span className="cursor-pointer text-sm font-medium text-primary" onClick={onClose} data-testid="close-button">
102104
{t("profile.edit.close")}
103105
</span>
104106
<ArrowButton loading={loading} disabled={loading} variant="outline-primary">

src/components/ui/Input.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface InputProps extends Omit<HTMLProps<HTMLInputElement>, "onInput"> {
1616
error?: string;
1717
inputClass?: string;
1818
fontSize?: string;
19+
testId?: string;
1920
}
2021

2122
/**
@@ -35,7 +36,7 @@ interface InputProps extends Omit<HTMLProps<HTMLInputElement>, "onInput"> {
3536
* @returns {ReactElement}
3637
*/
3738
const Input = forwardRef<HTMLInputElement, InputProps>(function (
38-
{ type = "text", label, disabled = false, placeholder = null!, error, inputClass, value, fontSize = "lg", ...props },
39+
{ type = "text", label, disabled = false, placeholder = null!, error, inputClass, value, fontSize = "lg", testId = "input", ...props },
3940
ref
4041
) {
4142
const [isFocused, setIsFocused] = useState(false);
@@ -82,7 +83,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(function (
8283
);
8384

8485
return (
85-
<div className="relative">
86+
<div data-testid={testId} className="relative" >
8687
<div className={inputComponentClassName}>
8788
{label && <label className={labelClasssName}>{label}</label>}
8889
<input

0 commit comments

Comments
 (0)