@eohjsc/react-native-smart-city 0.4.47 → 0.4.49

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.
Files changed (75) hide show
  1. package/README.md +1 -5
  2. package/android/build.gradle +24 -19
  3. package/package.json +12 -15
  4. package/src/commons/ActionGroup/__test__/ColorPickerTemplate.test.js +3 -6
  5. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +11 -1
  6. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +5 -0
  7. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +6 -1
  8. package/src/commons/DateTimeRangeChange/index.js +3 -3
  9. package/src/commons/Device/Hanet/ItemHanetDevice.js +1 -5
  10. package/src/commons/Device/HorizontalBarChart.js +3 -0
  11. package/src/commons/Device/ItemAddNew/index.js +2 -6
  12. package/src/commons/Device/ItemDevice.js +1 -5
  13. package/src/commons/FlatListDnD/__test__/index.test.js +25 -27
  14. package/src/commons/GroupCheckBox/__test__/GroupCheckBox.test.js +22 -1
  15. package/src/commons/HeaderAni/index.js +2 -12
  16. package/src/commons/MediaPlayerDetail/__test__/MediaPlayerFull.test.js +23 -1
  17. package/src/commons/SubUnit/OneTap/ItemOneTap.js +2 -10
  18. package/src/commons/Unit/HeaderUnit/index.js +7 -18
  19. package/src/commons/Unit/SharedUnit.js +43 -58
  20. package/src/commons/Unit/__test__/SharedUnit.test.js +100 -60
  21. package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +289 -0
  22. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +59 -1
  23. package/src/commons/WrapParallaxScrollView/index.js +0 -4
  24. package/src/configs/API.js +1 -0
  25. package/src/configs/AccessibilityLabel.js +0 -3
  26. package/src/hooks/IoT/__test__/useRemoteControl.test.js +51 -52
  27. package/src/hooks/IoT/__test__/useWatchConfigs.test.js +2 -3
  28. package/src/navigations/AutomateStack.js +2 -5
  29. package/src/navigations/NotificationStack.js +2 -28
  30. package/src/navigations/SharedStack.js +2 -8
  31. package/src/navigations/UnitStack.js +2 -2
  32. package/src/screens/AddNewGateway/ConnectingWifiDevice.js +5 -4
  33. package/src/screens/AddNewGateway/ConnectingWifiGuide.js +47 -12
  34. package/src/screens/AddNewGateway/RenameNewDevices.js +126 -10
  35. package/src/screens/AddNewGateway/RenameNewDevicesStyles.js +26 -5
  36. package/src/screens/AddNewGateway/ShareWifiPassword.js +39 -7
  37. package/src/screens/AddNewGateway/__test__/ConnectingWifiDevice.test.js +36 -7
  38. package/src/screens/AddNewGateway/__test__/ConnectingWifiGuide.test.js +41 -32
  39. package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +106 -2
  40. package/src/screens/AddNewGateway/__test__/ShareWifiPassword.test.js +35 -2
  41. package/src/screens/AllGateway/DeviceModbusDetail/__test__/index.test.js +32 -31
  42. package/src/screens/Automate/EditActionsList/__tests__/index.test.js +68 -69
  43. package/src/screens/Automate/ScriptDetail/Styles/indexStyles.js +0 -1
  44. package/src/screens/Automate/ScriptDetail/index.js +7 -4
  45. package/src/screens/ChangePosition/__test__/index.test.js +32 -34
  46. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +11 -1
  47. package/src/screens/Device/__test__/detail.test.js +3 -3
  48. package/src/screens/Device/components/ChartWrapper.js +12 -14
  49. package/src/screens/Device/components/VisualChart.js +1 -7
  50. package/src/screens/Device/components/__test__/VisualChart.test.js +3 -0
  51. package/src/screens/Device/detail.js +7 -12
  52. package/src/screens/Device/hooks/__test__/useEvaluateValue.test.js +18 -20
  53. package/src/screens/Device/styles.js +0 -3
  54. package/src/screens/Notification/__test__/Notification.test.js +8 -14
  55. package/src/screens/Notification/components/NotificationItem.js +0 -1
  56. package/src/screens/Notification/index.js +48 -42
  57. package/src/screens/Notification/styles/indexStyles.js +3 -6
  58. package/src/screens/SharedUnit/index.js +4 -1
  59. package/src/screens/Sharing/Components/CheckBoxCustom.js +14 -2
  60. package/src/screens/Sharing/MemberList.js +3 -16
  61. package/src/screens/Sharing/__test__/SelectPermission.test.js +137 -96
  62. package/src/screens/SmartAccount/Connecting/index.js +0 -1
  63. package/src/screens/SmartAccount/__test__/Connecting.test.js +92 -0
  64. package/src/screens/Template/__test__/EditTemplate.test.js +1 -7
  65. package/src/screens/Unit/__test__/SelectAddress.test.js +11 -4
  66. package/src/screens/Unit/components/SharedUnit/index.js +9 -6
  67. package/src/screens/Unit/components/__test__/SharedUnit.test.js +15 -19
  68. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +11 -1
  69. package/src/utils/I18n/translations/en.js +19 -5
  70. package/src/utils/I18n/translations/vi.js +19 -5
  71. package/src/utils/Monitor.js +2 -2
  72. package/src/Images/Common/pushpin-full.svg +0 -3
  73. package/src/Images/Common/pushpin-outline.svg +0 -3
  74. package/src/Images/Common/star-full.svg +0 -3
  75. package/src/Images/Common/star-outline.svg +0 -3
package/README.md CHANGED
@@ -3,11 +3,7 @@
3
3
  ## Getting started
4
4
 
5
5
  1. Install package dependencies:
6
- - Using [react-native-get-random-values](https://www.npmjs.com/package/react-native-get-random-values): `yarn add react-native-get-random-values`
7
- ```
8
- // Add this line to your 'index.js'
9
- import 'react-native-get-random-values'
10
- ```
6
+
11
7
  - Using [Yarn](https://yarnpkg.com/): `yarn add react-native-reanimated@^1.10.1`
12
8
 
13
9
  2. Install:
@@ -10,17 +10,17 @@
10
10
  // original location:
11
11
  // - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle
12
12
 
13
- def DEFAULT_COMPILE_SDK_VERSION = 33
14
- def DEFAULT_BUILD_TOOLS_VERSION = '33.0.0'
15
- def DEFAULT_MIN_SDK_VERSION = 24
16
- def DEFAULT_TARGET_SDK_VERSION = 33
13
+ def DEFAULT_COMPILE_SDK_VERSION = 28
14
+ def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
15
+ def DEFAULT_MIN_SDK_VERSION = 16
16
+ def DEFAULT_TARGET_SDK_VERSION = 28
17
17
 
18
18
  def safeExtGet(prop, fallback) {
19
19
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
20
20
  }
21
21
 
22
22
  apply plugin: 'com.android.library'
23
- apply plugin: 'maven-publish'
23
+ apply plugin: 'maven'
24
24
 
25
25
  buildscript {
26
26
  // The Android Gradle plugin is only required when opening the android folder stand-alone.
@@ -38,6 +38,9 @@ buildscript {
38
38
  }
39
39
  }
40
40
 
41
+ apply plugin: 'com.android.library'
42
+ apply plugin: 'maven'
43
+
41
44
  android {
42
45
  compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
43
46
  buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
@@ -103,17 +106,17 @@ def configureReactNativePom(def pom) {
103
106
  afterEvaluate { project ->
104
107
  // some Gradle build hooks ref:
105
108
  // https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
106
- // task androidJavadoc(type: Javadoc) {
107
- // source = android.sourceSets.main.java.srcDirs
108
- // classpath += files(android.bootClasspath)
109
- // classpath += files(project.getConfigurations().getByName('compile').asList())
110
- // include '**/*.java'
111
- // }
112
-
113
- // task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
114
- // classifier = 'javadoc'
115
- // from androidJavadoc.destinationDir
116
- // }
109
+ task androidJavadoc(type: Javadoc) {
110
+ source = android.sourceSets.main.java.srcDirs
111
+ classpath += files(android.bootClasspath)
112
+ classpath += files(project.getConfigurations().getByName('compile').asList())
113
+ include '**/*.java'
114
+ }
115
+
116
+ task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
117
+ classifier = 'javadoc'
118
+ from androidJavadoc.destinationDir
119
+ }
117
120
 
118
121
  task androidSourcesJar(type: Jar) {
119
122
  classifier = 'sources'
@@ -132,13 +135,15 @@ afterEvaluate { project ->
132
135
 
133
136
  artifacts {
134
137
  archives androidSourcesJar
135
- // archives androidJavadocJar
138
+ archives androidJavadocJar
136
139
  }
137
140
 
138
141
  task installArchives(type: Upload) {
139
142
  configuration = configurations.archives
140
- repositories.maven {
141
- url = uri("file://${projectDir}/../android/maven")
143
+ repositories.mavenDeployer {
144
+ // Deploy to react-native-event-bridge/maven, ready to publish to npm
145
+ repository url: "file://${projectDir}/../android/maven"
146
+ configureReactNativePom pom
142
147
  }
143
148
  }
144
149
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eohjsc/react-native-smart-city",
3
3
  "title": "React Native Smart Home",
4
- "version": "0.4.47",
4
+ "version": "0.4.49",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -65,9 +65,7 @@
65
65
  "peerDependencies": {
66
66
  "@react-native-community/clipboard": "*",
67
67
  "react": "*",
68
- "react-native": "*",
69
- "react-native-modal": "*",
70
- "react-native-modal-datetime-picker": "*"
68
+ "react-native": "*"
71
69
  },
72
70
  "devDependencies": {
73
71
  "@babel/core": "^7.12.9",
@@ -112,14 +110,15 @@
112
110
  "@miblanchard/react-native-slider": "^2.2.0",
113
111
  "@react-native-clipboard/clipboard": "^1.11.1",
114
112
  "@react-native-community/async-storage": "^1.12.1",
115
- "@react-native-community/cameraroll": "4.1.2",
113
+ "@react-native-community/cameraroll": "^4.0.0",
116
114
  "@react-native-community/checkbox": "^0.5.5",
117
- "@react-native-community/datetimepicker": "^7.0.1",
115
+ "@react-native-community/datetimepicker": "https://github.com/hinh-eoh/datepicker",
118
116
  "@react-native-community/geolocation": "^2.0.2",
119
117
  "@react-native-community/masked-view": "^0.1.10",
120
118
  "@react-native-community/netinfo": "^9.3.4",
121
119
  "@react-native-community/segmented-control": "^2.1.1",
122
120
  "@react-native-community/slider": "^3.0.3",
121
+ "@react-native-community/toolbar-android": "^0.1.0-rc.2",
123
122
  "@react-native-picker/picker": "^1.16.7",
124
123
  "@react-navigation/bottom-tabs": "^5.8.0",
125
124
  "@react-navigation/drawer": "^5.9.0",
@@ -130,7 +129,6 @@
130
129
  "apisauce": "^2.1.5",
131
130
  "axios": "^0.19.2",
132
131
  "base-64": "^1.0.0",
133
- "buffer": "^6.0.3",
134
132
  "deprecated-react-native-prop-types": "^2.3.0",
135
133
  "dotenv": "^8.2.0",
136
134
  "google-libphonenumber": "^3.2.10",
@@ -138,8 +136,7 @@
138
136
  "i18n-js": "^3.7.1",
139
137
  "i18next": "^20.1.0",
140
138
  "lodash": "^4.17.19",
141
- "lottie-ios": "3.4.1",
142
- "lottie-react-native": "5.1.4",
139
+ "lottie-react-native": "4.0.3",
143
140
  "moment": "^2.27.0",
144
141
  "moment-timezone": "^0.5.32",
145
142
  "numeral": "^2.0.6",
@@ -147,7 +144,7 @@
147
144
  "pluralize": "^8.0.0",
148
145
  "postinstall": "^0.7.0",
149
146
  "precompiled-mqtt": "^4.3.14-beta",
150
- "pusher-js": "^8.0.2",
147
+ "pusher-js": "^7.4.0",
151
148
  "pusher-js-auth": "^4.0.1",
152
149
  "python-struct": "^1.1.3",
153
150
  "querystring": "^0.2.0",
@@ -173,7 +170,7 @@
173
170
  "react-native-draggable-flatlist": "^2.6.2",
174
171
  "react-native-fast-image": "^8.3.2",
175
172
  "react-native-geocoder": "^0.5.0",
176
- "react-native-gesture-handler": "^2.10.0",
173
+ "react-native-gesture-handler": "^1.7.0",
177
174
  "react-native-get-location": "^2.0.0",
178
175
  "react-native-image-crop-picker": "^0.37.2",
179
176
  "react-native-image-resizer": "^1.4.5",
@@ -183,8 +180,8 @@
183
180
  "react-native-localize": "^1.4.1",
184
181
  "react-native-maps": "0.27.1",
185
182
  "react-native-maps-directions": "^1.8.0",
186
- "react-native-modal": "^13.0.1",
187
- "react-native-modal-datetime-picker": "15.0.0",
183
+ "react-native-modal": "^11.5.6",
184
+ "react-native-modal-datetime-picker": "^8.9.3",
188
185
  "react-native-new-snap-carousel": "^3.9.3",
189
186
  "react-native-onesignal": "^4.3.1",
190
187
  "react-native-pager-view": "^5.4.1",
@@ -203,7 +200,7 @@
203
200
  "react-native-udp": "^4.1.3",
204
201
  "react-native-version-check": "^3.4.2",
205
202
  "react-native-vlc-media-player": "^1.0.41",
206
- "react-native-webview": "^12.0.2",
203
+ "react-native-webview": "11.17.2",
207
204
  "react-native-wheel-color-picker": "^1.2.0",
208
205
  "react-native-wheel-scrollview-picker": "^1.2.2",
209
206
  "react-native-wifi-reborn": "^4.5.0",
@@ -211,8 +208,8 @@
211
208
  "string-format": "^2.0.0",
212
209
  "sync-directory": "^5.1.7",
213
210
  "timezone-mock": "^1.1.3",
214
- "uuid": "^9.0.0",
215
211
  "uuid-by-string": "^3.0.2",
212
+ "uuidv4": "^6.2.13",
216
213
  "validator": "^13.1.1",
217
214
  "victory-native": "^35.0.1"
218
215
  },
@@ -111,8 +111,7 @@ describe('Test ColorPickerTemplate', () => {
111
111
  await act(async () => {
112
112
  await wheelpicker.props.onStart();
113
113
  });
114
- // NOTE: Hinh will fix it later
115
- expect(mockSetAction).not.toBeCalled();
114
+ expect(mockSetAction).toBeCalled();
116
115
  });
117
116
 
118
117
  it('test WheelColorPicker onChangeColorComplete', async () => {
@@ -129,15 +128,13 @@ describe('Test ColorPickerTemplate', () => {
129
128
  await act(async () => {
130
129
  await wheelpicker.props.onStart();
131
130
  });
132
- // NOTE: Hinh will fix it later
133
- expect(mockSetAction).toBeCalledTimes(0);
131
+ expect(mockSetAction).toBeCalledTimes(1);
134
132
  expect(mockDoAction).toBeCalledTimes(0);
135
133
 
136
134
  await act(async () => {
137
135
  await wheelpicker.props.onChangeColorComplete('#ffffff');
138
136
  });
139
- // NOTE: Hinh will fix it later
140
- expect(mockSetAction).toBeCalledTimes(0);
137
+ expect(mockSetAction).toBeCalledTimes(2);
141
138
  expect(mockDoAction).toBeCalledTimes(1);
142
139
  });
143
140
  });
@@ -1,9 +1,14 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { TouchableOpacity } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
4
  import { DEVICE_TYPE } from '../../../configs/Constants';
5
5
  import TwoButtonTemplate from '../TwoButtonTemplate';
6
6
 
7
+ jest.mock('react', () => ({
8
+ ...jest.requireActual('react'),
9
+ useState: jest.fn(),
10
+ }));
11
+
7
12
  jest.mock('@react-navigation/native', () => {
8
13
  return {
9
14
  ...jest.requireActual('@react-navigation/native'),
@@ -68,7 +73,11 @@ describe('Test TwoButtonTemplate', () => {
68
73
  };
69
74
  let wrapper;
70
75
 
76
+ const setState = jest.fn();
77
+ useState.mockImplementation((init) => [init, setState]);
78
+
71
79
  const assertRender = async (state, text) => {
80
+ useState.mockImplementationOnce((init) => [state, setState]);
72
81
  const mockDoAction = jest.fn();
73
82
  await act(async () => {
74
83
  wrapper = create(
@@ -92,6 +101,7 @@ describe('Test TwoButtonTemplate', () => {
92
101
  });
93
102
 
94
103
  const assertActionCall = async (state, action_data) => {
104
+ useState.mockImplementationOnce((init) => [state, setState]);
95
105
  const mockDoAction = jest.fn();
96
106
  await act(async () => {
97
107
  wrapper = create(
@@ -12,6 +12,7 @@ import { API } from '../../../../configs';
12
12
  import { TouchableOpacity } from 'react-native';
13
13
  import api from '../../../../utils/Apis/axios';
14
14
  import SharedUnit from '../../../Unit/SharedUnit';
15
+ import { Action } from '../../../../context/actionType';
15
16
 
16
17
  const mock = new MockAdapter(api.axiosInstance);
17
18
 
@@ -74,6 +75,10 @@ describe('Test MyPinnedSharedUnit', () => {
74
75
  goToAllSharedUnits.props.onPress();
75
76
  });
76
77
  expect(mockedNavigate).toHaveBeenCalled();
78
+ expect(mockSetAction).toBeCalledWith(
79
+ Action.IS_CHECK_CLEAR_CACHE_UNITS,
80
+ false
81
+ );
77
82
  });
78
83
 
79
84
  it('render without item', async () => {
@@ -96,7 +96,12 @@ const MyPinnedSharedUnit = ({ refreshing }) => {
96
96
  .filter((sharedUnit) => sharedUnit?.is_pin)
97
97
  .map((item, index) => (
98
98
  <View key={item.id}>
99
- <SharedUnit item={item} index={index} isOptions={false} />
99
+ <SharedUnit
100
+ item={item}
101
+ index={index}
102
+ navigation={navigation}
103
+ isOptions={false}
104
+ />
100
105
  {index !== sharedUnits.length - 1 && (
101
106
  <View style={styles.separator} />
102
107
  )}
@@ -119,7 +119,7 @@ const DateTimeRangeChange = memo(
119
119
  </View>
120
120
  <DateTimePickerModal
121
121
  isVisible={eventPicker.showModalStart}
122
- date={startDate._d}
122
+ date={startDate.valueOf()}
123
123
  mode={mode}
124
124
  onConfirm={onConfirmStart}
125
125
  onCancel={onCancel}
@@ -132,7 +132,7 @@ const DateTimeRangeChange = memo(
132
132
  />
133
133
  <DateTimePickerModal
134
134
  isVisible={eventPicker.showModalEnd}
135
- date={endDate._d}
135
+ date={endDate.valueOf()}
136
136
  mode={mode}
137
137
  onConfirm={onConfirmEnd}
138
138
  onCancel={onCancel}
@@ -142,7 +142,7 @@ const DateTimeRangeChange = memo(
142
142
  cancelTextIOS={t('cancel')}
143
143
  confirmTextIOS={t('confirm')}
144
144
  maximumDate={new Date()}
145
- minimumDate={startDate._d}
145
+ minimumDate={startDate.valueOf()}
146
146
  />
147
147
  </View>
148
148
  );
@@ -1,6 +1,5 @@
1
1
  import React, { memo } from 'react';
2
2
  import {
3
- Platform,
4
3
  StyleSheet,
5
4
  TouchableOpacity,
6
5
  TouchableWithoutFeedback,
@@ -59,10 +58,7 @@ const ItemHanetDevice = memo(
59
58
  {title}
60
59
  </Text>
61
60
  <View style={styles.row}>
62
- <IconOutline
63
- name={Platform.OS === 'android' ? 'right-square' : 'right'}
64
- size={12}
65
- />
61
+ <IconOutline name="right" size={12} />
66
62
  </View>
67
63
  </TouchableOpacity>
68
64
  </View>
@@ -49,6 +49,9 @@ const HorizontalBarChart = memo(({ datas, config }) => {
49
49
  enabled: false,
50
50
  followTouchMove: false,
51
51
  },
52
+ exporting: {
53
+ enabled: false,
54
+ },
52
55
  plotOptions: {
53
56
  bar: {
54
57
  dataLabels: {
@@ -1,5 +1,5 @@
1
1
  import React, { memo } from 'react';
2
- import { Platform, TouchableWithoutFeedback, View } from 'react-native';
2
+ import { TouchableWithoutFeedback, View } from 'react-native';
3
3
  import { IconOutline } from '@ant-design/icons-react-native';
4
4
  import Text from '../../Text';
5
5
 
@@ -16,11 +16,7 @@ const ItemAddNew = memo(({ title, onAddNew, wrapStyle }) => {
16
16
  <View style={[styles.container, wrapStyle]}>
17
17
  <View style={styles.boxIcon}>
18
18
  <View style={styles.buttonPlus}>
19
- <IconOutline
20
- name={Platform.OS === 'android' ? 'plus-square' : 'plus'}
21
- size={22}
22
- color={Colors.Gray8}
23
- />
19
+ <IconOutline name="plus" size={22} color={Colors.Gray8} />
24
20
  </View>
25
21
  </View>
26
22
  <View>
@@ -1,6 +1,5 @@
1
1
  import React, { memo, useCallback } from 'react';
2
2
  import {
3
- Platform,
4
3
  StyleSheet,
5
4
  TouchableOpacity,
6
5
  TouchableWithoutFeedback,
@@ -160,10 +159,7 @@ const ItemDevice = memo(
160
159
  >
161
160
  {description || textConnected}
162
161
  </Text>
163
- <IconOutline
164
- name={Platform.OS === 'android' ? 'right-square' : 'right'}
165
- size={12}
166
- />
162
+ <IconOutline name="right" size={12} />
167
163
  </View>
168
164
  </TouchableOpacity>
169
165
  </View>
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-unused-vars */
2
1
  import React from 'react';
3
2
  import renderer, { act } from 'react-test-renderer';
4
3
  import DraggableFlatList from 'react-native-draggable-flatlist';
@@ -13,7 +12,6 @@ const wrapComponent = ({ ...rest }) => (
13
12
  </SCProvider>
14
13
  );
15
14
 
16
- // NOTE: Hinh will fix it later
17
15
  describe('Test FlatListDnD', () => {
18
16
  let tree;
19
17
  let setData = jest.fn();
@@ -21,31 +19,31 @@ describe('Test FlatListDnD', () => {
21
19
  let renderItem = () => <></>;
22
20
 
23
21
  it('render FlatListDnD onDragEndCT', async () => {
24
- // const onDragEndCT = jest.fn();
25
- // await act(async () => {
26
- // tree = renderer.create(
27
- // wrapComponent({ data, setData, onDragEndCT, renderItem })
28
- // );
29
- // });
30
- // const instance = tree.root;
31
- // const draggableFlatList = instance.findAllByType(DraggableFlatList);
32
- // expect(draggableFlatList.length).toBe(1);
33
- // await act(async () => {
34
- // draggableFlatList[0].props.onDragEnd({ data: [{ id: 2 }, { id: 1 }] });
35
- // });
36
- // expect(setData).toBeCalledWith([{ id: 2 }, { id: 1 }]);
22
+ const onDragEndCT = jest.fn();
23
+ await act(async () => {
24
+ tree = renderer.create(
25
+ wrapComponent({ data, setData, onDragEndCT, renderItem })
26
+ );
27
+ });
28
+ const instance = tree.root;
29
+ const draggableFlatList = instance.findAllByType(DraggableFlatList);
30
+ expect(draggableFlatList.length).toBe(1);
31
+ await act(async () => {
32
+ draggableFlatList[0].props.onDragEnd({ data: [{ id: 2 }, { id: 1 }] });
33
+ });
34
+ expect(setData).toBeCalledWith([{ id: 2 }, { id: 1 }]);
37
35
  });
38
36
 
39
- // it('render FlatListDnD onDragEnd', async () => {
40
- // await act(async () => {
41
- // tree = renderer.create(wrapComponent({ data, setData, renderItem }));
42
- // });
43
- // const instance = tree.root;
44
- // const draggableFlatList = instance.findAllByType(DraggableFlatList);
45
- // expect(draggableFlatList.length).toBe(1);
46
- // await act(async () => {
47
- // draggableFlatList[0].props.onDragEnd({ data: [{ id: 2 }, { id: 1 }] });
48
- // });
49
- // expect(setData).toBeCalledWith([{ id: 2 }, { id: 1 }]);
50
- // });
37
+ it('render FlatListDnD onDragEnd', async () => {
38
+ await act(async () => {
39
+ tree = renderer.create(wrapComponent({ data, setData, renderItem }));
40
+ });
41
+ const instance = tree.root;
42
+ const draggableFlatList = instance.findAllByType(DraggableFlatList);
43
+ expect(draggableFlatList.length).toBe(1);
44
+ await act(async () => {
45
+ draggableFlatList[0].props.onDragEnd({ data: [{ id: 2 }, { id: 1 }] });
46
+ });
47
+ expect(setData).toBeCalledWith([{ id: 2 }, { id: 1 }]);
48
+ });
51
49
  });
@@ -1,12 +1,22 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
3
  import { TouchableOpacity } from 'react-native';
4
4
 
5
5
  import { AccessibilityLabel } from '../../../configs/Constants';
6
6
  import GroupCheckBox from '..';
7
7
 
8
+ jest.mock('react', () => ({
9
+ ...jest.requireActual('react'),
10
+ useState: jest.fn(),
11
+ }));
12
+
8
13
  describe('Test Group CheckBox', () => {
9
14
  let tree;
15
+ const mockSetState = () => {
16
+ const setState = jest.fn();
17
+ useState.mockImplementation((init) => [init, setState]);
18
+ return setState;
19
+ };
10
20
 
11
21
  const findGroupCheckBoxItem = (instance) => {
12
22
  const item = instance.find(
@@ -24,6 +34,7 @@ describe('Test Group CheckBox', () => {
24
34
  description: 'description',
25
35
  },
26
36
  ];
37
+ mockSetState();
27
38
  await act(async () => {
28
39
  tree = await create(<GroupCheckBox data={data} />);
29
40
  });
@@ -40,6 +51,7 @@ describe('Test Group CheckBox', () => {
40
51
  },
41
52
  ];
42
53
  const mockFunc = jest.fn();
54
+ const setState = mockSetState();
43
55
  await act(async () => {
44
56
  tree = await create(
45
57
  <GroupCheckBox data={data} onSelect={mockFunc} multiple />
@@ -50,6 +62,9 @@ describe('Test Group CheckBox', () => {
50
62
  await act(async () => {
51
63
  item.props.onSelect(0);
52
64
  });
65
+ expect(setState).toHaveBeenCalledTimes(2);
66
+ expect(setState).toHaveBeenNthCalledWith(1, [0]);
67
+ expect(setState).toHaveBeenNthCalledWith(2, [0]);
53
68
  expect(mockFunc).toHaveBeenCalledWith([
54
69
  { description: 'description', source: 'source', title: 'testItem' },
55
70
  ]);
@@ -70,6 +85,7 @@ describe('Test Group CheckBox', () => {
70
85
  },
71
86
  ];
72
87
  const mockFunc = jest.fn();
88
+ const setState = mockSetState();
73
89
  await act(async () => {
74
90
  tree = await create(<GroupCheckBox data={data} onSelect={mockFunc} />);
75
91
  });
@@ -78,6 +94,8 @@ describe('Test Group CheckBox', () => {
78
94
  await act(async () => {
79
95
  item.props.onSelect(0);
80
96
  });
97
+ expect(setState).toHaveBeenNthCalledWith(1, [0]);
98
+ expect(setState).toHaveBeenNthCalledWith(2, [0]);
81
99
  expect(mockFunc).toHaveBeenCalledWith({
82
100
  description: 'description 1',
83
101
  title: 'title 1',
@@ -96,6 +114,8 @@ describe('Test Group CheckBox', () => {
96
114
  },
97
115
  ];
98
116
  const mockFunc = jest.fn();
117
+ const setState = jest.fn();
118
+ useState.mockImplementation((init) => [[0], setState]);
99
119
  await act(async () => {
100
120
  tree = await create(<GroupCheckBox data={data} onSelect={mockFunc} />);
101
121
  });
@@ -108,6 +128,7 @@ describe('Test Group CheckBox', () => {
108
128
  await act(async () => {
109
129
  items[1].props.onSelect(0);
110
130
  });
131
+ expect(setState).toHaveBeenCalledWith([]); // called 1 time
111
132
  expect(mockFunc).toHaveBeenCalledWith({
112
133
  description: 'description 1',
113
134
  title: 'title 1',
@@ -1,12 +1,6 @@
1
1
  import React, { memo, useCallback } from 'react';
2
2
  import { Icon } from '@ant-design/react-native';
3
- import {
4
- TouchableOpacity,
5
- StyleSheet,
6
- Animated,
7
- View,
8
- Platform,
9
- } from 'react-native';
3
+ import { TouchableOpacity, StyleSheet, Animated, View } from 'react-native';
10
4
  import { useNavigation } from '@react-navigation/native';
11
5
  import { getStatusBarHeight } from 'react-native-iphone-x-helper';
12
6
 
@@ -101,11 +95,7 @@ const HeaderAni = memo(
101
95
  onPress={onPressLeft}
102
96
  accessibilityLabel={AccessibilityLabel.ICON_BACK}
103
97
  >
104
- <Icon
105
- name={Platform.OS === 'android' ? 'left-square' : 'left'}
106
- size={27}
107
- color={Colors.Gray9}
108
- />
98
+ <Icon name={'left'} size={27} color={Colors.Gray9} />
109
99
  </TouchableOpacity>
110
100
  <View styles={styles.wrapRightComponent}>{rightComponent}</View>
111
101
  </Animated.View>
@@ -1,10 +1,18 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { TouchableOpacity } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
4
  import { SCProvider } from '../../../context';
5
5
  import { mockSCStore } from '../../../context/mockStore';
6
6
  import MediaPlayerFull from '../MediaPlayerFull';
7
7
 
8
+ const mockSetState = jest.fn();
9
+ jest.mock('react', () => {
10
+ return {
11
+ ...jest.requireActual('react'),
12
+ useState: jest.fn((init) => [init, mockSetState]),
13
+ };
14
+ });
15
+
8
16
  const wrapComponent = (props) => (
9
17
  <SCProvider initState={mockSCStore({})}>
10
18
  <MediaPlayerFull {...props} />
@@ -14,7 +22,14 @@ const wrapComponent = (props) => (
14
22
  describe('Test MediaPlayerFull', () => {
15
23
  let tree;
16
24
 
25
+ afterEach(() => {
26
+ useState.mockClear();
27
+ });
28
+
17
29
  it('Test render', async () => {
30
+ useState.mockImplementationOnce((init) => [false, mockSetState]);
31
+ useState.mockImplementationOnce((init) => [false, mockSetState]);
32
+ useState.mockImplementationOnce((init) => [init, mockSetState]);
18
33
  await act(async () => {
19
34
  tree = await create(
20
35
  wrapComponent({
@@ -29,13 +44,18 @@ describe('Test MediaPlayerFull', () => {
29
44
  await act(async () => {
30
45
  TouchableOpacities[0].props.onPress();
31
46
  });
47
+ expect(mockSetState).toBeCalledWith(false);
32
48
  await act(async () => {
33
49
  TouchableOpacities[1].props.onPress();
34
50
  TouchableOpacities[2].props.onPress();
35
51
  });
52
+ expect(mockSetState).toBeCalledWith(true);
36
53
  });
37
54
 
38
55
  it('Test render 2', async () => {
56
+ useState.mockImplementationOnce((init) => [true, mockSetState]);
57
+ useState.mockImplementationOnce((init) => [true, mockSetState]);
58
+ useState.mockImplementationOnce((init) => [init, mockSetState]);
39
59
  await act(async () => {
40
60
  tree = await create(
41
61
  wrapComponent({
@@ -52,9 +72,11 @@ describe('Test MediaPlayerFull', () => {
52
72
  await act(async () => {
53
73
  TouchableOpacities[0].props.onPress();
54
74
  });
75
+ expect(mockSetState).toBeCalledWith(false);
55
76
  await act(async () => {
56
77
  TouchableOpacities[1].props.onPress();
57
78
  TouchableOpacities[2].props.onPress();
58
79
  });
80
+ expect(mockSetState).toBeCalledWith(true);
59
81
  });
60
82
  });
@@ -1,10 +1,5 @@
1
1
  import React, { memo, useCallback } from 'react';
2
- import {
3
- Platform,
4
- TouchableOpacity,
5
- TouchableWithoutFeedback,
6
- View,
7
- } from 'react-native';
2
+ import { TouchableOpacity, TouchableWithoutFeedback, View } from 'react-native';
8
3
  import { IconOutline } from '@ant-design/icons-react-native';
9
4
  import moment from 'moment';
10
5
  import Text from '../../Text';
@@ -111,10 +106,7 @@ const ItemOneTap = memo(({ automate = {}, wrapSyles, onPressItem }) => {
111
106
  >
112
107
  {activateAt && t('activated_time', { time: activateAt })}
113
108
  </Text>
114
- <IconOutline
115
- name={Platform.OS === 'android' ? 'right-square' : 'right'}
116
- size={12}
117
- />
109
+ <IconOutline name="right" size={12} />
118
110
  </View>
119
111
  </TouchableOpacity>
120
112
  </View>