@@ -4,13 +4,50 @@ import '@testing-library/jest-dom/extend-expect';
44import { MemoryRouter } from 'react-router-dom' ;
55import { ThemeProvider , createTheme } from '@mui/material/styles' ;
66import NavBar from '../app/src/components/top/NavBar' ;
7- import navbarDropDown from '../app/src/components/top/navbarDropDown'
7+ import navBarButtons from '../app/src/components/top/NavBarButtons' ;
88import * as projectFunctions from '../app/src/helperFunctions/projectGetSaveDel' ;
99import { Provider } from 'react-redux' ;
1010import { configureStore } from '@reduxjs/toolkit' ;
1111import rootReducer from '../app/src/redux/reducers/rootReducer' ;
1212import { initialState as appStateInitialState } from '../app/src/redux/reducers/slice/appStateSlice' ;
1313
14+
15+
16+ // Mock the non-serializable HTMLTypes
17+ const mockHTMLTypes = [
18+ {
19+ id : 11 ,
20+ tag : 'div' ,
21+ name : 'Div' ,
22+ style : { } ,
23+ placeHolderShort : 'div' ,
24+ placeHolderLong : '' ,
25+ framework : 'reactClassic' ,
26+ nestable : true ,
27+ } ,
28+ {
29+ id : 1000 ,
30+ tag : 'separator' ,
31+ name : 'separator' ,
32+ style : { border : 'none' } ,
33+ placeHolderShort : '' ,
34+ placeHolderLong : '' ,
35+ framework : '' ,
36+ nestable : true ,
37+ } ,
38+ {
39+ id : 1 ,
40+ tag : 'img' ,
41+ name : 'Img' ,
42+ style : { } ,
43+ placeHolderShort : 'image' ,
44+ placeHolderLong : '' ,
45+ framework : 'reactClassic' ,
46+ nestable : false ,
47+ } ,
48+ ] ;
49+
50+
1451// Mocking the theme
1552const theme = createTheme ( {
1653 spacing : ( value ) => `${ value } px` ,
@@ -36,9 +73,9 @@ jest.mock('file-saver', () => ({
3673// console.error = jest.fn();
3774// });
3875
39- // afterAll(() => {
40- // console.error = originalError ;
41- // });
76+ afterAll ( ( ) => {
77+ jest . resetAllMocks ( ) ;
78+ } ) ;
4279
4380// Mocking the render
4481const renderNavBar = ( store ) => {
@@ -69,6 +106,7 @@ describe('NavBar Component', () => {
69106 ...appStateInitialState ,
70107 isLoggedIn : true ,
71108 name : 'Mock Project Name' ,
109+ HTMLTypes : mockHTMLTypes ,
72110 } ,
73111 } ,
74112 } ) ;
@@ -83,7 +121,7 @@ describe('NavBar Component', () => {
83121 fireEvent . click ( publishButton ) ;
84122 } ) ;
85123
86- xit ( 'handles publish correctly with new project' , async ( ) => {
124+ it ( 'handles publish correctly with new project' , async ( ) => {
87125 const publishProjectMock = jest . spyOn ( projectFunctions , 'publishProject' ) ;
88126 publishProjectMock . mockResolvedValueOnce ( {
89127 _id : 'mockedId' ,
@@ -98,6 +136,7 @@ describe('NavBar Component', () => {
98136 ...appStateInitialState ,
99137 isLoggedIn : true ,
100138 name : '' ,
139+ HTMLTypes : mockHTMLTypes ,
101140 } ,
102141 } ,
103142 } ) ;
@@ -129,7 +168,7 @@ describe('NavBar Component', () => {
129168 } ) ;
130169
131170
132- xit ( 'handles unpublish correctly' , async ( ) => {
171+ it ( 'handles unpublish correctly' , async ( ) => {
133172 const unpublishProjectMock = jest . spyOn ( projectFunctions , 'unpublishProject' ) ;
134173 unpublishProjectMock . mockResolvedValueOnce ( {
135174 _id : 'mockedId' ,
@@ -144,6 +183,7 @@ describe('NavBar Component', () => {
144183 ...appStateInitialState ,
145184 isLoggedIn : true ,
146185 name : 'Mock Project Name' ,
186+ HTMLTypes : mockHTMLTypes ,
147187 } ,
148188 } ,
149189 } ) ;
@@ -165,14 +205,15 @@ describe('NavBar Component', () => {
165205 }
166206 } ) ;
167207
168- xit ( 'handles export correctly' , async ( ) => {
208+ it ( 'handles export correctly' , async ( ) => {
169209 const store = configureStore ( {
170210 reducer : rootReducer ,
171211 preloadedState : {
172212 appState : {
173213 ...appStateInitialState ,
174214 isLoggedIn : true ,
175215 name : 'Mock Project Name' ,
216+ HTMLTypes : mockHTMLTypes ,
176217 } ,
177218 } ,
178219 } ) ;
@@ -187,43 +228,64 @@ describe('NavBar Component', () => {
187228 const exportButton = getByText ( '< > Export' ) ;
188229 fireEvent . click ( exportButton ) ;
189230
190-
231+ // Check if the modal for export options is displayed
191232 await waitFor ( ( ) => {
192233 const exportModal = getByText ( 'Click to download in zip file:' ) ;
193234 expect ( exportModal ) . toBeInTheDocument ( ) ;
194235 } ) ;
195236
196-
237+ // Simulate clicking the export components
197238 const exportComponentsOption = getByText ( 'Export components' ) ;
198239 fireEvent . click ( exportComponentsOption ) ;
199240
200241 } ) ;
201-
202-
203-
204- xit ( 'handles dropdown menu correctly' , ( ) => {
205- const store = configureStore ( {
206- reducer : rootReducer ,
207- preloadedState : {
208- appState : {
209- ...appStateInitialState ,
210- isLoggedIn : true ,
211- name : 'Mock Project Name' ,
242+ test ( 'handles dropdown menu correctly' , async ( ) => {
243+ const store = configureStore ( {
244+ reducer : rootReducer ,
245+ preloadedState : {
246+ appState : {
247+ ...appStateInitialState ,
248+ } ,
212249 } ,
213- } ,
214- } ) ;
215-
216- const { getByTestId } = renderNavBar ( store ) ;
217- const moreVertButton = getByTestId ( 'more-vert-button' ) ;
218-
219-
220- expect ( moreVertButton ) . toBeInTheDocument ( ) ;
221-
222-
223- fireEvent . click ( moreVertButton ) ;
224-
225-
226- } ) ;
227-
250+ } ) ;
228251
229- } ) ;
252+ // Render component
253+ const { getByTestId, getByText } = render (
254+ < Provider store = { store } >
255+ < MemoryRouter >
256+ < ThemeProvider theme = { theme } >
257+ < NavBar />
258+ </ ThemeProvider >
259+ </ MemoryRouter >
260+ </ Provider >
261+ ) ;
262+
263+ // Initially, the dropdown should have the "hideNavDropDown" class
264+ const dropdownMenu = getByTestId ( 'navDropDown' ) ;
265+ expect ( dropdownMenu ) . toHaveClass ( 'hideNavDropDown' ) ;
266+
267+ // Find and click the button to open the dropdown
268+ const moreVertButton = getByTestId ( 'more-vert-button' ) ;
269+ fireEvent . click ( moreVertButton ) ;
270+
271+ // After clicking, the dropdown should have the "navDropDown" class
272+ expect ( dropdownMenu ) . toHaveClass ( 'navDropDown' ) ;
273+
274+
275+ //clear canvas click
276+ const clearCanvasMenuItem = getByText ( 'Clear Canvas' ) ;
277+ fireEvent . click ( clearCanvasMenuItem ) ;
278+ expect ( dropdownMenu ) . toHaveClass ( 'navDropDown' ) ;
279+
280+ // After clicking "Marketplace", it should remain open
281+ const marketplaceMenuItem = getByText ( 'Marketplace' ) ;
282+ fireEvent . click ( marketplaceMenuItem ) ;
283+ expect ( dropdownMenu ) . toHaveClass ( 'navDropDown' ) ;
284+
285+ // Close the dropdown by clicking the button again
286+ fireEvent . click ( moreVertButton ) ;
287+
288+ // After closing, the dropdown should have the "hideNavDropDown" class
289+ expect ( dropdownMenu ) . toHaveClass ( 'hideNavDropDown' ) ;
290+ } ) ;
291+ } ) ;
0 commit comments