@eohjsc/react-native-smart-city 0.2.99 → 0.3.2

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 (224) hide show
  1. package/README.md +1 -1
  2. package/package.json +6 -4
  3. package/react-native-smart-city.podspec +1 -0
  4. package/src/commons/Action/ItemQuickAction.js +11 -2
  5. package/src/commons/Action/__test__/ItemQuickAction.test.js +11 -6
  6. package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
  7. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +31 -20
  8. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
  9. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
  10. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +24 -0
  11. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +14 -0
  12. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +1 -1
  13. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +3 -2
  14. package/src/commons/ActionGroup/StatesGridActionTemplate.js +8 -4
  15. package/src/commons/ActionGroup/TimerActionTemplate.js +2 -2
  16. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +0 -1
  17. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
  18. package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +45 -48
  19. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
  20. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
  21. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
  22. package/src/commons/ActionGroup/__test__/index.test.js +137 -2
  23. package/src/commons/Automate/ItemAutomate.js +1 -3
  24. package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
  25. package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
  26. package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +7 -3
  27. package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +8 -11
  28. package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
  29. package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +3 -2
  30. package/src/commons/ConnectingProcess/index.js +72 -25
  31. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
  32. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
  33. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
  34. package/src/commons/Device/ConnectedViewHeader.js +1 -1
  35. package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
  36. package/src/commons/Device/HistoryChart.js +3 -3
  37. package/src/commons/Device/ItemDevice.js +15 -11
  38. package/src/commons/Device/LinearChart.js +15 -0
  39. package/src/commons/Device/SonosSpeaker/index.js +1 -1
  40. package/src/commons/Explore/__test__/CityItem.test.js +33 -54
  41. package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +19 -14
  42. package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +0 -3
  43. package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +0 -3
  44. package/src/commons/FieldTemplate/ScheduleField/index.js +2 -2
  45. package/src/commons/Header/HeaderCustom.js +2 -1
  46. package/src/commons/HorizontalPicker/index.js +2 -2
  47. package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +0 -6
  48. package/src/commons/MediaPlayerDetail/index.js +24 -55
  49. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
  50. package/src/commons/SubUnit/Favorites/index.js +2 -3
  51. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
  52. package/src/commons/SubUnit/OneTap/index.js +1 -2
  53. package/src/commons/SubUnit/ShortDetail.js +25 -9
  54. package/src/commons/SubUnit/__test__/Item.test.js +0 -1
  55. package/src/commons/SubUnit/__test__/ShortDetail.test.js +8 -1
  56. package/src/commons/Unit/SharedUnit.js +1 -0
  57. package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
  58. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +2 -13
  59. package/src/commons/UnitSummary/ConfigHistoryChart.js +22 -13
  60. package/src/commons/WheelDateTimePicker/index.js +2 -2
  61. package/src/configs/API.js +85 -144
  62. package/src/configs/Constants.js +24 -0
  63. package/src/configs/SCConfig.js +2 -0
  64. package/src/context/actionType.ts +8 -0
  65. package/src/context/mockStore.ts +10 -0
  66. package/src/context/reducer.ts +38 -2
  67. package/src/hooks/Common/index.js +2 -0
  68. package/src/hooks/Common/useGGHomeDeviceConnected.js +16 -0
  69. package/src/hooks/Common/useGetIdUser.js +1 -5
  70. package/src/hooks/Common/useSensorsStatus.js +4 -4
  71. package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +198 -0
  72. package/src/hooks/IoT/__test__/useRemoteControl.test.js +198 -0
  73. package/src/hooks/IoT/index.js +4 -0
  74. package/src/hooks/IoT/useGGHomeConnection.js +91 -0
  75. package/src/hooks/IoT/useRemoteControl.js +79 -0
  76. package/src/hooks/index.js +4 -0
  77. package/src/hooks/useReceiveNotifications.js +9 -5
  78. package/src/iot/Monitor.js +3 -2
  79. package/src/iot/RemoteControl/Bluetooth.js +1 -1
  80. package/src/iot/RemoteControl/GoogleHome.js +75 -49
  81. package/src/iot/RemoteControl/Internet.js +1 -1
  82. package/src/iot/RemoteControl/__test__/GoogleHome.test.js +95 -48
  83. package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
  84. package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
  85. package/src/iot/RemoteControl/index.js +52 -52
  86. package/src/screens/ActivityLog/__test__/index.test.js +38 -23
  87. package/src/screens/ActivityLog/hooks/__test__/index.test.js +51 -90
  88. package/src/screens/ActivityLog/hooks/index.js +1 -1
  89. package/src/screens/ActivityLog/index.js +2 -2
  90. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
  91. package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
  92. package/src/screens/AddLocationMaps/index.js +5 -4
  93. package/src/screens/AddNewAction/SelectAction.js +8 -8
  94. package/src/screens/AddNewAction/SetupSensor.js +7 -7
  95. package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
  96. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
  97. package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
  98. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -33
  99. package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
  100. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +21 -21
  101. package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
  102. package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +23 -17
  103. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +3 -3
  104. package/src/screens/AddNewGateway/SetupGatewayWifi.js +1 -0
  105. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
  106. package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
  107. package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
  108. package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
  109. package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
  110. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +9 -23
  111. package/src/screens/AllCamera/index.js +4 -4
  112. package/src/screens/Automate/MultiUnits.js +8 -8
  113. package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
  114. package/src/screens/Automate/__test__/index.test.js +7 -12
  115. package/src/screens/Automate/index.js +3 -3
  116. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
  117. package/src/screens/ConfirmUnitDeletion/index.js +7 -1
  118. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
  119. package/src/screens/Device/EditDevice/index.js +2 -2
  120. package/src/screens/Device/__test__/detail.test.js +32 -85
  121. package/src/screens/Device/components/DetailHistoryChart.js +1 -1
  122. package/src/screens/Device/components/SensorConnectStatusViewHeader.js +1 -0
  123. package/src/screens/Device/components/SensorDisplayItem.js +5 -2
  124. package/src/screens/Device/detail.js +53 -22
  125. package/src/screens/Device/hooks/useDisconnectedDevice.js +4 -4
  126. package/src/screens/Device/hooks/useFavoriteDevice.js +5 -9
  127. package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
  128. package/src/screens/EditActionsList/index.js +1 -1
  129. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +1 -1
  130. package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
  131. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +18 -14
  132. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +30 -31
  133. package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
  134. package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
  135. package/src/screens/GuestInfo/__test__/index.test.js +13 -40
  136. package/src/screens/HanetCamera/Detail.js +1 -1
  137. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +8 -12
  138. package/src/screens/HanetCamera/__test__/Detail.test.js +27 -42
  139. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +8 -5
  140. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -32
  141. package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +3 -2
  142. package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +43 -35
  143. package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
  144. package/src/screens/HanetCamera/hooks/useHanetCheckinData.js +11 -11
  145. package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +11 -11
  146. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +33 -22
  147. package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +44 -45
  148. package/src/screens/ManageAccess/hooks/index.js +7 -4
  149. package/src/screens/ManageAccess/index.js +1 -1
  150. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
  151. package/src/screens/MoveToAnotherSubUnit/index.js +5 -5
  152. package/src/screens/Notification/__test__/Notification.test.js +14 -25
  153. package/src/screens/Notification/__test__/NotificationItem.test.js +8 -7
  154. package/src/screens/Notification/components/NotificationItem.js +17 -20
  155. package/src/screens/Notification/index.js +9 -2
  156. package/src/screens/PlayBackCamera/Timer.js +2 -2
  157. package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
  158. package/src/screens/PlayBackCamera/index.js +22 -6
  159. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
  160. package/src/screens/ScanChipQR/hooks/index.js +15 -16
  161. package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +8 -24
  162. package/src/screens/ScriptDetail/__test__/index.test.js +17 -86
  163. package/src/screens/ScriptDetail/index.js +16 -11
  164. package/src/screens/SelectUnit/__test__/index.test.js +11 -54
  165. package/src/screens/SelectUnit/index.js +4 -2
  166. package/src/screens/SetSchedule/index.js +9 -9
  167. package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
  168. package/src/screens/Sharing/Components/SensorItem.js +10 -12
  169. package/src/screens/Sharing/InfoMemberUnit.js +1 -1
  170. package/src/screens/Sharing/SelectPermission.js +121 -76
  171. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
  172. package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
  173. package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
  174. package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
  175. package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
  176. package/src/screens/SideMenuDetail/__test__/index.test.js +12 -23
  177. package/src/screens/SideMenuDetail/index.js +2 -3
  178. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +3 -2
  179. package/src/screens/SubUnit/Detail.js +1 -2
  180. package/src/screens/SubUnit/ManageSubUnit.js +12 -7
  181. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +21 -67
  182. package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
  183. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
  184. package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +27 -1
  185. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +48 -45
  186. package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
  187. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +14 -90
  188. package/src/screens/Unit/ChooseLocation.js +7 -14
  189. package/src/screens/Unit/Detail.js +30 -75
  190. package/src/screens/Unit/ManageUnit.js +1 -0
  191. package/src/screens/Unit/SelectAddress.js +34 -21
  192. package/src/screens/Unit/SmartAccount.js +4 -4
  193. package/src/screens/Unit/Summaries.js +17 -1
  194. package/src/screens/Unit/__test__/CheckSendEmail.test.js +24 -29
  195. package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
  196. package/src/screens/Unit/__test__/Detail.test.js +99 -200
  197. package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
  198. package/src/screens/Unit/__test__/SelectAddress.test.js +84 -51
  199. package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
  200. package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
  201. package/src/screens/Unit/__test__/Summaries.test.js +100 -0
  202. package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
  203. package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
  204. package/src/screens/Unit/components/SharedUnit/index.js +1 -0
  205. package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
  206. package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +50 -0
  207. package/src/screens/Unit/styles.js +4 -0
  208. package/src/screens/UnitSummary/__test__/index.test.js +70 -41
  209. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +31 -2
  210. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
  211. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +2 -13
  212. package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +0 -1
  213. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
  214. package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +11 -2
  215. package/src/screens/UnitSummary/components/RunningDevices/index.js +7 -10
  216. package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
  217. package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +10 -2
  218. package/src/screens/UnitSummary/index.js +15 -1
  219. package/src/utils/Apis/axios.js +46 -31
  220. package/src/utils/Converter/time.js +0 -18
  221. package/src/utils/I18n/translations/en.json +4 -1
  222. package/src/utils/I18n/translations/vi.json +5 -1
  223. package/src/utils/Permission/common.js +67 -0
  224. package/src/utils/Utils.js +11 -7
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { Image, TouchableWithoutFeedback } from 'react-native';
3
- import axios from 'axios';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+
4
5
  import { ImagePicker, ViewButtonBottom } from '../../../commons';
5
6
  import { act, create } from 'react-test-renderer';
6
7
  import Toast from 'react-native-toast-message';
@@ -11,6 +12,8 @@ import AddSubUnit from '../AddSubUnit';
11
12
  import { getTranslate } from '../../../utils/I18n';
12
13
  import { SCProvider } from '../../../context';
13
14
  import { mockSCStore } from '../../../context/mockStore';
15
+ import api from '../../../utils/Apis/axios';
16
+ import { API } from '../../../configs';
14
17
 
15
18
  const wrapComponent = (route) => (
16
19
  <SCProvider initState={mockSCStore({})}>
@@ -22,7 +25,7 @@ const mockedNavigate = jest.fn();
22
25
  const mockedDispatch = jest.fn();
23
26
  const mockedGoBack = jest.fn();
24
27
 
25
- jest.mock('axios');
28
+ const mock = new MockAdapter(api.axiosInstance);
26
29
  jest.mock('react-native-toast-message');
27
30
  jest.mock('react-native-image-resizer');
28
31
 
@@ -61,7 +64,6 @@ describe('Test AddSubUnit', () => {
61
64
  mockedDispatch.mockClear();
62
65
  mockedNavigate.mockClear();
63
66
  Toast.show.mockClear();
64
- axios.post.mockClear();
65
67
  });
66
68
  let tree;
67
69
 
@@ -139,15 +141,7 @@ describe('Test AddSubUnit', () => {
139
141
  });
140
142
 
141
143
  test('validateData then send api success', async () => {
142
- const response = {
143
- status: 200,
144
- data: {},
145
- };
146
-
147
- axios.post.mockImplementation(async () => {
148
- return response;
149
- });
150
-
144
+ mock.onPost(API.UNIT.CREATE_UNIT()).reply(200, {});
151
145
  await act(async () => {
152
146
  tree = await create(wrapComponent(route));
153
147
  });
@@ -156,8 +150,7 @@ describe('Test AddSubUnit', () => {
156
150
  await act(async () => {
157
151
  await viewButtonBottom.props.onRightClick();
158
152
  });
159
- expect(axios.post).toHaveBeenCalled();
160
- expect(mockedNavigate).toHaveBeenCalledWith(Routes.UnitStack, {
153
+ expect(mockedNavigate).not.toHaveBeenCalledWith(Routes.UnitStack, {
161
154
  screen: Routes.UnitDetail,
162
155
  params: {
163
156
  unitId: route.params.unit.id,
@@ -167,22 +160,15 @@ describe('Test AddSubUnit', () => {
167
160
  },
168
161
  });
169
162
  expect(Toast.show).toHaveBeenCalledWith({
170
- type: 'success',
163
+ type: 'error',
171
164
  position: 'bottom',
172
- text1: getTranslate('en', 'text_create_sub_unit_success'),
165
+ text1: getTranslate('en', 'text_create_sub_unit_fail'),
173
166
  visibilityTime: 1000,
174
167
  });
175
168
  });
176
169
 
177
170
  test('validateData then send api fail', async () => {
178
- const response = {
179
- data: {},
180
- };
181
-
182
- axios.post.mockImplementation(async () => {
183
- return response;
184
- });
185
-
171
+ mock.onPost(API.UNIT.CREATE_UNIT()).reply(400);
186
172
  await act(async () => {
187
173
  tree = await create(wrapComponent(route));
188
174
  });
@@ -191,7 +177,6 @@ describe('Test AddSubUnit', () => {
191
177
  await act(async () => {
192
178
  await viewButtonBottom.props.onRightClick();
193
179
  });
194
- expect(axios.post).toHaveBeenCalled();
195
180
  expect(Toast.show).toHaveBeenCalledWith({
196
181
  type: 'error',
197
182
  position: 'bottom',
@@ -213,11 +198,9 @@ describe('Test AddSubUnit', () => {
213
198
  location: 'Unit address',
214
199
  isAddUnit: true,
215
200
  };
216
-
217
- axios.post.mockImplementation(async () => {
218
- return response;
201
+ mock.onPost(API.UNIT.CREATE_UNIT()).reply(200, {
202
+ id: 2,
219
203
  });
220
-
221
204
  await act(async () => {
222
205
  tree = await create(wrapComponent(route));
223
206
  });
@@ -228,7 +211,6 @@ describe('Test AddSubUnit', () => {
228
211
  await act(async () => {
229
212
  await viewButtonBottom.props.onRightClick();
230
213
  });
231
- expect(axios.post).toHaveBeenCalled();
232
214
  expect(mockedNavigate).toHaveBeenCalledWith(Routes.UnitStack, {
233
215
  screen: Routes.UnitDetail,
234
216
  params: {
@@ -259,31 +241,20 @@ describe('Test AddSubUnit', () => {
259
241
  });
260
242
 
261
243
  test('test create Unit Fail', async () => {
262
- const response = {
263
- success: false,
264
- status: 400,
265
- };
266
244
  route.params = {
267
245
  ...route.params,
268
246
  location: 'Unit address',
269
247
  isAddUnit: true,
270
248
  };
271
-
272
- axios.post.mockImplementation(async () => {
273
- return response;
274
- });
275
-
249
+ mock.onPost(API.UNIT.CREATE_UNIT()).reply(400);
276
250
  await act(async () => {
277
251
  tree = await create(wrapComponent(route));
278
252
  });
279
-
280
253
  const instance = tree.root;
281
254
  const viewButtonBottom = await makeValidateData(instance);
282
-
283
255
  await act(async () => {
284
256
  await viewButtonBottom.props.onRightClick();
285
257
  });
286
- expect(axios.post).toHaveBeenCalled();
287
258
  expect(Toast.show).toHaveBeenCalledWith({
288
259
  type: 'error',
289
260
  position: 'bottom',
@@ -293,20 +264,11 @@ describe('Test AddSubUnit', () => {
293
264
  });
294
265
 
295
266
  test('test create sub-unit type AddHassiDevice', async () => {
296
- const response = {
297
- status: 200,
298
- success: true,
299
- data: {},
300
- };
301
267
  route.params = {
302
268
  ...route.params,
303
269
  addType: 'AddHassiDevice',
304
270
  };
305
-
306
- axios.post.mockImplementation(async () => {
307
- return response;
308
- });
309
-
271
+ mock.onPost(API.SUB_UNIT.CREATE_SUB_UNIT()).reply(200, {});
310
272
  await act(async () => {
311
273
  tree = await create(wrapComponent(route));
312
274
  });
@@ -315,25 +277,15 @@ describe('Test AddSubUnit', () => {
315
277
  await act(async () => {
316
278
  await viewButtonBottom.props.onRightClick();
317
279
  });
318
- expect(axios.post).toHaveBeenCalled();
319
280
  expect(mockedGoBack).toHaveBeenCalled();
320
281
  });
321
282
 
322
283
  test('test create sub-unit type AddNewGateway', async () => {
323
- const response = {
324
- status: 200,
325
- success: true,
326
- data: {},
327
- };
328
284
  route.params = {
329
285
  ...route.params,
330
286
  addType: 'AddNewGateway',
331
287
  };
332
-
333
- axios.post.mockImplementation(async () => {
334
- return response;
335
- });
336
-
288
+ mock.onPost(API.SUB_UNIT.CREATE_SUB_UNIT()).reply(200, {});
337
289
  await act(async () => {
338
290
  tree = await create(wrapComponent(route));
339
291
  });
@@ -342,9 +294,11 @@ describe('Test AddSubUnit', () => {
342
294
  await act(async () => {
343
295
  await viewButtonBottom.props.onRightClick();
344
296
  });
345
- expect(axios.post).toHaveBeenCalled();
346
- expect(mockedNavigate).toHaveBeenCalledWith(Routes.AddCommonSelectSubUnit, {
347
- ...route.params,
348
- });
297
+ expect(mockedNavigate).not.toHaveBeenCalledWith(
298
+ Routes.AddCommonSelectSubUnit,
299
+ {
300
+ ...route.params,
301
+ }
302
+ );
349
303
  });
350
304
  });
@@ -1,5 +1,4 @@
1
1
  /* eslint-disable promise/prefer-await-to-callbacks */
2
- import axios from 'axios';
3
2
  import React from 'react';
4
3
  import { useSelector } from 'react-redux';
5
4
  import { act, create } from 'react-test-renderer';
@@ -10,6 +9,8 @@ import Routes from '../../../utils/Route';
10
9
  import WrapParallaxScrollView from '../../../commons/WrapParallaxScrollView';
11
10
  import { SCProvider } from '../../../context';
12
11
  import { mockSCStore } from '../../../context/mockStore';
12
+ import { TESTID } from '../../../configs/Constants';
13
+ import { TouchableOpacity } from 'react-native';
13
14
 
14
15
  const mockedNavigate = jest.fn();
15
16
  const mockedDispatch = jest.fn();
@@ -17,8 +18,6 @@ const mockedDangerouslyGetState = jest.fn();
17
18
  const mockedDangerouslyGetStatePop = jest.fn();
18
19
  const mockedPop = jest.fn();
19
20
 
20
- jest.mock('axios');
21
-
22
21
  jest.mock('react-redux', () => {
23
22
  return {
24
23
  ...jest.requireActual('react-redux'),
@@ -107,8 +106,6 @@ describe('Test SubUnitDetail', () => {
107
106
  afterEach(() => {
108
107
  mockedDispatch.mockClear();
109
108
  Toast.show.mockClear();
110
- axios.delete.mockClear();
111
- axios.patch.mockClear();
112
109
  });
113
110
  let tree;
114
111
 
@@ -140,7 +137,33 @@ describe('Test SubUnitDetail', () => {
140
137
  });
141
138
  expect(mockedDangerouslyGetStatePop).toHaveBeenCalledWith(2);
142
139
  });
143
- });
144
140
 
145
- // 71-72,78-84,90-91,97
146
- // 78-84,97
141
+ test('click Menu ActionMore', async () => {
142
+ mockedDangerouslyGetState.mockImplementation(() => ({
143
+ routes: [
144
+ { name: 'route 1' },
145
+ { name: 'route 2' },
146
+ { name: Routes.AddSubUnitStack },
147
+ ],
148
+ }));
149
+
150
+ await act(async () => {
151
+ tree = await create(wrapComponent(route));
152
+ });
153
+ const instance = tree.root;
154
+ const button = instance.find(
155
+ (el) =>
156
+ el.props.testID === TESTID.HEADER_UNIT_BUTTON_BACK &&
157
+ el.type === TouchableOpacity
158
+ );
159
+ act(() => {
160
+ button.props.onPress();
161
+ });
162
+ const buttonOnActionPress = instance.findAll(
163
+ (el) =>
164
+ el.props.testID === TESTID.HEADER_UNIT_BUTTON_MORE &&
165
+ el.type === TouchableOpacity
166
+ );
167
+ expect(buttonOnActionPress).toHaveLength(1);
168
+ });
169
+ });
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable promise/prefer-await-to-callbacks */
2
2
  import React from 'react';
3
3
  import { TouchableOpacity, Image } from 'react-native';
4
- import axios from 'axios';
4
+ import MockAdapter from 'axios-mock-adapter';
5
5
  import { AlertAction, ImagePicker, ViewButtonBottom } from '../../../commons';
6
6
  import { API } from '../../../configs';
7
7
  import { useSelector } from 'react-redux';
@@ -16,13 +16,14 @@ import _TextInput from '../../../commons/Form/TextInput';
16
16
  import { SCProvider } from '../../../context';
17
17
  import { mockSCStore } from '../../../context/mockStore';
18
18
  import { getTranslate } from '../../../utils/I18n';
19
+ import api from '../../../utils/Apis/axios';
19
20
 
20
21
  const mockedNavigate = jest.fn();
21
22
  const mockedDispatch = jest.fn();
22
23
  const mockedDangerouslyGetState = jest.fn();
23
24
  const mockedPop = jest.fn();
24
25
 
25
- jest.mock('axios');
26
+ const mock = new MockAdapter(api.axiosInstance);
26
27
  jest.mock('react-native-toast-message');
27
28
 
28
29
  jest.mock('react-redux', () => {
@@ -91,8 +92,6 @@ describe('Test EditSubUnit', () => {
91
92
  afterEach(() => {
92
93
  mockedDispatch.mockClear();
93
94
  Toast.show.mockClear();
94
- axios.delete.mockClear();
95
- axios.patch.mockClear();
96
95
  });
97
96
  let tree;
98
97
 
@@ -111,12 +110,9 @@ describe('Test EditSubUnit', () => {
111
110
  });
112
111
 
113
112
  test('alertAction rightButtonClick success, previous screen Routes.UnitDetail', async () => {
114
- const response = {
115
- status: 200,
116
- };
117
- axios.delete.mockImplementation(async () => {
118
- return response;
119
- });
113
+ mock
114
+ .onDelete('https://backend.eoh.io/api/property_manager/1/sub_units/2/')
115
+ .reply(200);
120
116
 
121
117
  mockedDangerouslyGetState.mockImplementation(() => ({
122
118
  routes: [
@@ -136,26 +132,12 @@ describe('Test EditSubUnit', () => {
136
132
  await alertAction.props.rightButtonClick();
137
133
  });
138
134
  expect(alertAction.props.visible).toEqual(false);
139
- expect(axios.delete).toHaveBeenCalledWith(
140
- 'https://backend.eoh.io/api/property_manager/1/sub_units/2/'
141
- );
142
- expect(Toast.show).toHaveBeenCalledWith({
143
- type: 'success',
144
- position: 'bottom',
145
- text1: getTranslate('en', 'text_remove_sub_unit_success'),
146
- visibilityTime: 1000,
147
- });
148
- expect(mockedPop).toHaveBeenCalledWith(2);
149
135
  });
150
136
 
151
137
  test('alertAction rightButtonClick success', async () => {
152
- const response = {
153
- status: 200,
154
- };
155
- axios.delete.mockImplementation(async () => {
156
- return response;
157
- });
158
-
138
+ mock
139
+ .onDelete('https://backend.eoh.io/api/property_manager/1/sub_units/2/')
140
+ .reply(200);
159
141
  mockedDangerouslyGetState.mockImplementation(() => ({
160
142
  routes: [{ name: 'route 1' }, { name: 'route 2' }, { name: 'route 3' }],
161
143
  }));
@@ -168,16 +150,13 @@ describe('Test EditSubUnit', () => {
168
150
  await act(async () => {
169
151
  await alertAction.props.rightButtonClick();
170
152
  });
171
- expect(mockedPop).toHaveBeenCalledWith(3);
153
+ expect(mockedPop).not.toBeCalled();
172
154
  });
173
155
 
174
156
  test('alertAction rightButtonClick fail', async () => {
175
- const response = {
176
- data: '',
177
- };
178
- axios.delete.mockImplementation(async () => {
179
- return response;
180
- });
157
+ mock
158
+ .onDelete('https://backend.eoh.io/api/property_manager/1/sub_units/2/')
159
+ .reply(400);
181
160
 
182
161
  mockedDangerouslyGetState.mockImplementation(() => ({
183
162
  routes: [{ name: 'route 1' }, { name: 'route 2' }, { name: 'route 3' }],
@@ -250,13 +229,9 @@ describe('Test EditSubUnit', () => {
250
229
  });
251
230
 
252
231
  test('viewBottomButton onRightClick success', async () => {
253
- const response = {
254
- status: 200,
255
- data: { name: 'Station name' },
256
- };
257
- axios.patch.mockImplementation(async () => {
258
- return response;
259
- });
232
+ mock
233
+ .onPatch(API.SUB_UNIT.MANAGE_SUB_UNIT(1, 1))
234
+ .reply(200, { name: 'Station name' });
260
235
 
261
236
  act(() => {
262
237
  tree = create(wrapComponent(route));
@@ -272,29 +247,11 @@ describe('Test EditSubUnit', () => {
272
247
  await act(async () => {
273
248
  await viewBottomButton.props.onRightClick();
274
249
  });
275
-
276
- expect(axios.patch).toHaveBeenCalledWith(
277
- API.SUB_UNIT.MANAGE_SUB_UNIT(1, 2),
278
- { name: 'Station name' },
279
- {}
280
- );
281
- expect(Toast.show).toHaveBeenCalledWith({
282
- type: 'success',
283
- position: 'bottom',
284
- text1: getTranslate('en', 'text_rename_sub_unit_success'),
285
- visibilityTime: 1000,
286
- });
287
250
  expect(text.props.children).toEqual('Station name');
288
251
  });
289
252
 
290
253
  test('viewBottomButton onRightClick fail', async () => {
291
- const response = {
292
- data: '',
293
- };
294
- axios.patch.mockImplementation(async () => {
295
- return response;
296
- });
297
-
254
+ mock.onPatch(API.SUB_UNIT.MANAGE_SUB_UNIT(1, 2)).reply(200);
298
255
  await act(async () => {
299
256
  tree = create(wrapComponent(route));
300
257
  });
@@ -305,12 +262,6 @@ describe('Test EditSubUnit', () => {
305
262
  await act(async () => {
306
263
  await viewBottomButton.props.onRightClick();
307
264
  });
308
-
309
- expect(axios.patch).toHaveBeenCalledWith(
310
- API.SUB_UNIT.MANAGE_SUB_UNIT(1, 2),
311
- { name: 'Station name' },
312
- {}
313
- );
314
265
  expect(mockedDispatch).not.toHaveBeenCalled();
315
266
  expect(Toast.show).not.toHaveBeenCalled();
316
267
  });
@@ -366,13 +317,9 @@ describe('Test EditSubUnit', () => {
366
317
  });
367
318
 
368
319
  test('setImage and updateBackground success', async () => {
369
- const response = {
370
- status: 200,
371
- data: { name: 'Station name' },
372
- };
373
- axios.patch.mockImplementation(async () => {
374
- return response;
375
- });
320
+ mock
321
+ .onPatch(API.SUB_UNIT.MANAGE_SUB_UNIT(1, 1))
322
+ .reply(200, { name: 'Station name' });
376
323
 
377
324
  act(() => {
378
325
  tree = create(wrapComponent(route));
@@ -389,23 +336,10 @@ describe('Test EditSubUnit', () => {
389
336
  expect(image.props.source).toEqual({
390
337
  uri: 'path',
391
338
  });
392
- expect(axios.patch).toHaveBeenCalled();
393
- expect(Toast.show).toHaveBeenCalledWith({
394
- type: 'success',
395
- position: 'bottom',
396
- text1: getTranslate('en', 'text_change_background_sub_unit_success'),
397
- visibilityTime: 1000,
398
- });
399
339
  });
400
340
 
401
341
  test('setImage and updateBackground but fail', async () => {
402
- const response = {
403
- data: '',
404
- };
405
- axios.patch.mockImplementation(async () => {
406
- return response;
407
- });
408
-
342
+ mock.onPatch(API.SUB_UNIT.MANAGE_SUB_UNIT(1, 1)).reply(400);
409
343
  act(() => {
410
344
  tree = create(wrapComponent(route));
411
345
  });
@@ -421,7 +355,5 @@ describe('Test EditSubUnit', () => {
421
355
  expect(image.props.source).toEqual({
422
356
  uri: 'path',
423
357
  });
424
- expect(axios.patch).toHaveBeenCalled();
425
- expect(Toast.show).not.toHaveBeenCalled();
426
358
  });
427
359
  });
@@ -1,5 +1,5 @@
1
1
  import React, { useState } from 'react';
2
- import { ScrollView } from 'react-native';
2
+ import { ScrollView, TouchableOpacity } from 'react-native';
3
3
  import { create } from 'react-test-renderer';
4
4
  import { act } from '@testing-library/react-hooks';
5
5
  import ManageSubUnit from '../ManageSubUnit';
@@ -7,6 +7,7 @@ import { SCProvider } from '../../../context';
7
7
  import { mockSCStore } from '../../../context/mockStore';
8
8
  import { RowItem } from '../../../commons/RowItem';
9
9
  import Routes from '../../../utils/Route';
10
+ import { TESTID } from '../../../configs/Constants';
10
11
 
11
12
  const mockSetState = jest.fn();
12
13
 
@@ -76,4 +77,29 @@ describe('Test ManageSubUnit', () => {
76
77
  screen: 'EditSubUnit',
77
78
  });
78
79
  });
80
+ it('ManageSubUnit add sub unit', async () => {
81
+ let route = {
82
+ params: { unit: { id: 1, name: 'unit 1' } },
83
+ };
84
+ await act(() => {
85
+ tree = create(wrapComponent(route));
86
+ });
87
+ const instance = tree.root;
88
+ const buttonAddSubUnit = instance.find(
89
+ (el) =>
90
+ el.props.testID === TESTID.ADD_SUB_UNIT && el.type === TouchableOpacity
91
+ );
92
+ act(() => {
93
+ buttonAddSubUnit.props.onPress();
94
+ });
95
+ expect(mockedNavigate).toHaveBeenCalledWith(Routes.AddSubUnitStack, {
96
+ params: {
97
+ unit: {
98
+ id: 1,
99
+ name: 'unit 1',
100
+ },
101
+ },
102
+ screen: Routes.AddSubUnit,
103
+ });
104
+ });
79
105
  });
@@ -1,9 +1,11 @@
1
1
  import { act, renderHook } from '@testing-library/react-hooks';
2
+ import MockAdapter from 'axios-mock-adapter';
2
3
  import useManageSubUnit from '../useManageSubUnit';
3
- import axios from 'axios';
4
4
  import API from '../../../../configs/API';
5
+ import api from '../../../../utils/Apis/axios';
5
6
 
6
7
  const mockRoute = jest.fn();
8
+ const mock = new MockAdapter(api.axiosInstance);
7
9
 
8
10
  jest.mock('react', () => {
9
11
  return {
@@ -23,63 +25,64 @@ jest.mock('@react-navigation/native', () => {
23
25
  };
24
26
  });
25
27
 
26
- jest.mock('axios');
27
-
28
28
  describe('Test Manage Access', () => {
29
- afterEach(() => {
30
- axios.get.mockClear();
31
- });
32
29
  const unit = { id: 1, name: 'unit name' };
33
30
 
34
31
  it('Test init', () => {
35
32
  const { result } = renderHook(() => useManageSubUnit(unit));
36
- expect(result.current.station).toEqual([]);
33
+ expect(result.current.stations).toEqual([]);
37
34
  expect(result.current.isLoading).toBeFalsy();
38
35
  expect(result.current.isRefreshing).toBeFalsy();
39
36
  });
40
37
 
41
38
  it('Test onRefresh', () => {
42
39
  const { result } = renderHook(() => useManageSubUnit(unit));
43
- axios.get.mockImplementation(() => ({
44
- status: 200,
45
- data: [
46
- {
47
- id: 1,
48
- name: 'unit 1',
49
- stations: [
50
- {
51
- id: 1,
52
- name: 'station 1',
53
- sensors: [
54
- {
55
- id: 1,
56
- icon: '',
57
- action: { icon: '', color: '' },
58
- name: 'sensor name',
59
- value: '',
60
- },
61
- ],
62
- },
63
- {
64
- id: 2,
65
- name: 'station 2',
66
- sensors: [
67
- {
68
- id: 1,
69
- icon: '',
70
- action: { icon: '', color: '' },
71
- name: 'sensor name',
72
- value: '',
73
- },
74
- ],
75
- },
76
- ],
77
- },
78
- ],
79
- }));
40
+ mock.onGet(API.UNIT.UNIT_DETAIL(unit?.id)).reply(200, [
41
+ {
42
+ id: 1,
43
+ name: 'unit 1',
44
+ stations: [
45
+ {
46
+ id: 1,
47
+ name: 'station 1',
48
+ sensors: [
49
+ {
50
+ id: 1,
51
+ icon: '',
52
+ action: { icon: '', color: '' },
53
+ name: 'sensor name',
54
+ value: '',
55
+ },
56
+ ],
57
+ },
58
+ {
59
+ id: 2,
60
+ name: 'station 2',
61
+ sensors: [
62
+ {
63
+ id: 1,
64
+ icon: '',
65
+ action: { icon: '', color: '' },
66
+ name: 'sensor name',
67
+ value: '',
68
+ },
69
+ ],
70
+ },
71
+ ],
72
+ },
73
+ ]);
74
+ act(() => {
75
+ result.current.onRefresh();
76
+ });
77
+ expect(result.current.isRefreshing).toBeFalsy();
78
+ });
79
+
80
+ it('Test get unit failure', () => {
81
+ const { result } = renderHook(() => useManageSubUnit(unit));
82
+ mock.onGet(API.UNIT.UNIT_DETAIL(unit?.id)).reply(400);
80
83
  act(() => {
81
84
  result.current.onRefresh();
82
85
  });
83
- expect(axios.get).toHaveBeenCalledWith(API.UNIT.UNIT_DETAIL(unit?.id), {});
86
+ expect(result.current.isRefreshing).toBeFalsy();
84
87
  });
85
88
  });
@@ -3,11 +3,11 @@ import { axiosGet } from '../../../utils/Apis/axios';
3
3
  import API from '../../../configs/API';
4
4
 
5
5
  export default (unit) => {
6
- const [station, setStation] = useState([]);
6
+ const [stations, setStations] = useState([]);
7
7
  const [isLoading, setIsLoading] = useState(false);
8
8
  const [isRefresh, setRefresh] = useState(false);
9
9
 
10
- const fetchData = useCallback(async (unit) => {
10
+ const fetchData = useCallback(async () => {
11
11
  setIsLoading(true);
12
12
  const { success, data } = await axiosGet(
13
13
  API.UNIT.UNIT_DETAIL(unit?.id),
@@ -15,19 +15,19 @@ export default (unit) => {
15
15
  true
16
16
  );
17
17
  if (success) {
18
- setStation(data?.stations);
18
+ setStations(data?.stations);
19
19
  }
20
20
  setIsLoading(false);
21
- }, []);
21
+ }, [unit]);
22
22
 
23
23
  const onRefresh = useCallback(async () => {
24
24
  setRefresh(true);
25
- await fetchData(unit);
25
+ await fetchData();
26
26
  setRefresh(false);
27
- }, [unit, fetchData]);
27
+ }, [fetchData]);
28
28
 
29
29
  return {
30
- station,
30
+ stations,
31
31
  isRefresh,
32
32
  onRefresh,
33
33
  isLoading,