2023-01-05 04:15:16 +00:00
|
|
|
import React from 'react'
|
|
|
|
import 'react-native'
|
2023-07-07 01:17:19 +00:00
|
|
|
import { fireEvent, render, waitFor } from '@testing-library/react-native'
|
2023-06-27 03:16:59 +00:00
|
|
|
import { MockProviders } from '../mock-providers'
|
|
|
|
import { Plan } from '../plan'
|
2023-01-05 04:15:16 +00:00
|
|
|
import PlanPage from '../PlanPage'
|
|
|
|
|
|
|
|
jest.mock('../db.ts', () => ({
|
|
|
|
setRepo: {
|
|
|
|
createQueryBuilder: () => ({
|
|
|
|
select: jest.fn().mockReturnThis(),
|
|
|
|
addSelect: jest.fn().mockReturnThis(),
|
|
|
|
where: jest.fn().mockReturnThis(),
|
|
|
|
andWhere: jest.fn().mockReturnThis(),
|
2023-02-14 03:39:47 +00:00
|
|
|
orderBy: jest.fn().mockReturnThis(),
|
2023-01-05 04:15:16 +00:00
|
|
|
groupBy: jest.fn().mockReturnThis(),
|
|
|
|
distinct: jest.fn().mockReturnThis(),
|
|
|
|
getRawMany: jest.fn(() =>
|
|
|
|
Promise.resolve([
|
|
|
|
{
|
|
|
|
name: 'Bench press',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Bicep curls',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Rows',
|
|
|
|
},
|
2023-06-27 03:16:59 +00:00
|
|
|
])
|
2023-01-05 04:15:16 +00:00
|
|
|
),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
planRepo: {
|
|
|
|
find: () =>
|
|
|
|
Promise.resolve([
|
|
|
|
{
|
|
|
|
days: 'Monday,Tuesday,Wednesday',
|
|
|
|
workouts: 'Bench press,Side raises, Bicep curls',
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
days: 'Thursday,Friday,Saturday',
|
|
|
|
workouts: 'Deadlifts,Barbell rows,Pull ups',
|
|
|
|
id: 2,
|
|
|
|
},
|
|
|
|
] as Plan[]),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
|
|
|
test('renders correctly', async () => {
|
2023-06-27 03:16:59 +00:00
|
|
|
const { getByText } = render(
|
2023-01-05 04:15:16 +00:00
|
|
|
<MockProviders>
|
|
|
|
<PlanPage />
|
|
|
|
</MockProviders>,
|
|
|
|
)
|
|
|
|
const title = await waitFor(() => getByText('Plans'))
|
|
|
|
expect(title).toBeDefined()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('adds', async () => {
|
2023-06-27 03:16:59 +00:00
|
|
|
const { getByTestId, getByText } = render(
|
2023-01-05 04:15:16 +00:00
|
|
|
<MockProviders>
|
|
|
|
<PlanPage />
|
|
|
|
</MockProviders>,
|
|
|
|
)
|
|
|
|
fireEvent.press(await waitFor(() => getByTestId('add')))
|
2023-01-08 05:08:46 +00:00
|
|
|
expect(await waitFor(() => getByText('Add plan'))).toBeDefined()
|
2023-01-05 04:15:16 +00:00
|
|
|
})
|