Skip to content

Commit ca152ce

Browse files
authored
Merge pull request #1348 from Real-Dev-Squad/develop
Dev to Main Sync
2 parents a4160f4 + e262dad commit ca152ce

File tree

9 files changed

+385
-158
lines changed

9 files changed

+385
-158
lines changed

__tests__/Unit/Components/Tasks/TaskDetails.test.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -246,21 +246,6 @@ describe('TaskDetails Page', () => {
246246
).toBeGreaterThanOrEqual(1)
247247
);
248248
});
249-
it('Renders Task status Done as selected when task status is Completed, when dev flag is on in edit mode', async () => {
250-
renderWithRouter(
251-
<Provider store={store()}>
252-
<TaskDetails taskID={details.completedTaskID} />
253-
</Provider>
254-
);
255-
await waitFor(() => {
256-
const editButton = screen.getByRole('button', { name: 'Edit' });
257-
fireEvent.click(editButton);
258-
});
259-
const option: HTMLOptionElement = screen.getByTestId(
260-
'task-status-DONE'
261-
) as HTMLOptionElement;
262-
expect(option.selected).toBeTruthy();
263-
});
264249
});
265250
it('Renders Task Ends-on Date', async () => {
266251
renderWithRouter(

__tests__/Unit/Components/Tasks/TaskDropDown.test.tsx renamed to __tests__/Unit/Components/Tasks/TaskStatusDropdown.test.tsx

Lines changed: 116 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
import TaskDropDown from '@/components/tasks/TaskDropDown';
1+
import { TaskStatusDropdown } from '@/components/tasks/TaskStatusDropdown';
22
import TaskDropDownModel from '@/components/tasks/TaskDropDownModel';
33
import { MSG_ON_0_PROGRESS, MSG_ON_100_PROGRESS } from '@/constants/constants';
44
import { BACKEND_TASK_STATUS } from '@/constants/task-status';
55
import { fireEvent, render, screen } from '@testing-library/react';
66

7+
jest.mock('@/hooks/useUserData', () => ({
8+
__esModule: true,
9+
default: () => ({
10+
data: { roles: { super_user: true } },
11+
isSuccess: true,
12+
isLoading: false,
13+
}),
14+
}));
15+
716
const onChange = jest.fn();
817

9-
describe('TaskDropDown', () => {
18+
describe('TaskStatusDropdown', () => {
1019
beforeEach(() => {
1120
onChange.mockReset();
1221
});
@@ -15,7 +24,7 @@ describe('TaskDropDown', () => {
1524
const oldStatus = BACKEND_TASK_STATUS.IN_PROGRESS;
1625

1726
render(
18-
<TaskDropDown
27+
<TaskStatusDropdown
1928
isDevMode={true}
2029
oldProgress={oldProgress}
2130
oldStatus={oldStatus}
@@ -37,7 +46,7 @@ describe('TaskDropDown', () => {
3746
const oldStatus = BACKEND_TASK_STATUS.NEEDS_REVIEW;
3847

3948
render(
40-
<TaskDropDown
49+
<TaskStatusDropdown
4150
isDevMode={true}
4251
oldProgress={oldProgress}
4352
oldStatus={oldStatus}
@@ -59,7 +68,7 @@ describe('TaskDropDown', () => {
5968
const oldStatus = BACKEND_TASK_STATUS.NEEDS_REVIEW;
6069

6170
render(
62-
<TaskDropDown
71+
<TaskStatusDropdown
6372
isDevMode={true}
6473
oldProgress={oldProgress}
6574
oldStatus={oldStatus}
@@ -82,7 +91,7 @@ describe('TaskDropDown', () => {
8291
const oldStatus = BACKEND_TASK_STATUS.NEEDS_REVIEW;
8392

8493
render(
85-
<TaskDropDown
94+
<TaskStatusDropdown
8695
isDevMode={true}
8796
oldProgress={oldProgress}
8897
oldStatus={oldStatus}
@@ -97,35 +106,13 @@ describe('TaskDropDown', () => {
97106
expect(onChange).toHaveBeenCalledTimes(0);
98107
expect(screen.getByTestId('task-status')).toHaveValue(oldStatus);
99108
});
100-
it('should not show any model info on change of status from in progress to backlog', () => {
101-
const oldProgress = 80;
102-
const oldStatus = BACKEND_TASK_STATUS.IN_PROGRESS;
103109

104-
render(
105-
<TaskDropDown
106-
isDevMode={true}
107-
oldProgress={oldProgress}
108-
oldStatus={oldStatus}
109-
onChange={onChange}
110-
/>
111-
);
112-
113-
fireEvent.change(screen.getByTestId('task-status'), {
114-
target: { value: BACKEND_TASK_STATUS.BACKLOG },
115-
});
116-
expect(onChange).toHaveBeenCalledTimes(1);
117-
expect(onChange).toHaveBeenCalledWith({
118-
newStatus: BACKEND_TASK_STATUS.BACKLOG,
119-
});
120-
const msgTag = screen.queryByTestId('msg');
121-
expect(msgTag).toBeNull();
122-
});
123110
it('should show text Done as selected option when a task with completed status is passed down.', () => {
124111
const oldProgress = 100;
125112
const oldStatus = BACKEND_TASK_STATUS.DONE;
126113

127114
render(
128-
<TaskDropDown
115+
<TaskStatusDropdown
129116
oldProgress={oldProgress}
130117
oldStatus={oldStatus}
131118
onChange={onChange}
@@ -136,13 +123,12 @@ describe('TaskDropDown', () => {
136123
) as HTMLOptionElement;
137124
expect(option.selected).toBeTruthy();
138125
});
139-
140126
it('should not show any model info on change of status from in progress to blocked', () => {
141127
const oldProgress = 70;
142128
const oldStatus = BACKEND_TASK_STATUS.IN_PROGRESS;
143129

144130
render(
145-
<TaskDropDown
131+
<TaskStatusDropdown
146132
isDevMode={true}
147133
oldProgress={oldProgress}
148134
oldStatus={oldStatus}
@@ -176,4 +162,103 @@ describe('TaskDropDown', () => {
176162
expect(msgTag).toHaveTextContent(msg);
177163
});
178164
});
165+
describe('Task Status Dropdown Rendering in DevMode', () => {
166+
it('should renders TaskStatusDropdown with correct classes', () => {
167+
render(
168+
<TaskStatusDropdown
169+
isDevMode={true}
170+
oldProgress={0}
171+
oldStatus={BACKEND_TASK_STATUS.IN_PROGRESS}
172+
onChange={onChange}
173+
/>
174+
);
175+
176+
const label = screen.getByTestId('task-status-label');
177+
expect(label).toHaveClass('cardPurposeAndStatusFont');
178+
179+
const select = screen.getByTestId('task-status');
180+
expect(select).toHaveClass('taskStatusUpdate');
181+
});
182+
183+
it('should update state and call onChange when selecting a status', () => {
184+
const onChange = jest.fn();
185+
186+
const { getByTestId } = render(
187+
<TaskStatusDropdown
188+
oldStatus={BACKEND_TASK_STATUS.UN_ASSIGNED}
189+
oldProgress={0}
190+
onChange={onChange}
191+
/>
192+
);
193+
194+
const statusSelect = getByTestId('task-status');
195+
196+
fireEvent.change(statusSelect, {
197+
target: { value: BACKEND_TASK_STATUS.NEEDS_REVIEW },
198+
});
199+
200+
expect(statusSelect).toHaveValue(BACKEND_TASK_STATUS.NEEDS_REVIEW);
201+
expect(onChange).toHaveBeenCalledWith({
202+
newStatus: BACKEND_TASK_STATUS.NEEDS_REVIEW,
203+
});
204+
});
205+
206+
it('should show the current status as selected', () => {
207+
const currentStatus = BACKEND_TASK_STATUS.BLOCKED;
208+
209+
render(
210+
<TaskStatusDropdown
211+
isDevMode={true}
212+
oldProgress={0}
213+
oldStatus={currentStatus}
214+
onChange={onChange}
215+
/>
216+
);
217+
218+
const select = screen.getByTestId('task-status');
219+
expect(select).toHaveValue(currentStatus);
220+
});
221+
});
222+
223+
describe('Task Status Dropdown Rendering in non-DevMode', () => {
224+
it('should not render TaskStatusDropdown', () => {
225+
render(
226+
<TaskStatusDropdown
227+
isDevMode={false}
228+
oldProgress={0}
229+
oldStatus={BACKEND_TASK_STATUS.IN_PROGRESS}
230+
onChange={onChange}
231+
/>
232+
);
233+
234+
const label = screen.getByText('Status:');
235+
expect(label).toBeInTheDocument();
236+
237+
expect(label).not.toHaveClass('cardPurposeAndStatusFont');
238+
239+
const select = screen.getByTestId('task-status');
240+
expect(select).toHaveClass('taskStatusUpdate');
241+
});
242+
});
243+
244+
describe('Status Change Handling', () => {
245+
it('should not call onChange when selected status is the same as current status', () => {
246+
const currentStatus = BACKEND_TASK_STATUS.IN_PROGRESS;
247+
248+
render(
249+
<TaskStatusDropdown
250+
isDevMode={true}
251+
oldProgress={0}
252+
oldStatus={currentStatus}
253+
onChange={onChange}
254+
/>
255+
);
256+
257+
fireEvent.change(screen.getByTestId('task-status'), {
258+
target: { value: currentStatus },
259+
});
260+
261+
expect(onChange).not.toHaveBeenCalled();
262+
});
263+
});
179264
});

0 commit comments

Comments
 (0)