1
1
import React from 'react' ;
2
2
import { render , fireEvent , waitFor } from '@testing-library/react' ;
3
+ import '@testing-library/jest-dom/extend-expect' ;
3
4
import { MemoryRouter } from 'react-router-dom' ;
4
5
import { ThemeProvider , createTheme } from '@mui/material/styles' ;
5
6
import NavBar from '../app/src/components/top/NavBar' ;
7
+ import navbarDropDown from '../app/src/components/top/navbarDropDown'
6
8
import * as projectFunctions from '../app/src/helperFunctions/projectGetSaveDel' ;
7
9
import { Provider } from 'react-redux' ;
8
10
import { configureStore } from '@reduxjs/toolkit' ;
@@ -23,14 +25,20 @@ jest.mock('../app/src/helperFunctions/projectGetSaveDel', () => ({
23
25
unpublishProject : jest . fn ( ) ,
24
26
} ) ) ;
25
27
26
- const originalError = console . error ;
27
- beforeAll ( ( ) => {
28
- console . error = jest . fn ( ) ;
29
- } ) ;
28
+ //mock the file saver library
29
+ jest . mock ( 'file-saver' , ( ) => ( {
30
+ ...jest . requireActual ( 'file-saver' ) ,
31
+ saveAs : jest . fn ( ) ,
32
+ } ) ) ;
30
33
31
- afterAll ( ( ) => {
32
- console . error = originalError ;
33
- } ) ;
34
+ // const originalError = console.error;
35
+ // beforeAll(() => {
36
+ // console.error = jest.fn();
37
+ // });
38
+
39
+ // afterAll(() => {
40
+ // console.error = originalError;
41
+ // });
34
42
35
43
// Mocking the render
36
44
const renderNavBar = ( store ) => {
@@ -156,4 +164,66 @@ describe('NavBar Component', () => {
156
164
fireEvent . click ( unpublishButton ) ;
157
165
}
158
166
} ) ;
167
+
168
+ it ( 'handles export correctly' , async ( ) => {
169
+ const store = configureStore ( {
170
+ reducer : rootReducer ,
171
+ preloadedState : {
172
+ appState : {
173
+ ...appStateInitialState ,
174
+ isLoggedIn : true ,
175
+ name : 'Mock Project Name' ,
176
+ } ,
177
+ } ,
178
+ } ) ;
179
+
180
+ console . log ( 'Before rendering NavBar' ) ;
181
+
182
+ const { getByText } = renderNavBar ( store ) ;
183
+
184
+ console . log ( 'After rendering NavBar' ) ;
185
+
186
+ // Find and click the export button
187
+ const exportButton = getByText ( '< > Export' ) ;
188
+ fireEvent . click ( exportButton ) ;
189
+
190
+
191
+ await waitFor ( ( ) => {
192
+ const exportModal = getByText ( 'Click to download in zip file:' ) ;
193
+ expect ( exportModal ) . toBeInTheDocument ( ) ;
194
+ } ) ;
195
+
196
+
197
+ const exportComponentsOption = getByText ( 'Export components' ) ;
198
+ fireEvent . click ( exportComponentsOption ) ;
199
+
200
+ } ) ;
201
+
202
+
203
+
204
+ it ( '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' ,
212
+ } ,
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
+
228
+
159
229
} ) ;
0 commit comments