-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TaskBox tests were included in the TaskList, since the component is growing in complexity it should have it's own tests.
- Loading branch information
1 parent
909a0a1
commit 265623b
Showing
2 changed files
with
102 additions
and
53 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
frontend/src/app/tasks/__tests__/components/TaskBox.test.tsx
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,100 @@ | ||
import { renderWithUser, screen } from '@/test-utils/test-utils' | ||
import { TaskBox } from '../../components/TaskBox' | ||
import { useDeleteTask } from '../../hooks/useDeleteTask' | ||
import { useCreateTaskForm } from '../../hooks/useCreateTaskForm' | ||
|
||
jest.mock('../../hooks/useDeleteTask') | ||
jest.mock('../../hooks/useCreateTaskForm') | ||
|
||
const setupTaskBox = () => { | ||
const task = { | ||
date: '2023-11-01', | ||
story: 'task story', | ||
description: 'task description', | ||
taskType: 'task type one', | ||
projectId: 1, | ||
userId: 4, | ||
startTime: '11:12', | ||
endTime: '11:14', | ||
id: 18, | ||
projectName: 'Holidays', | ||
customerName: 'Internal' | ||
} | ||
|
||
return renderWithUser(<TaskBox projects={[]} taskTypes={[]} task={task} />) | ||
} | ||
|
||
describe('TaskBox', () => { | ||
beforeEach(() => { | ||
;(useDeleteTask as jest.Mock).mockReturnValue({ removeTask: () => {} }) | ||
;(useCreateTaskForm as jest.Mock).mockReturnValue({ cloneTask: () => {} }) | ||
}) | ||
|
||
it('Shows the task info', () => { | ||
setupTaskBox() | ||
|
||
expect(screen.getByText('Holidays - Internal')).toBeInTheDocument() | ||
expect(screen.getByText('task type one')).toBeInTheDocument() | ||
expect(screen.getByText('11:12-11:14 (0h 2m)')).toBeInTheDocument() | ||
}) | ||
|
||
describe('Clicking expand Button', () => { | ||
it('shows the complete task information', async () => { | ||
const { user } = setupTaskBox() | ||
|
||
await user.click(screen.getByRole('button', { name: 'Expand Task' })) | ||
|
||
expect(screen.getByText('task description')).toBeInTheDocument() | ||
expect(screen.getByText('task story')).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
describe('Clicking delete button', () => { | ||
it('Opens the delete confirmation modal', async () => { | ||
const { user } = setupTaskBox() | ||
|
||
await user.click(screen.getByRole('button', { name: 'Delete task 18' })) | ||
|
||
expect(screen.getByRole('heading', { name: 'Confirm Deletion' })).toBeInTheDocument() | ||
}) | ||
|
||
it('deletes the task from the list', async () => { | ||
const deleteTask = jest.fn() | ||
;(useDeleteTask as jest.Mock).mockReturnValue({ deleteTask }) | ||
|
||
const { user } = setupTaskBox() | ||
|
||
await user.click(screen.getByRole('button', { name: 'Delete task 18' })) | ||
|
||
await user.click(screen.getByRole('button', { name: 'Delete' })) | ||
|
||
expect(deleteTask).toBeCalledWith(18) | ||
}) | ||
|
||
it('closes the modal without submit if cancel is clicked', async () => { | ||
const deleteTask = jest.fn() | ||
;(useDeleteTask as jest.Mock).mockReturnValue({ deleteTask }) | ||
|
||
const { user } = setupTaskBox() | ||
|
||
await user.click(screen.getByRole('button', { name: 'Delete task 18' })) | ||
|
||
await user.click(screen.getByRole('button', { name: 'Cancel' })) | ||
|
||
expect(deleteTask).not.toBeCalled() | ||
}) | ||
}) | ||
|
||
describe('Clicking clone task button', () => { | ||
it('calls the clone task function', async () => { | ||
const cloneTask = jest.fn() | ||
;(useCreateTaskForm as jest.Mock).mockReturnValue({ cloneTask }) | ||
|
||
const { user } = setupTaskBox() | ||
|
||
await user.click(screen.getByRole('button', { name: 'Clone Task' })) | ||
|
||
expect(cloneTask).toBeCalled() | ||
}) | ||
}) | ||
}) |
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