From 8e8961419c1e9ab022d9f9bdfbf080ed7ccb842d Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Thu, 5 Jan 2023 17:15:16 +1300 Subject: [PATCH] Add plan list unit tests --- tests/PlanList.test.tsx | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/PlanList.test.tsx diff --git a/tests/PlanList.test.tsx b/tests/PlanList.test.tsx new file mode 100644 index 0000000..0a94ee1 --- /dev/null +++ b/tests/PlanList.test.tsx @@ -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( + + + , + ) + const title = await waitFor(() => getByText('Plans')) + expect(title).toBeDefined() +}) + +test('adds', async () => { + const {getByTestId, getByText} = render( + + + , + ) + fireEvent.press(await waitFor(() => getByTestId('add'))) + expect(await waitFor(() => getByText('Edit plan'))).toBeDefined() +})