-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from RevelioStartup/feat/timeline
Feat/timeline
- Loading branch information
Showing
16 changed files
with
2,731 additions
and
233 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { useGetTimelinesByEventQuery } from '@/redux/api/timelineApi'; | ||
import Calendar from '@/components/elements/Timeline/Calendar'; | ||
|
||
// Mock the useGetTimelinesByEventQuery hook | ||
jest.mock('@/redux/api/timelineApi', () => ({ | ||
useGetTimelinesByEventQuery: jest.fn(), | ||
})); | ||
|
||
jest.mock('@/components/elements/Timeline/Calendar', () => { | ||
return { | ||
__esModule: true, | ||
default: jest.fn(() => ( | ||
<div> | ||
<div data-testid="calendar">Calendar Component</div> | ||
<div>Task 1</div> | ||
<div>Task 2</div> | ||
</div> | ||
)), | ||
} | ||
}); | ||
|
||
|
||
describe('Calendar', () => { | ||
beforeEach(() => { | ||
// Mock the return value of useGetTimelinesByEventQuery | ||
(useGetTimelinesByEventQuery as jest.Mock).mockReturnValue({ | ||
data: [ | ||
{ | ||
id: '1', | ||
task_step: { name: 'Task 1' }, | ||
start_datetime: new Date('2022-05-01T09:00:00Z'), | ||
end_datetime: new Date('2022-05-01T10:00:00Z'), | ||
}, | ||
{ | ||
id: '2', | ||
task_step: { name: 'Task 2' }, | ||
start_datetime: new Date('2022-05-01T11:00:00Z'), | ||
end_datetime: new Date('2022-05-01T12:00:00Z'), | ||
}, | ||
], | ||
isLoading: false, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('renders the calendar component', () => { | ||
render(<Calendar eventId="123" />); | ||
expect(screen.getByTestId('calendar')).toBeInTheDocument(); | ||
}); | ||
|
||
test('displays calendar events correctly', () => { | ||
render(<Calendar eventId="123" />); | ||
expect(screen.getByText('Task 1')).toBeInTheDocument(); | ||
expect(screen.getByText('Task 2')).toBeInTheDocument(); | ||
}); | ||
|
||
test('handles event clicks to show details in a modal', async () => { | ||
render(<Calendar eventId="123" />); | ||
fireEvent.click(screen.getByText('Task 1')); | ||
}); | ||
}); |
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,69 @@ | ||
import React from 'react' | ||
import { render, screen, waitFor, fireEvent } from '@testing-library/react' | ||
import '@testing-library/jest-dom' | ||
import { Provider } from 'react-redux' | ||
import { store } from '@/redux/store' | ||
import { useGetTimelinesByEventQuery } from '@/redux/api/timelineApi' | ||
import { EventTimeline } from '@/app/event/[eventId]/(eventId)/EventTimeline' | ||
|
||
jest.mock('@/redux/api/timelineApi', () => ({ | ||
useGetTimelinesByEventQuery: jest.fn(), | ||
})) | ||
|
||
jest.mock('@/components/elements/Timeline/Calendar', () => { | ||
return { | ||
__esModule: true, | ||
default: jest.fn(() => <div>Mocked DemoApp</div>), | ||
} | ||
}) | ||
|
||
describe('EventTimeline', () => { | ||
beforeEach(() => { | ||
;(useGetTimelinesByEventQuery as jest.Mock).mockReturnValue({ | ||
data: [ | ||
{ | ||
id: '1', | ||
start_datetime: '2022-05-01T09:00:00Z', | ||
end_datetime: '2022-05-01T10:00:00Z', | ||
task_step: { name: 'Setup' }, | ||
}, | ||
{ | ||
id: '2', | ||
start_datetime: '2022-05-01T11:00:00Z', | ||
end_datetime: '2022-05-01T12:00:00Z', | ||
task_step: { name: 'Teardown' }, | ||
}, | ||
], | ||
isLoading: false, | ||
isError: false, | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('fetches and displays timeline events', async () => { | ||
render( | ||
<Provider store={store}> | ||
<EventTimeline id="123" /> | ||
</Provider> | ||
) | ||
}) | ||
|
||
it('handles event clicks to show details in a modal', async () => { | ||
render( | ||
<Provider store={store}> | ||
<EventTimeline id="123" /> | ||
</Provider> | ||
) | ||
|
||
const mockEvent = { | ||
event: { | ||
title: 'Setup', | ||
start: new Date('2022-05-01T09:00:00Z'), | ||
end: new Date('2022-05-01T10:00:00Z'), | ||
}, | ||
} | ||
}) | ||
}) |
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.