Skip to content

Commit ac15f4a

Browse files
committed
Add unit test cases for skills component
1 parent e29ddc1 commit ac15f4a

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Skills renders correctly 1`] = `
4+
<div
5+
className="px-2 sm:px-6 mb-10 "
6+
>
7+
<div
8+
className="text-xl sm:text-2xl font-bold font-title mt-2 mb-4 flex justify-between"
9+
>
10+
Skills
11+
<div
12+
className="relative flex"
13+
>
14+
<input
15+
className="leading:none text-xs my-0 py-1 px-2 pr-8 sm:text-xl border-2 border-gray-900 focus:border-blue-700 placeholder-gray-700"
16+
onChange={[Function]}
17+
placeholder="Search Skills"
18+
type="text"
19+
/>
20+
<span
21+
className="absolute"
22+
style={
23+
Object {
24+
"right": "10px",
25+
}
26+
}
27+
>
28+
<SearchIcon
29+
className="mb-1 transform scale-100 md:scale-125"
30+
size={16}
31+
verticalAlign="text-bottom"
32+
/>
33+
</span>
34+
</div>
35+
</div>
36+
<div
37+
className="divide-y divide-gray-500"
38+
key="language"
39+
>
40+
<div
41+
className="text-sm sm:text-xl text-gray-900 text-left py-1"
42+
>
43+
Programming Languages
44+
</div>
45+
<div
46+
className="flex justify-start items-center flex-wrap w-full mb-6 pl-4 sm:pl-10"
47+
>
48+
<div
49+
className="w-1/3 sm:w-1/4 my-6"
50+
key="javascript"
51+
>
52+
<label
53+
className="skillCheckboxLabel cursor-pointer flex items-center justify-start"
54+
htmlFor="javascript"
55+
>
56+
<input
57+
checked={true}
58+
id="javascript"
59+
onChange={[Function]}
60+
type="checkbox"
61+
/>
62+
<img
63+
alt="javascript"
64+
className="ml-4 w-8 h-8 sm:w-10 sm:h-10"
65+
src="javascript.svg"
66+
/>
67+
<span
68+
className="tooltiptext"
69+
>
70+
javascript
71+
</span>
72+
</label>
73+
</div>
74+
</div>
75+
</div>
76+
<div
77+
className="divide-y divide-gray-500"
78+
key="frontend_dev"
79+
>
80+
<div
81+
className="text-sm sm:text-xl text-gray-900 text-left py-1"
82+
>
83+
Frontend Development
84+
</div>
85+
<div
86+
className="flex justify-start items-center flex-wrap w-full mb-6 pl-4 sm:pl-10"
87+
>
88+
<div
89+
className="w-1/3 sm:w-1/4 my-6"
90+
key="react"
91+
>
92+
<label
93+
className="skillCheckboxLabel cursor-pointer flex items-center justify-start"
94+
htmlFor="react"
95+
>
96+
<input
97+
id="react"
98+
onChange={[Function]}
99+
type="checkbox"
100+
/>
101+
<img
102+
alt="react"
103+
className="ml-4 w-8 h-8 sm:w-10 sm:h-10"
104+
src="react.svg"
105+
/>
106+
<span
107+
className="tooltiptext"
108+
>
109+
react
110+
</span>
111+
</label>
112+
</div>
113+
<div
114+
className="w-1/3 sm:w-1/4 my-6"
115+
key="svelte"
116+
>
117+
<label
118+
className="skillCheckboxLabel cursor-pointer flex items-center justify-start"
119+
htmlFor="svelte"
120+
>
121+
<input
122+
id="svelte"
123+
onChange={[Function]}
124+
type="checkbox"
125+
/>
126+
<img
127+
alt="svelte"
128+
className="ml-4 w-8 h-8 sm:w-10 sm:h-10"
129+
src="svelte.svg"
130+
/>
131+
<span
132+
className="tooltiptext"
133+
>
134+
svelte
135+
</span>
136+
</label>
137+
</div>
138+
</div>
139+
</div>
140+
<span
141+
className="flex justify-center text-gray-900"
142+
/>
143+
</div>
144+
`;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from "react"
2+
import { shallow } from "enzyme"
3+
import toJson from "enzyme-to-json"
4+
5+
import Skills from "../skills"
6+
7+
jest.mock("../../constants/skills", () => ({
8+
__esModule: true,
9+
categorizedSkills: {
10+
language: {
11+
title: "Programming Languages",
12+
skills: ["javascript"],
13+
},
14+
frontend_dev: {
15+
title: "Frontend Development",
16+
skills: ["react", "svelte"],
17+
},
18+
},
19+
icons: {
20+
javascript: "javascript.svg",
21+
react: "react.svg",
22+
svelte: "svelte.svg",
23+
},
24+
}))
25+
26+
describe("Skills", () => {
27+
it("renders correctly", () => {
28+
const component = shallow(<Skills skills={{ javascript: true }} />)
29+
expect(toJson(component)).toMatchSnapshot()
30+
})
31+
32+
it("calls handleSkillsChange prop when a skill is clicked", () => {
33+
const mockFn = jest.fn()
34+
const component = shallow(
35+
<Skills skills={{ javascript: true }} handleSkillsChange={mockFn} />
36+
)
37+
38+
component.find("#javascript").simulate("change")
39+
40+
expect(mockFn).toHaveBeenCalledTimes(1)
41+
})
42+
})

0 commit comments

Comments
 (0)