Skip to content

Commit 5fef101

Browse files
authored
Unit tests and code coverage #82 (#83)
* Refactor Jest configuration and add test coverage * Add test coverage workflow * Refactor animationStyles.test.js: Add tests for getAnimationStyles function * Refactor Nav component PropTypes * Remove test script until tests are added * Revert * Multiple tests added * Refactor of how ids are given to menu items * Refactor of how ids are given to menu items * https example added * https example added * Menu and test optimized * Refactor switch to if/else * Optimize rmm__menu * MenuContext tests WIP * MenuContext WIP * Refactor MenuContext and optimize code * Refactor stateMachine function to use a switch statement for better readability and maintainability * Update package version to 2.2.0
1 parent 8de50f8 commit 5fef101

25 files changed

+10191
-2422
lines changed

.babelrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
],
1414
"@babel/preset-react"
1515
],
16-
"plugins": []
16+
"plugins": ["istanbul"]
1717
}

.eslintrc.cjs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
module.exports = {
22
env: {
33
browser: true,
4-
es2021: true
4+
es2021: true,
5+
jest: true
56
},
6-
extends: [
7-
'plugin:react/recommended',
8-
'standard'
9-
],
10-
overrides: [
11-
],
7+
extends: ['plugin:react/recommended', 'standard'],
8+
overrides: [],
129
parserOptions: {
1310
ecmaVersion: 'latest',
1411
sourceType: 'module'
1512
},
16-
plugins: [
17-
'react'
18-
],
19-
rules: {
20-
}
13+
plugins: ['react'],
14+
rules: {}
2115
}

.github/workflows/test-coverage.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Test Coverage
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
test-coverage:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 20
20+
21+
- name: Install dependencies
22+
run: npm ci
23+
24+
- name: Run tests with coverage
25+
run: npm test -- --coverage
26+
27+
- name: Upload coverage report
28+
uses: actions/upload-artifact@v3
29+
with:
30+
name: coverage-report
31+
path: coverage

demo/src/App.tsx

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Menu } from '@jasonrundell/react-mega-menu'
44
import './App.css'
55

66
export interface MenuItem {
7+
id: string
78
label: string
89
type: string
910
url: string
@@ -44,60 +45,70 @@ const menuConfig: MenuConfig = {
4445
menu: {
4546
items: [
4647
{
48+
id: 'home',
4749
label: 'Home',
4850
type: 'main',
4951
url: '/'
5052
},
5153
{
54+
id: 'about',
5255
label: 'About',
5356
type: 'main',
5457
url: '/about/'
5558
},
5659
{
60+
id: 'store',
5761
label: 'Store',
5862
type: 'mega',
5963
url: '/store/',
6064
items: [
6165
{
66+
id: 'store-deals',
6267
label: 'Deals',
6368
type: 'link',
6469
url: '/store/deals/',
6570
description:
6671
"Three lined small description that accompanies link in the React Mega Menu project. This maybe too much text? Who's to say, really. We'll leave it to fate to decide."
6772
},
6873
{
74+
id: 'store-kitchen',
6975
label: 'Kitchen',
7076
type: 'link',
7177
url: '/store/kitchen/',
7278
description:
7379
"Three lined small description that accompanies link in the React Mega Menu project. This maybe too much text? Who's to say, really. We'll leave it to fate to decide."
7480
},
7581
{
82+
id: 'store-outdoors',
7683
label: 'Outdoors',
7784
type: 'sub',
7885
url: '/store/outdoors/',
7986
description:
8087
"Three lined small description that accompanies link in the React Mega Menu project. This maybe too much text? Who's to say, really. We'll leave it to fate to decide.",
8188
items: [
8289
{
90+
id: 'store-outdoors-tools',
8391
label: 'Tools',
8492
type: 'link',
8593
url: '/store/outdoors/tools/',
8694
description: 'Single line description that accompanies link'
8795
},
8896
{
97+
id: 'store-outdoors-plants',
8998
label: 'Plants',
9099
type: 'link',
91100
url: '/store/outdoors/plants/',
92101
description: 'Single line description that accompanies link'
93102
},
94103
{
104+
id: 'store-outdoors-patio',
95105
label: 'Patio',
96106
type: 'link',
97107
url: '/store/outdoors/patio/',
98108
description: 'Single line description that accompanies link'
99109
},
100110
{
111+
id: 'store-outdoors-decking',
101112
label: 'Decking',
102113
type: 'link',
103114
url: '/store/outdoors/decking/',
@@ -106,33 +117,38 @@ const menuConfig: MenuConfig = {
106117
]
107118
},
108119
{
120+
id: 'store-bedroom',
109121
label: 'Bedroom',
110122
type: 'sub',
111123
url: '/store/bedroom/',
112124
description:
113125
"Three lined small description that accompanies link in the React Mega Menu project. This maybe too much text? Who's to say, really. We'll leave it to fate to decide.",
114126
items: [
115127
{
128+
id: 'store-bedroom-beds',
116129
label: 'Beds',
117130
type: 'link',
118131
url: '/store/bedroom/beds/',
119132
description: 'Single line description that accompanies link'
120133
},
121134
{
135+
id: 'store-bedroom-dressers',
122136
label: 'Dressers',
123137
type: 'link',
124138
url: '/store/bedroom/dressers/',
125139
description:
126140
'Double lined small description that accompanies link in the React Mega Menu project'
127141
},
128142
{
143+
id: 'store-bedroom-nightstands',
129144
label: 'Nightstands',
130145
type: 'link',
131146
url: '/store/bedroom/nightstands/',
132147
description:
133148
'Double lined small description that accompanies link in the React Mega Menu project'
134149
},
135150
{
151+
id: 'store-bedroom-benches',
136152
label: 'Benches',
137153
type: 'link',
138154
url: '/store/bedroom/benches/',
@@ -144,38 +160,45 @@ const menuConfig: MenuConfig = {
144160
]
145161
},
146162
{
163+
id: 'blog',
147164
label: 'Blog',
148165
type: 'mega',
149166
url: '/blog/',
150167
items: [
151168
{
169+
id: 'blog-latest-post-title',
152170
label: 'Latest Post Title',
153171
type: 'link',
154172
url: '/blog/posts/latest-post-title/',
155173
description:
156174
'Double lined small description that accompanies link in the React Mega Menu project'
157175
},
158176
{
177+
id: 'blog-categories',
159178
label: 'Categories',
160179
type: 'sub',
161180
url: '/blog/categories/',
162181
items: [
163182
{
183+
id: 'blog-news',
164184
label: 'News',
165185
type: 'link',
166186
url: '/blog/news/'
167187
},
168188
{
189+
id: 'blog-recipes',
169190
label: 'Recipes',
170191
type: 'link',
171192
url: '/blog/recipes/'
172193
},
173194
{
195+
id: 'blog-health',
174196
label: 'Health',
175197
type: 'link',
176198
url: '/blog/health/'
177199
},
178200
{
201+
id: 'blog-diet',
179202
label: 'Diet',
180203
type: 'link',
181204
url: '/blog/diet/'
@@ -185,17 +208,28 @@ const menuConfig: MenuConfig = {
185208
]
186209
},
187210
{
211+
id: 'help',
188212
label: 'Help',
189213
type: 'mega',
190214
url: '/help/',
191215
items: [
192216
{
217+
id: 'help-react-mega-menu',
218+
label: 'React Mega Menu',
219+
type: 'link',
220+
url: 'https://github.com/jasonrundell/react-mega-menu',
221+
description:
222+
'A React project which aims to be an accessible, responsive, boilerplate top navigation menu with a "Mega Menu"!'
223+
},
224+
{
225+
id: 'help-faq',
193226
label: 'FAQ',
194227
type: 'link',
195228
url: '/help/faq/',
196229
description: 'Single line description that accompanies link'
197230
},
198231
{
232+
id: 'help-knowledge-base',
199233
label: 'Knowledge Base',
200234
type: 'link',
201235
url: '/help/knowledge-base/',
@@ -205,64 +239,75 @@ const menuConfig: MenuConfig = {
205239
]
206240
},
207241
{
242+
id: 'settings',
208243
label: 'Settings',
209244
type: 'mega',
210245
url: '/settings/',
211246
items: [
212247
{
248+
id: 'settings-profile',
213249
label: 'Profile',
214250
type: 'link',
215251
url: '/settings/profile/',
216252
description: 'Single line description that accompanies link'
217253
},
218254
{
255+
id: 'settings-billing',
219256
label: 'Billing',
220257
type: 'link',
221258
url: '/settings/billing/',
222259
description: 'Single line description that accompanies link'
223260
},
224261
{
262+
id: 'settings-theme',
225263
label: 'Theme',
226264
type: 'sub',
227-
url: '/?theme',
265+
url: '#',
228266
description: 'Change the React Mega Menu theme',
229267
items: [
230268
{
269+
id: 'settings-theme-light',
231270
label: 'Light',
232271
type: 'link',
233272
url: '/?theme=light'
234273
},
235274
{
275+
id: 'settings-theme-dark',
236276
label: 'Dark',
237277
type: 'link',
238278
url: '/?theme=dark'
239279
},
240280
{
281+
id: 'settings-theme-monokai',
241282
label: 'Monokai',
242283
type: 'link',
243284
url: '/?theme=monokai'
244285
},
245286
{
287+
id: 'settings-theme-retro',
246288
label: 'Retro',
247289
type: 'link',
248290
url: '/?theme=retro'
249291
},
250292
{
293+
id: 'settings-theme-synthwave',
251294
label: 'Synthwave',
252295
type: 'link',
253296
url: '/?theme=synthwave'
254297
}
255298
]
256299
},
257300
{
301+
id: 'settings-logout',
258302
label: 'Logout',
259303
type: 'link',
260-
url: '/?logout',
304+
url: '/settings/logout/',
261305
description: 'Single line description that accompanies link'
262306
}
263307
]
264308
},
265309
{
310+
id: 'contact',
266311
label: 'Contact',
267312
type: 'main',
268313
url: '#contact'

demo/src/themes/dark.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414

1515
.rmm__theme--dark[class*='css-'],
16-
.rmm__theme--dark[class*='css-'] .rmm__topbar,
16+
.rmm__theme--dark[class*='css-'] #rmm__topbar,
1717
.rmm__theme--dark[class*='css-'] .rmm__nav,
1818
.rmm__theme--dark[class*='css-'] .rmm__mega-list,
1919
.rmm__theme--dark[class*='css-'] .rmm__nav-list,
@@ -24,7 +24,7 @@
2424
font-family: Arial, Helvetica, sans-serif;
2525
}
2626

27-
.rmm__theme--dark[class*='css-'] .rmm__topbar {
27+
.rmm__theme--dark[class*='css-'] #rmm__topbar {
2828
height: 2rem;
2929
padding: var(--menu-padding-left);
3030
}
@@ -43,7 +43,7 @@
4343
background-color: var(--dark-text-color);
4444
}
4545

46-
.rmm__theme--dark[class*='css-'] .rmm__menu {
46+
.rmm__theme--dark[class*='css-'] #rmm__nav {
4747
border-top: var(--menu-border-width) solid var(--dark-border-color);
4848
border-bottom: var(--menu-border-width) solid var(--dark-border-color);
4949
top: var(--menu-top-spacing);
@@ -103,7 +103,7 @@
103103
}
104104

105105
.rmm__theme--dark[class*='css-'] h1,
106-
.rmm__theme--dark[class*='css-'] .rmm__title,
106+
.rmm__theme--dark[class*='css-'] #rmm__title,
107107
.rmm__theme--dark[class*='css-'] .rmm__main-nav-item-link,
108108
.rmm__theme--dark[class*='css-'] .rmm__nav-item-description {
109109
color: var(--dark-text-color);
@@ -114,7 +114,7 @@
114114
}
115115

116116
.rmm__theme--dark[class*='css-'] .rmm__main-nav-item,
117-
.rmm__theme--dark[class*='css-'] .rmm__menu {
117+
.rmm__theme--dark[class*='css-'] #rmm__nav {
118118
background-color: var(--dark-bg-color);
119119
}
120120

@@ -127,12 +127,12 @@
127127
}
128128

129129
@media (min-width: 64rem) {
130-
.rmm__theme--dark[class*='css-'] .rmm__topbar {
130+
.rmm__theme--dark[class*='css-'] #rmm__topbar {
131131
border-top: none;
132132
border-right: none;
133133
}
134134

135-
.rmm__theme--dark[class*='css-'] .rmm__menu {
135+
.rmm__theme--dark[class*='css-'] #rmm__nav {
136136
top: 4rem;
137137
height: auto;
138138
border-top: var(--menu-border-width) solid var(--dark-border-color);

0 commit comments

Comments
 (0)