@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 { act, create } from 'react-test-renderer';
3
- import axios from 'axios';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+ import Toast from 'react-native-toast-message';
4
5
 
5
6
  import { ToastBottomHelper } from '../../../utils/Utils';
6
7
  import { TESTID } from '../../../configs/Constants';
@@ -8,8 +9,11 @@ import { TESTID } from '../../../configs/Constants';
8
9
  import ManageUnit from '../ManageUnit';
9
10
  import { SCProvider } from '../../../context';
10
11
  import { mockSCStore } from '../../../context/mockStore';
12
+ import api from '../../../utils/Apis/axios';
13
+ import { API } from '../../../configs';
14
+ import { getTranslate } from '../../../utils/I18n';
11
15
 
12
- jest.mock('axios');
16
+ const mock = new MockAdapter(api.axiosInstance);
13
17
 
14
18
  const mockNavigate = jest.fn();
15
19
  jest.mock('@react-navigation/native', () => {
@@ -55,7 +59,6 @@ describe('Test Manage Unit', () => {
55
59
 
56
60
  beforeEach(() => {
57
61
  mockNavigate.mockClear();
58
- axios.get.mockClear();
59
62
  });
60
63
 
61
64
  const getElement = (instance) => {
@@ -116,33 +119,28 @@ describe('Test Manage Unit', () => {
116
119
  await act(async () => {
117
120
  tree = create(wrapComponent(route));
118
121
  });
119
-
120
122
  const instance = tree.root;
121
123
  const { changeName, inputRename } = getElement(instance);
122
-
123
124
  await act(async () => {
124
125
  await changeName[0].props.onPress();
125
126
  });
126
-
127
127
  const bottomButton = instance.find(
128
128
  (item) =>
129
129
  item.props.testID ===
130
130
  `${TESTID.PREFIX.MANAGE_UNIT}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
131
131
  );
132
-
133
- const response = {
134
- data: {},
135
- };
136
- axios.patch.mockImplementation(async () => {
137
- return response;
138
- });
139
-
132
+ mock.onPatch(API.UNIT.MANAGE_UNIT(1)).reply(200, {});
140
133
  await act(async () => {
141
134
  await inputRename[0].props.onChange('input station');
142
135
  await bottomButton.props.onPress();
143
136
  });
144
-
145
- expect(axios.patch).toBeCalled();
137
+ expect(Toast.show).toBeCalledWith({
138
+ position: 'bottom',
139
+ text1: getTranslate('en', 'unit_updated_successfully'),
140
+ text2: undefined,
141
+ type: 'success',
142
+ visibilityTime: 1000,
143
+ });
146
144
  });
147
145
 
148
146
  test('remove Unit success', async () => {
@@ -162,23 +160,10 @@ describe('Test Manage Unit', () => {
162
160
  item.props.testID ===
163
161
  `${TESTID.PREFIX.MANAGE_UNIT_ALERT}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
164
162
  );
165
-
166
163
  expect(bottomButton).toBeDefined();
167
-
168
- const response = {
169
- status: 200,
170
- success: true,
171
- data: {},
172
- };
173
-
174
- axios.delete.mockImplementation(async () => {
175
- return response;
176
- });
177
-
178
164
  await act(async () => {
179
165
  await bottomButton.props.onPress();
180
166
  });
181
-
182
167
  expect(mockedDispatch).not.toBeCalled();
183
168
  });
184
169
 
@@ -200,29 +185,19 @@ describe('Test Manage Unit', () => {
200
185
  item.props.testID ===
201
186
  `${TESTID.PREFIX.MANAGE_UNIT}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
202
187
  );
203
-
204
- const response = {
205
- status: 200,
206
- success: true,
207
- data: {},
208
- };
209
-
210
- axios.patch.mockImplementation(async () => {
211
- return response;
212
- });
188
+ mock.onPatch(API.UNIT.MANAGE_UNIT(1)).reply(200);
213
189
 
214
190
  await act(async () => {
215
191
  await inputRename[0].props.onChange('input station');
216
192
  await bottomButton.props.onPress();
217
193
  });
218
194
 
219
- expect(axios.patch).toBeCalled();
220
-
221
195
  expect(mockedDispatch).not.toBeCalled();
222
196
  expect(spyToast).toBeCalled();
223
197
  spyToast.mockReset();
224
198
  spyToast.mockRestore();
225
199
  });
200
+
226
201
  test('test onPress onUpdateImage', async () => {
227
202
  await act(async () => {
228
203
  tree = create(wrapComponent(route));
@@ -243,9 +218,9 @@ describe('Test Manage Unit', () => {
243
218
  imagePicker.props.setImageUrl('abc');
244
219
  });
245
220
 
246
- expect(axios.patch).toBeCalled();
247
221
  expect(imagePicker.props.showImagePicker).toBeTruthy();
248
222
  });
223
+
249
224
  test('test onPress goSelectLocation', async () => {
250
225
  await act(async () => {
251
226
  tree = create(wrapComponent(route));
@@ -261,6 +236,7 @@ describe('Test Manage Unit', () => {
261
236
  });
262
237
  expect(mockNavigate).toBeCalled();
263
238
  });
239
+
264
240
  test('test onPress goToManageSubUnit', async () => {
265
241
  await act(async () => {
266
242
  tree = create(wrapComponent(route));
@@ -1,14 +1,22 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+ import RNP from 'react-native-permissions';
5
+
3
6
  import { SCProvider } from '../../../context';
4
7
  import { mockSCStore } from '../../../context/mockStore';
5
8
  import SelectAddress from '../SelectAddress';
6
9
  import SearchBarLocation from '../../../commons/SearchLocation';
7
10
  import RowLocation from '../../../commons/SearchLocation/RowLocation';
8
11
  import BottomButtonView from '../../../commons/BottomButtonView';
9
- import axios from 'axios';
10
- import { API, SCConfig } from '../../../configs';
12
+ import { API } from '../../../configs';
11
13
  import { TESTID } from '../../../configs/Constants';
14
+ import api from '../../../utils/Apis/axios';
15
+ import {
16
+ GEOLOCATION_ERROR,
17
+ OpenSetting,
18
+ } from '../../../utils/Permission/common';
19
+ import { RESULTS } from 'react-native-permissions';
12
20
 
13
21
  const wrapComponent = (route) => (
14
22
  <SCProvider initState={mockSCStore({})}>
@@ -16,6 +24,8 @@ const wrapComponent = (route) => (
16
24
  </SCProvider>
17
25
  );
18
26
 
27
+ const mock = new MockAdapter(api.axiosInstance);
28
+
19
29
  const mockNavigate = jest.fn();
20
30
  const mockGoBack = jest.fn();
21
31
  jest.mock('@react-navigation/native', () => {
@@ -52,29 +62,32 @@ jest.mock('react-native-maps', () => {
52
62
  };
53
63
  });
54
64
 
55
- jest.mock('@react-native-community/geolocation', () => {
56
- const position = {
57
- coords: {
58
- latitude: 100,
59
- longitude: 100,
60
- },
61
- };
62
- return {
63
- getCurrentPosition: (onSuccess, onError, options) => {
64
- onSuccess(position);
65
- },
66
- };
65
+ jest.mock('../../../utils/Permission/common');
66
+
67
+ const position = {
68
+ coords: {
69
+ latitude: 100,
70
+ longitude: 100,
71
+ },
72
+ };
73
+ const mockGeolocation = {
74
+ getCurrentPosition: (onSuccess, onError, options) => {
75
+ onSuccess(position);
76
+ },
77
+ };
78
+ global.navigator.geolocation = mockGeolocation;
79
+
80
+ jest.mock('react-native-permissions', () => {
81
+ return require('react-native-permissions/mock');
67
82
  });
68
83
 
69
- jest.mock('axios');
70
-
71
84
  describe('Test SelectAddress', () => {
72
85
  let tree;
73
86
  let route;
74
87
  const mockUpdateLocation = jest.fn();
75
88
 
76
89
  beforeAll(() => {
77
- axios.get.mockClear();
90
+ RNP.check.mockClear();
78
91
  route = {
79
92
  params: {
80
93
  updateLocation: mockUpdateLocation,
@@ -100,8 +113,7 @@ describe('Test SelectAddress', () => {
100
113
  ],
101
114
  },
102
115
  };
103
- axios.get.mockImplementation(async () => response);
104
-
116
+ mock.onGet(API.EXTERNAL.GOOGLE_MAP.AUTO_COMPLETE).reply(200, response.data);
105
117
  await act(async () => {
106
118
  await searchBars[0].props.onTextInput('');
107
119
  });
@@ -111,19 +123,8 @@ describe('Test SelectAddress', () => {
111
123
  await act(async () => {
112
124
  await searchBars[0].props.onTextInput('input');
113
125
  });
114
- expect(axios.get).toBeCalledWith(API.EXTERNAL.GOOGLE_MAP.AUTO_COMPLETE, {
115
- params: {
116
- input: 'input',
117
- key: SCConfig.GOOGLE_MAP_API_KEY,
118
- sessiontoken: 123456324,
119
- strictBounds: false,
120
- types: ['establishment'],
121
- },
122
- });
123
126
  rowLocations = instance.findAllByType(RowLocation);
124
127
  expect(rowLocations).toHaveLength(3);
125
-
126
- axios.get.mockClear();
127
128
  response = {
128
129
  status: 200,
129
130
  data: {
@@ -137,21 +138,13 @@ describe('Test SelectAddress', () => {
137
138
  },
138
139
  },
139
140
  };
140
- axios.get.mockImplementation(async () => response);
141
+ mock
142
+ .onGet(API.EXTERNAL.GOOGLE_MAP.GET_LAT_LNG_BY_PLACE_ID)
143
+ .reply(200, response.data);
141
144
 
142
145
  await act(async () => {
143
146
  await rowLocations[0].props.onPress({ place_id: 1, description: '1' });
144
147
  });
145
- expect(axios.get).toBeCalledWith(
146
- API.EXTERNAL.GOOGLE_MAP.GET_LAT_LNG_BY_PLACE_ID,
147
- {
148
- params: {
149
- place_id: 1,
150
- key: SCConfig.GOOGLE_MAP_API_KEY,
151
- },
152
- }
153
- );
154
-
155
148
  const bottomButton = instance.findByType(BottomButtonView);
156
149
  await act(async () => {
157
150
  await bottomButton.props.onPressMain();
@@ -160,7 +153,7 @@ describe('Test SelectAddress', () => {
160
153
  expect(mockGoBack).toBeCalled();
161
154
  });
162
155
 
163
- test('test get current location', async () => {
156
+ test('test get current location success', async () => {
164
157
  await act(async () => {
165
158
  tree = await create(wrapComponent(route));
166
159
  });
@@ -185,19 +178,59 @@ describe('Test SelectAddress', () => {
185
178
  ],
186
179
  },
187
180
  };
188
- axios.get.mockImplementation(async () => response);
181
+ mock
182
+ .onGet(API.EXTERNAL.GOOGLE_MAP.GET_LOCATION_FROM_LAT_LNG)
183
+ .reply(200, response.data);
189
184
  await act(async () => {
190
185
  await button.props.onPress();
191
186
  });
192
- expect(axios.get).toBeCalledWith(
193
- API.EXTERNAL.GOOGLE_MAP.GET_LOCATION_FROM_LAT_LNG,
194
- {
195
- params: {
196
- latlng: '100,100',
197
- key: SCConfig.GOOGLE_MAP_API_KEY,
198
- },
199
- }
187
+ });
188
+
189
+ test('test get current location failed permission denied', async () => {
190
+ await act(async () => {
191
+ tree = await create(wrapComponent(route));
192
+ });
193
+ const instance = tree.root;
194
+ const button = instance.find(
195
+ (el) => el.props.testID === TESTID.BUTTON_YOUR_LOCATION
200
196
  );
197
+
198
+ global.navigator.geolocation = {
199
+ getCurrentPosition: (onSuccess, onError, options) => {
200
+ onError({ code: GEOLOCATION_ERROR.PERMISSION_DENIED });
201
+ },
202
+ };
203
+ RNP.check.mockImplementationOnce(() => RESULTS.BLOCKED);
204
+ OpenSetting.mockImplementationOnce(() => {});
205
+
206
+ await act(async () => {
207
+ await button.props.onPress();
208
+ });
209
+ OpenSetting.mockClear();
210
+ });
211
+
212
+ test('test get current failed error not handle', async () => {
213
+ await act(async () => {
214
+ tree = await create(wrapComponent(route));
215
+ });
216
+ const instance = tree.root;
217
+ const button = instance.find(
218
+ (el) => el.props.testID === TESTID.BUTTON_YOUR_LOCATION
219
+ );
220
+
221
+ global.navigator.geolocation = {
222
+ getCurrentPosition: (onSuccess, onError, options) => {
223
+ onError({ code: GEOLOCATION_ERROR.TIMEOUT });
224
+ },
225
+ };
226
+ RNP.check.mockImplementationOnce(() => RESULTS.DENIED);
227
+ OpenSetting.mockImplementationOnce(() => {});
228
+
229
+ await act(async () => {
230
+ await button.props.onPress();
231
+ });
232
+ expect(OpenSetting).toBeCalledTimes(0);
233
+ OpenSetting.mockClear();
201
234
  });
202
235
 
203
236
  test('test choose on map', async () => {
@@ -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 { SCProvider } from '../../../context';
6
6
  import { mockSCStore } from '../../../context/mockStore';
@@ -8,6 +8,8 @@ import ListSmartAccount from '../SmartAccount';
8
8
  import { SmartAccountItem } from '../SmartAccountItem';
9
9
  import { AlertAction, MenuActionMore } from '../../../commons';
10
10
  import Routes from '../../../utils/Route';
11
+ import api from '../../../utils/Apis/axios';
12
+ import { API } from '../../../configs';
11
13
 
12
14
  const wrapComponent = (route, navigation) => (
13
15
  <SCProvider initState={mockSCStore({})}>
@@ -15,6 +17,8 @@ const wrapComponent = (route, navigation) => (
15
17
  </SCProvider>
16
18
  );
17
19
 
20
+ const mock = new MockAdapter(api.axiosInstance);
21
+
18
22
  const mockNavigate = jest.fn();
19
23
  jest.mock('@react-navigation/native', () => {
20
24
  return {
@@ -33,7 +37,6 @@ jest.mock('react', () => {
33
37
  };
34
38
  });
35
39
 
36
- jest.mock('axios');
37
40
  describe('Test SmartAccount', () => {
38
41
  let tree;
39
42
  let route = {
@@ -42,7 +45,7 @@ describe('Test SmartAccount', () => {
42
45
  },
43
46
  };
44
47
  test('test render SmartAccount', async () => {
45
- const reponse = {
48
+ const response = {
46
49
  status: 200,
47
50
  data: [
48
51
  {
@@ -65,7 +68,9 @@ describe('Test SmartAccount', () => {
65
68
  },
66
69
  ],
67
70
  };
68
- axios.get.mockImplementationOnce(() => reponse);
71
+ mock
72
+ .onGet(API.SMART_ACCOUNT.LIST_SMART_ACCOUNT(1))
73
+ .reply(response.status, response.data);
69
74
  await act(async () => {
70
75
  tree = await renderer.create(wrapComponent(route));
71
76
  });
@@ -74,13 +79,16 @@ describe('Test SmartAccount', () => {
74
79
  const smartAccountItem = instance.findAllByType(SmartAccountItem);
75
80
  expect(smartAccountItem.length).toEqual(3);
76
81
  act(() => {
77
- smartAccountItem[0].props.gotoSmartAccountDetail(reponse.data[0]);
78
- smartAccountItem[0].props.onShowMenuMore(reponse.data[0]);
82
+ smartAccountItem[0].props.gotoSmartAccountDetail(response.data[0]);
83
+ smartAccountItem[0].props.onShowMenuMore(response.data[0]);
79
84
  });
85
+ const alertAction = instance.findAllByType(AlertAction);
86
+ mock.onDelete(API.SMART_ACCOUNT.REMOVE_SMART_ACCOUNT(1)).reply(200);
87
+ await alertAction[0].props.leftButtonClick();
80
88
  expect(mockNavigate).toBeCalledWith(Routes.ListDeviceSmartAccount, {
81
- username: reponse.data[0].username,
82
- brand: reponse.data[0].brand,
83
- smart_account_id: reponse.data[0].id,
89
+ username: response.data[0].username,
90
+ brand: response.data[0].brand,
91
+ smart_account_id: response.data[0].id,
84
92
  unit_id: route.params.unitId,
85
93
  });
86
94
  });
@@ -37,7 +37,6 @@ jest.mock('react', () => {
37
37
  };
38
38
  });
39
39
 
40
- jest.mock('axios');
41
40
  describe('Test SmartAccountItem', () => {
42
41
  let tree;
43
42
  test('test render SmartAccountItem', async () => {
@@ -0,0 +1,100 @@
1
+ import React from 'react';
2
+ import { ScrollView } from 'react-native';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+ import renderer, { act } from 'react-test-renderer';
5
+ import { API } from '../../../configs';
6
+ import { SCProvider } from '../../../context';
7
+ import { mockSCStore } from '../../../context/mockStore';
8
+ import Summaries from '../Summaries';
9
+ import SummaryItem from '../../../commons/SummaryItem';
10
+ import api from '../../../utils/Apis/axios';
11
+ import { useReceiveNotifications } from '../../../hooks';
12
+
13
+ const mock = new MockAdapter(api.axiosInstance);
14
+
15
+ const wrapComponent = (props) => (
16
+ <SCProvider initState={mockSCStore({})}>
17
+ <Summaries {...props} />
18
+ </SCProvider>
19
+ );
20
+
21
+ jest.mock('react', () => {
22
+ return {
23
+ ...jest.requireActual('react'),
24
+ memo: (x) => x,
25
+ };
26
+ });
27
+
28
+ const mockedNavigate = jest.fn();
29
+ jest.mock('@react-navigation/native', () => {
30
+ return {
31
+ ...jest.requireActual('@react-navigation/native'),
32
+ useIsFocused: jest.fn(),
33
+ useNavigation: () => ({
34
+ navigate: mockedNavigate,
35
+ }),
36
+ };
37
+ });
38
+
39
+ jest.mock('react-native-onesignal', () => {
40
+ return {
41
+ setNotificationWillShowInForegroundHandler: jest.fn(),
42
+ };
43
+ });
44
+
45
+ jest.mock('../../../hooks', () => {
46
+ return {
47
+ ...jest.requireActual('../../../hooks'),
48
+ useReceiveNotifications: jest.fn(() => ({ dataNotification: null })),
49
+ };
50
+ });
51
+
52
+ describe('Test Summaries', () => {
53
+ let tree, props;
54
+
55
+ beforeEach(() => {
56
+ props = {
57
+ unit: {
58
+ id: 1,
59
+ },
60
+ };
61
+ });
62
+
63
+ test('render Summaries receive noti with summary_id then reload', async () => {
64
+ mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200, [{ id: 1 }]);
65
+ const dataNotification = {
66
+ params: {
67
+ summary_id: 1,
68
+ },
69
+ };
70
+ useReceiveNotifications.mockImplementationOnce(() => ({
71
+ dataNotification,
72
+ }));
73
+ await act(async () => {
74
+ tree = await renderer.create(wrapComponent(props));
75
+ });
76
+ const instance = tree.root;
77
+ const scrollview = instance.findByType(ScrollView);
78
+ expect(scrollview).toBeDefined();
79
+ const items = instance.findAllByType(SummaryItem);
80
+ await act(async () => {
81
+ items[0].props.goToSummary({ id: 1 });
82
+ });
83
+ expect(mockedNavigate).toBeCalled();
84
+ });
85
+
86
+ test('render Summaries receive noti with summary_id then not reload', async () => {
87
+ mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200, [{ id: 1 }]);
88
+ const dataNotification = {
89
+ params: {
90
+ unit_id: 1,
91
+ },
92
+ };
93
+ useReceiveNotifications.mockImplementationOnce(() => ({
94
+ dataNotification,
95
+ }));
96
+ await act(async () => {
97
+ tree = await renderer.create(wrapComponent(props));
98
+ });
99
+ });
100
+ });
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { SafeAreaView } from 'react-native';
3
+ import { act, create } from 'react-test-renderer';
4
+ import MyAllUnit from '../index';
5
+ import { SCProvider } from '../../../../../context';
6
+ import { mockSCStore } from '../../../../../context/mockStore';
7
+
8
+ const wrapComponent = (route) => (
9
+ <SCProvider initState={mockSCStore({})}>
10
+ <MyAllUnit route={route} />
11
+ </SCProvider>
12
+ );
13
+ describe('Test MyAllUnit', () => {
14
+ let tree;
15
+ test('render MyAllUnit', async () => {
16
+ const route = {
17
+ params: {
18
+ myUnits: [
19
+ {
20
+ background: '',
21
+ name: '',
22
+ stations: [
23
+ { id: 1, name: 'station', sensors: [{ id: 1, name: 'sensor' }] },
24
+ ],
25
+ },
26
+ ],
27
+ },
28
+ };
29
+ act(() => {
30
+ tree = create(wrapComponent(route));
31
+ });
32
+ const instance = tree.root;
33
+ const safeAreaView = instance.findAllByType(SafeAreaView);
34
+ expect(safeAreaView).toHaveLength(1);
35
+ });
36
+ });
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+ import { act, create } from 'react-test-renderer';
3
+ import MyAllUnit from '../index';
4
+ import Header from '../../Header';
5
+ import { SCProvider } from '../../../../../context';
6
+ import { mockSCStore } from '../../../../../context/mockStore';
7
+
8
+ const wrapComponent = (props) => (
9
+ <SCProvider initState={mockSCStore({})}>
10
+ <MyAllUnit {...props} />
11
+ </SCProvider>
12
+ );
13
+
14
+ test('test MyAllUnit', () => {
15
+ let tree, props;
16
+ let mockGoBack = jest.fn();
17
+
18
+ props = {
19
+ route: {
20
+ params: {
21
+ myUnits: [
22
+ {
23
+ background: '',
24
+ name: 'name',
25
+ stations: [
26
+ {
27
+ name: 'station',
28
+ sensors: [
29
+ {
30
+ name: 'sensor',
31
+ },
32
+ ],
33
+ },
34
+ ],
35
+ },
36
+ ],
37
+ },
38
+ },
39
+ navigation: {
40
+ goBack: mockGoBack,
41
+ },
42
+ };
43
+
44
+ act(() => {
45
+ tree = create(wrapComponent(props));
46
+ });
47
+
48
+ const instance = tree.root;
49
+ const header = instance.findByType(Header);
50
+ act(() => {
51
+ header.props.goBack();
52
+ });
53
+ expect(mockGoBack).toBeCalled();
54
+ });
@@ -39,6 +39,7 @@ const SharedUnit = ({
39
39
  }, [renewItem, index, unit, item]);
40
40
  const addPinSharedUnit = useCallback(async () => {
41
41
  const { success } = await axiosPost(API.UNIT.PIN_UNIT(unit.id));
42
+
42
43
  if (success) {
43
44
  item.is_pin = true;
44
45
  renewItem(index);