generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added test case and refactored code * Changed name of variables * Made not needed test skip * Added test for tasks status drop down * Removed test cases * Removed extra file * Add test file * Removed not needed test case --------- Co-authored-by: Shubham Sharma <[email protected]>
- Loading branch information
1 parent
a00373b
commit 8eff409
Showing
10 changed files
with
467 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import TaskDropDown from '@/components/tasks/TaskDropDown'; | ||
import TaskDropDownModel from '@/components/tasks/TaskDropDownModel'; | ||
import { MSG_ON_0_PROGRESS, MSG_ON_100_PROGRESS } from '@/constants/constants'; | ||
import { BACKEND_TASK_STATUS } from '@/constants/task-status'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
|
||
const onChange = jest.fn(); | ||
|
||
describe('TaskDropDown', () => { | ||
beforeEach(() => { | ||
onChange.mockReset(); | ||
}); | ||
it('should display model informing user that proceeding further will make progress 100%, on task status change from in progress to needs review', () => { | ||
const oldProgress = 80; | ||
const oldStatus = BACKEND_TASK_STATUS.IN_PROGRESS; | ||
|
||
render( | ||
<TaskDropDown | ||
isDevMode={true} | ||
oldProgress={oldProgress} | ||
oldStatus={oldStatus} | ||
onChange={onChange} | ||
/> | ||
); | ||
|
||
const msg = `The progress of current task is ${oldProgress}%. ${MSG_ON_100_PROGRESS}`; | ||
fireEvent.change(screen.getByTestId('task-status'), { | ||
target: { value: BACKEND_TASK_STATUS.NEEDS_REVIEW }, | ||
}); | ||
|
||
const msgTag = screen.getByTestId('msg'); | ||
expect(msgTag).toBeInTheDocument(); | ||
expect(msgTag).toHaveTextContent(msg); | ||
}); | ||
it('should display model informing user that proceeding further will make progress 0%, on task status change from needs review to in progress', () => { | ||
const oldProgress = 100; | ||
const oldStatus = BACKEND_TASK_STATUS.NEEDS_REVIEW; | ||
|
||
render( | ||
<TaskDropDown | ||
isDevMode={true} | ||
oldProgress={oldProgress} | ||
oldStatus={oldStatus} | ||
onChange={onChange} | ||
/> | ||
); | ||
|
||
const msg = `The progress of current task is ${oldProgress}%. ${MSG_ON_0_PROGRESS}`; | ||
fireEvent.change(screen.getByTestId('task-status'), { | ||
target: { value: BACKEND_TASK_STATUS.IN_PROGRESS }, | ||
}); | ||
|
||
const msgTag = screen.getByTestId('msg'); | ||
expect(msgTag).toBeInTheDocument(); | ||
expect(msgTag).toHaveTextContent(msg); | ||
}); | ||
it('should send changed status and progress if user click the proceed button of the model, on task status change from needs review to in progress', () => { | ||
const oldProgress = 100; | ||
const oldStatus = BACKEND_TASK_STATUS.NEEDS_REVIEW; | ||
|
||
render( | ||
<TaskDropDown | ||
isDevMode={true} | ||
oldProgress={oldProgress} | ||
oldStatus={oldStatus} | ||
onChange={onChange} | ||
/> | ||
); | ||
|
||
fireEvent.change(screen.getByTestId('task-status'), { | ||
target: { value: BACKEND_TASK_STATUS.IN_PROGRESS }, | ||
}); | ||
fireEvent.click(screen.getByTestId('proceed')); | ||
expect(onChange).toHaveBeenCalledWith({ | ||
newStatus: BACKEND_TASK_STATUS.IN_PROGRESS, | ||
newProgress: 0, | ||
}); | ||
expect(onChange).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should send reset status and progress if user click the cancel button of the model, on task status change from needs review to in progress', () => { | ||
const oldProgress = 100; | ||
const oldStatus = BACKEND_TASK_STATUS.NEEDS_REVIEW; | ||
|
||
render( | ||
<TaskDropDown | ||
isDevMode={true} | ||
oldProgress={oldProgress} | ||
oldStatus={oldStatus} | ||
onChange={onChange} | ||
/> | ||
); | ||
|
||
fireEvent.change(screen.getByTestId('task-status'), { | ||
target: { value: BACKEND_TASK_STATUS.IN_PROGRESS }, | ||
}); | ||
fireEvent.click(screen.getByTestId('cancel')); | ||
expect(onChange).toHaveBeenCalledTimes(0); | ||
expect(screen.getByTestId('task-status')).toHaveValue(oldStatus); | ||
}); | ||
it('should not show any model info on change of status from in progress to backlog', () => { | ||
const oldProgress = 80; | ||
const oldStatus = BACKEND_TASK_STATUS.IN_PROGRESS; | ||
|
||
render( | ||
<TaskDropDown | ||
isDevMode={true} | ||
oldProgress={oldProgress} | ||
oldStatus={oldStatus} | ||
onChange={onChange} | ||
/> | ||
); | ||
|
||
fireEvent.change(screen.getByTestId('task-status'), { | ||
target: { value: BACKEND_TASK_STATUS.BACKLOG }, | ||
}); | ||
expect(onChange).toHaveBeenCalledTimes(1); | ||
expect(onChange).toHaveBeenCalledWith({ | ||
newStatus: BACKEND_TASK_STATUS.BACKLOG, | ||
}); | ||
const msgTag = screen.queryByTestId('msg'); | ||
expect(msgTag).toBeNull(); | ||
}); | ||
it('should not show any model info on change of status from in progress to blocked', () => { | ||
const oldProgress = 70; | ||
const oldStatus = BACKEND_TASK_STATUS.IN_PROGRESS; | ||
|
||
render( | ||
<TaskDropDown | ||
isDevMode={true} | ||
oldProgress={oldProgress} | ||
oldStatus={oldStatus} | ||
onChange={onChange} | ||
/> | ||
); | ||
|
||
fireEvent.change(screen.getByTestId('task-status'), { | ||
target: { value: BACKEND_TASK_STATUS.BLOCKED }, | ||
}); | ||
expect(onChange).toHaveBeenCalledTimes(1); | ||
expect(onChange).toHaveBeenCalledWith({ | ||
newStatus: BACKEND_TASK_STATUS.BLOCKED, | ||
}); | ||
const msgTag = screen.queryByTestId('msg'); | ||
expect(msgTag).toBeNull(); | ||
}); | ||
describe('TaskDropDownModel', () => { | ||
const handleProceed = jest.fn(); | ||
const resetProgressAndStatus = jest.fn(); | ||
it('should render message sent to it', () => { | ||
const msg = 'This is random msg'; | ||
render( | ||
<TaskDropDownModel | ||
message={msg} | ||
handleProceed={handleProceed} | ||
resetProgressAndStatus={resetProgressAndStatus} | ||
/> | ||
); | ||
const msgTag = screen.queryByTestId('msg'); | ||
expect(msgTag).toHaveTextContent(msg); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.