-
Notifications
You must be signed in to change notification settings - Fork 74
test(Tasks): Add Recur, Priority, and Reports toggle tests #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ShivaGupta-14
wants to merge
1
commit into
CCExtractor:main
Choose a base branch
from
ShivaGupta-14:test/300-tasks-recur-priority-reports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -58,10 +58,10 @@ jest.mock('@/components/ui/multi-select', () => ({ | |
|
|
||
| jest.mock('@/components/ui/select', () => { | ||
| return { | ||
| Select: ({ children, onValueChange, value }: any) => { | ||
| Select: ({ children, onValueChange, value, ...props }: any) => { | ||
| return ( | ||
| <select | ||
| data-testid="project-select" | ||
| {...props} | ||
| value={value} | ||
| onChange={(e) => onValueChange?.(e.target.value)} | ||
| > | ||
|
|
@@ -182,6 +182,12 @@ jest.mock('../TaskSkeleton', () => { | |
|
|
||
| global.fetch = jest.fn().mockResolvedValue({ ok: true }); | ||
|
|
||
| global.ResizeObserver = class ResizeObserver { | ||
its-me-abhishek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| observe() {} | ||
| unobserve() {} | ||
| disconnect() {} | ||
| }; | ||
|
|
||
| describe('Tasks Component', () => { | ||
| const localStorageMock = (() => { | ||
| let store: { [key: string]: string } = {}; | ||
|
|
@@ -1229,7 +1235,7 @@ describe('Tasks Component', () => { | |
| const editButton = within(priorityRow).getByLabelText('edit'); | ||
| fireEvent.click(editButton); | ||
|
|
||
| const select = within(priorityRow).getByTestId('project-select'); | ||
| const select = within(priorityRow).getByTestId('priority-select'); | ||
| fireEvent.change(select, { target: { value: 'H' } }); | ||
|
|
||
| const saveButton = screen.getByLabelText('save'); | ||
|
|
@@ -1339,7 +1345,7 @@ describe('Tasks Component', () => { | |
| const editButton = within(recurRow).getByLabelText('edit'); | ||
| fireEvent.click(editButton); | ||
|
|
||
| const select = within(recurRow).getByTestId('project-select'); | ||
| const select = within(recurRow).getByTestId('recur-select'); | ||
| fireEvent.change(select, { target: { value: 'weekly' } }); | ||
|
|
||
| const saveButton = screen.getByLabelText('save'); | ||
|
|
@@ -1737,4 +1743,211 @@ describe('Tasks Component', () => { | |
| expect(task1Row).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Recur Editing', () => { | ||
| test('does not save when recur is set to "none"', async () => { | ||
| render(<Tasks {...mockProps} />); | ||
|
|
||
| await screen.findByText('Task 12'); | ||
| fireEvent.click(screen.getByText('Task 12')); | ||
|
|
||
| expect(await screen.findByText('Recur:')).toBeInTheDocument(); | ||
|
|
||
| const recurLabel = screen.getByText('Recur:'); | ||
| const recurRow = recurLabel.closest('tr') as HTMLElement; | ||
| const editButton = within(recurRow).getByLabelText('edit'); | ||
|
|
||
| fireEvent.click(editButton); | ||
|
|
||
| const select = within(recurRow).getByTestId('recur-select'); | ||
| fireEvent.change(select, { target: { value: 'none' } }); | ||
|
|
||
| const saveButton = screen.getByLabelText('save'); | ||
| fireEvent.click(saveButton); | ||
|
|
||
| const hooks = require('../hooks'); | ||
| expect(hooks.editTaskOnBackend).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('saves recur when a valid value is selected', async () => { | ||
| render(<Tasks {...mockProps} />); | ||
|
|
||
| await screen.findByText('Task 12'); | ||
| fireEvent.click(screen.getByText('Task 12')); | ||
|
|
||
| expect(await screen.findByText('Recur:')).toBeInTheDocument(); | ||
|
|
||
| const recurLabel = screen.getByText('Recur:'); | ||
| const recurRow = recurLabel.closest('tr') as HTMLElement; | ||
| const editButton = within(recurRow).getByLabelText('edit'); | ||
|
|
||
| fireEvent.click(editButton); | ||
|
|
||
| const select = within(recurRow).getByTestId('recur-select'); | ||
| fireEvent.change(select, { target: { value: 'daily' } }); | ||
|
|
||
| const saveButton = screen.getByLabelText('save'); | ||
| fireEvent.click(saveButton); | ||
|
|
||
| const hooks = require('../hooks'); | ||
| expect(hooks.editTaskOnBackend).toHaveBeenCalledWith( | ||
| expect.objectContaining({ recur: 'daily' }) | ||
| ); | ||
| }); | ||
|
|
||
| test('does not save when recur is empty string', async () => { | ||
| render(<Tasks {...mockProps} />); | ||
|
|
||
| await screen.findByText('Task 12'); | ||
| fireEvent.click(screen.getByText('Task 12')); | ||
|
|
||
| expect(await screen.findByText('Recur:')).toBeInTheDocument(); | ||
|
|
||
| const recurLabel = screen.getByText('Recur:'); | ||
| const recurRow = recurLabel.closest('tr') as HTMLElement; | ||
| const editButton = within(recurRow).getByLabelText('edit'); | ||
| fireEvent.click(editButton); | ||
|
|
||
| const select = within(recurRow).getByTestId('recur-select'); | ||
| fireEvent.change(select, { target: { value: '' } }); | ||
| const saveButton = within(recurRow).getByLabelText('save'); | ||
| fireEvent.click(saveButton); | ||
|
|
||
| const hooks = require('../hooks'); | ||
| expect(hooks.editTaskOnBackend).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Priority Editing', () => { | ||
| test('saving priority calls modifyTaskOnBackend with correct value', async () => { | ||
| render(<Tasks {...mockProps} />); | ||
|
|
||
| await screen.findByText('Task 12'); | ||
| fireEvent.click(screen.getByText('Task 12')); | ||
|
|
||
| expect(await screen.findByText('Priority:')).toBeInTheDocument(); | ||
|
|
||
| const priorityLabel = screen.getByText('Priority:'); | ||
| const priorityRow = priorityLabel.closest('tr') as HTMLElement; | ||
| const editButton = within(priorityRow).getByLabelText('edit'); | ||
| fireEvent.click(editButton); | ||
|
|
||
| const select = within(priorityRow).getByTestId('priority-select'); | ||
| fireEvent.change(select, { target: { value: 'H' } }); | ||
|
|
||
| const saveButton = screen.getByLabelText('save'); | ||
| fireEvent.click(saveButton); | ||
|
|
||
| await waitFor(() => { | ||
| const hooks = require('../hooks'); | ||
| expect(hooks.modifyTaskOnBackend).toHaveBeenCalledWith( | ||
| expect.objectContaining({ priority: 'H' }) | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| test('saving "NONE" priority sends empty string to backend', async () => { | ||
| render(<Tasks {...mockProps} />); | ||
|
|
||
| await screen.findByText('Task 12'); | ||
its-me-abhishek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fireEvent.click(screen.getByText('Task 12')); | ||
|
|
||
| expect(await screen.findByText('Priority:')).toBeInTheDocument(); | ||
|
|
||
| const priorityLabel = screen.getByText('Priority:'); | ||
| const priorityRow = priorityLabel.closest('tr') as HTMLElement; | ||
| const editButton = within(priorityRow).getByLabelText('edit'); | ||
| fireEvent.click(editButton); | ||
|
|
||
| const select = within(priorityRow).getByTestId('priority-select'); | ||
| fireEvent.change(select, { target: { value: 'NONE' } }); | ||
|
|
||
| const saveButton = screen.getByLabelText('save'); | ||
| fireEvent.click(saveButton); | ||
|
|
||
| await waitFor(() => { | ||
| const hooks = require('../hooks'); | ||
| expect(hooks.modifyTaskOnBackend).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| priority: '', | ||
| }) | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| test('shows error toast when priority save fails', async () => { | ||
| const { toast } = require('react-toastify'); | ||
| const hooks = require('../hooks'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo just move this to the top, its being reused a lot
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, i will |
||
|
|
||
| hooks.modifyTaskOnBackend.mockRejectedValueOnce( | ||
| new Error('Network error') | ||
| ); | ||
|
|
||
| render(<Tasks {...mockProps} />); | ||
| await screen.findByText('Task 12'); | ||
|
|
||
| fireEvent.click(screen.getByText('Task 12')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Priority:')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const priorityLabel = screen.getByText('Priority:'); | ||
| const priorityRow = priorityLabel.closest('tr') as HTMLElement; | ||
|
|
||
| const editButton = within(priorityRow).getByLabelText('edit'); | ||
| fireEvent.click(editButton); | ||
|
|
||
| const select = within(priorityRow).getByTestId('priority-select'); | ||
| fireEvent.change(select, { target: { value: 'H' } }); | ||
|
|
||
| const saveButton = within(priorityRow).getByLabelText('save'); | ||
| fireEvent.click(saveButton); | ||
|
|
||
| await waitFor(() => { | ||
| expect(toast.error).toHaveBeenCalledWith( | ||
| expect.stringContaining('Failed to update priority') | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Reports Toggle', () => { | ||
| test('clicking "Show Reports" button switches view from tasks to reports', async () => { | ||
| render(<Tasks {...mockProps} />); | ||
|
|
||
| await screen.findByText('Task 1'); | ||
|
|
||
| expect(screen.getByText('Here are')).toBeInTheDocument(); | ||
|
|
||
| const toggleBtn = screen.getByRole('button', { name: /show reports/i }); | ||
| fireEvent.click(toggleBtn); | ||
|
|
||
| expect( | ||
| screen.getByRole('button', { name: /show tasks/i }) | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('clicking "Show Tasks" returns to task list view', async () => { | ||
| render(<Tasks {...mockProps} />); | ||
| await screen.findByText('Task 1'); | ||
|
|
||
| fireEvent.click(screen.getByRole('button', { name: /show reports/i })); | ||
| fireEvent.click(screen.getByRole('button', { name: /show tasks/i })); | ||
|
|
||
| expect(screen.getByText('Task 1')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('hotkeys are disabled when reports view is shown', async () => { | ||
| render(<Tasks {...mockProps} />); | ||
| await screen.findByText('Task 1'); | ||
|
|
||
| fireEvent.click(screen.getByRole('button', { name: /show reports/i })); | ||
| fireEvent.keyDown(window, { key: 'a' }); | ||
|
|
||
| expect( | ||
| screen.queryByText(/fill in the details below/i) | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these data-testid related changes are not really desired.
should be reverted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert these as those spreaded props are kind of vague, and make it hard to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, i will do that, could you please confirm the structure mentioned above?(for new tests)