From b41c30d886751505e9b636e9ec0a9d4370afd661 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Wed, 4 Jan 2023 13:44:28 +1300 Subject: [PATCH] Replace it with test for jest files Test explains what it is we are writing, whereas it doesn't. --- .gitignore | 1 + tests/App.test.tsx | 2 +- tests/BestPage.test.tsx | 54 ++++++++++++++++++++++++++++++++----- tests/EditPlan.test.tsx | 2 +- tests/EditSet.test.tsx | 4 +-- tests/EditSets.test.tsx | 4 +-- tests/EditWorkout.test.tsx | 2 +- tests/HomePage.test.tsx | 2 +- tests/PlanPage.test.tsx | 2 +- tests/SettingsPage.test.tsx | 2 +- tests/StartPlan.test.tsx | 4 +-- tests/TimerPage.test.tsx | 2 +- tests/WorkoutsPage.test.tsx | 2 +- 13 files changed, 63 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 1290f1c..3b6ac8b 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,4 @@ massive-build !.yarn/releases !.yarn/sdks !.yarn/versions +coverage diff --git a/tests/App.test.tsx b/tests/App.test.tsx index 6cb0586..0317f7d 100644 --- a/tests/App.test.tsx +++ b/tests/App.test.tsx @@ -17,7 +17,7 @@ jest.mock('../data-source.ts', () => ({ }, })) -it('renders correctly', async () => { +test('renders correctly', async () => { const {getAllByText} = render() const title = await waitFor(() => getAllByText('Home')) expect(title.length).toBeGreaterThan(0) diff --git a/tests/BestPage.test.tsx b/tests/BestPage.test.tsx index 31300f4..feba379 100644 --- a/tests/BestPage.test.tsx +++ b/tests/BestPage.test.tsx @@ -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, + 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( @@ -23,3 +52,16 @@ it('renders correctly', async () => { const title = await waitFor(() => getByText('Best')) expect(title).toBeDefined() }) + +test('searches', async () => { + const {getByDisplayValue, getByPlaceholder} = render( + + + , + ) + const search = await waitFor(() => getByPlaceholder('Search')) + expect(search).toBeDefined() + fireEvent.changeText(search, 'SearchValue') + const value = await waitFor(() => getByDisplayValue('SearchValue')) + expect(value).toBeDefined() +}) diff --git a/tests/EditPlan.test.tsx b/tests/EditPlan.test.tsx index c8b0f1f..0764d30 100644 --- a/tests/EditPlan.test.tsx +++ b/tests/EditPlan.test.tsx @@ -23,7 +23,7 @@ jest.mock('../db.ts', () => ({ }, })) -it('renders correctly', async () => { +test('renders correctly', async () => { const Stack = createStackNavigator() const {getByText, getAllByText} = render( diff --git a/tests/EditSet.test.tsx b/tests/EditSet.test.tsx index 6897e96..553dfa8 100644 --- a/tests/EditSet.test.tsx +++ b/tests/EditSet.test.tsx @@ -25,7 +25,7 @@ jest.mock('../db.ts', () => ({ }, })) -it('renders correctly', async () => { +test('renders correctly', async () => { const Stack = createStackNavigator() const {getByText, getAllByText} = render( @@ -53,7 +53,7 @@ it('renders correctly', async () => { expect(getAllByText('Image').length).toBeGreaterThan(0) }) -it('saves', async () => { +test('saves', async () => { const Stack = createStackNavigator() const {getByText, getAllByText, getByTestId} = render( diff --git a/tests/EditSets.test.tsx b/tests/EditSets.test.tsx index 8b773c7..2622fef 100644 --- a/tests/EditSets.test.tsx +++ b/tests/EditSets.test.tsx @@ -36,7 +36,7 @@ jest.mock('../db.ts', () => ({ }, })) -it('renders correctly', async () => { +test('renders correctly', async () => { const Stack = createStackNavigator() const {getByText, getAllByText} = render( @@ -58,7 +58,7 @@ it('renders correctly', async () => { expect(getAllByText(/Image/i).length).toBeGreaterThan(0) }) -it('saves', async () => { +test('saves', async () => { const Stack = createStackNavigator() const {getByText, getAllByText} = render( diff --git a/tests/EditWorkout.test.tsx b/tests/EditWorkout.test.tsx index 3c7d7d4..5668cfa 100644 --- a/tests/EditWorkout.test.tsx +++ b/tests/EditWorkout.test.tsx @@ -18,7 +18,7 @@ jest.mock('../db.ts', () => ({ }, })) -it('renders correctly', async () => { +test('renders correctly', async () => { const Stack = createStackNavigator() const {getByText, getAllByText} = render( diff --git a/tests/HomePage.test.tsx b/tests/HomePage.test.tsx index 21e59fc..9e4dd76 100644 --- a/tests/HomePage.test.tsx +++ b/tests/HomePage.test.tsx @@ -14,7 +14,7 @@ jest.mock('../db.ts', () => ({ }, })) -it('renders correctly', async () => { +test('renders correctly', async () => { const {getByText} = render( diff --git a/tests/PlanPage.test.tsx b/tests/PlanPage.test.tsx index 9ee7f31..02496b7 100644 --- a/tests/PlanPage.test.tsx +++ b/tests/PlanPage.test.tsx @@ -14,7 +14,7 @@ jest.mock('../db.ts', () => ({ }, })) -it('renders correctly', async () => { +test('renders correctly', async () => { const {getByText} = render( diff --git a/tests/SettingsPage.test.tsx b/tests/SettingsPage.test.tsx index 9b189a3..16afc62 100644 --- a/tests/SettingsPage.test.tsx +++ b/tests/SettingsPage.test.tsx @@ -14,7 +14,7 @@ jest.mock('../db.ts', () => ({ }, })) -it('renders correctly', async () => { +test('renders correctly', async () => { const {getByText, getAllByText} = render( diff --git a/tests/StartPlan.test.tsx b/tests/StartPlan.test.tsx index 7de29f2..12eaa74 100644 --- a/tests/StartPlan.test.tsx +++ b/tests/StartPlan.test.tsx @@ -43,7 +43,7 @@ jest.mock('../data-source.ts', () => ({ }, })) -it('renders correctly', async () => { +test('renders correctly', async () => { const Stack = createStackNavigator() const {getByText, getAllByText} = render( @@ -73,7 +73,7 @@ it('renders correctly', async () => { expect(getAllByText('Save').length).toBeGreaterThan(0) }) -it('saves', async () => { +test('saves', async () => { const Stack = createStackNavigator() const {getByText} = render( diff --git a/tests/TimerPage.test.tsx b/tests/TimerPage.test.tsx index 2bb532f..b4eed8a 100644 --- a/tests/TimerPage.test.tsx +++ b/tests/TimerPage.test.tsx @@ -14,7 +14,7 @@ jest.mock('../db.ts', () => ({ }, })) -it('renders correctly', async () => { +test('renders correctly', async () => { const {getByText} = render( diff --git a/tests/WorkoutsPage.test.tsx b/tests/WorkoutsPage.test.tsx index 356a704..378c0d8 100644 --- a/tests/WorkoutsPage.test.tsx +++ b/tests/WorkoutsPage.test.tsx @@ -14,7 +14,7 @@ jest.mock('../db.ts', () => ({ }, })) -it('renders correctly', async () => { +test('renders correctly', async () => { const {getByText} = render(