Add plan list unit tests

This commit is contained in:
Brandon Presley 2023-01-05 17:15:16 +13:00
parent b0696d1d58
commit 8e8961419c
1 changed files with 67 additions and 0 deletions

67
tests/PlanList.test.tsx Normal file
View File

@ -0,0 +1,67 @@
import React from 'react'
import 'react-native'
import {fireEvent, render, waitFor} from 'react-native-testing-library'
import {MockProviders} from '../mock-providers'
import {Plan} from '../plan'
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(),
groupBy: jest.fn().mockReturnThis(),
distinct: jest.fn().mockReturnThis(),
getRawMany: jest.fn(() =>
Promise.resolve([
{
name: 'Bench press',
},
{
name: 'Bicep curls',
},
{
name: 'Rows',
},
]),
),
}),
},
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 () => {
const {getByText} = render(
<MockProviders>
<PlanPage />
</MockProviders>,
)
const title = await waitFor(() => getByText('Plans'))
expect(title).toBeDefined()
})
test('adds', async () => {
const {getByTestId, getByText} = render(
<MockProviders>
<PlanPage />
</MockProviders>,
)
fireEvent.press(await waitFor(() => getByTestId('add')))
expect(await waitFor(() => getByText('Edit plan'))).toBeDefined()
})