@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,18 +1,16 @@
1
1
  import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
- import axios from 'axios';
3
+ import MockAdapter from 'axios-mock-adapter';
4
4
 
5
5
  import SelectAction from '../SelectAction';
6
6
  import { SCProvider } from '../../../context';
7
7
  import { mockSCStore } from '../../../context/mockStore';
8
8
  import BottomButtonView from '../../../commons/BottomButtonView';
9
9
  import { TESTID } from '../../../configs/Constants';
10
- import ActionTemplate from '../../../commons/ActionTemplate';
11
- import NumberUpDownActionTemplate from '../../../commons/OneTapTemplate/NumberUpDownActionTemplate';
12
- import OptionsDropdownActionTemplate from '../../../commons/OneTapTemplate/OptionsDropdownActionTemplate';
13
- import StatesGridActionTemplate from '../../../commons/OneTapTemplate/StatesGridActionTemplate';
10
+ import api from '../../../utils/Apis/axios';
11
+ import { API } from '../../../configs';
14
12
 
15
- jest.mock('axios');
13
+ const mock = new MockAdapter(api.axiosInstance);
16
14
 
17
15
  const mockedNavigate = jest.fn();
18
16
  jest.mock('@react-navigation/native', () => {
@@ -49,38 +47,21 @@ describe('Test SelectAction', () => {
49
47
  },
50
48
  };
51
49
 
52
- beforeEach(() => {
53
- axios.get.mockClear();
54
- });
55
-
56
50
  test('test onSave have automateId', async () => {
57
- const response = {
58
- status: 200,
59
- success: true,
60
- };
61
- axios.post.mockImplementation(async () => {
62
- return response;
63
- });
51
+ mock.onPost(API.AUTOMATE.ADD_SCRIPT_ACTION(1)).reply(200);
64
52
  await act(async () => {
65
53
  tree = await renderer.create(wrapComponent(route));
66
54
  });
67
55
  const instance = tree.root;
68
-
69
56
  const bottomButton = instance.findByType(BottomButtonView);
70
57
  await act(async () => {
71
58
  bottomButton.props.onPressMain();
72
59
  });
73
- expect(axios.post).toHaveBeenCalled();
74
60
  expect(mockedNavigate).toHaveBeenCalled();
75
61
  });
76
62
 
77
63
  test('test onSave fail not permission', async () => {
78
- const response = {
79
- status: 404,
80
- };
81
- axios.post.mockImplementation(async () => {
82
- return response;
83
- });
64
+ mock.onPost(API.AUTOMATE.ADD_SCRIPT_ACTION(1)).reply(404);
84
65
  await act(async () => {
85
66
  tree = await renderer.create(wrapComponent(route));
86
67
  });
@@ -90,7 +71,7 @@ describe('Test SelectAction', () => {
90
71
  await act(async () => {
91
72
  bottomButton.props.onPressMain();
92
73
  });
93
- expect(axios.post).toHaveBeenCalled();
74
+ expect(mockedNavigate).toHaveBeenCalled();
94
75
  });
95
76
 
96
77
  test('test fetchData', async () => {
@@ -103,13 +84,11 @@ describe('Test SelectAction', () => {
103
84
  { template: 'three_button_action_template' },
104
85
  ],
105
86
  };
106
- axios.get.mockImplementation(async () => {
107
- return response;
108
- });
87
+ mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response.data);
109
88
  await act(async () => {
110
89
  tree = await renderer.create(wrapComponent(route));
111
90
  });
112
- expect(axios.get).toHaveBeenCalled();
91
+ expect(mockedNavigate).toHaveBeenCalled();
113
92
  });
114
93
 
115
94
  test('test RenderActionItem', async () => {
@@ -186,9 +165,7 @@ describe('Test SelectAction', () => {
186
165
  },
187
166
  ],
188
167
  };
189
- axios.get.mockImplementation(async () => {
190
- return response;
191
- });
168
+ mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response.data);
192
169
  await act(async () => {
193
170
  tree = renderer.create(wrapComponent(route));
194
171
  });
@@ -196,64 +173,6 @@ describe('Test SelectAction', () => {
196
173
  const renderActionItem = instance.find(
197
174
  (el) => el.props.testID === TESTID.ACTION_ITEM
198
175
  );
199
- const actionTemplate = instance.findByType(ActionTemplate);
200
- const numberUpDownActionTemplate = instance.findByType(
201
- NumberUpDownActionTemplate
202
- );
203
- const optionsDropdownActionTemplate = instance.findByType(
204
- OptionsDropdownActionTemplate
205
- );
206
- const statesGridActionTemplate = instance.findByType(
207
- StatesGridActionTemplate
208
- );
209
-
210
176
  expect(renderActionItem.props.data.length).toBe(4);
211
- expect(actionTemplate).toBeDefined();
212
- expect(numberUpDownActionTemplate).toBeDefined();
213
- expect(optionsDropdownActionTemplate).toBeDefined();
214
- expect(statesGridActionTemplate).toBeDefined();
215
- });
216
-
217
- test('test onPress handleOnSelectAction', async () => {
218
- const response = {
219
- status: 200,
220
- success: true,
221
- data: [
222
- {
223
- title: '',
224
- template: 'three_button_action_template',
225
- configuration: {
226
- action1: '94ae262d-46e3-42ff-9d10-516831ecc830',
227
- action2: '94ae262d-46e3-42ff-9d10-516831ecc830',
228
- action3: '94ae262d-46e3-42ff-9d10-516831ecc830',
229
- icon1: 'up',
230
- icon2: 'stop',
231
- icon3: 'down',
232
- text1: 'OPEN',
233
- text2: 'STOP',
234
- text3: 'CLOSE',
235
- text_lock: 'Door lock',
236
- is_display_lock: true,
237
- },
238
- },
239
- ],
240
- };
241
- axios.get.mockImplementation(async () => {
242
- return response;
243
- });
244
- await act(async () => {
245
- tree = await renderer.create(wrapComponent(route));
246
- });
247
- const instance = tree.root;
248
- const actionTemplate = instance.findByType(ActionTemplate);
249
- const bottomButton = instance.findByType(BottomButtonView);
250
- act(() => {
251
- actionTemplate.props.onSelectAction({
252
- name: 'OPEN',
253
- action: '94ae262d-46e3-42ff-9d10-516831ecc830',
254
- template: 'three_button_action_template',
255
- });
256
- });
257
- expect(bottomButton.props.typeMain).toEqual('primary');
258
177
  });
259
178
  });
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
- import axios from 'axios';
3
+ import MockAdapter from 'axios-mock-adapter';
4
4
 
5
5
  import SelectSensorDevices from '../SelectSensorDevices';
6
6
  import { SCProvider } from '../../../context';
@@ -9,18 +9,22 @@ import Device from '../Device';
9
9
  import BottomButtonView from '../../../commons/BottomButtonView';
10
10
  import NavBar from '../../../commons/NavBar';
11
11
  import API from '../../../configs/API';
12
- import { TESTID } from '../../../configs/Constants';
12
+ import { AUTOMATE_SELECT, TESTID } from '../../../configs/Constants';
13
13
  import { TouchableOpacity } from 'react-native';
14
14
  import Routes from '../../../utils/Route';
15
+ import api from '../../../utils/Apis/axios';
15
16
 
16
- jest.mock('axios');
17
+ const mock = new MockAdapter(api.axiosInstance);
17
18
 
18
19
  const mockedNavigate = jest.fn();
20
+ const mockedDispatch = jest.fn();
21
+
19
22
  jest.mock('@react-navigation/native', () => {
20
23
  return {
21
24
  ...jest.requireActual('@react-navigation/native'),
22
25
  useNavigation: () => ({
23
26
  navigate: mockedNavigate,
27
+ dispatch: mockedDispatch,
24
28
  }),
25
29
  };
26
30
  });
@@ -45,6 +49,9 @@ describe('Test SelectSensorDevices', () => {
45
49
  unit: { id: 1, name: 'Unit test' },
46
50
  automateId: 1,
47
51
  scriptName: 'scriptName test',
52
+ automate: {
53
+ sensor_id: 1,
54
+ },
48
55
  },
49
56
  };
50
57
  const response = {
@@ -63,29 +70,21 @@ describe('Test SelectSensorDevices', () => {
63
70
  };
64
71
 
65
72
  beforeEach(() => {
66
- axios.get.mockClear();
67
73
  mockedNavigate.mockClear();
68
74
  });
69
75
 
70
76
  test('fetch Device success', async () => {
71
- axios.get.mockImplementation(async () => {
72
- return response;
73
- });
74
-
77
+ mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response.data);
75
78
  await act(async () => {
76
79
  tree = renderer.create(wrapComponent(route));
77
80
  });
78
81
  const instance = tree.root;
79
82
  const navBar = instance.findByType(NavBar);
80
-
81
- expect(axios.get).toHaveBeenCalledWith(API.UNIT.DEVICE_CONTROL(1), {});
82
83
  expect(navBar.props.listStation).toHaveLength(1);
83
84
  });
84
85
 
85
86
  test('onPress continue', async () => {
86
- axios.get.mockImplementation(async () => {
87
- return response;
88
- });
87
+ mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response.data);
89
88
  await act(async () => {
90
89
  tree = renderer.create(wrapComponent(route));
91
90
  });
@@ -99,9 +98,7 @@ describe('Test SelectSensorDevices', () => {
99
98
  });
100
99
 
101
100
  test('test onPressDevice', async () => {
102
- axios.get.mockImplementation(async () => {
103
- return response;
104
- });
101
+ mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response.data);
105
102
  await act(async () => {
106
103
  tree = renderer.create(wrapComponent(route));
107
104
  });
@@ -113,7 +110,6 @@ describe('Test SelectSensorDevices', () => {
113
110
  device[0].props.onPress({ id: 1, name: 'sensor' });
114
111
  });
115
112
  expect(device[0].props.isSelectDevice).toEqual(true);
116
-
117
113
  act(() => {
118
114
  device[0].props.onPress({ id: 1, name: 'sensor' });
119
115
  });
@@ -121,16 +117,12 @@ describe('Test SelectSensorDevices', () => {
121
117
  });
122
118
 
123
119
  test('test onSnapItem', async () => {
124
- axios.get.mockImplementation(async () => {
125
- return response;
126
- });
127
-
120
+ mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response.data);
128
121
  await act(async () => {
129
122
  tree = renderer.create(wrapComponent(route));
130
123
  });
131
124
  const instance = tree.root;
132
125
  const navBar = instance.findByType(NavBar);
133
-
134
126
  act(() => {
135
127
  navBar.props.onSnapToItem({ id: 1, name: 'sensor' }, 0);
136
128
  });
@@ -138,9 +130,7 @@ describe('Test SelectSensorDevices', () => {
138
130
  });
139
131
 
140
132
  test('test onPressClose user already has an automateId', async () => {
141
- axios.get.mockImplementation(async () => {
142
- return response;
143
- });
133
+ mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response.data);
144
134
  await act(async () => {
145
135
  tree = renderer.create(wrapComponent(route));
146
136
  });
@@ -154,7 +144,6 @@ describe('Test SelectSensorDevices', () => {
154
144
  await act(async () => {
155
145
  iconClose[0].props.onPress();
156
146
  });
157
-
158
147
  expect(mockedNavigate).toHaveBeenCalledWith(Routes.ScriptDetail, {
159
148
  havePermission: true,
160
149
  id: 1,
@@ -166,4 +155,29 @@ describe('Test SelectSensorDevices', () => {
166
155
  unit: { id: 1, name: 'Unit test' },
167
156
  });
168
157
  });
158
+
159
+ test('test onPressClose user already has not an automateId', async () => {
160
+ mock.onGet(API.UNIT.DEVICE_SENSOR(1)).reply(200, response.data);
161
+ const new_route = {
162
+ ...route,
163
+ params: {
164
+ ...route.params,
165
+ automateId: null,
166
+ title: AUTOMATE_SELECT.SELECT_SENSOR,
167
+ },
168
+ };
169
+ await act(async () => {
170
+ tree = renderer.create(wrapComponent(new_route));
171
+ });
172
+ const instance = tree.root;
173
+ const iconClose = instance.findAll(
174
+ (el) =>
175
+ el.props.testID === TESTID.ICON_CLOSE && el.type === TouchableOpacity
176
+ );
177
+ expect(iconClose).toHaveLength(1);
178
+ await act(async () => {
179
+ iconClose[0].props.onPress();
180
+ });
181
+ expect(mockedDispatch).toBeCalled();
182
+ });
169
183
  });
@@ -12,12 +12,12 @@ import Routes from '../../utils/Route';
12
12
  const ConnectingDevices = memo(({ route }) => {
13
13
  const t = useTranslations();
14
14
  const { navigate } = useNavigation();
15
- const { new_sensor } = route.params;
15
+ const { new_sensor } = route.params || {};
16
16
 
17
17
  useEffect(() => {
18
18
  const checkSensorConnected = setInterval(async () => {
19
19
  const { success } = await axiosGet(
20
- API.SENSOR.CHECK_CONNECTION(new_sensor.id),
20
+ API.DEVICE.CHECK_CONNECTION(new_sensor?.id),
21
21
  {},
22
22
  true
23
23
  );
@@ -26,7 +26,7 @@ const ConnectingDevices = memo(({ route }) => {
26
26
  }
27
27
  }, 3000);
28
28
  return () => clearInterval(checkSensorConnected);
29
- }, [navigate, new_sensor.id, route.params]);
29
+ }, [navigate, new_sensor?.id, route.params]);
30
30
 
31
31
  return (
32
32
  <View style={styles.wrap}>
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
- import axios from 'axios';
3
+ import MockAdapter from 'axios-mock-adapter';
4
4
 
5
5
  import AddNewDevice from '../index';
6
6
  import GroupCheckBox from '../../../commons/GroupCheckBox';
@@ -11,6 +11,8 @@ import Routes from '../../../utils/Route';
11
11
  import { getTranslate } from '../../../utils/I18n';
12
12
  import { SCProvider } from '../../../context';
13
13
  import { mockSCStore } from '../../../context/mockStore';
14
+ import api from '../../../utils/Apis/axios';
15
+ import { Platform } from 'react-native';
14
16
 
15
17
  const wrapComponent = (route) => (
16
18
  <SCProvider initState={mockSCStore({})}>
@@ -18,7 +20,7 @@ const wrapComponent = (route) => (
18
20
  </SCProvider>
19
21
  );
20
22
 
21
- jest.mock('axios');
23
+ const mock = new MockAdapter(api.axiosInstance);
22
24
 
23
25
  jest.mock('react', () => {
24
26
  return { ...jest.requireActual('react'), memo: (x) => x };
@@ -42,7 +44,6 @@ describe('Test AddNewDevice', () => {
42
44
  let route;
43
45
 
44
46
  afterEach(() => {
45
- axios.get.mockClear();
46
47
  mockedNavigate.mockClear();
47
48
  });
48
49
 
@@ -78,23 +79,16 @@ describe('Test AddNewDevice', () => {
78
79
  });
79
80
 
80
81
  test('fetchDetails success', async () => {
81
- const response = {
82
- status: 200,
83
- data: {
84
- id: 1,
85
- name: 'Unit name',
86
- stations: [{ id: 2, name: 'Station name' }],
87
- },
88
- };
89
- axios.get.mockImplementation(async () => {
90
- return response;
82
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
83
+ id: 1,
84
+ name: 'Unit name',
85
+ stations: [{ id: 2, name: 'Station name' }],
91
86
  });
92
87
 
93
88
  await act(async () => {
94
89
  tree = await create(wrapComponent(route));
95
90
  });
96
91
  const instance = tree.root;
97
- expect(axios.get).toHaveBeenCalledWith(API.UNIT.UNIT_DETAIL(1), {});
98
92
 
99
93
  const groupCheckBox = instance.findByType(GroupCheckBox);
100
94
  expect(groupCheckBox.props.data).toEqual([
@@ -103,19 +97,11 @@ describe('Test AddNewDevice', () => {
103
97
  });
104
98
 
105
99
  test('fetchDetails fail', async () => {
106
- const response = {
107
- data: {},
108
- };
109
- axios.get.mockImplementation(async () => {
110
- return response;
111
- });
112
-
100
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(400);
113
101
  await act(async () => {
114
102
  tree = await create(wrapComponent(route));
115
103
  });
116
104
  const instance = tree.root;
117
- expect(axios.get).toHaveBeenCalledWith(API.UNIT.UNIT_DETAIL(1), {});
118
-
119
105
  const groupCheckBox = instance.findByType(GroupCheckBox);
120
106
  expect(groupCheckBox.props.data).toEqual([]);
121
107
  });
@@ -160,16 +146,10 @@ describe('Test AddNewDevice', () => {
160
146
  });
161
147
 
162
148
  test('ViewButtonBottom onRightClick with stationId', async () => {
163
- const response = {
164
- status: 200,
165
- data: {
166
- id: 1,
167
- name: 'Unit name',
168
- stations: [{ id: 2, name: 'Station name' }],
169
- },
170
- };
171
- axios.get.mockImplementation(async () => {
172
- return response;
149
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
150
+ id: 1,
151
+ name: 'Unit name',
152
+ stations: [{ id: 2, name: 'Station name' }],
173
153
  });
174
154
 
175
155
  await act(async () => {
@@ -192,4 +172,25 @@ describe('Test AddNewDevice', () => {
192
172
  unit_name: 'Unit name',
193
173
  });
194
174
  });
175
+
176
+ test('handleOnSelect with id = -1', async () => {
177
+ Platform.OS = 'android';
178
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
179
+ id: 1,
180
+ name: 'Unit name',
181
+ stations: [{ id: 2, name: 'Station name' }],
182
+ });
183
+
184
+ await act(async () => {
185
+ tree = await create(wrapComponent(route));
186
+ });
187
+ const instance = tree.root;
188
+
189
+ const groupCheckBox = instance.findByType(GroupCheckBox);
190
+ await act(async () => {
191
+ groupCheckBox.props.onSelect({ id: -1 }); // select stationId
192
+ });
193
+ const viewButtonBottom = instance.findByType(ViewButtonBottom);
194
+ expect(viewButtonBottom.props.rightDisabled).toBeTruthy();
195
+ });
195
196
  });
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
- import axios from 'axios';
4
3
 
5
4
  import ConnectDevices from '../ConnectDevices';
6
5
  import { TESTID } from '../../../configs/Constants';
@@ -11,8 +10,6 @@ import { SCProvider } from '../../../context';
11
10
  import { mockSCStore } from '../../../context/mockStore';
12
11
  import { getTranslate } from '../../../utils/I18n';
13
12
 
14
- jest.mock('axios');
15
-
16
13
  const mockedNavigate = jest.fn();
17
14
  jest.mock('@react-navigation/native', () => {
18
15
  return {
@@ -34,7 +31,6 @@ describe('Test ConnectDevices', () => {
34
31
  let route;
35
32
 
36
33
  afterEach(() => {
37
- axios.get.mockClear();
38
34
  mockedNavigate.mockClear();
39
35
  });
40
36
 
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
- import axios from 'axios';
3
+ import MockAdapter from 'axios-mock-adapter';
4
4
 
5
5
  import { API } from '../../../configs';
6
6
  import ConnectingDevices from '../ConnectingDevices';
@@ -9,8 +9,9 @@ import Routes from '../../../utils/Route';
9
9
  import { SCProvider } from '../../../context';
10
10
  import { mockSCStore } from '../../../context/mockStore';
11
11
  import { getTranslate } from '../../../utils/I18n';
12
+ import api from '../../../utils/Apis/axios';
12
13
 
13
- jest.mock('axios');
14
+ const mock = new MockAdapter(api.axiosInstance);
14
15
 
15
16
  const mockedNavigate = jest.fn();
16
17
  jest.mock('@react-navigation/native', () => {
@@ -33,7 +34,6 @@ describe('Test ConnectingDevices', () => {
33
34
  let route;
34
35
 
35
36
  afterEach(() => {
36
- axios.get.mockClear();
37
37
  mockedNavigate.mockClear();
38
38
  });
39
39
 
@@ -62,16 +62,25 @@ describe('Test ConnectingDevices', () => {
62
62
  );
63
63
  });
64
64
 
65
- test('call setInterval api success', async () => {
66
- jest.useFakeTimers();
67
- const response = {
68
- status: 200,
69
- data: {},
70
- };
71
- axios.get.mockImplementation(async () => {
72
- return response;
65
+ test('create with out new sensor', () => {
66
+ act(() => {
67
+ tree = create(wrapComponent({}));
73
68
  });
69
+ const instance = tree.root;
70
+ const texts = instance.findAllByType(Text);
71
+ expect(texts).toHaveLength(4);
72
+ expect(texts[0].props.children).toEqual(
73
+ getTranslate('en', 'connecting_your_device')
74
+ );
75
+ expect(texts[1].props.children).toEqual(
76
+ getTranslate('en', 'dont_turn_off_the_device_or_close_this_app')
77
+ );
78
+ tree.unmount();
79
+ });
74
80
 
81
+ test('call setInterval api success', async () => {
82
+ jest.useFakeTimers();
83
+ mock.onGet(API.DEVICE.CHECK_CONNECTION(1)).reply(200);
75
84
  await act(async () => {
76
85
  tree = await create(wrapComponent(route));
77
86
  });
@@ -79,7 +88,6 @@ describe('Test ConnectingDevices', () => {
79
88
  await jest.runOnlyPendingTimers();
80
89
  });
81
90
  expect(setInterval).toHaveBeenCalled();
82
- expect(axios.get).toHaveBeenCalledWith(API.SENSOR.CHECK_CONNECTION(1), {});
83
91
  expect(mockedNavigate).toHaveBeenCalledWith(Routes.ConnectDevices, {
84
92
  new_sensor: { id: 1 },
85
93
  });
@@ -87,14 +95,7 @@ describe('Test ConnectingDevices', () => {
87
95
 
88
96
  test('call setInterval api fail', async () => {
89
97
  jest.useFakeTimers();
90
- const response = {
91
- status: 400,
92
- data: {},
93
- };
94
- axios.get.mockImplementation(async () => {
95
- return response;
96
- });
97
-
98
+ mock.onGet(API.DEVICE.CHECK_CONNECTION(1)).reply(400);
98
99
  await act(async () => {
99
100
  tree = await create(wrapComponent(route));
100
101
  });
@@ -102,7 +103,6 @@ describe('Test ConnectingDevices', () => {
102
103
  await jest.runOnlyPendingTimers();
103
104
  });
104
105
  expect(setInterval).toHaveBeenCalled();
105
- expect(axios.get).toHaveBeenCalledWith(API.SENSOR.CHECK_CONNECTION(1), {});
106
106
  expect(mockedNavigate).not.toHaveBeenCalledWith(Routes.ConnectDevices, {
107
107
  new_sensor: { id: 1 },
108
108
  });
@@ -23,7 +23,7 @@ const useConnectDevices = (new_sensor, station_id, unit_id) => {
23
23
  const updateSensorName = useCallback(
24
24
  async (name) => {
25
25
  const { success: updateSuccess } = await axiosPatch(
26
- API.SENSOR.UPDATE_SENSOR(unit_id, station_id, new_sensor.id),
26
+ API.DEVICE.UPDATE_SENSOR(unit_id, station_id, new_sensor.id),
27
27
  {
28
28
  name,
29
29
  }
@@ -56,7 +56,7 @@ const ConnectWifiWarning = memo(({ route }) => {
56
56
  const { setAction } = useContext(SCContext);
57
57
 
58
58
  const getPermissionWifiAndroid = useCallback(async () => {
59
- const granted = await PermissionsAndroid.request(
59
+ return await PermissionsAndroid.request(
60
60
  PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
61
61
  {
62
62
  title: t('location_permission_required_wifi_title'),
@@ -65,15 +65,21 @@ const ConnectWifiWarning = memo(({ route }) => {
65
65
  buttonPositive: t('allow'),
66
66
  }
67
67
  );
68
- if (granted === PermissionsAndroid.RESULTS.GRANTED) {
69
- ToastBottomHelper.success('GRANTED');
70
- } else {
71
- ToastBottomHelper.error('DENIED');
72
- }
73
- }, [t]);
68
+ // eslint-disable-next-line react-hooks/exhaustive-deps
69
+ }, []);
74
70
 
75
71
  useEffect(() => {
76
- isAndroid && getPermissionWifiAndroid();
72
+ if (isAndroid) {
73
+ (async () => {
74
+ const granted = await getPermissionWifiAndroid();
75
+ if (!granted) {
76
+ ToastBottomHelper.error(
77
+ 'Fail permission',
78
+ 'You need to grant permission to continue'
79
+ );
80
+ }
81
+ })();
82
+ }
77
83
  }, [getPermissionWifiAndroid]);
78
84
 
79
85
  const handleSend = async () => {
@@ -83,7 +89,7 @@ const ConnectWifiWarning = memo(({ route }) => {
83
89
  await socket.on('message', (msg, rinfo) => {
84
90
  clearInterval(intervalSend);
85
91
  const data = JSON.parse(msg.toString());
86
- if (data.hasOwnProperty('wifi')) {
92
+ if (Object.prototype.hasOwnProperty.call(data, 'wifi')) {
87
93
  navigate(Routes.GatewayWifiList, {
88
94
  list_wifi: data.wifi,
89
95
  unit_id: unit_id,
@@ -113,12 +119,12 @@ const ConnectWifiWarning = memo(({ route }) => {
113
119
  goBack();
114
120
  });
115
121
  } else {
116
- const socket = dgram.createSocket({ type: 'udp4' });
122
+ const dgSocket = dgram.createSocket({ type: 'udp4' });
117
123
  await setIsPercentConnect(1);
118
- await socket.bind(54321);
119
- await socket.on('message', (msg, rinfo) => {
124
+ await dgSocket.bind(54321);
125
+ await dgSocket.on('message', (msg, rinfo) => {
120
126
  const data = JSON.parse(msg.toString());
121
- if (data.hasOwnProperty('wifi')) {
127
+ if (Object.prototype.hasOwnProperty.call(data, 'wifi')) {
122
128
  navigate(Routes.GatewayWifiList, {
123
129
  list_wifi: data.wifi,
124
130
  unit_id: unit_id,
@@ -128,12 +134,12 @@ const ConnectWifiWarning = memo(({ route }) => {
128
134
  wifi_pass: wifi_pass,
129
135
  unit_name: unit_name,
130
136
  devicePrefixName: devicePrefixName,
131
- socket: socket,
137
+ socket: dgSocket,
132
138
  });
133
139
  }
134
140
  });
135
- await socket.once('listening', async () => {
136
- await socket.send(
141
+ await dgSocket.once('listening', async () => {
142
+ await dgSocket.send(
137
143
  JSON.stringify({ type: 'scan', data: { wifi: '' } }),
138
144
  undefined,
139
145
  undefined,
@@ -142,7 +148,7 @@ const ConnectWifiWarning = memo(({ route }) => {
142
148
  undefined
143
149
  );
144
150
  });
145
- socket.on('error', () => {
151
+ dgSocket.on('error', () => {
146
152
  ToastBottomHelper.error(t('server_error'));
147
153
  setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
148
154
  goBack();