From 46dd50adfb949883c23bcb54e5a0e19072aaa5b4 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Fri, 30 Dec 2022 13:25:47 +1300 Subject: [PATCH] Pause adding unit tests --- SetList.tsx | 3 +++ StartPlan.tsx | 3 +-- jestSetup.ts | 10 ++++---- package.json | 1 + tests/HomePage.test.tsx | 57 +++++++++++++++++++++++++++++++++++++++++ yarn.lock | 15 ++++++++++- 6 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 tests/HomePage.test.tsx diff --git a/SetList.tsx b/SetList.tsx index 9378c70..d7a5498 100644 --- a/SetList.tsx +++ b/SetList.tsx @@ -27,7 +27,10 @@ export default function SetList() { const [ids, setIds] = useState([]) const navigation = useNavigation>() + console.log('Rendered SetList') + const refresh = useCallback(async (value: string) => { + console.log('Getting sets...') const newSets = await setRepo.find({ where: {name: Like(`%${value}%`), hidden: 0 as any}, take: limit, diff --git a/StartPlan.tsx b/StartPlan.tsx index 6d9fa34..52af346 100644 --- a/StartPlan.tsx +++ b/StartPlan.tsx @@ -1,7 +1,6 @@ import {RouteProp, useFocusEffect, useRoute} from '@react-navigation/native' import {useCallback, useMemo, useRef, useState} from 'react' -import {NativeModules, TextInput, View} from 'react-native' -import {FlatList} from 'react-native-gesture-handler' +import {FlatList, NativeModules, TextInput, View} from 'react-native' import {Button, ProgressBar} from 'react-native-paper' import {getBestSet} from './best.service' import {PADDING} from './constants' diff --git a/jestSetup.ts b/jestSetup.ts index a58c006..5cf80af 100644 --- a/jestSetup.ts +++ b/jestSetup.ts @@ -9,8 +9,8 @@ jest.mock('react-native-file-access', () => jest.fn()) jest.mock('react-native-share', () => jest.fn()) jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper') jest.useFakeTimers() -jest.mock('react-native-reanimated', () => { - const Reanimated = require('react-native-reanimated/mock') - Reanimated.default.call = () => {} - return Reanimated -}) +//jest.mock('react-native-reanimated', () => { +// const Reanimated = require('react-native-reanimated/mock') +// Reanimated.default.call = () => {} +// return Reanimated +//}) diff --git a/package.json b/package.json index f17af21..5d5de6e 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "@typescript-eslint/parser": "^5.29.0", "eslint": "^8.26.0", "metro-react-native-babel-preset": "^0.73.3", + "react-native-testing-library": "^6.0.0", "typescript": "^4.8.4" }, "eslintConfig": { diff --git a/tests/HomePage.test.tsx b/tests/HomePage.test.tsx new file mode 100644 index 0000000..5e37f22 --- /dev/null +++ b/tests/HomePage.test.tsx @@ -0,0 +1,57 @@ +import 'react-native' +import React from 'react' +import {render} from 'react-native-testing-library' +import HomePage from '../HomePage' +import {NavigationContainer} from '@react-navigation/native' +import {Provider} from 'react-native-paper' +import MaterialIcon from 'react-native-vector-icons/MaterialIcons' +import SetList from '../SetList' +import {Text} from 'react-native' +import {AppDataSource} from '../data-source' + +jest.mock('typeorm', () => ({ + createConnection: jest.fn(() => ({ + close: jest.fn(), + })), + Entity: (name: string) => { + return (target: any) => { + target.name = name + } + }, + Column: (type: any) => { + return (target: any, propertyName: string) => { + target.columns = target.columns || [] + target.columns.push({ + propertyName, + type, + }) + } + }, + PrimaryColumn: () => { + return (target: any, propertyName: string) => { + target.primaryColumn = { + propertyName, + } + } + }, + PrimaryGeneratedColumn: () => { + return (target: any, propertyName: string) => { + target.primaryColumn = { + propertyName, + } + } + }, +})) + +describe('HomePage', () => { + it('renders correctly', async () => { + const {getByText} = render( + }}> + + + + , + ) + expect(getByText('Home')).toBeDefined() + }) +}) diff --git a/yarn.lock b/yarn.lock index 6259514..2b25a91 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7309,6 +7309,7 @@ __metadata: react-native-sqlite-storage: ^6.0.1 react-native-svg: ^13.4.0 react-native-svg-charts: ^5.4.0 + react-native-testing-library: ^6.0.0 react-native-vector-icons: ^9.2.0 react-native-view-shot: ^3.4.0 react-test-renderer: ^18.2.0 @@ -8612,7 +8613,7 @@ __metadata: languageName: node linkType: hard -"pretty-format@npm:^26.5.2, pretty-format@npm:^26.6.2": +"pretty-format@npm:^26.0.1, pretty-format@npm:^26.5.2, pretty-format@npm:^26.6.2": version: 26.6.2 resolution: "pretty-format@npm:26.6.2" dependencies: @@ -8980,6 +8981,18 @@ __metadata: languageName: node linkType: hard +"react-native-testing-library@npm:^6.0.0": + version: 6.0.0 + resolution: "react-native-testing-library@npm:6.0.0" + dependencies: + pretty-format: ^26.0.1 + peerDependencies: + react: ">=16.0.0" + react-test-renderer: ">=16.0.0" + checksum: 291c0e54f29e68733ec73a9ec201991a3ad7d14a8b624ce8e69fdd9306d63198511882a56d8d4ea40349c7a48468fc6eba5cf5043397cbe9974dd9fcd3d37e6a + languageName: node + linkType: hard + "react-native-vector-icons@npm:^9.2.0": version: 9.2.0 resolution: "react-native-vector-icons@npm:9.2.0"