Skip to content

Commit

Permalink
Merge pull request #74 from RevelioStartup/staging
Browse files Browse the repository at this point in the history
Deploy to PROD
  • Loading branch information
nataniadeandra authored May 8, 2024
2 parents eb3b31e + 8aa3d2c commit 07919a5
Show file tree
Hide file tree
Showing 59 changed files with 4,882 additions and 485 deletions.
66 changes: 66 additions & 0 deletions __tests__/elements/calendar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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'))
})
})
40 changes: 40 additions & 0 deletions __tests__/event/event_detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,46 @@ jest.mock('@/redux/api/taskApi', () => ({
.fn()
.mockReturnValue([jest.fn().mockResolvedValue({ data: { id: 1 } })]),
}))
jest.mock('@/redux/api/timelineApi', () => ({
useGetTimelinesByEventQuery: jest.fn().mockReturnValue({
data: [],
isLoading: false,
}),
}))
jest.mock('@/redux/api/rundownApi', () => ({
useDeleteAllRundownMutation: jest
.fn()
.mockReturnValue([
jest.fn().mockImplementation(({ id }) => Promise.resolve({ data: '' })),
{ isLoading: false },
]),
useDeleteRundownMutation: jest
.fn()
.mockReturnValue([
jest.fn().mockImplementation(({ id }) => Promise.resolve({ data: '' })),
{ isLoading: false },
]),
useGetEventRundownQuery: jest.fn().mockReturnValue({
data: [
{
id: 'efa74992-001f-4e09-9cb9-7cee4d59746e',
start_time: '12:00:00',
end_time: '13:50:00',
description: 'pembukaan',
rundown_order: 1,
event: 'bf8d2392-2bf5-4659-8ff4-652e46c21749',
},
],
}),
useUpdateRundownMutation: jest.fn().mockReturnValue([]),
}))

jest.mock('@/components/elements/Timeline/Calendar', () => {
return {
__esModule: true,
default: jest.fn(() => <div>Mocked DemoApp</div>),
}
})

describe('Event Detail', () => {
it('renders the myplan', () => {
Expand Down
39 changes: 39 additions & 0 deletions __tests__/package/package-list-free.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react'
import { render } from '@testing-library/react'
import '@testing-library/jest-dom'
import PackageList from '@/app/package/page'

jest.mock('@/redux/api/packageApi', () => ({
useGetPackageDetailQuery: jest.fn((id) => ({
data: {
name: 'Default Package',
price: 5000,
event_planner: true,
event_tracker: true,
event_timeline: true,
event_rundown: true,
ai_assistant: false,
},
})),
}))

jest.mock('@/redux/api/subscriptionApi', () => ({
useGetLatestSubscriptionQuery: jest.fn((id) => ({
data: {
id: 1,
plan: 'PREMIUM',
start_date: '2024-05-05T13:30:00.000Z',
end_date: '2025-05-05T13:30:00.000Z',
user: 1,
is_active: false,
},
})),
}))

describe('PackageList component', () => {
it('renders correctly', () => {
const { getByTestId } = render(<PackageList />)
const packageDetail = getByTestId('package-detail')
expect(packageDetail).toBeInTheDocument()
})
})
39 changes: 39 additions & 0 deletions __tests__/package/package-list-premium.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react'
import { render } from '@testing-library/react'
import '@testing-library/jest-dom'
import PackageList from '@/app/package/page'

jest.mock('@/redux/api/packageApi', () => ({
useGetPackageDetailQuery: jest.fn((id) => ({
data: {
name: 'Default Package',
price: 5000,
event_planner: true,
event_tracker: true,
event_timeline: true,
event_rundown: true,
ai_assistant: false,
},
})),
}))

jest.mock('@/redux/api/subscriptionApi', () => ({
useGetLatestSubscriptionQuery: jest.fn((id) => ({
data: {
id: 1,
plan: 'PREMIUM',
start_date: '2024-05-05T13:30:00.000Z',
end_date: '2025-05-05T13:30:00.000Z',
user: 1,
is_active: true,
},
})),
}))

describe('PackageList component', () => {
it('renders correctly', () => {
const { getByTestId } = render(<PackageList />)
const packageDetail = getByTestId('package-detail')
expect(packageDetail).toBeInTheDocument()
})
})
41 changes: 41 additions & 0 deletions __tests__/profile/profile.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Provider } from 'react-redux'
import { store } from '@/redux/store' // Update the import path according to your file structure
import { useGetProfileQuery, useGetEventsQuery } from '@/redux/api/profileApi'
import Profile from '@/app/profile/page'
import { useGetSubscriptionsQuery } from '@/redux/api/subscriptionApi'

// Mock data based on the IEvent type
const mockEventsData = [
Expand All @@ -21,6 +22,12 @@ const mockEventsData = [
// ... add more mock events as needed
]

jest.mock('@/redux/api/subscriptionApi', () => ({
useGetSubscriptionsQuery: jest.fn().mockReturnValue({
data: [],
}),
}))

// Mocking the RTK Query hook used in the component
jest.mock('@/redux/api/profileApi', () => ({
useGetProfileQuery: jest.fn(),
Expand Down Expand Up @@ -130,4 +137,38 @@ describe('Profile Component', () => {
fireEvent.click(getByTestId('logout-button'))
fireEvent.click(getByTestId('button-yes'))
})

it('Showing Subscription History', () => {
const myInitialState = 'history'

React.useState = jest.fn().mockReturnValue([myInitialState, {}])

const { getByText } = render(
<Provider store={store}>
<Profile />
</Provider>
)

const history = getByText('Subscription History')

expect(history).toBeInTheDocument()
})

it('Show subscription not found', () => {
const myInitialState = 'history'

React.useState = jest.fn().mockReturnValue([myInitialState, {}])
const mockGetEventQuery = useGetSubscriptionsQuery as jest.Mock

mockGetEventQuery.mockReturnValue({
data: null,
isLoading: true,
})

const { getByText } = render(
<Provider store={store}>
<Profile />
</Provider>
)
})
})
Loading

0 comments on commit 07919a5

Please sign in to comment.