@tarojs/taro-rn 4.0.1-alpha.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +8 -8
- package/apiList.js +31 -31
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/lib/Mask.js +2 -2
- package/dist/lib/Mask.js.map +1 -1
- package/dist/lib/Popup.js +13 -20
- package/dist/lib/Popup.js.map +1 -1
- package/dist/lib/StyleSheet.js +1 -1
- package/dist/lib/StyleSheet.js.map +1 -1
- package/dist/lib/accelerometer.js +1 -1
- package/dist/lib/accelerometer.js.map +1 -1
- package/dist/lib/chooseImage/index.js +151 -3
- package/dist/lib/chooseImage/index.js.map +1 -1
- package/dist/lib/chooseVideo/index.js +55 -1
- package/dist/lib/chooseVideo/index.js.map +1 -1
- package/dist/lib/clearStorage/index.js +2 -2
- package/dist/lib/clearStorage/index.js.map +1 -1
- package/dist/lib/compressImage/index.js +1 -1
- package/dist/lib/compressImage/index.js.map +1 -1
- package/dist/lib/connectSocket/index.js.map +1 -1
- package/dist/lib/connectSocket/socketTask.js +1 -1
- package/dist/lib/connectSocket/socketTask.js.map +1 -1
- package/dist/lib/createCameraContext/index.js +3 -3
- package/dist/lib/createCameraContext/index.js.map +1 -1
- package/dist/lib/createInnerAudioContext/index.js +2 -2
- package/dist/lib/createInnerAudioContext/index.js.map +1 -1
- package/dist/lib/createVideoContext/index.js +7 -7
- package/dist/lib/createVideoContext/index.js.map +1 -1
- package/dist/lib/deviceMotion.js +2 -2
- package/dist/lib/deviceMotion.js.map +1 -1
- package/dist/lib/file.js +4 -4
- package/dist/lib/file.js.map +1 -1
- package/dist/lib/getAppBaseInfo/index.js +2 -2
- package/dist/lib/getAppBaseInfo/index.js.map +1 -1
- package/dist/lib/getClipboardData/index.js.map +1 -1
- package/dist/lib/getImageInfo/index.js +2 -2
- package/dist/lib/getImageInfo/index.js.map +1 -1
- package/dist/lib/getLocation/index.js +4 -8
- package/dist/lib/getLocation/index.js.map +1 -1
- package/dist/lib/getRecorderManager/index.js +6 -11
- package/dist/lib/getRecorderManager/index.js.map +1 -1
- package/dist/lib/getStorage/index.js.map +1 -1
- package/dist/lib/getStorageInfo/index.js +2 -2
- package/dist/lib/getStorageInfo/index.js.map +1 -1
- package/dist/lib/getSystemInfo/index.js +1 -1
- package/dist/lib/getSystemInfo/index.js.map +1 -1
- package/dist/lib/getSystemInfoSync/index.js +2 -2
- package/dist/lib/getSystemInfoSync/index.js.map +1 -1
- package/dist/lib/gyroscope.js +1 -1
- package/dist/lib/gyroscope.js.map +1 -1
- package/dist/lib/index.js +0 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/keyboard.js +3 -3
- package/dist/lib/keyboard.js.map +1 -1
- package/dist/lib/location.js.map +1 -1
- package/dist/lib/makePhoneCall/index.js +1 -1
- package/dist/lib/makePhoneCall/index.js.map +1 -1
- package/dist/lib/media.js +30 -61
- package/dist/lib/media.js.map +1 -1
- package/dist/lib/network.js +1 -1
- package/dist/lib/network.js.map +1 -1
- package/dist/lib/offWindowResize/index.js.map +1 -1
- package/dist/lib/onWindowResize/index.js +1 -1
- package/dist/lib/onWindowResize/index.js.map +1 -1
- package/dist/lib/openUrl/index.js +1 -1
- package/dist/lib/openUrl/index.js.map +1 -1
- package/dist/lib/permission.js +5 -6
- package/dist/lib/permission.js.map +1 -1
- package/dist/lib/previewImage/index.js +3 -3
- package/dist/lib/previewImage/index.js.map +1 -1
- package/dist/lib/request/index.js +1 -1
- package/dist/lib/request/index.js.map +1 -1
- package/dist/lib/scanCode/index.js +23 -23
- package/dist/lib/scanCode/index.js.map +1 -1
- package/dist/lib/screen.js +2 -2
- package/dist/lib/screen.js.map +1 -1
- package/dist/lib/setClipboardData/index.js +2 -2
- package/dist/lib/setClipboardData/index.js.map +1 -1
- package/dist/lib/setKeepScreenOn/index.js +1 -1
- package/dist/lib/setKeepScreenOn/index.js.map +1 -1
- package/dist/lib/setStorage/index.js.map +1 -1
- package/dist/lib/showActionSheet/ActionSheet.js +23 -11
- package/dist/lib/showActionSheet/ActionSheet.js.map +1 -1
- package/dist/lib/showActionSheet/index.js +24 -10
- package/dist/lib/showActionSheet/index.js.map +1 -1
- package/dist/lib/showModal/Dialog.js +36 -22
- package/dist/lib/showModal/Dialog.js.map +1 -1
- package/dist/lib/showModal/index.js.map +1 -1
- package/dist/lib/showModal/toast.js +6 -6
- package/dist/lib/showModal/toast.js.map +1 -1
- package/dist/lib/unsupportedApi.js +4 -2
- package/dist/lib/unsupportedApi.js.map +1 -1
- package/dist/lib/variable.js +1 -1
- package/dist/lib/variable.js.map +1 -1
- package/dist/lib/vibrate.js +1 -1
- package/dist/lib/vibrate.js.map +1 -1
- package/dist/lib/window.js.map +1 -1
- package/dist/setup.js +75 -0
- package/dist/setup.js.map +1 -0
- package/dist/utils/callbackManager.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/libList.js +0 -1
- package/package.json +69 -70
- package/src/__tests__/__mock__/mockAsyncStorage.js +47 -0
- package/src/__tests__/__mock__/mockClipboard.js +15 -0
- package/src/__tests__/__mock__/mockNavigator.js +20 -0
- package/src/__tests__/__mock__/mockNetwork.js +59 -0
- package/src/__tests__/__mock__/mockRNCCameraRoll.js +16 -0
- package/src/__tests__/__mock__/mockRNCGeolocation.js +13 -0
- package/src/__tests__/__mock__/mockVibrate.js +6 -0
- package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +125 -0
- package/src/__tests__/clipboard.test.ts +88 -0
- package/src/__tests__/deviceMotion.test.ts +37 -0
- package/src/__tests__/geolocation.test.ts +60 -0
- package/src/__tests__/interactive.test.tsx +101 -0
- package/src/__tests__/keyboard.test.ts +46 -0
- package/src/__tests__/media.test.ts +104 -0
- package/src/__tests__/network.test.ts +57 -0
- package/src/__tests__/others.test.ts +25 -0
- package/src/__tests__/phone.test.ts +31 -0
- package/src/__tests__/request.test.ts +146 -0
- package/src/__tests__/scanCode.test.tsx +14 -0
- package/src/__tests__/storage.test.ts +202 -0
- package/src/__tests__/system.test.ts +69 -0
- package/src/__tests__/vibrate.test.ts +27 -0
- package/src/__tests__/websocket.test.ts +169 -0
- package/src/api/index.ts +31 -31
- package/src/lib/ENV_TYPE/index.ts +1 -1
- package/src/lib/Mask.tsx +2 -2
- package/src/lib/Popup.tsx +19 -26
- package/src/lib/StyleSheet.ts +1 -1
- package/src/lib/accelerometer.ts +1 -2
- package/src/lib/arrayBufferToBase64/index.ts +1 -1
- package/src/lib/base64ToArrayBuffer/index.ts +1 -1
- package/src/lib/chooseImage/index.ts +155 -3
- package/src/lib/chooseVideo/index.ts +56 -1
- package/src/lib/clearStorage/index.ts +0 -1
- package/src/lib/clearStorageSync/index.ts +1 -1
- package/src/lib/compressImage/index.ts +0 -1
- package/src/lib/connectSocket/socketTask.ts +9 -7
- package/src/lib/createCameraContext/index.ts +4 -6
- package/src/lib/createInnerAudioContext/index.ts +0 -1
- package/src/lib/createSelectorQuery/index.ts +1 -1
- package/src/lib/deviceMotion.ts +3 -4
- package/src/lib/file.ts +8 -9
- package/src/lib/getClipboardData/index.ts +0 -1
- package/src/lib/getEnv/index.ts +1 -1
- package/src/lib/getFileSystemManager/index.ts +1 -1
- package/src/lib/getLocation/index.ts +2 -7
- package/src/lib/getRecorderManager/index.ts +2 -7
- package/src/lib/getStorage/index.ts +0 -1
- package/src/lib/getStorageInfo/index.ts +0 -1
- package/src/lib/getStorageInfoSync/index.ts +1 -1
- package/src/lib/getStorageSync/index.ts +1 -1
- package/src/lib/getSystemInfo/index.ts +2 -2
- package/src/lib/getSystemInfoSync/index.ts +3 -3
- package/src/lib/gyroscope.ts +46 -47
- package/src/lib/index.ts +0 -1
- package/src/lib/keyboard.ts +4 -5
- package/src/lib/location.ts +5 -6
- package/src/lib/makePhoneCall/index.ts +1 -2
- package/src/lib/media.ts +31 -83
- package/src/lib/network.ts +5 -5
- package/src/lib/offLocationChange/index.ts +1 -1
- package/src/lib/offUserCaptureScreen/index.ts +1 -1
- package/src/lib/onLocationChange/index.ts +1 -1
- package/src/lib/onUserCaptureScreen/index.ts +1 -1
- package/src/lib/onWindowResize/index.ts +2 -2
- package/src/lib/openUrl/index.d.ts +22 -23
- package/src/lib/openUrl/index.ts +1 -2
- package/src/lib/permission.ts +25 -33
- package/src/lib/previewImage/index.tsx +3 -4
- package/src/lib/removeStorageSync/index.ts +1 -1
- package/src/lib/request/index.ts +2 -2
- package/src/lib/scanCode/index.tsx +16 -18
- package/src/lib/screen.ts +0 -1
- package/src/lib/setClipboardData/index.ts +2 -3
- package/src/lib/setKeepScreenOn/index.ts +1 -2
- package/src/lib/setStorage/index.ts +0 -1
- package/src/lib/setStorageSync/index.ts +1 -1
- package/src/lib/showActionSheet/ActionSheet.tsx +43 -34
- package/src/lib/showActionSheet/index.tsx +36 -11
- package/src/lib/showModal/Dialog.tsx +39 -34
- package/src/lib/showModal/index.tsx +0 -1
- package/src/lib/showModal/toast.tsx +13 -14
- package/src/lib/startGyroscope/index.ts +1 -1
- package/src/lib/startLocationUpdate/index.ts +1 -1
- package/src/lib/unsupportedApi.ts +5 -3
- package/src/lib/vibrate.ts +10 -11
- package/src/lib/window.ts +2 -3
- package/src/setup.ts +84 -0
- package/{types → src/types}/vue/index.d.ts +3 -2
- package/src/utils/callbackManager.ts +5 -5
- package/src/utils/index.ts +4 -4
- package/dist/lib/chooseMedia/index.js +0 -19
- package/dist/lib/chooseMedia/index.js.map +0 -1
- package/src/lib/chooseMedia/index.ts +0 -15
- /package/{types → src/types}/definition.d.ts +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Text } from 'react-native'
|
|
3
|
+
import { render, fireEvent } from '@testing-library/react-native';
|
|
4
|
+
import ActionSheet from '../lib/showActionSheet/ActionSheet'
|
|
5
|
+
import Dialog from '../lib/showModal/Dialog'
|
|
6
|
+
import { Mask } from '../lib/Mask'
|
|
7
|
+
import { Popup } from '../lib/Popup'
|
|
8
|
+
|
|
9
|
+
describe('interactive', function () {
|
|
10
|
+
describe('showActionSheet', function () {
|
|
11
|
+
it('should call success callback', function () {
|
|
12
|
+
const onPress = jest.fn()
|
|
13
|
+
const { getByText, getAllByText } = render(<ActionSheet
|
|
14
|
+
autoDectect
|
|
15
|
+
type={'ios'}
|
|
16
|
+
visible
|
|
17
|
+
onClose={jest.fn()}
|
|
18
|
+
menus={['Option One', 'Option Two'].map((item) => {
|
|
19
|
+
return {
|
|
20
|
+
type: 'default',
|
|
21
|
+
label: item,
|
|
22
|
+
textStyle: { color: '#000000' },
|
|
23
|
+
onPress,
|
|
24
|
+
}
|
|
25
|
+
})}
|
|
26
|
+
actions={[
|
|
27
|
+
{
|
|
28
|
+
type: 'default',
|
|
29
|
+
label: 'cancel',
|
|
30
|
+
textStyle: { color: '#000000' },
|
|
31
|
+
onPress: jest.fn()
|
|
32
|
+
}
|
|
33
|
+
]}
|
|
34
|
+
/>)
|
|
35
|
+
expect(getAllByText('Option One')).toHaveLength(1)
|
|
36
|
+
expect(getAllByText('Option Two')).toHaveLength(1)
|
|
37
|
+
expect(getAllByText('cancel')).toHaveLength(1)
|
|
38
|
+
fireEvent.press(getByText('Option One'))
|
|
39
|
+
expect(onPress).toHaveBeenCalled();
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
describe('showModal', function () {
|
|
43
|
+
it('should render Dialog success', function () {
|
|
44
|
+
const { getByText } = render(<Dialog
|
|
45
|
+
visible
|
|
46
|
+
autoDectect
|
|
47
|
+
title='TITLE'
|
|
48
|
+
onClose={jest.fn()}
|
|
49
|
+
buttons={[
|
|
50
|
+
{
|
|
51
|
+
type: '#000000',
|
|
52
|
+
label: 'cancel',
|
|
53
|
+
onPress: jest.fn()
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: '#3CC51F',
|
|
57
|
+
label: 'confirm',
|
|
58
|
+
onPress: jest.fn()
|
|
59
|
+
}
|
|
60
|
+
].filter(Boolean)}
|
|
61
|
+
><Text>Test</Text></Dialog>)
|
|
62
|
+
expect(getByText('TITLE')).toHaveStyle({
|
|
63
|
+
fontSize: 18
|
|
64
|
+
})
|
|
65
|
+
expect(getByText('Test')).toHaveStyle({
|
|
66
|
+
fontSize: 15
|
|
67
|
+
})
|
|
68
|
+
expect(getByText('confirm')).toHaveStyle({
|
|
69
|
+
color: '#3CC51F'
|
|
70
|
+
})
|
|
71
|
+
expect(getByText('cancel')).toHaveStyle({
|
|
72
|
+
color: '#000000'
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
describe('Mask', () => {
|
|
77
|
+
it('should emit Mask event success', () => {
|
|
78
|
+
const onPress = jest.fn()
|
|
79
|
+
const { getByText, getByLabelText } = render(<Mask style={{ backgroundColor: 'red' }} onPress={onPress}><Text>Press me</Text></Mask>)
|
|
80
|
+
expect(getByLabelText('mask')).toHaveStyle({
|
|
81
|
+
backgroundColor: 'red'
|
|
82
|
+
})
|
|
83
|
+
fireEvent.press(getByText('Press me'));
|
|
84
|
+
expect(onPress).toHaveBeenCalled();
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
describe('Popup', () => {
|
|
88
|
+
it('should emit Popup event success', async () => {
|
|
89
|
+
const onShow = jest.fn()
|
|
90
|
+
const onClose = jest.fn()
|
|
91
|
+
const { getByText } = render(<Popup
|
|
92
|
+
visible
|
|
93
|
+
style={{ backgroundColor: 'red' }}
|
|
94
|
+
onShow={onShow}
|
|
95
|
+
onClose={onClose}
|
|
96
|
+
><Text>Press me</Text></Popup>)
|
|
97
|
+
fireEvent.press(getByText('Press me'));
|
|
98
|
+
expect(onClose).toHaveBeenCalled();
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
})
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DeviceEventEmitter } from 'react-native'
|
|
2
|
+
import * as Taro from '../lib/keyboard'
|
|
3
|
+
|
|
4
|
+
describe('keyboard', () => {
|
|
5
|
+
it('should hideKeyboard success', () => {
|
|
6
|
+
const success = jest.fn()
|
|
7
|
+
const fail = jest.fn()
|
|
8
|
+
const complete = jest.fn()
|
|
9
|
+
Taro.hideKeyboard({
|
|
10
|
+
success,
|
|
11
|
+
fail,
|
|
12
|
+
complete,
|
|
13
|
+
})
|
|
14
|
+
expect(success.mock.calls.length).toBe(1)
|
|
15
|
+
expect(fail.mock.calls.length).toBe(0)
|
|
16
|
+
expect(success.mock.calls.length).toBe(1)
|
|
17
|
+
})
|
|
18
|
+
it('should onKeyboardHeightChange success', () => {
|
|
19
|
+
expect.assertions(4)
|
|
20
|
+
const endCoordinates = { height: 200 }
|
|
21
|
+
const change = jest.fn().mockImplementation(({ height }) => expect(height).toBe(endCoordinates.height))
|
|
22
|
+
Taro.onKeyboardHeightChange(change)
|
|
23
|
+
DeviceEventEmitter.emit('keyboardDidShow', { endCoordinates })
|
|
24
|
+
expect(change.mock.calls.length).toBe(1)
|
|
25
|
+
endCoordinates.height = 0
|
|
26
|
+
DeviceEventEmitter.emit('keyboardDidHide', { endCoordinates })
|
|
27
|
+
expect(change.mock.calls.length).toBe(2)
|
|
28
|
+
Taro.offKeyboardHeightChange(change)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('should offKeyboardHeightChange success', () => {
|
|
32
|
+
expect.assertions(4)
|
|
33
|
+
const endCoordinates = { height: 200 }
|
|
34
|
+
const firstChange = jest.fn()
|
|
35
|
+
const secondChange = jest.fn()
|
|
36
|
+
Taro.onKeyboardHeightChange(firstChange)
|
|
37
|
+
Taro.onKeyboardHeightChange(secondChange)
|
|
38
|
+
DeviceEventEmitter.emit('keyboardDidShow', { endCoordinates })
|
|
39
|
+
expect(firstChange.mock.calls.length).toBe(1)
|
|
40
|
+
expect(secondChange.mock.calls.length).toBe(1)
|
|
41
|
+
Taro.offKeyboardHeightChange(secondChange)
|
|
42
|
+
DeviceEventEmitter.emit('keyboardDidHide', { endCoordinates })
|
|
43
|
+
expect(firstChange.mock.calls.length).toBe(2)
|
|
44
|
+
expect(secondChange.mock.calls.length).toBe(1)
|
|
45
|
+
})
|
|
46
|
+
})
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { getImageInfo } from '../lib/getImageInfo'
|
|
2
|
+
import { saveImageToPhotosAlbum } from '../lib/saveImageToPhotosAlbum'
|
|
3
|
+
import { saveVideoToPhotosAlbum } from '../lib/saveVideoToPhotosAlbum'
|
|
4
|
+
|
|
5
|
+
const Taro = {
|
|
6
|
+
getImageInfo,
|
|
7
|
+
saveImageToPhotosAlbum,
|
|
8
|
+
saveVideoToPhotosAlbum,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// 原生模块导出缺少 react_native_1.NativeModules.RNCCameraRoll setup mock
|
|
12
|
+
|
|
13
|
+
describe('media', () => {
|
|
14
|
+
describe('getImageInfo', () => {
|
|
15
|
+
test('能正确获取图片信息', () => {
|
|
16
|
+
const url = 'https://img12.360buyimg.com/ling/jfs/t19387/224/2632923601/58290/3bbe4eda/5b03f63cN17d4a46c.png'
|
|
17
|
+
const width = 320
|
|
18
|
+
const height = 240
|
|
19
|
+
const success = jest.fn()
|
|
20
|
+
const fail = jest.fn()
|
|
21
|
+
const complete = jest.fn()
|
|
22
|
+
|
|
23
|
+
expect.assertions(8)
|
|
24
|
+
return Taro.getImageInfo({
|
|
25
|
+
src: url,
|
|
26
|
+
success,
|
|
27
|
+
fail,
|
|
28
|
+
complete
|
|
29
|
+
}).then((res) => {
|
|
30
|
+
const expectRes = {
|
|
31
|
+
width,
|
|
32
|
+
height,
|
|
33
|
+
path: url,
|
|
34
|
+
orientation: 'up',
|
|
35
|
+
type: ''
|
|
36
|
+
}
|
|
37
|
+
expect(success.mock.calls.length).toBe(1)
|
|
38
|
+
expect(success.mock.calls[0][0]).toMatchObject(expectRes)
|
|
39
|
+
expect(fail.mock.calls.length).toBe(0)
|
|
40
|
+
expect(complete.mock.calls.length).toBe(1)
|
|
41
|
+
expect(complete.mock.calls[0][0]).toMatchObject(expectRes)
|
|
42
|
+
expect(res.width).toEqual(width)
|
|
43
|
+
expect(res.height).toEqual(height)
|
|
44
|
+
expect(res.path).toEqual(url)
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
describe('saveImageToPhotosAlbum', () => {
|
|
50
|
+
test('能够正常保存图片', () => {
|
|
51
|
+
const url = 'test.io/a.png'
|
|
52
|
+
const expectMsg = 'saveImageToPhotosAlbum:ok'
|
|
53
|
+
|
|
54
|
+
const success = jest.fn()
|
|
55
|
+
const fail = jest.fn()
|
|
56
|
+
const complete = jest.fn()
|
|
57
|
+
|
|
58
|
+
expect.assertions(6)
|
|
59
|
+
return Taro.saveImageToPhotosAlbum({
|
|
60
|
+
filePath: url,
|
|
61
|
+
success,
|
|
62
|
+
fail,
|
|
63
|
+
complete
|
|
64
|
+
}).then((res) => {
|
|
65
|
+
const path = `photo://${url}`
|
|
66
|
+
expect(success.mock.calls.length).toBe(1)
|
|
67
|
+
expect(success.mock.calls[0][0]).toEqual({ errMsg: expectMsg, path })
|
|
68
|
+
expect(fail.mock.calls.length).toBe(0)
|
|
69
|
+
expect(complete.mock.calls.length).toBe(1)
|
|
70
|
+
expect(complete.mock.calls[0][0]).toEqual({ errMsg: expectMsg, path })
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
expect(res.path).toEqual(path)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
describe('saveVideoToPhotosAlbum', () => {
|
|
78
|
+
test('能够正常保存视频', () => {
|
|
79
|
+
const url = 'test.io/a.mp4'
|
|
80
|
+
const expectMsg = 'saveVideoToPhotosAlbum:ok'
|
|
81
|
+
|
|
82
|
+
const success = jest.fn()
|
|
83
|
+
const fail = jest.fn()
|
|
84
|
+
const complete = jest.fn()
|
|
85
|
+
|
|
86
|
+
expect.assertions(6)
|
|
87
|
+
return Taro.saveVideoToPhotosAlbum({
|
|
88
|
+
filePath: url,
|
|
89
|
+
success,
|
|
90
|
+
fail,
|
|
91
|
+
complete
|
|
92
|
+
}).then((res) => {
|
|
93
|
+
const path = `video://${url}`
|
|
94
|
+
expect(success.mock.calls.length).toBe(1)
|
|
95
|
+
expect(success.mock.calls[0][0]).toEqual({ errMsg: expectMsg, path })
|
|
96
|
+
expect(fail.mock.calls.length).toBe(0)
|
|
97
|
+
expect(complete.mock.calls.length).toBe(1)
|
|
98
|
+
expect(complete.mock.calls[0][0]).toEqual({ errMsg: expectMsg, path })
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
expect(res.path).toEqual(path)
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as network from '../lib/network'
|
|
2
|
+
const Taro = Object.assign({}, network)
|
|
3
|
+
|
|
4
|
+
describe('network', () => {
|
|
5
|
+
describe('getNetworkType', () => {
|
|
6
|
+
test('能正常返回网络类型', () => {
|
|
7
|
+
const networkType = expect.any(String)
|
|
8
|
+
const success = jest.fn()
|
|
9
|
+
const fail = jest.fn()
|
|
10
|
+
const complete = jest.fn()
|
|
11
|
+
|
|
12
|
+
return Taro.getNetworkType({
|
|
13
|
+
success,
|
|
14
|
+
fail,
|
|
15
|
+
complete
|
|
16
|
+
}).then((res) => {
|
|
17
|
+
expect.assertions(6)
|
|
18
|
+
expect(success.mock.calls.length).toBe(1)
|
|
19
|
+
expect(success.mock.calls[0][0]).toEqual({ networkType, errMsg: 'getNetworkType:ok' })
|
|
20
|
+
expect(fail.mock.calls.length).toBe(0)
|
|
21
|
+
expect(complete.mock.calls.length).toBe(1)
|
|
22
|
+
expect(complete.mock.calls[0][0]).toEqual({ networkType, errMsg: 'getNetworkType:ok' })
|
|
23
|
+
expect(res.networkType).toEqual(networkType)
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
// mock react_native_1.NativeModules.RNCNetInfo 暂不mock 内部实现,比如事件的发布订阅
|
|
28
|
+
// describe('onNetworkStatusChange', () => {
|
|
29
|
+
// test('能够正常监听网络状态的变化', done => {
|
|
30
|
+
// const networkType = '3g'
|
|
31
|
+
// const networkCb = (res) => {
|
|
32
|
+
// expect(res).toEqual({ networkType, isConnected: true })
|
|
33
|
+
// done()
|
|
34
|
+
// }
|
|
35
|
+
// expect.assertions(1)
|
|
36
|
+
|
|
37
|
+
// Taro.onNetworkStatusChange(networkCb)
|
|
38
|
+
// NetInfo.changeNetworkType('cellular', networkType)
|
|
39
|
+
// NetInfo.fetch().then(state => {
|
|
40
|
+
// console.log("Connection type", state.type)
|
|
41
|
+
// console.log("Is connected?", state.isConnected)
|
|
42
|
+
// })
|
|
43
|
+
// })
|
|
44
|
+
|
|
45
|
+
// test('能返回正确的关于网络状态的判断', done => {
|
|
46
|
+
// const networkType = 'none'
|
|
47
|
+
// const networkCb = (res) => {
|
|
48
|
+
// expect(res).toEqual({ networkType, isConnected: false })
|
|
49
|
+
// done()
|
|
50
|
+
// }
|
|
51
|
+
// expect.assertions(1)
|
|
52
|
+
|
|
53
|
+
// Taro.onNetworkStatusChange(networkCb)
|
|
54
|
+
// NetInfo.changeNetworkType('none')
|
|
55
|
+
// })
|
|
56
|
+
// })
|
|
57
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { base64ToArrayBuffer } from '../lib/base64ToArrayBuffer'
|
|
2
|
+
import { arrayBufferToBase64 } from '../lib/arrayBufferToBase64'
|
|
3
|
+
|
|
4
|
+
const Taro = { base64ToArrayBuffer, arrayBufferToBase64 }
|
|
5
|
+
|
|
6
|
+
describe('base64 and arrayBuffer', () => {
|
|
7
|
+
describe('arrayBufferToBase64', () => {
|
|
8
|
+
test('能正常转换为base64', () => {
|
|
9
|
+
const expectBase64 = 'CxZY'
|
|
10
|
+
const arrayBuffer = new Uint8Array([11, 22, 88])
|
|
11
|
+
const base64 = Taro.arrayBufferToBase64(arrayBuffer)
|
|
12
|
+
expect(base64).toBe(expectBase64)
|
|
13
|
+
})
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
describe('base64ToArrayBuffer', () => {
|
|
17
|
+
test('能正常转换为ArrayBuffer', () => {
|
|
18
|
+
const base64 = 'CxZY'
|
|
19
|
+
const arrayBuffer = Taro.base64ToArrayBuffer(base64)
|
|
20
|
+
expect(arrayBuffer[0]).toBe(11)
|
|
21
|
+
expect(arrayBuffer[1]).toBe(22)
|
|
22
|
+
expect(arrayBuffer[2]).toBe(88)
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as phone from '../lib/makePhoneCall'
|
|
2
|
+
|
|
3
|
+
const Taro = Object.assign({}, phone)
|
|
4
|
+
|
|
5
|
+
describe('phone', () => {
|
|
6
|
+
describe('makePhoneCall', () => {
|
|
7
|
+
test('能正常调用电话功能', () => {
|
|
8
|
+
const phoneNumber = '12345678911'
|
|
9
|
+
const success = jest.fn()
|
|
10
|
+
const fail = jest.fn()
|
|
11
|
+
const complete = jest.fn()
|
|
12
|
+
|
|
13
|
+
expect.assertions(6)
|
|
14
|
+
|
|
15
|
+
return Taro.makePhoneCall({
|
|
16
|
+
phoneNumber,
|
|
17
|
+
success,
|
|
18
|
+
fail,
|
|
19
|
+
complete
|
|
20
|
+
}).then((res) => {
|
|
21
|
+
const expectMsg = 'makePhoneCall:ok'
|
|
22
|
+
expect(success.mock.calls.length).toBe(1)
|
|
23
|
+
expect(success.mock.calls[0][0]).toEqual({ errMsg: expectMsg })
|
|
24
|
+
expect(fail.mock.calls.length).toBe(0)
|
|
25
|
+
expect(complete.mock.calls.length).toBe(1)
|
|
26
|
+
expect(complete.mock.calls[0][0]).toEqual({ errMsg: expectMsg })
|
|
27
|
+
expect(res.errMsg).toMatch(expectMsg)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
})
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import * as request from '../lib/request'
|
|
2
|
+
|
|
3
|
+
const Taro = Object.assign({}, request)
|
|
4
|
+
|
|
5
|
+
describe('request', () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
const fetch = jest.fn(() => {
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
resolve({
|
|
10
|
+
ok: true,
|
|
11
|
+
status: 200,
|
|
12
|
+
headers: {},
|
|
13
|
+
json: () => {
|
|
14
|
+
return Promise.resolve({ data: 'calorie' })
|
|
15
|
+
},
|
|
16
|
+
text: () => {
|
|
17
|
+
return Promise.resolve('卡路里卡路里卡路')
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
global.fetch = fetch
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
describe('request', () => {
|
|
27
|
+
// taro@3 不支持
|
|
28
|
+
// test('直接传入url时能正常返回', async () => {
|
|
29
|
+
// const expectData = { data: 'calorie' }
|
|
30
|
+
|
|
31
|
+
// const url = 'https://test.taro.com/v1'
|
|
32
|
+
// const res = await Taro.request(url)
|
|
33
|
+
|
|
34
|
+
// expect(res.data).toEqual(expectData)
|
|
35
|
+
// })
|
|
36
|
+
|
|
37
|
+
test('接口数据返回json对象', async () => {
|
|
38
|
+
const expectData = { data: 'calorie' }
|
|
39
|
+
|
|
40
|
+
const url = 'https://test.taro.com/v1'
|
|
41
|
+
const options = {
|
|
42
|
+
url,
|
|
43
|
+
dataType: 'json'
|
|
44
|
+
}
|
|
45
|
+
const res = await Taro.request(options)
|
|
46
|
+
|
|
47
|
+
expect(res.data).toEqual(expectData)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('接口数据返回text', async () => {
|
|
51
|
+
const expectData = { data: 'calorie' }
|
|
52
|
+
|
|
53
|
+
const url = 'https://test.taro.com/v1'
|
|
54
|
+
const options = {
|
|
55
|
+
url,
|
|
56
|
+
responseType: 'text'
|
|
57
|
+
}
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
const res = await Taro.request(options)
|
|
60
|
+
expect(res.data).toEqual(expectData)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('RN请求入参同于微信小程序', () => {
|
|
64
|
+
const url = 'https://test.taro.com/v1'
|
|
65
|
+
const expectData = JSON.stringify({ data: 'calorie' })
|
|
66
|
+
const options = {
|
|
67
|
+
url,
|
|
68
|
+
dataType: 'json',
|
|
69
|
+
complete: jest.fn(),
|
|
70
|
+
success: (res) => {
|
|
71
|
+
expect(JSON.stringify(res.data)).toMatch(expectData)
|
|
72
|
+
},
|
|
73
|
+
fail: jest.fn()
|
|
74
|
+
}
|
|
75
|
+
Taro.request(options)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test('数据被序列化', async () => {
|
|
79
|
+
const fetch = jest.fn((url, params) => {
|
|
80
|
+
return new Promise((resolve) => {
|
|
81
|
+
resolve({
|
|
82
|
+
ok: true,
|
|
83
|
+
status: 200,
|
|
84
|
+
headers: {},
|
|
85
|
+
json: () => {
|
|
86
|
+
return Promise.resolve({ url, params })
|
|
87
|
+
},
|
|
88
|
+
text: () => {
|
|
89
|
+
return Promise.resolve('卡路里卡路里卡路')
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
global.fetch = fetch
|
|
96
|
+
|
|
97
|
+
const url = 'https://test.taro.com/v1'
|
|
98
|
+
const optionsOne = {
|
|
99
|
+
url,
|
|
100
|
+
dataType: 'json',
|
|
101
|
+
data: {
|
|
102
|
+
a: 1
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const expectUrl = `https://test.taro.com/v1?${encodeURIComponent('a')}=${encodeURIComponent(1)}`
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
const res = await Taro.request(optionsOne)
|
|
109
|
+
expect(res.data.url).toMatch(expectUrl)
|
|
110
|
+
|
|
111
|
+
const optionsTwo = {
|
|
112
|
+
url,
|
|
113
|
+
method: 'post',
|
|
114
|
+
dataType: 'json',
|
|
115
|
+
header: {
|
|
116
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
117
|
+
},
|
|
118
|
+
data: {
|
|
119
|
+
a: 1
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const expectBodyOne = JSON.stringify({ a: 1 })
|
|
124
|
+
// @ts-ignore
|
|
125
|
+
const resTwo = await Taro.request(optionsTwo)
|
|
126
|
+
expect(resTwo.data.params.body).toMatch(expectBodyOne)
|
|
127
|
+
|
|
128
|
+
const optionsThree = {
|
|
129
|
+
url,
|
|
130
|
+
method: 'POST',
|
|
131
|
+
dataType: 'json',
|
|
132
|
+
header: {
|
|
133
|
+
'content-type': 'application/x-www-form-urlencoded'
|
|
134
|
+
},
|
|
135
|
+
data: {
|
|
136
|
+
a: 1
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const expectBodyTwo = `${encodeURIComponent('a')}=${encodeURIComponent(1)}`
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
const resThree = await Taro.request(optionsThree)
|
|
143
|
+
expect(resThree.data.params.body).toMatch(expectBodyTwo)
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { RootSiblingParent } from 'react-native-root-siblings';
|
|
3
|
+
import { render, waitFor } from '@testing-library/react-native';
|
|
4
|
+
import { scanCode } from '../lib/scanCode'
|
|
5
|
+
|
|
6
|
+
describe('scanCode', () => {
|
|
7
|
+
it('should render scanCode success', async () => {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const { toJSON, getByLabelText } = render(<RootSiblingParent />)
|
|
10
|
+
scanCode()
|
|
11
|
+
await waitFor(() => getByLabelText('Close'));
|
|
12
|
+
expect(toJSON()).toMatchSnapshot()
|
|
13
|
+
})
|
|
14
|
+
})
|