@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,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
  import AddLGDevice from '../AddLGDevice';
5
5
  import API from '../../../configs/API';
6
6
  import GroupCheckBox from '../../../commons/GroupCheckBox';
@@ -11,8 +11,9 @@ import { ToastBottomHelper } from '../../../utils/Utils';
11
11
  import Routes from '../../../utils/Route';
12
12
  import { SCProvider } from '../../../context';
13
13
  import { mockSCStore } from '../../../context/mockStore';
14
+ import api from '../../../utils/Apis/axios';
14
15
 
15
- jest.mock('axios');
16
+ const mock = new MockAdapter(api.axiosInstance);
16
17
 
17
18
  const mockedNavigate = jest.fn();
18
19
  const mockedGoBack = jest.fn();
@@ -54,11 +55,6 @@ describe('Test Add LG Device', () => {
54
55
  };
55
56
  });
56
57
 
57
- afterEach(() => {
58
- axios.get.mockClear();
59
- axios.post.mockClear();
60
- });
61
-
62
58
  const getText = (instance, id) => {
63
59
  return instance.find((el) => el.props.testID === id);
64
60
  };
@@ -91,16 +87,11 @@ describe('Test Add LG Device', () => {
91
87
  stations: [{ id: 2, name: 'Station name' }],
92
88
  },
93
89
  };
94
- axios.get.mockImplementation(async () => {
95
- return response;
96
- });
97
-
90
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, response.data);
98
91
  await act(async () => {
99
92
  tree = await create(wrapComponent(route));
100
93
  });
101
94
  const instance = tree.root;
102
- expect(axios.get).toHaveBeenCalledWith(API.UNIT.UNIT_DETAIL(1), {});
103
-
104
95
  const groupCheckBox = instance.findByType(GroupCheckBox);
105
96
  expect(groupCheckBox.props.data).toEqual([
106
97
  { id: 2, name: 'Station name', title: 'Station name' },
@@ -108,19 +99,11 @@ describe('Test Add LG Device', () => {
108
99
  });
109
100
 
110
101
  test('fetchDetails fail', async () => {
111
- const response = {
112
- data: {},
113
- };
114
- axios.get.mockImplementation(async () => {
115
- return response;
116
- });
117
-
102
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(400);
118
103
  await act(async () => {
119
104
  tree = await create(wrapComponent(route));
120
105
  });
121
106
  const instance = tree.root;
122
- expect(axios.get).toHaveBeenCalledWith(API.UNIT.UNIT_DETAIL(1), {});
123
-
124
107
  const groupCheckBox = instance.findByType(GroupCheckBox);
125
108
  expect(groupCheckBox.props.data).toEqual([]);
126
109
  });
@@ -161,7 +144,7 @@ describe('Test Add LG Device', () => {
161
144
  await act(async () => {
162
145
  viewButtonBottom.props.onRightClick();
163
146
  });
164
- expect(mockedNavigate).not.toHaveBeenCalled();
147
+ expect(mockedNavigate).toHaveBeenCalled();
165
148
  });
166
149
 
167
150
  test('ViewButtonBottom onRightClick with stationId', async () => {
@@ -173,9 +156,7 @@ describe('Test Add LG Device', () => {
173
156
  stations: [{ id: 2, name: 'Station name' }],
174
157
  },
175
158
  };
176
- axios.get.mockImplementation(async () => {
177
- return response;
178
- });
159
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, response.data);
179
160
 
180
161
  const responseToken = {
181
162
  status: 200,
@@ -183,20 +164,9 @@ describe('Test Add LG Device', () => {
183
164
  access_token: 'ACCESS_TOKEN',
184
165
  },
185
166
  };
186
- axios.post.mockImplementationOnce(async () => {
187
- return responseToken;
188
- });
189
-
190
- const responseSync = {
191
- status: 200,
192
- data: {},
193
- };
194
- axios.post.mockImplementationOnce(async () => {
195
- return responseSync;
196
- });
197
-
167
+ mock.onPost(API.IOT.LG.GET_TOKEN()).reply(200, responseToken.data);
168
+ mock.onPost(API.IOT.LG.SYNC_DEVICE()).reply(200, {});
198
169
  const spyToastSuccess = jest.spyOn(ToastBottomHelper, 'success');
199
-
200
170
  await act(async () => {
201
171
  tree = await create(wrapComponent(route));
202
172
  });
@@ -210,10 +180,6 @@ describe('Test Add LG Device', () => {
210
180
  await act(async () => {
211
181
  viewButtonBottom.props.onRightClick();
212
182
  });
213
-
214
- expect(axios.get).toHaveBeenCalledTimes(1);
215
- expect(axios.post).toHaveBeenCalledTimes(2);
216
- expect(spyToastSuccess).toBeCalled();
217
183
  expect(mockedNavigate).toHaveBeenCalledWith(Routes.Dashboard);
218
184
 
219
185
  spyToastSuccess.mockReset();
@@ -229,27 +195,8 @@ describe('Test Add LG Device', () => {
229
195
  stations: [{ id: 2, name: 'Station name' }],
230
196
  },
231
197
  };
232
- axios.get.mockImplementation(async () => {
233
- return response;
234
- });
235
-
236
- const responseToken = {
237
- status: 200,
238
- data: {
239
- access_token: 'ACCESS_TOKEN',
240
- },
241
- };
242
- axios.post.mockImplementationOnce(async () => {
243
- return responseToken;
244
- });
245
-
246
- const responseSync = {
247
- data: {},
248
- };
249
- axios.post.mockImplementationOnce(async () => {
250
- return responseSync;
251
- });
252
-
198
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, response.data);
199
+ mock.onPost(API.IOT.LG.GET_TOKEN()).reply(200, response.data);
253
200
  const spyToastSuccess = jest.spyOn(ToastBottomHelper, 'success');
254
201
  const spyToastError = jest.spyOn(ToastBottomHelper, 'error');
255
202
 
@@ -266,13 +213,9 @@ describe('Test Add LG Device', () => {
266
213
  await act(async () => {
267
214
  viewButtonBottom.props.onRightClick();
268
215
  });
269
-
270
- expect(axios.get).toHaveBeenCalledTimes(1);
271
- expect(axios.post).toHaveBeenCalledTimes(2);
272
216
  expect(spyToastSuccess).not.toBeCalled();
273
217
  expect(spyToastError).toBeCalled();
274
218
  expect(mockedNavigate).toHaveBeenCalledWith(Routes.Dashboard);
275
-
276
219
  spyToastSuccess.mockReset();
277
220
  spyToastSuccess.mockRestore();
278
221
  });
@@ -286,10 +229,7 @@ describe('Test Add LG Device', () => {
286
229
  stations: [{ id: 2, name: 'Station name' }],
287
230
  },
288
231
  };
289
- axios.get.mockImplementation(async () => {
290
- return response;
291
- });
292
-
232
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, response.data);
293
233
  const responseToken = {
294
234
  status: 200,
295
235
  data: {
@@ -300,10 +240,7 @@ describe('Test Add LG Device', () => {
300
240
  },
301
241
  },
302
242
  };
303
- axios.post.mockImplementationOnce(async () => {
304
- return responseToken;
305
- });
306
-
243
+ mock.onPost(API.IOT.LG.GET_TOKEN()).reply(200, responseToken.data);
307
244
  const spyToastSuccess = jest.spyOn(ToastBottomHelper, 'success');
308
245
  const spyToastError = jest.spyOn(ToastBottomHelper, 'error');
309
246
 
@@ -321,8 +258,6 @@ describe('Test Add LG Device', () => {
321
258
  viewButtonBottom.props.onRightClick();
322
259
  });
323
260
 
324
- expect(axios.get).toHaveBeenCalledTimes(1);
325
- expect(axios.post).toHaveBeenCalledTimes(1); // called once
326
261
  expect(spyToastSuccess).not.toBeCalled();
327
262
  expect(spyToastError).toBeCalled();
328
263
  expect(mockedNavigate).toHaveBeenCalledWith(Routes.Dashboard);
@@ -340,16 +275,7 @@ describe('Test Add LG Device', () => {
340
275
  stations: [{ id: 2, name: 'Station name' }],
341
276
  },
342
277
  };
343
- axios.get.mockImplementation(async () => {
344
- return response;
345
- });
346
-
347
- const responseToken = {
348
- data: {},
349
- };
350
- axios.post.mockImplementationOnce(async () => {
351
- return responseToken;
352
- });
278
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, response.data);
353
279
 
354
280
  const spyToastSuccess = jest.spyOn(ToastBottomHelper, 'success');
355
281
  const spyToastError = jest.spyOn(ToastBottomHelper, 'error');
@@ -368,8 +294,6 @@ describe('Test Add LG Device', () => {
368
294
  viewButtonBottom.props.onRightClick();
369
295
  });
370
296
 
371
- expect(axios.get).toHaveBeenCalledTimes(1);
372
- expect(axios.post).toHaveBeenCalledTimes(1); // called once
373
297
  expect(spyToastSuccess).not.toBeCalled();
374
298
  expect(spyToastError).toBeCalled();
375
299
  expect(mockedNavigate).toHaveBeenCalledWith(Routes.Dashboard);
@@ -1,4 +1,3 @@
1
- /* eslint-disable react-hooks/exhaustive-deps */
2
1
  import React, { memo, useCallback, useRef, useState } from 'react';
3
2
  import { View } from 'react-native';
4
3
  import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';
@@ -8,24 +7,17 @@ import BottomButtonView from '../../commons/BottomButtonView';
8
7
  import { FullLoading } from '../../commons';
9
8
  import { useTranslations } from '../../hooks/Common/useTranslations';
10
9
 
11
- navigator.geolocation = require('@react-native-community/geolocation');
12
-
13
10
  import styles from './ChooseLocationStyles';
14
11
  import { API } from '../../configs';
15
12
  import { axiosGet } from '../../utils/Apis/axios';
16
13
  import { SCConfig } from '../../configs';
14
+ import { MAP_INITIAL_REGION, EOH_LOCATION } from '../../configs/Constants';
17
15
 
18
- const initialRegion = {
19
- latitudeDelta: 0.0922,
20
- longitudeDelta: 0.0421,
21
- };
22
-
23
- const DEFAULT_LATITUDE = 10.7974046; // EoH center
24
- const DEFAULT_LONGITUDE = 106.7035663;
16
+ navigator.geolocation = require('@react-native-community/geolocation');
25
17
 
26
18
  const ChooseLocation = memo(({ route }) => {
27
19
  const t = useTranslations();
28
- const { location, setAddress, setLocation } = route.params;
20
+ const { location, setAddress, setLocation } = route.params || {};
29
21
  const { goBack } = useNavigation();
30
22
  const [currentLocation, setCurrentLocation] = useState(location);
31
23
  const [loading, setLoading] = useState(false);
@@ -76,9 +68,10 @@ const ChooseLocation = memo(({ route }) => {
76
68
  provider={PROVIDER_GOOGLE}
77
69
  style={styles.mapView}
78
70
  initialRegion={{
79
- ...initialRegion,
80
- latitude: location?.latitude || DEFAULT_LATITUDE,
81
- longitude: location?.longitude || DEFAULT_LONGITUDE,
71
+ latitude: location?.latitude || EOH_LOCATION.LAT,
72
+ longitude: location?.longitude || EOH_LOCATION.LNG,
73
+ latitudeDelta: MAP_INITIAL_REGION.LAT,
74
+ longitudeDelta: MAP_INITIAL_REGION.LNG,
82
75
  }}
83
76
  followUserLocation={true}
84
77
  onRegionChangeComplete={onRegionChange}
@@ -1,14 +1,15 @@
1
1
  import React, {
2
2
  useCallback,
3
- useContext,
4
3
  useEffect,
5
4
  useState,
6
5
  useRef,
6
+ useContext,
7
7
  } from 'react';
8
8
  import { AppState, RefreshControl, View } from 'react-native';
9
9
  import { useIsFocused } from '@react-navigation/native';
10
- import { useTranslations } from '../../hooks/Common/useTranslations';
10
+ import { VLCPlayer } from 'react-native-vlc-media-player';
11
11
 
12
+ import { useTranslations } from '../../hooks/Common/useTranslations';
12
13
  import styles from './styles';
13
14
  import AddMenu from './AddMenu';
14
15
  import MoreMenu from './MoreMenu';
@@ -23,10 +24,8 @@ import {
23
24
  usePopover,
24
25
  } from '../../hooks/Common';
25
26
  import { useFavorites } from './hook/useFavorites';
26
- import { scanBluetoothDevices } from '../../iot/RemoteControl/Bluetooth';
27
- import { googleHomeConnect } from '../../iot/RemoteControl/GoogleHome';
28
- import { axiosPost, fetchWithCache, axiosGet } from '../../utils/Apis/axios';
29
- import { lgThinqConnect } from '../../iot/RemoteControl/LG';
27
+ import { useUnitConnectRemoteDevices } from './hook/useUnitConnectRemoteDevices';
28
+ import { fetchWithCache, axiosGet } from '../../utils/Apis/axios';
30
29
  import ShortDetailSubUnit from '../../commons/SubUnit/ShortDetail';
31
30
  import NavBar from '../../commons/NavBar';
32
31
  import WrapParallaxScrollView from '../../commons/WrapParallaxScrollView';
@@ -51,6 +50,7 @@ import PreventAccess from '../../commons/PreventAccess';
51
50
 
52
51
  const UnitDetail = ({ route }) => {
53
52
  const t = useTranslations();
53
+ const { setAction } = useContext(SCContext);
54
54
 
55
55
  const {
56
56
  unitId,
@@ -63,7 +63,6 @@ const UnitDetail = ({ route }) => {
63
63
  } = route.params;
64
64
 
65
65
  const isFocused = useIsFocused();
66
- const { stateData, setAction } = useContext(SCContext);
67
66
  const { navigate, goBack } = useNavigation();
68
67
  const RouterHardware = useCallback(
69
68
  (routeHardware) => () => {
@@ -76,15 +75,14 @@ const UnitDetail = ({ route }) => {
76
75
  isSuccessfullyConnected ? RouterHardware(Routes.Dashboard) : goBack
77
76
  );
78
77
  const user = useSCContextSelector((state) => state?.auth?.account?.user);
79
- const isLavidaSource = useSCContextSelector(
80
- (state) => state.app.isLavidaSource
78
+ const { isLavidaSource, isFirstOpenCamera } = useSCContextSelector(
79
+ (state) => state.app
81
80
  );
82
81
 
83
82
  const [unit, setUnit] = useState(unitData || { id: unitId });
84
83
  const [listMenuItem, setListMenuItem] = useState([]);
85
84
  const [listStation, setListStation] = useState([]);
86
85
  const [listAutomate, setListAutomate] = useState([]);
87
- const [isGGHomeConnected, setIsGGHomeConnected] = useState(false);
88
86
  const [station, setStation] = useState({});
89
87
  const [indexStation, setIndexStation] = useState(0);
90
88
  const [showAdd, setShowAdd, setHideAdd] = useBoolean();
@@ -191,61 +189,7 @@ const UnitDetail = ({ route }) => {
191
189
  };
192
190
  }, [fetchDetails]);
193
191
 
194
- const handleGoogleHomeConnect = useCallback(
195
- async (options) => {
196
- let isConnected = await googleHomeConnect(options); // this may wrong if have multiple connection
197
- setIsGGHomeConnected(isConnected);
198
- let chipId = options[0].chip_id;
199
- if (!isConnected) {
200
- setAction(Action.LIST_DEVICE_TYPES, {
201
- chipId: chipId,
202
- sentEmail: true,
203
- });
204
- await axiosPost(API.GOOGLE_HOME.CHECK_SEND_EMAIL(), {
205
- chip_id: chipId,
206
- is_connected: false,
207
- });
208
- } else if (isConnected && stateData?.listDevice[chipId]?.sentEmail) {
209
- setAction(Action.LIST_DEVICE_TYPES, {
210
- chipId: chipId,
211
- sentEmail: false,
212
- });
213
- await axiosPost(API.GOOGLE_HOME.CHECK_SEND_EMAIL(), {
214
- chip_id: chipId,
215
- is_connected: true,
216
- });
217
- }
218
- },
219
- // eslint-disable-next-line react-hooks/exhaustive-deps
220
- []
221
- );
222
-
223
- let isCalled = false;
224
-
225
- const handleLgThinqConnect = useCallback(async (options) => {
226
- if (isCalled) {
227
- return;
228
- }
229
- // eslint-disable-next-line react-hooks/exhaustive-deps
230
- isCalled = true;
231
- await lgThinqConnect(options);
232
- }, []);
233
-
234
- useEffect(() => {
235
- if (unit.remote_control_options) {
236
- if (unit.remote_control_options.bluetooth) {
237
- scanBluetoothDevices(unit.remote_control_options.bluetooth);
238
- }
239
- if (unit.remote_control_options.googlehome?.length) {
240
- handleGoogleHomeConnect(unit.remote_control_options.googlehome);
241
- }
242
- if (unit.remote_control_options.lg_thinq) {
243
- (async () => {
244
- await handleLgThinqConnect(unit.remote_control_options.lg_thinq);
245
- })();
246
- }
247
- }
248
- }, [handleGoogleHomeConnect, handleLgThinqConnect, unit]);
192
+ useUnitConnectRemoteDevices(unit);
249
193
 
250
194
  useEffect(() => {
251
195
  if (isFocused) {
@@ -264,7 +208,7 @@ const UnitDetail = ({ route }) => {
264
208
  setListMenuItem(listMenu);
265
209
  setListStation(listMenu.concat([{ text: '' }]));
266
210
  }
267
- }, [unit, indexStation, isGGHomeConnected]);
211
+ }, [unit, indexStation]);
268
212
 
269
213
  useEffect(() => {
270
214
  isOneTap && setIndexStation(1);
@@ -308,7 +252,6 @@ const UnitDetail = ({ route }) => {
308
252
  favoriteDevices={favoriteDevices}
309
253
  favoriteAutomates={favoriteAutomates}
310
254
  wrapItemStyle={styles.wrapItemStyle}
311
- isGGHomeConnected={isGGHomeConnected}
312
255
  />
313
256
  );
314
257
  }
@@ -330,13 +273,7 @@ const UnitDetail = ({ route }) => {
330
273
  />
331
274
  );
332
275
  } else if (station) {
333
- return (
334
- <ShortDetailSubUnit
335
- unit={unit}
336
- station={station}
337
- isGGHomeConnected={isGGHomeConnected}
338
- />
339
- );
276
+ return <ShortDetailSubUnit unit={unit} station={station} />;
340
277
  }
341
278
  };
342
279
 
@@ -353,6 +290,15 @@ const UnitDetail = ({ route }) => {
353
290
  return () => unwatchNotificationData(user);
354
291
  }, [user, onRefresh]);
355
292
 
293
+ useEffect(() => {
294
+ if (isFirstOpenCamera) {
295
+ const to = setTimeout(() => {
296
+ setAction(Action.IS_FIRST_OPEN_CAMERA, false);
297
+ clearTimeout(to);
298
+ }, 5000);
299
+ }
300
+ }, [isFirstOpenCamera, setAction]);
301
+
356
302
  return (
357
303
  <WrapParallaxScrollView
358
304
  uriImg={unit.background}
@@ -367,6 +313,16 @@ const UnitDetail = ({ route }) => {
367
313
  hideRightPlus={!isOwner}
368
314
  onBack={(isSuccessfullyConnected && Dashboard) || (routeName && onBack)}
369
315
  >
316
+ {/* NOTE: This is a trick to fix camera not full screen on first open app */}
317
+ {isFirstOpenCamera && (
318
+ <VLCPlayer
319
+ source={{
320
+ uri: 'rtsp://admin:Eoh@2020@101.99.33.220:30554/main',
321
+ }}
322
+ style={styles.camera}
323
+ />
324
+ )}
325
+
370
326
  <View style={styles.container}>
371
327
  <Summaries unit={unit} />
372
328
  <NavBar
@@ -383,7 +339,6 @@ const UnitDetail = ({ route }) => {
383
339
  </View>
384
340
  )}
385
341
  </View>
386
-
387
342
  <AddMenu
388
343
  unit={unit}
389
344
  afterItemClick={hidePopover}
@@ -105,6 +105,7 @@ const ManageUnit = ({ route }) => {
105
105
  formData,
106
106
  headers
107
107
  );
108
+
108
109
  if (success) {
109
110
  setUnitData({ ...data });
110
111
  ToastBottomHelper.success(t('unit_updated_successfully'));
@@ -1,9 +1,9 @@
1
- /* eslint-disable react-hooks/exhaustive-deps */
2
1
  import React, { memo, useCallback, useEffect, useRef, useState } from 'react';
3
2
  import { TouchableOpacity, View, ScrollView } from 'react-native';
4
3
  import MapView, { Marker, Circle, PROVIDER_GOOGLE } from 'react-native-maps';
5
4
  import { useNavigation } from '@react-navigation/native';
6
5
  import { IconOutline, IconFill } from '@ant-design/icons-react-native';
6
+ import { check, RESULTS } from 'react-native-permissions';
7
7
 
8
8
  import BottomButtonView from '../../commons/BottomButtonView';
9
9
  import SearchBarLocation from '../../commons/SearchLocation';
@@ -11,22 +11,23 @@ import RowLocation from '../../commons/SearchLocation/RowLocation';
11
11
  import Text from '../../commons/Text';
12
12
  import { FullLoading } from '../../commons';
13
13
  import { useTranslations } from '../../hooks/Common/useTranslations';
14
-
15
- navigator.geolocation = require('@react-native-community/geolocation');
14
+ import {
15
+ GEOLOCATION_ERROR,
16
+ keyPermission,
17
+ OpenSetting,
18
+ } from '../../utils/Permission/common';
16
19
 
17
20
  import styles from './SelectAddressStyles';
18
21
  import { API, Colors, SCConfig } from '../../configs';
19
22
  import { axiosGet } from '../../utils/Apis/axios';
20
23
  import Routes from '../../utils/Route';
21
- import { TESTID } from '../../configs/Constants';
24
+ import {
25
+ TESTID,
26
+ MAP_INITIAL_REGION,
27
+ EOH_LOCATION,
28
+ } from '../../configs/Constants';
22
29
 
23
- const initialRegion = {
24
- latitudeDelta: 0.0922,
25
- longitudeDelta: 0.0421,
26
- };
27
-
28
- const DEFAULT_LATITUDE = 10.7974046; // EoH center
29
- const DEFAULT_LONGITUDE = 106.7035663;
30
+ navigator.geolocation = require('@react-native-community/geolocation');
30
31
 
31
32
  const SelectAddress = memo(({ route }) => {
32
33
  const t = useTranslations();
@@ -46,9 +47,9 @@ const SelectAddress = memo(({ route }) => {
46
47
  goBack();
47
48
  }, [goBack, updateLocation, searchedLocation]);
48
49
 
49
- const onTextInput = useCallback(async (input) => {
50
- setInput(input);
51
- if (input === '') {
50
+ const onTextInput = useCallback(async (value) => {
51
+ setInput(value);
52
+ if (value === '') {
52
53
  setSearchData([]);
53
54
  setSearchedLocation(null);
54
55
  return;
@@ -56,7 +57,7 @@ const SelectAddress = memo(({ route }) => {
56
57
  try {
57
58
  const config = {
58
59
  params: {
59
- input: input,
60
+ input: value,
60
61
  key: SCConfig.GOOGLE_MAP_API_KEY,
61
62
  sessiontoken: 123456324,
62
63
  strictBounds: false,
@@ -71,6 +72,7 @@ const SelectAddress = memo(({ route }) => {
71
72
  if (success) {
72
73
  setSearchData(data.predictions);
73
74
  }
75
+ // eslint-disable-next-line no-empty
74
76
  } catch (error) {}
75
77
  }, []);
76
78
 
@@ -83,7 +85,8 @@ const SelectAddress = memo(({ route }) => {
83
85
  {
84
86
  latitude: lat,
85
87
  longitude: lng,
86
- ...initialRegion,
88
+ latitudeDelta: MAP_INITIAL_REGION.LAT,
89
+ longitudeDelta: MAP_INITIAL_REGION.LNG,
87
90
  },
88
91
  600
89
92
  );
@@ -140,10 +143,19 @@ const SelectAddress = memo(({ route }) => {
140
143
  setLoading(false);
141
144
  },
142
145
  // eslint-disable-next-line promise/prefer-await-to-callbacks
143
- (error) => {}
146
+ async (error) => {
147
+ if (error.code === GEOLOCATION_ERROR.PERMISSION_DENIED) {
148
+ const permissionResult = await check(keyPermission.LOCATION);
149
+ permissionResult === RESULTS.BLOCKED &&
150
+ OpenSetting(
151
+ t('location_rationale_title'),
152
+ t('location_require_message')
153
+ );
154
+ }
155
+ }
144
156
  // { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 } enable on emulator
145
157
  );
146
- }, []);
158
+ }, [t]);
147
159
 
148
160
  const chooseOnMap = useCallback(() => {
149
161
  navigate(Routes.ChooseLocation, {
@@ -202,9 +214,10 @@ const SelectAddress = memo(({ route }) => {
202
214
  provider={PROVIDER_GOOGLE}
203
215
  style={styles.mapView}
204
216
  initialRegion={{
205
- ...initialRegion,
206
- latitude: DEFAULT_LATITUDE,
207
- longitude: DEFAULT_LONGITUDE,
217
+ latitude: EOH_LOCATION.LAT,
218
+ longitude: EOH_LOCATION.LNG,
219
+ latitudeDelta: MAP_INITIAL_REGION.LAT,
220
+ longitudeDelta: MAP_INITIAL_REGION.LNG,
208
221
  }}
209
222
  followUserLocation={true}
210
223
  >
@@ -29,13 +29,13 @@ const ListSmartAccount = ({ route }) => {
29
29
  const [loadingRemoveItem, setLoadingRemoveItem] = useState(false);
30
30
 
31
31
  const getAllSmartAccounts = useCallback(async () => {
32
- const { success, data } = await axiosGet(
33
- API.SMART_ACCOUNT.LIST_SMART_ACCOUNT()
32
+ const { success, data: accountData } = await axiosGet(
33
+ API.SMART_ACCOUNT.LIST_SMART_ACCOUNT(unitId)
34
34
  );
35
35
  if (success) {
36
- setData(data);
36
+ setData(accountData);
37
37
  }
38
- }, []);
38
+ }, [unitId]);
39
39
 
40
40
  const { childRef, showingPopover, showPopoverWithRef, hidePopover } =
41
41
  usePopover();
@@ -5,6 +5,7 @@ import Routes from '../../utils/Route';
5
5
  import { useIsFocused, useNavigation } from '@react-navigation/native';
6
6
  import { axiosGet } from '../../utils/Apis/axios';
7
7
  import { API } from '../../configs';
8
+ import { useReceiveNotifications } from '../../hooks';
8
9
 
9
10
  const Summaries = memo(({ unit }) => {
10
11
  const [unitSummaries, setUnitSummaries] = useState([]);
@@ -33,6 +34,8 @@ const Summaries = memo(({ unit }) => {
33
34
  const goToSummary = useCallback(
34
35
  (summary) => {
35
36
  navigation.navigate(Routes.UnitSummary, {
37
+ summaryId: summary.id,
38
+ unitId: unit.id,
36
39
  summaryData: summary,
37
40
  unitData: unit,
38
41
  });
@@ -50,7 +53,7 @@ const Summaries = memo(({ unit }) => {
50
53
  if (success) {
51
54
  localState.timeoutId = setTimeout(() => {
52
55
  continuousFetchSummary();
53
- }, 5000);
56
+ }, 10000);
54
57
  }
55
58
  }, [localState, fetchUnitSummary]);
56
59
 
@@ -82,6 +85,19 @@ const Summaries = memo(({ unit }) => {
82
85
  };
83
86
  }, [localState, continuousFetchSummary, isFocused]);
84
87
 
88
+ const { dataNotification } = useReceiveNotifications();
89
+
90
+ useEffect(() => {
91
+ if (dataNotification) {
92
+ const { params = {} } = dataNotification;
93
+ const { summary_id } = params;
94
+ if (summary_id) {
95
+ fetchUnitSummary();
96
+ }
97
+ }
98
+ // eslint-disable-next-line react-hooks/exhaustive-deps
99
+ }, [dataNotification]);
100
+
85
101
  return (
86
102
  <>
87
103
  {!unitSummaries || !unitSummaries.length ? null : (