|
|
|
@ -1,20 +1,49 @@
|
|
|
|
|
import React from 'react'
|
|
|
|
|
import 'react-native'
|
|
|
|
|
import {render, waitFor} from 'react-native-testing-library'
|
|
|
|
|
import {Repository} from 'typeorm'
|
|
|
|
|
import {fireEvent, render, waitFor} from 'react-native-testing-library'
|
|
|
|
|
import BestPage from '../BestPage'
|
|
|
|
|
import GymSet from '../gym-set'
|
|
|
|
|
import {MockProviders} from '../mock-providers'
|
|
|
|
|
import Settings from '../settings'
|
|
|
|
|
|
|
|
|
|
jest.mock('../db.ts', () => ({
|
|
|
|
|
setRepo: {find: () => Promise.resolve([])} as Repository<GymSet>,
|
|
|
|
|
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(),
|
|
|
|
|
getMany: jest.fn(() =>
|
|
|
|
|
Promise.resolve([
|
|
|
|
|
{
|
|
|
|
|
name: 'Bench press',
|
|
|
|
|
weight: 60,
|
|
|
|
|
reps: 8,
|
|
|
|
|
image: 'https://picsum.photos/id/10/1000/600',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Bicep curls',
|
|
|
|
|
weight: 20,
|
|
|
|
|
reps: 10,
|
|
|
|
|
image: 'https://picsum.photos/id/0/1000/600',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Rows',
|
|
|
|
|
weight: 100,
|
|
|
|
|
reps: 10,
|
|
|
|
|
image: 'https://picsum.photos/id/1/1000/600',
|
|
|
|
|
},
|
|
|
|
|
]),
|
|
|
|
|
),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
settingsRepo: {
|
|
|
|
|
findOne: () => Promise.resolve({} as Settings),
|
|
|
|
|
findOne: () => Promise.resolve({images: true} as Settings),
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
it('renders correctly', async () => {
|
|
|
|
|
test('renders correctly', async () => {
|
|
|
|
|
const {getByText} = render(
|
|
|
|
|
<MockProviders>
|
|
|
|
|
<BestPage />
|
|
|
|
@ -23,3 +52,16 @@ it('renders correctly', async () => {
|
|
|
|
|
const title = await waitFor(() => getByText('Best'))
|
|
|
|
|
expect(title).toBeDefined()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('searches', async () => {
|
|
|
|
|
const {getByDisplayValue, getByPlaceholder} = render(
|
|
|
|
|
<MockProviders>
|
|
|
|
|
<BestPage />
|
|
|
|
|
</MockProviders>,
|
|
|
|
|
)
|
|
|
|
|
const search = await waitFor(() => getByPlaceholder('Search'))
|
|
|
|
|
expect(search).toBeDefined()
|
|
|
|
|
fireEvent.changeText(search, 'SearchValue')
|
|
|
|
|
const value = await waitFor(() => getByDisplayValue('SearchValue'))
|
|
|
|
|
expect(value).toBeDefined()
|
|
|
|
|
})
|
|
|
|
|