Skip to content

Commit 2d0e249

Browse files
authored
Merge pull request #47 from oslabs-beta/Ahnafkhvn/testing2
Ahnafkhvn/testing2
2 parents cbcac1f + 276ad2e commit 2d0e249

File tree

2 files changed

+61
-58
lines changed

2 files changed

+61
-58
lines changed

__tests__/NavBar.test.tsx

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import '@testing-library/jest-dom/extend-expect';
44
import { MemoryRouter } from 'react-router-dom';
55
import { ThemeProvider, createTheme } from '@mui/material/styles';
66
import NavBar from '../app/src/components/top/NavBar';
7-
import navBarButtons from '../app/src/components/top/NavBarButtons';
87
import * as projectFunctions from '../app/src/helperFunctions/projectGetSaveDel';
98
import { Provider } from 'react-redux';
9+
import { act } from 'react-dom/test-utils';
1010
import { configureStore } from '@reduxjs/toolkit';
1111
import rootReducer from '../app/src/redux/reducers/rootReducer';
1212
import { initialState as appStateInitialState } from '../app/src/redux/reducers/slice/appStateSlice';
1313

14-
15-
1614
// Mock the non-serializable HTMLTypes
1715
const mockHTMLTypes = [
1816
{
@@ -47,7 +45,6 @@ const mockHTMLTypes = [
4745
},
4846
];
4947

50-
5148
// Mocking the theme
5249
const theme = createTheme({
5350
spacing: (value) => `${value}px`,
@@ -117,8 +114,10 @@ describe('NavBar Component', () => {
117114

118115
console.log('After rendering NavBar');
119116

120-
const publishButton = getByText('Publish');
121-
fireEvent.click(publishButton);
117+
await act(async () => {
118+
const publishButton = getByText('Publish');
119+
fireEvent.click(publishButton);
120+
});
122121
});
123122

124123
it('handles publish correctly with new project', async () => {
@@ -147,26 +146,27 @@ describe('NavBar Component', () => {
147146

148147
console.log('After rendering NavBar');
149148

150-
// Check if the "Publish" button is present
151-
const publishButton = queryByText('Publish');
149+
await act(async () => {
150+
// Check if the "Publish" button is present
151+
const publishButton = queryByText('Publish');
152152

153-
if (publishButton) {
154-
fireEvent.click(publishButton);
155-
} else {
156-
// If "Publish" button is not found, look for the "Unpublish" button
157-
const unpublishButton = getByText('Unpublish');
158-
fireEvent.click(unpublishButton);
159-
}
153+
if (publishButton) {
154+
fireEvent.click(publishButton);
155+
} else {
156+
// If "Publish" button is not found, look for the "Unpublish" button
157+
const unpublishButton = getByText('Unpublish');
158+
fireEvent.click(unpublishButton);
159+
}
160160

161-
// Check if the modal for a new project is displayed
162-
const projectNameInput = queryByTestId('project-name-input');
161+
// Check if the modal for a new project is displayed
162+
const projectNameInput = queryByTestId('project-name-input');
163163

164-
if (projectNameInput) {
165-
// entering a project name in the modal
166-
fireEvent.change(projectNameInput, { target: { value: 'My Project' } });
167-
}
164+
if (projectNameInput) {
165+
// entering a project name in the modal
166+
fireEvent.change(projectNameInput, { target: { value: 'My Project' } });
167+
}
168168
});
169-
169+
});
170170

171171
it('handles unpublish correctly', async () => {
172172
const unpublishProjectMock = jest.spyOn(projectFunctions, 'unpublishProject');
@@ -239,7 +239,8 @@ describe('NavBar Component', () => {
239239
fireEvent.click(exportComponentsOption);
240240

241241
});
242-
test('handles dropdown menu correctly', async () => {
242+
243+
it('handles dropdown menu correctly', async () => {
243244
const store = configureStore({
244245
reducer: rootReducer,
245246
preloadedState: {
@@ -248,8 +249,9 @@ describe('NavBar Component', () => {
248249
},
249250
},
250251
});
251-
252-
// Render component
252+
253+
console.log('Before rendering NavBar');
254+
253255
const { getByTestId, getByText } = render(
254256
<Provider store={store}>
255257
<MemoryRouter>
@@ -259,33 +261,34 @@ describe('NavBar Component', () => {
259261
</MemoryRouter>
260262
</Provider>
261263
);
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');
264+
265+
console.log('After rendering NavBar');
266+
267+
await act(async () => {
268+
269+
const dropdownMenu = getByTestId('navDropDown');
270+
expect(dropdownMenu).toHaveClass('hideNavDropDown');
271+
272+
273+
const moreVertButton = getByTestId('more-vert-button');
274+
fireEvent.click(moreVertButton);
275+
276+
277+
expect(dropdownMenu).toHaveClass('hideNavDropDown');
278+
279+
280+
const clearCanvasMenuItem = getByText('Clear Canvas');
281+
fireEvent.click(clearCanvasMenuItem);
282+
expect(dropdownMenu).toHaveClass('hideNavDropDown');
283+
284+
285+
const marketplaceMenuItem = getByText('Marketplace');
286+
fireEvent.click(marketplaceMenuItem);
287+
expect(dropdownMenu).toHaveClass('hideNavDropDown');
288+
289+
fireEvent.click(moreVertButton);
290+
291+
expect(dropdownMenu).toHaveClass('hideNavDropDown');
292+
});
290293
});
291-
});
294+
})

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"main": "app/electron/main.js",
77
"author": "OS Labs",
88
"contributors": [
9-
"Victor Martins",
10-
"Liam Roh",
11-
"Denton Wong",
12-
"Ahnaf Khan",
9+
"Victor Martins",
10+
"Liam Roh",
11+
"Denton Wong",
12+
"Ahnaf Khan",
1313
"Hernan Damazo",
1414
"Adam Vanek",
1515
"Matteo Diterlizzi",

0 commit comments

Comments
 (0)