Skip to content

Commit a66da0f

Browse files
committed
Made additional changes to **/_tests__**
1 parent d2d0de2 commit a66da0f

7 files changed

Lines changed: 129 additions & 139 deletions

File tree

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React from 'react';
21
import { render, fireEvent, screen } from '@testing-library/react';
32
import '@testing-library/jest-dom/extend-expect';
43
import userEvent from '@testing-library/user-event';
5-
import { TaskEditSuggestionRow } from 'components/TaskEditSuggestions/Components/TaskEditSuggestionRow';
4+
import { TaskEditSuggestionRow } from '../TaskEditSuggestionRow';
65

76
// Mock the `datetimeToDate` function
87
jest.mock('components/TeamMemberTasks/components/TaskDifferenceModal', () => ({
@@ -21,43 +20,37 @@ describe('TaskEditSuggestionRow', () => {
2120
jest.clearAllMocks();
2221
});
2322

24-
25-
2623
it('renders the task edit suggestion information', () => {
2724
render(
2825
<TaskEditSuggestionRow
2926
taskEditSuggestion={taskEditSuggestionMock}
3027
handleToggleTaskEditSuggestionModal={mockHandleToggle}
31-
/>
28+
/>,
3229
);
3330

3431
expect(screen.getByText('Mocked Date')).toBeInTheDocument();
3532
expect(screen.getByText(taskEditSuggestionMock.user)).toBeInTheDocument();
3633
expect(screen.getByText(taskEditSuggestionMock.oldTask.taskName)).toBeInTheDocument();
3734
});
3835

39-
40-
4136
it('calls handleToggleTaskEditSuggestionModal with taskEditSuggestion data when the row is clicked', () => {
4237
render(
4338
<TaskEditSuggestionRow
4439
taskEditSuggestion={taskEditSuggestionMock}
4540
handleToggleTaskEditSuggestionModal={mockHandleToggle}
46-
/>
41+
/>,
4742
);
4843

4944
fireEvent.click(screen.getByRole('row'));
5045
expect(mockHandleToggle).toHaveBeenCalledWith(taskEditSuggestionMock);
5146
});
5247

53-
54-
5548
it('calls handleToggleTaskEditSuggestionModal with taskEditSuggestion data when the button is clicked', () => {
5649
render(
5750
<TaskEditSuggestionRow
5851
taskEditSuggestion={taskEditSuggestionMock}
5952
handleToggleTaskEditSuggestionModal={mockHandleToggle}
60-
/>
53+
/>,
6154
);
6255

6356
fireEvent.click(screen.getByText('View Suggestion'));
@@ -66,9 +59,7 @@ describe('TaskEditSuggestionRow', () => {
6659
expect(mockHandleToggle).toHaveBeenCalledTimes(1);
6760
});
6861

69-
7062
it('prevents event propagation when the button is clicked', () => {
71-
7263
const mockParentHandler = jest.fn();
7364

7465
render(
@@ -77,24 +68,22 @@ describe('TaskEditSuggestionRow', () => {
7768
taskEditSuggestion={taskEditSuggestionMock}
7869
handleToggleTaskEditSuggestionModal={mockHandleToggle}
7970
/>
80-
</div>
71+
</div>,
8172
);
8273

8374
const button = screen.getByText('View Suggestion');
8475
userEvent.click(button);
8576

8677
expect(mockParentHandler).not.toHaveBeenCalled();
8778
expect(mockHandleToggle).toHaveBeenCalledWith(taskEditSuggestionMock);
88-
8979
});
9080

91-
9281
it('applies inline styles to the button', () => {
9382
render(
9483
<TaskEditSuggestionRow
9584
taskEditSuggestion={taskEditSuggestionMock}
9685
handleToggleTaskEditSuggestionModal={mockHandleToggle}
97-
/>
86+
/>,
9887
);
9988

10089
const button = screen.getByText('View Suggestion');
@@ -106,14 +95,12 @@ describe('TaskEditSuggestionRow', () => {
10695
});
10796
});
10897

109-
110-
11198
it('updates when taskEditSuggestion prop changes', () => {
11299
const { rerender } = render(
113100
<TaskEditSuggestionRow
114101
taskEditSuggestion={taskEditSuggestionMock}
115102
handleToggleTaskEditSuggestionModal={mockHandleToggle}
116-
/>
103+
/>,
117104
);
118105

119106
const newTaskEditSuggestion = {
@@ -126,10 +113,10 @@ describe('TaskEditSuggestionRow', () => {
126113
<TaskEditSuggestionRow
127114
taskEditSuggestion={newTaskEditSuggestion}
128115
handleToggleTaskEditSuggestionModal={mockHandleToggle}
129-
/>
116+
/>,
130117
);
131118

132119
expect(screen.getByText('new-user')).toBeInTheDocument();
133120
expect(screen.getByText('New Task')).toBeInTheDocument();
134121
});
135-
});
122+
});

src/components/TaskEditSuggestions/Components/__tests__/TaskEditSuggestionsModal.test.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import React from 'react';
2-
import { TaskEditSuggestionsModal } from 'components/TaskEditSuggestions/Components/TaskEditSuggestionsModal';
1+
/* eslint-disable react/jsx-props-no-spreading */
32
import * as reduxHooks from 'react-redux';
4-
import { waitFor, render, fireEvent, screen } from '@testing-library/react';
5-
import { act } from 'react-dom/test-utils';
3+
import { render, screen } from '@testing-library/react';
4+
import { TaskEditSuggestionsModal } from '../TaskEditSuggestionsModal';
65

76
jest.mock('react-redux', () => ({
87
useDispatch: jest.fn(),
98
useSelector: jest.fn(),
109
useStore: jest.fn(),
1110
}));
1211

13-
1412
const mockDispatch = jest.fn();
1513
const mockGetState = jest.fn();
1614
const mockToggleModal = jest.fn();
@@ -24,7 +22,6 @@ beforeEach(() => {
2422
jest.clearAllMocks();
2523
reduxHooks.useDispatch.mockReturnValue(mockDispatch);
2624
reduxHooks.useStore.mockReturnValue({ getState: mockGetState });
27-
2825
});
2926

3027
describe('TaskEditSuggestionsModal Rendering', () => {
@@ -43,7 +40,7 @@ describe('TaskEditSuggestionsModal Rendering', () => {
4340
const taskEditSuggestion = {
4441
user: 'John Doe',
4542
oldTask: {
46-
taskName: 'Old Task Name',
43+
taskName: 'Old Task Name',
4744
},
4845
newTask: {
4946
taskName: 'New Task Name',
@@ -52,16 +49,12 @@ describe('TaskEditSuggestionsModal Rendering', () => {
5249
const props = { ...defaultProps, taskEditSuggestion, isTaskEditSuggestionsModalOpen: true };
5350
const { queryByText } = render(<TaskEditSuggestionsModal {...props} />);
5451
expect(queryByText(/John Doe/i)).not.toBeInTheDocument();
55-
5652
});
5753
});
5854

59-
60-
6155
describe('TaskEditSuggestionsModal Redux Integration', () => {
6256
it('uses useDispatch hook', () => {
6357
render(<TaskEditSuggestionsModal {...defaultProps} />);
6458
expect(reduxHooks.useDispatch).toHaveBeenCalled();
6559
});
66-
6760
});

src/components/TaskEditSuggestions/__tests__/TaskEditSuggestions.test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import React from 'react';
21
import { render, fireEvent, screen } from '@testing-library/react';
32
import * as reduxHooks from 'react-redux';
43
import configureStore from 'redux-mock-store';
54
import { Provider } from 'react-redux';
65
import { waitFor } from '@testing-library/react';
7-
import { themeMock } from '__tests__/mockStates';
6+
import { themeMock } from '../../../__tests__/mockStates';
87
import { toggleDateSuggestedSortDirection, toggleUserSortDirection } from '../actions';
98
import TaskEditSuggestions from '../TaskEditSuggestions';
109

@@ -151,8 +150,6 @@ describe('TaskEditSuggestions loading', () => {
151150
});
152151
testStore.dispatch({ type: 'FETCH_TASK_EDIT_SUGGESTIONS_BEGIN' });
153152

154-
const state = testStore.getState();
155-
156153
render(
157154
<Provider store={testStore}>
158155
<TaskEditSuggestions />

src/components/TaskEditSuggestions/__tests__/actions.test.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import configureMockStore from 'redux-mock-store';
2-
import thunk from 'redux-thunk';
31
import {
42
fetchTaskEditSuggestionsBegin,
53
fetchTaskEditSuggestionsSuccess,
@@ -8,10 +6,7 @@ import {
86
toggleDateSuggestedSortDirection,
97
toggleUserSortDirection,
108
fetchTaskEditSuggestionCountSuccess,
11-
} from '../actions';
12-
13-
const middlewares = [thunk];
14-
const mockStore = configureMockStore(middlewares);
9+
} from '../actions';
1510

1611
describe('Redux Actions', () => {
1712
it('should create an action to begin fetching task edit suggestions', () => {
@@ -20,7 +15,9 @@ describe('Redux Actions', () => {
2015
});
2116

2217
it('should create an action for successful task edit suggestions fetching', () => {
23-
const data = { /* your data here */ };
18+
const data = {
19+
/* your data here */
20+
};
2421
const expectedAction = { type: 'FETCH_TASK_EDIT_SUGGESTIONS_SUCESS', payload: data };
2522
expect(fetchTaskEditSuggestionsSuccess(data)).toEqual(expectedAction);
2623
});
@@ -62,4 +59,4 @@ describe('Redux Actions', () => {
6259
};
6360
expect(fetchTaskEditSuggestionCountSuccess(count)).toEqual(expectedAction);
6461
});
65-
});
62+
});

0 commit comments

Comments
 (0)