Skip to content

Commit

Permalink
updated tests and linting
Browse files Browse the repository at this point in the history
Signed-off-by: wadeking98 <[email protected]>
  • Loading branch information
wadeking98 committed Dec 12, 2023
1 parent 7db948c commit 456d7f7
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 38 deletions.
8 changes: 3 additions & 5 deletions packages/legacy/core/App/components/misc/NewQRView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { StackScreenProps } from '@react-navigation/stack'
import React, { useCallback, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Vibration, View, StyleSheet, Text, ScrollView, useWindowDimensions } from 'react-native'
import { BarCodeReadEvent, RNCamera } from 'react-native-camera'
import { TouchableOpacity } from 'react-native-gesture-handler'
import { SafeAreaView } from 'react-native-safe-area-context'
import Icon from 'react-native-vector-icons/MaterialIcons'
import { Camera, Code, useCameraDevice, useCodeScanner } from 'react-native-vision-camera'

import { useStore } from '../../contexts/store'
import { useTheme } from '../../contexts/theme'
Expand All @@ -21,7 +21,6 @@ import LoadingIndicator from '../animated/LoadingIndicator'
import QRRenderer from './QRRenderer'
import QRScannerTorch from './QRScannerTorch'
import ScanTab from './ScanTab'
import { Camera, Code, useCameraDevice, useCodeScanner } from 'react-native-vision-camera'

type ConnectProps = StackScreenProps<ConnectStackParams>

Expand Down Expand Up @@ -221,8 +220,7 @@ const NewQRView: React.FC<Props> = ({ defaultToConnect, handleCodeScan, error, e
</View>
</View>
</ScrollView>
)
}
)}

<View style={styles.tabContainer}>
<ScanTab
Expand All @@ -238,7 +236,7 @@ const NewQRView: React.FC<Props> = ({ defaultToConnect, handleCodeScan, error, e
active={!firstTabActive}
/>
</View>
</SafeAreaView >
</SafeAreaView>
)
}

Expand Down
7 changes: 2 additions & 5 deletions packages/legacy/core/App/components/misc/QRScanner.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useNavigation } from '@react-navigation/core'
import React, { useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { View, Modal, Vibration, Pressable, StyleSheet, Text, PermissionsAndroid } from 'react-native'
import { BarCodeReadEvent, RNCamera } from 'react-native-camera'
import { View, Modal, Vibration, Pressable, StyleSheet, Text } from 'react-native'
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
import { Camera, Code, useCameraDevice, useCodeScanner } from 'react-native-vision-camera'

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

import QRScannerTorch from './QRScannerTorch'

import { Camera, Code, useCameraDevice, useCameraPermission, useCodeScanner } from 'react-native-vision-camera'

interface Props {
handleCodeScan: (value: string) => Promise<void>
error?: QrCodeScanError | null
Expand All @@ -32,7 +30,6 @@ const QRScanner: React.FC<Props> = ({ handleCodeScan, error, enableCameraOnError
const { t } = useTranslation()
const invalidQrCodes = new Set<string>()
const { ColorPallet, TextTheme } = useTheme()
const { hasPermission, requestPermission } = useCameraPermission()
const device = useCameraDevice('back')

const styles = StyleSheet.create({
Expand Down
8 changes: 5 additions & 3 deletions packages/legacy/core/App/screens/Scan.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { BarCodeReadEvent } from 'react-native-camera'

import { useAgent } from '@aries-framework/react-hooks'
import { StackScreenProps } from '@react-navigation/stack'
import React, { useState, useEffect } from 'react'
Expand Down Expand Up @@ -106,7 +104,11 @@ const Scan: React.FC<ScanProps> = ({ navigation, route }) => {
}
}

const permissionFlow = async (method: PermissionContract, permission: Permission, rationale?: Rationale): Promise<boolean> => {
const permissionFlow = async (
method: PermissionContract,
permission: Permission,
rationale?: Rationale
): Promise<boolean> => {
try {
const permissionResult = await method(permission, rationale)
if (permissionResult === RESULTS.GRANTED) {
Expand Down
37 changes: 14 additions & 23 deletions packages/legacy/core/__mocks__/custom/react-native-camera.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
import React from 'react';

const Constants = {
Aspect: {},
BarCodeType: {},
Type: {},
CaptureMode: {},
CaptureTarget: {},
CaptureQuality: {},
Orientation: {},
FlashMode: {
on:'on',
off:'off',
torch:'torch',
auto: 'auto'
},
TorchMode: {}
};
device: {},
torch: {
on: 'on',
off: 'off',
auto: 'auto',
},
isActive: false,
codeScanner: {}
};

class RNCamera extends React.Component {
class Camera extends React.Component {
static Constants = Constants
render() {
return null;
}
}

interface BarCodeReadEvent {
data: string;
}
RNCamera.Constants = Constants

export { RNCamera };
export type { BarCodeReadEvent };
Camera.Constants = Constants
const useCameraDevice = jest.fn();
const useCodeScanner = jest.fn();
export { Camera, useCameraDevice, useCodeScanner };
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jest.mock('@react-navigation/native', () => {
return require('../../__mocks__/custom/@react-navigation/native')
})

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,143 @@ exports[`NewQRView Component Renders correctly on first tab 1`] = `
}
}
>
<View
style={
Object {
"alignItems": "center",
"flex": 1,
"width": "100%",
}
}
>
<View
style={
Object {
"alignItems": "center",
"flexDirection": "row",
"marginTop": 20,
"paddingHorizontal": 20,
}
}
>
<Text
style={
Array [
Object {
"color": "#FFFFFF",
"fontSize": 18,
"fontWeight": "normal",
},
Object {
"color": "#FFFFFF",
},
]
}
>
Scan.WillScanAutomatically
</Text>
</View>
<View
style={
Object {
"alignItems": "center",
"flex": 1,
"justifyContent": "center",
"width": "100%",
}
}
>
<View
style={
Object {
"borderColor": "#FFFFFF",
"borderRadius": 24,
"borderWidth": 2,
"height": 250,
"width": 250,
}
}
/>
</View>
<View
accessibilityLabel="Scan.Torch"
accessibilityRole="button"
accessibilityState={
Object {
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
Object {
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
focusable={true}
hitSlop={
Object {
"bottom": 44,
"left": 44,
"right": 44,
"top": 44,
}
}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"alignItems": "center",
"backgroundColor": undefined,
"borderColor": "#FFFFFF",
"borderRadius": 24,
"borderWidth": 1,
"height": 24,
"justifyContent": "center",
"marginBottom": 50,
"opacity": 1,
"width": 24,
}
}
testID="com.ariesbifold:id/ScanTorch"
>
<Text
allowFontScaling={false}
selectable={false}
style={
Array [
Object {
"color": "#FFFFFF",
"fontSize": 24,
},
Object {
"alignItems": "center",
},
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
"fontWeight": "normal",
},
Object {},
]
}
>
</Text>
</View>
</View>
<View
style={
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jest.mock('@hyperledger/anoncreds-react-native', () => ({}))
jest.mock('@hyperledger/aries-askar-react-native', () => ({}))
jest.mock('@hyperledger/indy-vdr-react-native', () => ({}))
jest.mock('react-native-permissions', () => require('react-native-permissions/mock'))
jest.mock('react-native-vision-camera', () => {
return require('../../__mocks__/custom/react-native-camera')
})
jest.mock('react-native-device-info', () => {
return {
getVersion: () => 1,
Expand Down
3 changes: 3 additions & 0 deletions packages/legacy/core/__tests__/screens/NameWallet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jest.mock('@hyperledger/anoncreds-react-native', () => ({}))
jest.mock('@hyperledger/aries-askar-react-native', () => ({}))
jest.mock('@hyperledger/indy-vdr-react-native', () => ({}))
jest.mock('react-native-permissions', () => require('react-native-permissions/mock'))
jest.mock('react-native-vision-camera', () => {
return require('../../__mocks__/custom/react-native-camera')
})

jest.mock('react-native-device-info', () => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jest.mock('react-native-fs', () => ({}))
jest.mock('@react-navigation/native', () => {
return require('../../__mocks__/custom/@react-navigation/native')
})
jest.mock('react-native-vision-camera', () => {
return require('../../__mocks__/custom/react-native-camera')
})
// eslint-disable-next-line @typescript-eslint/no-empty-function
jest.mock('react-native-localize', () => { })
jest.mock('react-native-device-info', () => () => jest.fn())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ jest.mock('@hyperledger/aries-bifold-verifier',() => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
jest.mock('react-native-localize', () => {})
jest.mock('react-native-device-info', () => () => jest.fn())
jest.mock('react-native-vision-camera', () => {
return require('../../__mocks__/custom/react-native-camera')
})

jest.useFakeTimers({ legacyFakeTimers: true })
jest.spyOn(global, 'setTimeout')
Expand Down
2 changes: 1 addition & 1 deletion packages/legacy/core/__tests__/screens/Scan.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jest.mock('@react-navigation/native', () => {
return require('../../__mocks__/custom/@react-navigation/native')
})

jest.mock('react-native-camera', () => {
jest.mock('react-native-vision-camera', () => {
return require('../../__mocks__/custom/react-native-camera')
})
jest.mock('../../App/contexts/configuration', () => ({
Expand Down
3 changes: 3 additions & 0 deletions packages/legacy/core/__tests__/screens/Settings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jest.mock('@hyperledger/anoncreds-react-native', () => ({}))
jest.mock('@hyperledger/aries-askar-react-native', () => ({}))
jest.mock('@hyperledger/indy-vdr-react-native', () => ({}))
jest.mock('react-native-permissions', () => require('react-native-permissions/mock'))
jest.mock('react-native-vision-camera', () => {
return require('../../__mocks__/custom/react-native-camera')
})

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

0 comments on commit 456d7f7

Please sign in to comment.