generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes date picker alignment and date value not showing up while editi…
…ng on task details page (#1260) * fix: date picker alignment and prefilled * fix: test cases for dates and details * update: test files * refactor: detail content component * fix: useEffect to be conditional * Improved test coverage for taskDates * revert back to original change * fix: edge case of invalid date * fix: redundancy in detailsContent * added more restriction to date validation * fix: test case for invalid-date * fix: test case with await * updated test case for failure onsave * refactor: detailsContent * update test case for isValidDate utils * updated feature flag * fix: test case name --------- Co-authored-by: Achintya Chatterjee <[email protected]> Co-authored-by: Yash Raj <[email protected]>
- Loading branch information
1 parent
4476ba9
commit b2743f2
Showing
12 changed files
with
500 additions
and
118 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 |
---|---|---|
@@ -1,28 +1,176 @@ | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { screen, fireEvent } from '@testing-library/react'; | ||
import { TaskDates } from '@/components/taskDetails/TaskDates'; | ||
import { store } from '@/app/store'; | ||
import { renderWithRouter } from '@/test_utils/createMockRouter'; | ||
|
||
const mockSetNewEndOnDate = jest.fn(); | ||
const mockHandleBlurOfEndsOn = jest.fn(); | ||
jest.mock('@/hooks/useUserData', () => { | ||
return () => ({ | ||
data: { | ||
roles: { | ||
admin: true, | ||
super_user: false, | ||
}, | ||
}, | ||
isUserAuthorized: true, | ||
isSuccess: true, | ||
}); | ||
}); | ||
|
||
const mockHandleEditedTaskDetails = jest.fn(); | ||
|
||
describe('TaskDates Component', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render input field for End On date when in editing mode', () => { | ||
render( | ||
<TaskDates | ||
isEditing={true} | ||
isUserAuthorized={true} | ||
startedOn="2024-03-30T11:20:00Z" | ||
endsOn={1700000000} | ||
newEndOnDate="2024-03-30" | ||
setNewEndOnDate={mockSetNewEndOnDate} | ||
handleBlurOfEndsOn={mockHandleBlurOfEndsOn} | ||
isExtensionRequestPending={false} | ||
taskId="1" | ||
/> | ||
renderWithRouter( | ||
<Provider store={store()}> | ||
<TaskDates | ||
isEditing={true} | ||
startedOn="2024-03-30T11:20:00Z" | ||
endsOn={1700000000} | ||
setEditedTaskDetails={mockHandleEditedTaskDetails} | ||
isExtensionRequestPending={false} | ||
taskId="1" | ||
/> | ||
</Provider> | ||
); | ||
|
||
const input = screen.getByTestId( | ||
'endsOnTaskDetails' | ||
) as HTMLInputElement; | ||
fireEvent.change(input, { target: { value: '2024-04-15' } }); | ||
fireEvent.blur(input); | ||
expect(input.value).toBe('2024-04-15'); | ||
}); | ||
|
||
it('should not render input field for End On date when not in editing mode', () => { | ||
renderWithRouter( | ||
<Provider store={store()}> | ||
<TaskDates | ||
isEditing={false} | ||
startedOn="2024-03-30T11:20:00Z" | ||
endsOn={1700000000} | ||
setEditedTaskDetails={mockHandleEditedTaskDetails} | ||
isExtensionRequestPending={false} | ||
taskId="1" | ||
/> | ||
</Provider> | ||
); | ||
|
||
const input = screen.queryByTestId('endsOnTaskDetails'); | ||
expect(input).toBeNull(); | ||
}); | ||
|
||
it('should display an extension icon, when isExtensionRequestPending is true', () => { | ||
renderWithRouter( | ||
<Provider store={store()}> | ||
<TaskDates | ||
isEditing={true} | ||
startedOn="2024-03-30T11:20:00Z" | ||
endsOn={1700000000} | ||
setEditedTaskDetails={mockHandleEditedTaskDetails} | ||
isExtensionRequestPending={true} | ||
taskId="1" | ||
/> | ||
</Provider> | ||
); | ||
|
||
const extensionIcon = screen.getByTestId('extension-request-icon'); | ||
expect(extensionIcon).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not update the input value if invalid date is entered', () => { | ||
renderWithRouter( | ||
<Provider store={store()}> | ||
<TaskDates | ||
isEditing={true} | ||
startedOn="2024-03-30T11:20:00Z" | ||
endsOn={null} | ||
setEditedTaskDetails={mockHandleEditedTaskDetails} | ||
isExtensionRequestPending={false} | ||
taskId="1" | ||
/> | ||
</Provider> | ||
); | ||
|
||
const input = screen.getByTestId( | ||
'endsOnTaskDetails' | ||
) as HTMLInputElement; | ||
fireEvent.change(input, { target: { value: 'invalid-date' } }); | ||
fireEvent.blur(input); | ||
expect(input.value).toBe(''); | ||
}); | ||
|
||
it('should render input element correctly with admin role', () => { | ||
renderWithRouter( | ||
<Provider store={store()}> | ||
<TaskDates | ||
isEditing={true} | ||
startedOn="2024-03-30T11:20:00Z" | ||
endsOn={1700000000} | ||
setEditedTaskDetails={mockHandleEditedTaskDetails} | ||
isExtensionRequestPending={false} | ||
taskId="1" | ||
/> | ||
</Provider> | ||
); | ||
|
||
const input = screen.getByTestId('endsOnTaskDetails'); | ||
expect(input).toBeInTheDocument(); | ||
fireEvent.blur(input); | ||
expect(mockHandleBlurOfEndsOn).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should render input element correctly with non-admin role', () => { | ||
jest.mock('@/hooks/useUserData', () => { | ||
return () => ({ | ||
data: { | ||
roles: { | ||
admin: false, | ||
super_user: true, | ||
}, | ||
}, | ||
isUserAuthorized: true, | ||
isSuccess: true, | ||
}); | ||
}); | ||
|
||
renderWithRouter( | ||
<Provider store={store()}> | ||
<TaskDates | ||
isEditing={true} | ||
startedOn="2024-03-30T11:20:00Z" | ||
endsOn={1700000000} | ||
setEditedTaskDetails={mockHandleEditedTaskDetails} | ||
isExtensionRequestPending={false} | ||
taskId="1" | ||
/> | ||
</Provider> | ||
); | ||
|
||
const input = screen.getByTestId('endsOnTaskDetails'); | ||
expect(input).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the correct date when endsOn is null', () => { | ||
renderWithRouter( | ||
<Provider store={store()}> | ||
<TaskDates | ||
isEditing={true} | ||
startedOn="2024-03-30T11:20:00Z" | ||
endsOn={null} | ||
setEditedTaskDetails={mockHandleEditedTaskDetails} | ||
isExtensionRequestPending={false} | ||
taskId="1" | ||
/> | ||
</Provider> | ||
); | ||
|
||
const input = screen.getByTestId( | ||
'endsOnTaskDetails' | ||
) as HTMLInputElement; | ||
expect(input.value).toBe(''); | ||
}); | ||
}); |
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.