Skip to content

Commit 456d7f7

Browse files
committed
updated tests and linting
Signed-off-by: wadeking98 <[email protected]>
1 parent 7db948c commit 456d7f7

File tree

12 files changed

+178
-38
lines changed

12 files changed

+178
-38
lines changed

packages/legacy/core/App/components/misc/NewQRView.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { StackScreenProps } from '@react-navigation/stack'
44
import React, { useCallback, useEffect, useState } from 'react'
55
import { useTranslation } from 'react-i18next'
66
import { Vibration, View, StyleSheet, Text, ScrollView, useWindowDimensions } from 'react-native'
7-
import { BarCodeReadEvent, RNCamera } from 'react-native-camera'
87
import { TouchableOpacity } from 'react-native-gesture-handler'
98
import { SafeAreaView } from 'react-native-safe-area-context'
109
import Icon from 'react-native-vector-icons/MaterialIcons'
10+
import { Camera, Code, useCameraDevice, useCodeScanner } from 'react-native-vision-camera'
1111

1212
import { useStore } from '../../contexts/store'
1313
import { useTheme } from '../../contexts/theme'
@@ -21,7 +21,6 @@ import LoadingIndicator from '../animated/LoadingIndicator'
2121
import QRRenderer from './QRRenderer'
2222
import QRScannerTorch from './QRScannerTorch'
2323
import ScanTab from './ScanTab'
24-
import { Camera, Code, useCameraDevice, useCodeScanner } from 'react-native-vision-camera'
2524

2625
type ConnectProps = StackScreenProps<ConnectStackParams>
2726

@@ -221,8 +220,7 @@ const NewQRView: React.FC<Props> = ({ defaultToConnect, handleCodeScan, error, e
221220
</View>
222221
</View>
223222
</ScrollView>
224-
)
225-
}
223+
)}
226224

227225
<View style={styles.tabContainer}>
228226
<ScanTab
@@ -238,7 +236,7 @@ const NewQRView: React.FC<Props> = ({ defaultToConnect, handleCodeScan, error, e
238236
active={!firstTabActive}
239237
/>
240238
</View>
241-
</SafeAreaView >
239+
</SafeAreaView>
242240
)
243241
}
244242

packages/legacy/core/App/components/misc/QRScanner.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useNavigation } from '@react-navigation/core'
22
import React, { useCallback, useState } from 'react'
33
import { useTranslation } from 'react-i18next'
4-
import { View, Modal, Vibration, Pressable, StyleSheet, Text, PermissionsAndroid } from 'react-native'
5-
import { BarCodeReadEvent, RNCamera } from 'react-native-camera'
4+
import { View, Modal, Vibration, Pressable, StyleSheet, Text } from 'react-native'
65
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
6+
import { Camera, Code, useCameraDevice, useCodeScanner } from 'react-native-vision-camera'
77

88
import { hitSlop } from '../../constants'
99
import { useConfiguration } from '../../contexts/configuration'
@@ -15,8 +15,6 @@ import InfoBox, { InfoBoxType } from '../misc/InfoBox'
1515

1616
import QRScannerTorch from './QRScannerTorch'
1717

18-
import { Camera, Code, useCameraDevice, useCameraPermission, useCodeScanner } from 'react-native-vision-camera'
19-
2018
interface Props {
2119
handleCodeScan: (value: string) => Promise<void>
2220
error?: QrCodeScanError | null
@@ -32,7 +30,6 @@ const QRScanner: React.FC<Props> = ({ handleCodeScan, error, enableCameraOnError
3230
const { t } = useTranslation()
3331
const invalidQrCodes = new Set<string>()
3432
const { ColorPallet, TextTheme } = useTheme()
35-
const { hasPermission, requestPermission } = useCameraPermission()
3633
const device = useCameraDevice('back')
3734

3835
const styles = StyleSheet.create({

packages/legacy/core/App/screens/Scan.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { BarCodeReadEvent } from 'react-native-camera'
2-
31
import { useAgent } from '@aries-framework/react-hooks'
42
import { StackScreenProps } from '@react-navigation/stack'
53
import React, { useState, useEffect } from 'react'
@@ -106,7 +104,11 @@ const Scan: React.FC<ScanProps> = ({ navigation, route }) => {
106104
}
107105
}
108106

109-
const permissionFlow = async (method: PermissionContract, permission: Permission, rationale?: Rationale): Promise<boolean> => {
107+
const permissionFlow = async (
108+
method: PermissionContract,
109+
permission: Permission,
110+
rationale?: Rationale
111+
): Promise<boolean> => {
110112
try {
111113
const permissionResult = await method(permission, rationale)
112114
if (permissionResult === RESULTS.GRANTED) {
Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
11
import React from 'react';
22

33
const Constants = {
4-
Aspect: {},
5-
BarCodeType: {},
6-
Type: {},
7-
CaptureMode: {},
8-
CaptureTarget: {},
9-
CaptureQuality: {},
10-
Orientation: {},
11-
FlashMode: {
12-
on:'on',
13-
off:'off',
14-
torch:'torch',
15-
auto: 'auto'
16-
},
17-
TorchMode: {}
18-
};
4+
device: {},
5+
torch: {
6+
on: 'on',
7+
off: 'off',
8+
auto: 'auto',
9+
},
10+
isActive: false,
11+
codeScanner: {}
12+
};
1913

20-
class RNCamera extends React.Component {
14+
class Camera extends React.Component {
2115
static Constants = Constants
2216
render() {
2317
return null;
2418
}
2519
}
2620

27-
interface BarCodeReadEvent {
28-
data: string;
29-
}
30-
RNCamera.Constants = Constants
31-
32-
export { RNCamera };
33-
export type { BarCodeReadEvent };
21+
Camera.Constants = Constants
22+
const useCameraDevice = jest.fn();
23+
const useCodeScanner = jest.fn();
24+
export { Camera, useCameraDevice, useCodeScanner };

packages/legacy/core/__tests__/components/NewQRView.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jest.mock('@react-navigation/native', () => {
1717
return require('../../__mocks__/custom/@react-navigation/native')
1818
})
1919

20-
jest.mock('react-native-camera', () => {
20+
jest.mock('react-native-vision-camera', () => {
2121
return require('../../__mocks__/custom/react-native-camera')
2222
})
2323

packages/legacy/core/__tests__/components/__snapshots__/NewQRView.test.tsx.snap

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,143 @@ exports[`NewQRView Component Renders correctly on first tab 1`] = `
1616
}
1717
}
1818
>
19+
<View
20+
style={
21+
Object {
22+
"alignItems": "center",
23+
"flex": 1,
24+
"width": "100%",
25+
}
26+
}
27+
>
28+
<View
29+
style={
30+
Object {
31+
"alignItems": "center",
32+
"flexDirection": "row",
33+
"marginTop": 20,
34+
"paddingHorizontal": 20,
35+
}
36+
}
37+
>
38+
<Text
39+
style={
40+
Array [
41+
Object {
42+
"color": "#FFFFFF",
43+
"fontSize": 18,
44+
"fontWeight": "normal",
45+
},
46+
Object {
47+
"color": "#FFFFFF",
48+
},
49+
]
50+
}
51+
>
52+
Scan.WillScanAutomatically
53+
</Text>
54+
</View>
55+
<View
56+
style={
57+
Object {
58+
"alignItems": "center",
59+
"flex": 1,
60+
"justifyContent": "center",
61+
"width": "100%",
62+
}
63+
}
64+
>
65+
<View
66+
style={
67+
Object {
68+
"borderColor": "#FFFFFF",
69+
"borderRadius": 24,
70+
"borderWidth": 2,
71+
"height": 250,
72+
"width": 250,
73+
}
74+
}
75+
/>
76+
</View>
77+
<View
78+
accessibilityLabel="Scan.Torch"
79+
accessibilityRole="button"
80+
accessibilityState={
81+
Object {
82+
"busy": undefined,
83+
"checked": undefined,
84+
"disabled": undefined,
85+
"expanded": undefined,
86+
"selected": undefined,
87+
}
88+
}
89+
accessibilityValue={
90+
Object {
91+
"max": undefined,
92+
"min": undefined,
93+
"now": undefined,
94+
"text": undefined,
95+
}
96+
}
97+
accessible={true}
98+
collapsable={false}
99+
focusable={true}
100+
hitSlop={
101+
Object {
102+
"bottom": 44,
103+
"left": 44,
104+
"right": 44,
105+
"top": 44,
106+
}
107+
}
108+
onClick={[Function]}
109+
onResponderGrant={[Function]}
110+
onResponderMove={[Function]}
111+
onResponderRelease={[Function]}
112+
onResponderTerminate={[Function]}
113+
onResponderTerminationRequest={[Function]}
114+
onStartShouldSetResponder={[Function]}
115+
style={
116+
Object {
117+
"alignItems": "center",
118+
"backgroundColor": undefined,
119+
"borderColor": "#FFFFFF",
120+
"borderRadius": 24,
121+
"borderWidth": 1,
122+
"height": 24,
123+
"justifyContent": "center",
124+
"marginBottom": 50,
125+
"opacity": 1,
126+
"width": 24,
127+
}
128+
}
129+
testID="com.ariesbifold:id/ScanTorch"
130+
>
131+
<Text
132+
allowFontScaling={false}
133+
selectable={false}
134+
style={
135+
Array [
136+
Object {
137+
"color": "#FFFFFF",
138+
"fontSize": 24,
139+
},
140+
Object {
141+
"alignItems": "center",
142+
},
143+
Object {
144+
"fontFamily": "Material Icons",
145+
"fontStyle": "normal",
146+
"fontWeight": "normal",
147+
},
148+
Object {},
149+
]
150+
}
151+
>
152+
153+
</Text>
154+
</View>
155+
</View>
19156
<View
20157
style={
21158
Object {

packages/legacy/core/__tests__/screens/ContactDetails.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jest.mock('@hyperledger/anoncreds-react-native', () => ({}))
2323
jest.mock('@hyperledger/aries-askar-react-native', () => ({}))
2424
jest.mock('@hyperledger/indy-vdr-react-native', () => ({}))
2525
jest.mock('react-native-permissions', () => require('react-native-permissions/mock'))
26+
jest.mock('react-native-vision-camera', () => {
27+
return require('../../__mocks__/custom/react-native-camera')
28+
})
2629
jest.mock('react-native-device-info', () => {
2730
return {
2831
getVersion: () => 1,

packages/legacy/core/__tests__/screens/NameWallet.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jest.mock('@hyperledger/anoncreds-react-native', () => ({}))
1919
jest.mock('@hyperledger/aries-askar-react-native', () => ({}))
2020
jest.mock('@hyperledger/indy-vdr-react-native', () => ({}))
2121
jest.mock('react-native-permissions', () => require('react-native-permissions/mock'))
22+
jest.mock('react-native-vision-camera', () => {
23+
return require('../../__mocks__/custom/react-native-camera')
24+
})
2225

2326
jest.mock('react-native-device-info', () => {
2427
return {

packages/legacy/core/__tests__/screens/ProofRequestDetails.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jest.mock('react-native-fs', () => ({}))
2525
jest.mock('@react-navigation/native', () => {
2626
return require('../../__mocks__/custom/@react-navigation/native')
2727
})
28+
jest.mock('react-native-vision-camera', () => {
29+
return require('../../__mocks__/custom/react-native-camera')
30+
})
2831
// eslint-disable-next-line @typescript-eslint/no-empty-function
2932
jest.mock('react-native-localize', () => { })
3033
jest.mock('react-native-device-info', () => () => jest.fn())

packages/legacy/core/__tests__/screens/ProofRequesting.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ jest.mock('@hyperledger/aries-bifold-verifier',() => {
4444
// eslint-disable-next-line @typescript-eslint/no-empty-function
4545
jest.mock('react-native-localize', () => {})
4646
jest.mock('react-native-device-info', () => () => jest.fn())
47+
jest.mock('react-native-vision-camera', () => {
48+
return require('../../__mocks__/custom/react-native-camera')
49+
})
4750

4851
jest.useFakeTimers({ legacyFakeTimers: true })
4952
jest.spyOn(global, 'setTimeout')

packages/legacy/core/__tests__/screens/Scan.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jest.mock('@react-navigation/native', () => {
1212
return require('../../__mocks__/custom/@react-navigation/native')
1313
})
1414

15-
jest.mock('react-native-camera', () => {
15+
jest.mock('react-native-vision-camera', () => {
1616
return require('../../__mocks__/custom/react-native-camera')
1717
})
1818
jest.mock('../../App/contexts/configuration', () => ({

packages/legacy/core/__tests__/screens/Settings.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jest.mock('@hyperledger/anoncreds-react-native', () => ({}))
2020
jest.mock('@hyperledger/aries-askar-react-native', () => ({}))
2121
jest.mock('@hyperledger/indy-vdr-react-native', () => ({}))
2222
jest.mock('react-native-permissions', () => require('react-native-permissions/mock'))
23+
jest.mock('react-native-vision-camera', () => {
24+
return require('../../__mocks__/custom/react-native-camera')
25+
})
2326

2427
jest.mock('react-native-device-info', () => {
2528
return {

0 commit comments

Comments
 (0)