Skip to content

Commit

Permalink
Merge pull request #67 from RevelioStartup/feat/membuat-timeline
Browse files Browse the repository at this point in the history
PBI Membuat Timeline
  • Loading branch information
catherineeangel authored May 4, 2024
2 parents 18a268e + f6ec53b commit 73f2f6c
Show file tree
Hide file tree
Showing 17 changed files with 399 additions and 103 deletions.
9 changes: 4 additions & 5 deletions __tests__/rundown/rundown-table-filled.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useUpdateRundownMutation } from '@/redux/api/rundownApi'
import { RundownsDetail } from '@/types/rundown'
import { toast } from 'react-hot-toast'


jest.mock('@/redux/api/rundownApi', () => ({
useGetEventRundownQuery: jest.fn().mockReturnValue({
data: [
Expand Down Expand Up @@ -40,7 +39,7 @@ jest.mock('@/redux/api/rundownApi', () => ({
useUpdateRundownMutation: jest.fn(),
}))

const mockUpdateRundownData:RundownsDetail = {
const mockUpdateRundownData: RundownsDetail = {
id: '89f5ded5-3267-4c34-ac6b-a5f345621682',
start_time: '14:05:00',
end_time: '15:50:00',
Expand Down Expand Up @@ -130,9 +129,9 @@ describe('Rundown Edit', () => {
test('display update rundown error correctly', async () => {
jest.spyOn(toast, 'error').mockImplementation(jest.fn())

const mockUseUpdateRundownMutation = jest
.fn()
.mockResolvedValue({ error: {data: {"message":"Invalid rundown data"}} })
const mockUseUpdateRundownMutation = jest.fn().mockResolvedValue({
error: { data: { message: 'Invalid rundown data' } },
})
;(useUpdateRundownMutation as jest.Mock).mockReturnValue([
mockUseUpdateRundownMutation,
])
Expand Down
81 changes: 67 additions & 14 deletions __tests__/task-detail/task-detail-with-step.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
useUpdateTaskStepMutation,
} from '@/redux/api/taskStepApi'
import '@testing-library/jest-dom'
import dayjs from '@/configs/dayjs.config'
import { Step } from '@/types/taskDetails'
import { store } from '@/redux/store'
import { Provider } from 'react-redux'

jest.mock('@/redux/api/eventApi', () => ({
useGetEventQuery: jest.fn(),
Expand All @@ -25,18 +29,10 @@ jest.mock('@/redux/api/taskStepApi', () => ({
useUpdateTaskStepMutation: jest.fn(),
useDeleteTaskStepMutation: jest.fn(),
useDeleteAllTaskStepsMutation: jest.fn(),
useCreateTimelineMutation: jest.fn(),
}))

describe('TaskDetailPage with step', () => {
interface Step {
id: string
name: string
description: string
status: string
step_order: number
task: string
}

const mockEventData = {
id: '1',
name: 'event name',
Expand All @@ -55,6 +51,8 @@ describe('TaskDetailPage with step', () => {
status: 'NOT_STARTED',
step_order: 1,
task: '1',
start_datetime: '2024-04-19T12:40:19.827000Z',
end_datetime: '2024-04-19T12:40:19.827000Z',
}

const mockStepData2: Step = {
Expand All @@ -64,6 +62,8 @@ describe('TaskDetailPage with step', () => {
status: 'NOT_STARTED',
step_order: 2,
task: '1',
start_datetime: null,
end_datetime: null,
}

const mockUpdatedStepData1: Step = {
Expand All @@ -73,6 +73,8 @@ describe('TaskDetailPage with step', () => {
status: 'DONE',
step_order: 1,
task: '1',
start_datetime: null,
end_datetime: null,
}

const mockUpdatedStepData12: Step = {
Expand All @@ -82,6 +84,8 @@ describe('TaskDetailPage with step', () => {
status: 'NOT_STARTED',
step_order: 1,
task: '1',
start_datetime: null,
end_datetime: null,
}

const mockTaskData = {
Expand Down Expand Up @@ -171,7 +175,11 @@ describe('TaskDetailPage with step', () => {
mockUseUpdateTaskStepMutation,
])

render(<TaskDetailPage params={{ eventId: '1', taskId: '1' }} />)
render(
<Provider store={store}>
<TaskDetailPage params={{ eventId: '1', taskId: '1' }} />
</Provider>
)

expect(screen.getByText('event name')).toBeInTheDocument()
expect(screen.getByText('task status')).toBeInTheDocument()
Expand Down Expand Up @@ -199,7 +207,11 @@ describe('TaskDetailPage with step', () => {
mockUseUpdateTaskStepMutation,
])

render(<TaskDetailPage params={{ eventId: '1', taskId: '1' }} />)
render(
<Provider store={store}>
<TaskDetailPage params={{ eventId: '1', taskId: '1' }} />
</Provider>
)

act(() => {
const buttonEdit = screen.getByTestId('button-edit-form')
Expand Down Expand Up @@ -232,7 +244,11 @@ describe('TaskDetailPage with step', () => {
mockUseUpdateTaskStepMutation,
])

render(<TaskDetailPage params={{ eventId: '1', taskId: '1' }} />)
render(
<Provider store={store}>
<TaskDetailPage params={{ eventId: '1', taskId: '1' }} />
</Provider>
)

expect(screen.getByText('step name')).toBeInTheDocument()
expect(screen.getByText('step name 2')).toBeInTheDocument()
Expand All @@ -247,7 +263,11 @@ describe('TaskDetailPage with step', () => {
})

test('delete task correctly', async () => {
render(<TaskDetailPage params={{ eventId: '1', taskId: '1' }} />)
render(
<Provider store={store}>
<TaskDetailPage params={{ eventId: '1', taskId: '1' }} />
</Provider>
)

const buttonDelete = screen.getByTestId('delete-task')
fireEvent.click(buttonDelete)
Expand All @@ -261,10 +281,43 @@ describe('TaskDetailPage with step', () => {
{ isLoading: false },
])

render(<TaskDetailPage params={{ eventId: '1', taskId: '1' }} />)
render(
<Provider store={store}>
<TaskDetailPage params={{ eventId: '1', taskId: '1' }} />
</Provider>
)

const buttonDelete = screen.getByTestId('delete-task')
fireEvent.click(buttonDelete)
await waitFor(() => expect(mockDeleteTaskMutation).toHaveBeenCalledTimes(1))
})

test('renders task details with correct date format', () => {
const mockGetEventQuery = useGetEventQuery as jest.Mock
mockGetEventQuery.mockReturnValue({
data: mockEventData,
isLoading: false,
})

const mockGetTaskDetailQuery = useGetTaskDetailQuery as jest.Mock
mockGetTaskDetailQuery.mockReturnValue({
data: mockTaskData,
isLoading: false,
})

render(
<Provider store={store}>
<TaskDetailPage params={{ eventId: '1', taskId: '1' }} />
</Provider>
)

expect(
screen.getByText(
dayjs(mockStepData.start_datetime).format('ddd, D MMM YY HH:mm')
)
).toBeInTheDocument()
expect(
screen.getByText(dayjs(mockStepData.end_datetime).format('HH:mm'))
).toBeInTheDocument()
})
})
18 changes: 16 additions & 2 deletions __tests__/task-steps/delete-steps.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
useUpdateTaskStepMutation,
} from '@/redux/api/taskStepApi'
import StepStepper from '@/app/event/[eventId]/(eventId)/task/[taskId]/StepStepper'
import { Provider } from 'react-redux'
import { store } from '@/redux/store'

jest.mock('@/redux/api/taskStepApi', () => ({
useDeleteTaskStepMutation: jest.fn(),
Expand All @@ -24,6 +26,8 @@ const mockTask = {
status: 'NOT_STARTED',
step_order: 1,
task: '1',
start_datetime: '2024-04-19T12:40:19.827000Z',
end_datetime: '2024-04-19T12:40:19.827000Z',
},
{
id: 'step2',
Expand All @@ -32,6 +36,8 @@ const mockTask = {
status: 'NOT_STARTED',
step_order: 2,
task: '1',
start_datetime: null,
end_datetime: null,
},
],
title: 'Task Title',
Expand Down Expand Up @@ -77,13 +83,21 @@ describe('StepStepper', () => {
})

test('deletes a single task step correctly', async () => {
render(<StepStepper taskId={mockTask.id} task={mockTask} />)
render(
<Provider store={store}>
<StepStepper taskId={mockTask.id} task={mockTask} />
</Provider>
)

fireEvent.click(screen.getAllByText('Delete')[0])
})

test('deletes all task steps correctly', async () => {
render(<StepStepper taskId={mockTask.id} task={mockTask} />)
render(
<Provider store={store}>
<StepStepper taskId={mockTask.id} task={mockTask} />
</Provider>
)

fireEvent.click(screen.getByText('Delete All'))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export const CreateRundownButton = () => {
return (
<div className="flex flex-col gap-8 px-5 py-3 lg:px-10 lg:py-6">
<p
data-testid="no-rundown-text"
className="text-lg text-md text-teal-600 font-bold"
>
Your event does not have a schedule yet! Create one now!
</p>
data-testid="no-rundown-text"
className="text-lg text-md text-teal-600 font-bold"
>
Your event does not have a schedule yet! Create one now!
</p>
<Link href={`${pathname}/create-rundown`} className="w-full">
<Button
variant={'ghost'}
Expand Down
Loading

0 comments on commit 73f2f6c

Please sign in to comment.