@eohjsc/react-native-smart-city 0.3.4 → 0.3.7

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 (293) hide show
  1. package/README.md +15 -36
  2. package/package.json +5 -9
  3. package/react-native-smart-city.podspec +0 -1
  4. package/src/commons/Action/ItemQuickAction.js +4 -16
  5. package/src/commons/Action/__test__/ItemQuickAction.test.js +6 -11
  6. package/src/commons/ActionGroup/ColorPickerTemplate.js +24 -37
  7. package/src/commons/ActionGroup/CurtainButtonTemplate.js +5 -10
  8. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +31 -12
  9. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +0 -4
  10. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
  11. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +0 -14
  12. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/index.js +0 -1
  13. package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +2 -8
  14. package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplate.js +10 -10
  15. package/src/commons/ActionGroup/OnOffTemplate/index.js +2 -3
  16. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +9 -7
  17. package/src/commons/ActionGroup/SliderRangeTemplate.js +2 -6
  18. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +3 -7
  19. package/src/commons/ActionGroup/StatesGridActionTemplate.js +8 -22
  20. package/src/commons/ActionGroup/TimerActionTemplate.js +3 -11
  21. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +5 -1
  22. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +4 -53
  23. package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +83 -3
  24. package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +14 -14
  25. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +78 -53
  26. package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +20 -36
  27. package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +57 -1
  28. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +6 -58
  29. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +1 -49
  30. package/src/commons/ActionGroup/__test__/index.test.js +4 -142
  31. package/src/commons/Auth/AccountList.js +1 -1
  32. package/src/commons/Automate/ItemAutomate.js +3 -1
  33. package/src/commons/Connecting/__test__/Connecting.test.js +2 -19
  34. package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +3 -7
  35. package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +11 -8
  36. package/src/commons/ConnectingProcess/__test__/Connecting.test.js +3 -136
  37. package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +2 -3
  38. package/src/commons/ConnectingProcess/index.js +25 -75
  39. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +13 -16
  40. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
  41. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +5 -0
  42. package/src/commons/Device/ConnectedViewHeader.js +1 -1
  43. package/src/commons/Device/HistoryChart.js +3 -7
  44. package/src/commons/Device/ItemDevice.js +12 -19
  45. package/src/commons/Device/LinearChart.js +0 -15
  46. package/src/commons/Device/PMSensor/PMSensorIndicatior.js +12 -16
  47. package/src/commons/Device/PMSensor/PMSensorIndicatorStyles.js +0 -3
  48. package/src/commons/Device/SonosSpeaker/index.js +1 -1
  49. package/src/commons/Device/WaterQualitySensor/ListQualityIndicator.js +0 -1
  50. package/src/commons/Device/WaterQualitySensor/QualityIndicatorsItem.js +2 -7
  51. package/src/commons/Explore/__test__/CityItem.test.js +54 -33
  52. package/src/commons/Form/CurrencyInput.js +1 -15
  53. package/src/commons/Form/TextInputPassword.js +1 -1
  54. package/src/commons/FullLoading/index.js +1 -2
  55. package/src/commons/Header/HeaderCustom.js +1 -2
  56. package/src/commons/HeaderAni/index.js +1 -6
  57. package/src/commons/HorizontalPicker/index.js +2 -2
  58. package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +6 -0
  59. package/src/commons/MediaPlayerDetail/index.js +47 -25
  60. package/src/commons/MenuActionAddnew/index.js +0 -1
  61. package/src/commons/MenuActionList/index.js +0 -1
  62. package/src/commons/MenuActionMore/index.js +1 -1
  63. package/src/commons/PreventAccess/index.js +1 -9
  64. package/src/commons/Sharing/MemberList.js +2 -10
  65. package/src/commons/Sharing/WrapHeaderScrollable.js +0 -2
  66. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +1 -0
  67. package/src/commons/SubUnit/Favorites/index.js +3 -2
  68. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +35 -8
  69. package/src/commons/SubUnit/OneTap/index.js +2 -1
  70. package/src/commons/SubUnit/ShortDetail.js +9 -25
  71. package/src/commons/SubUnit/__test__/Item.test.js +1 -0
  72. package/src/commons/SubUnit/__test__/ShortDetail.test.js +2 -9
  73. package/src/commons/Unit/SharedUnit.js +0 -1
  74. package/src/commons/Unit/__test__/SharedUnit.test.js +183 -38
  75. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +13 -2
  76. package/src/commons/UnitSummary/ConfigHistoryChart.js +13 -22
  77. package/src/commons/WheelDateTimePicker/index.js +3 -4
  78. package/src/configs/API.js +143 -87
  79. package/src/configs/Constants.js +2 -57
  80. package/src/configs/SCConfig.js +0 -4
  81. package/src/context/actionType.ts +0 -8
  82. package/src/context/mockStore.ts +0 -10
  83. package/src/context/reducer.ts +2 -38
  84. package/src/hooks/Common/index.js +0 -2
  85. package/src/hooks/Common/useGetIdUser.js +5 -1
  86. package/src/hooks/Common/useSensorsStatus.js +4 -4
  87. package/src/hooks/useReceiveNotifications.js +5 -9
  88. package/src/iot/Monitor.js +2 -3
  89. package/src/iot/RemoteControl/Bluetooth.js +1 -1
  90. package/src/iot/RemoteControl/GoogleHome.js +49 -75
  91. package/src/iot/RemoteControl/Internet.js +1 -1
  92. package/src/iot/RemoteControl/__test__/GoogleHome.test.js +48 -95
  93. package/src/iot/RemoteControl/__test__/Internet.test.js +7 -18
  94. package/src/iot/RemoteControl/__test__/LgThinq.test.js +177 -36
  95. package/src/iot/RemoteControl/index.js +52 -52
  96. package/src/navigations/UnitStack.js +20 -11
  97. package/src/screens/AQIGuide/index.js +1 -1
  98. package/src/screens/ActivityLog/FilterPopup.js +0 -2
  99. package/src/screens/ActivityLog/__test__/index.test.js +23 -38
  100. package/src/screens/ActivityLog/hooks/__test__/index.test.js +90 -51
  101. package/src/screens/ActivityLog/hooks/index.js +1 -1
  102. package/src/screens/ActivityLog/index.js +2 -2
  103. package/src/screens/AddCommon/SelectSubUnit.js +0 -1
  104. package/src/screens/AddCommon/SelectUnit.js +0 -1
  105. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +24 -13
  106. package/src/screens/AddCommon/__test__/SelectUnit.test.js +33 -9
  107. package/src/screens/AddLocationMaps/index.js +5 -9
  108. package/src/screens/AddNewAction/SelectAction.js +8 -8
  109. package/src/screens/AddNewAction/SelectSensorDevices.js +2 -8
  110. package/src/screens/AddNewAction/SetupSensor.js +7 -7
  111. package/src/screens/AddNewAction/__test__/SelectAction.test.js +91 -10
  112. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +26 -40
  113. package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +1 -3
  114. package/src/screens/AddNewAutoSmart/index.js +2 -5
  115. package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
  116. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -42
  117. package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +4 -0
  118. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +22 -22
  119. package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
  120. package/src/screens/AddNewDevice/index.js +0 -1
  121. package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +17 -23
  122. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +4 -7
  123. package/src/screens/AddNewGateway/SelectGateway.js +0 -1
  124. package/src/screens/AddNewGateway/SetupGatewayWifi.js +0 -2
  125. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +6 -4
  126. package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +4 -0
  127. package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +29 -5
  128. package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +4 -0
  129. package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +4 -0
  130. package/src/screens/AddNewGateway/index.js +0 -1
  131. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +24 -10
  132. package/src/screens/AddNewOneTap/index.js +2 -3
  133. package/src/screens/AllCamera/index.js +4 -4
  134. package/src/screens/Automate/MultiUnits.js +8 -8
  135. package/src/screens/Automate/__test__/MultiUnits.test.js +9 -6
  136. package/src/screens/Automate/__test__/index.test.js +12 -7
  137. package/src/screens/Automate/index.js +3 -5
  138. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +8 -36
  139. package/src/screens/ConfirmUnitDeletion/index.js +1 -7
  140. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +22 -71
  141. package/src/screens/Device/EditDevice/index.js +15 -17
  142. package/src/screens/Device/__test__/detail.test.js +86 -33
  143. package/src/screens/Device/components/DetailHistoryChart.js +1 -1
  144. package/src/screens/Device/components/SensorConnectStatusViewHeader.js +0 -1
  145. package/src/screens/Device/components/SensorDisplayItem.js +2 -5
  146. package/src/screens/Device/detail.js +24 -80
  147. package/src/screens/Device/hooks/useDisconnectedDevice.js +4 -4
  148. package/src/screens/Device/hooks/useFavoriteDevice.js +9 -5
  149. package/src/screens/DeviceInfo/__test__/index.test.js +2 -0
  150. package/src/screens/EditActionsList/index.js +1 -1
  151. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +3 -6
  152. package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +19 -7
  153. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +2 -20
  154. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +23 -40
  155. package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
  156. package/src/screens/EmergencySetting/index.js +1 -4
  157. package/src/screens/EnterPassword/__test__/EnterPassword.test.js +25 -41
  158. package/src/screens/Explore/index.js +0 -2
  159. package/src/screens/GuestInfo/__test__/index.test.js +41 -14
  160. package/src/screens/GuestInfo/components/RecurringDetail.js +0 -1
  161. package/src/screens/GuestInfo/components/TemporaryDetail.js +2 -2
  162. package/src/screens/HanetCamera/Detail.js +1 -1
  163. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +12 -8
  164. package/src/screens/HanetCamera/__test__/Detail.test.js +42 -27
  165. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +5 -8
  166. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +32 -10
  167. package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +2 -3
  168. package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +35 -43
  169. package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +21 -10
  170. package/src/screens/HanetCamera/hooks/useHanetCheckinData.js +11 -11
  171. package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +11 -11
  172. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +22 -33
  173. package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +45 -44
  174. package/src/screens/ManageAccess/hooks/index.js +4 -7
  175. package/src/screens/ManageAccess/index.js +1 -2
  176. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +12 -35
  177. package/src/screens/MoveToAnotherSubUnit/index.js +6 -6
  178. package/src/screens/Notification/__test__/Notification.test.js +25 -14
  179. package/src/screens/Notification/__test__/NotificationItem.test.js +7 -8
  180. package/src/screens/Notification/components/NotificationItem.js +20 -17
  181. package/src/screens/Notification/index.js +2 -9
  182. package/src/screens/PlayBackCamera/Timer.js +2 -2
  183. package/src/screens/PlayBackCamera/__test__/index.test.js +2 -87
  184. package/src/screens/PlayBackCamera/index.js +6 -22
  185. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +20 -7
  186. package/src/screens/ScanChipQR/components/QRScan/index.js +0 -1
  187. package/src/screens/ScanChipQR/hooks/index.js +16 -15
  188. package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +24 -8
  189. package/src/screens/ScriptDetail/__test__/index.test.js +86 -17
  190. package/src/screens/ScriptDetail/index.js +14 -19
  191. package/src/screens/SelectUnit/__test__/index.test.js +55 -12
  192. package/src/screens/SelectUnit/index.js +4 -9
  193. package/src/screens/SetSchedule/index.js +11 -15
  194. package/src/screens/SharedUnit/__test__/TabHeader.test.js +2 -0
  195. package/src/screens/SharedUnit/index.js +0 -2
  196. package/src/screens/Sharing/Components/SensorItem.js +12 -10
  197. package/src/screens/Sharing/InfoMemberUnit.js +1 -1
  198. package/src/screens/Sharing/MemberList.js +11 -12
  199. package/src/screens/Sharing/SelectPermission.js +76 -121
  200. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +29 -47
  201. package/src/screens/Sharing/__test__/MemberList.test.js +127 -13
  202. package/src/screens/Sharing/__test__/SelectPermission.test.js +38 -28
  203. package/src/screens/Sharing/__test__/SelectUser.test.js +38 -17
  204. package/src/screens/Sharing/hooks/index.js +0 -3
  205. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +2 -3
  206. package/src/screens/SmartIr/components/SelectBrand.js +1 -1
  207. package/src/screens/SubUnit/AddSubUnit.js +17 -23
  208. package/src/screens/SubUnit/Detail.js +2 -1
  209. package/src/screens/SubUnit/EditSubUnit.js +13 -15
  210. package/src/screens/SubUnit/ManageSubUnit.js +7 -13
  211. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +89 -29
  212. package/src/screens/SubUnit/__test__/Detail.test.js +8 -31
  213. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +89 -21
  214. package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +1 -27
  215. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +45 -48
  216. package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
  217. package/src/screens/SyncLGDevice/AddLGDevice.js +0 -1
  218. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +91 -22
  219. package/src/screens/TDSGuide/index.js +1 -4
  220. package/src/screens/UVIndexGuide/index.js +1 -1
  221. package/src/screens/Unit/ChooseLocation.js +14 -7
  222. package/src/screens/Unit/Detail.js +75 -30
  223. package/src/screens/Unit/ManageUnit.js +0 -1
  224. package/src/screens/Unit/SelectAddress.js +23 -45
  225. package/src/screens/Unit/SmartAccount.js +4 -4
  226. package/src/screens/Unit/Station/index.js +0 -4
  227. package/src/screens/Unit/Summaries.js +2 -18
  228. package/src/screens/Unit/__test__/CheckSendEmail.test.js +29 -24
  229. package/src/screens/Unit/__test__/ChooseLocation.test.js +14 -27
  230. package/src/screens/Unit/__test__/Detail.test.js +200 -99
  231. package/src/screens/Unit/__test__/ManageUnit.test.js +42 -18
  232. package/src/screens/Unit/__test__/SelectAddress.test.js +49 -159
  233. package/src/screens/Unit/__test__/SmartAccount.test.js +9 -17
  234. package/src/screens/Unit/__test__/SmartAccountItem.test.js +1 -0
  235. package/src/screens/Unit/components/MyUnitDevice/index.js +4 -4
  236. package/src/screens/Unit/components/SharedUnit/index.js +0 -1
  237. package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +2 -2
  238. package/src/screens/Unit/components/__test__/SharedUnit.test.js +34 -31
  239. package/src/screens/Unit/styles.js +0 -4
  240. package/src/screens/UnitSummary/__test__/index.test.js +30 -91
  241. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +2 -31
  242. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +4 -7
  243. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +13 -2
  244. package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +1 -0
  245. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +16 -14
  246. package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +2 -11
  247. package/src/screens/UnitSummary/components/RunningDevices/index.js +10 -7
  248. package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
  249. package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +2 -10
  250. package/src/screens/UnitSummary/index.js +1 -15
  251. package/src/screens/WaterQualityGuide/index.js +1 -1
  252. package/src/utils/Apis/axios.js +31 -54
  253. package/src/utils/Converter/time.js +18 -0
  254. package/src/utils/I18n/translations/en.json +1 -7
  255. package/src/utils/I18n/translations/vi.json +1 -8
  256. package/src/utils/Route/index.js +0 -1
  257. package/src/utils/Utils.js +7 -11
  258. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +0 -24
  259. package/src/commons/ActionGroup/__test__/NumberUpDownTemplateWithNullConfigValue.test.js +0 -60
  260. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +0 -77
  261. package/src/commons/Calendar/__test__/Calendar.test.js +0 -33
  262. package/src/commons/Device/Hanet/ItemHanetDevice.test.js +0 -58
  263. package/src/commons/FieldTemplate/ChooseUserField/ChooseFieldStyles.js +0 -25
  264. package/src/commons/FieldTemplate/ChooseUserField/ChoosePopup.js +0 -96
  265. package/src/commons/FieldTemplate/ChooseUserField/ChoosePopupStyles.js +0 -39
  266. package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +0 -118
  267. package/src/commons/FieldTemplate/ChooseUserField/index.js +0 -62
  268. package/src/commons/FieldTemplate/PasscodeField/PasscodeFieldStyles.js +0 -30
  269. package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +0 -90
  270. package/src/commons/FieldTemplate/PasscodeField/index.js +0 -43
  271. package/src/commons/FieldTemplate/ScheduleField/ScheduleFieldStyles.js +0 -13
  272. package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +0 -179
  273. package/src/commons/FieldTemplate/ScheduleField/index.js +0 -176
  274. package/src/commons/PreventAccess/__test__/PreventAccess.test.js +0 -62
  275. package/src/hooks/Common/useGGHomeDeviceConnected.js +0 -16
  276. package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +0 -198
  277. package/src/hooks/IoT/__test__/useRemoteControl.test.js +0 -198
  278. package/src/hooks/IoT/index.js +0 -4
  279. package/src/hooks/IoT/useGGHomeConnection.js +0 -91
  280. package/src/hooks/IoT/useRemoteControl.js +0 -79
  281. package/src/hooks/index.js +0 -4
  282. package/src/navigations/UnitStackStyles.js +0 -21
  283. package/src/screens/Sharing/__test__/MemberList2.test.js +0 -80
  284. package/src/screens/SideMenuDetail/SideMenuDetailStyles.js +0 -28
  285. package/src/screens/SideMenuDetail/__test__/index.test.js +0 -154
  286. package/src/screens/SideMenuDetail/index.js +0 -148
  287. package/src/screens/Unit/__test__/Summaries.test.js +0 -100
  288. package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +0 -36
  289. package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +0 -54
  290. package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +0 -50
  291. package/src/utils/Permission/common.js +0 -67
  292. package/src/utils/Setting/Location.js +0 -30
  293. package/src/utils/__test__/Utils.test.js +0 -12
@@ -1,24 +1,24 @@
1
+ import axios from 'axios';
1
2
  import React from 'react';
2
- import { TouchableOpacity, View } from 'react-native';
3
- import MockAdapter from 'axios-mock-adapter';
3
+ import { TouchableOpacity } from 'react-native';
4
4
  import renderer, { act } from 'react-test-renderer';
5
+ import { createConnection, getStates } from 'home-assistant-js-websocket';
5
6
  import ParallaxScrollView from '../../../libs/react-native-parallax-scroll-view';
6
7
  import { BleManager } from 'react-native-ble-plx';
7
8
  import { useIsFocused } from '@react-navigation/native';
8
9
  import AsyncStorage from '@react-native-community/async-storage';
9
10
  import UnitDetail from '../Detail';
10
11
  import { API } from '../../../configs';
12
+ import ShortDetailSubUnit from '../../../commons/SubUnit/ShortDetail';
11
13
  import { TESTID } from '../../../configs/Constants';
12
14
  import { SCProvider } from '../../../context';
13
15
  import { mockSCStore } from '../../../context/mockStore';
14
16
  import CameraDevice from '../../../commons/CameraDevice';
15
17
  import { ModalFullVideo } from '../../../commons/Modal';
16
18
  import SubUnitFavorites from '../../../commons/SubUnit/Favorites';
17
- import api from '../../../utils/Apis/axios';
18
- import PreventAccess from '../../../commons/PreventAccess';
19
19
 
20
20
  const mockDispatch = jest.fn();
21
- jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
21
+
22
22
  const wrapComponent = (route, account) => (
23
23
  <SCProvider initState={mockSCStore({})}>
24
24
  <UnitDetail route={route} account={account} />
@@ -54,23 +54,15 @@ jest.mock('@react-navigation/native', () => {
54
54
  };
55
55
  });
56
56
 
57
- const mockConnectGoogleHome = jest.fn();
58
- jest.mock('../../../hooks/IoT', () => {
59
- return {
60
- ...jest.requireActual('../../../hooks/IoT'),
61
- useGGHomeConnection: () => ({
62
- connectGoogleHome: mockConnectGoogleHome,
63
- }),
64
- };
65
- });
66
-
67
- jest.mock('react-native-onesignal', () => {
57
+ jest.mock('home-assistant-js-websocket', () => {
68
58
  return {
69
- setNotificationWillShowInForegroundHandler: jest.fn(),
59
+ ...jest.requireActual('home-assistant-js-websocket'),
60
+ createConnection: jest.fn(),
61
+ getStates: jest.fn(),
70
62
  };
71
63
  });
72
64
 
73
- const mock = new MockAdapter(api.axiosInstance);
65
+ jest.mock('axios');
74
66
 
75
67
  describe('Test UnitDetail', () => {
76
68
  const route = {
@@ -86,110 +78,155 @@ describe('Test UnitDetail', () => {
86
78
 
87
79
  let tree;
88
80
 
81
+ axios.get.mockImplementation(() => ({ status: 200 }));
82
+
89
83
  beforeEach(() => {
90
84
  jest.clearAllTimers();
85
+ axios.get.mockClear();
91
86
  useIsFocused.mockImplementation(() => true);
92
87
  AsyncStorage.clear();
93
88
  });
94
89
 
95
90
  test('fetch unit detail success', async () => {
96
- mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
97
- address: null,
98
- background: 'https://eoh-gateway-backend.eoh.io/smarthome_1_juLMJGE.jpg',
99
- can_add: false,
100
- group: null,
101
- icon: 'https://eoh-gateway-backend.eoh.io/iconsmarthome_SVG1NTj.png',
102
- id: 1006,
103
- main_config_count: 0,
104
- name: 'Zigbee Gateway',
105
- remote_control_options: {
106
- bluetooth: [],
107
- googlehome: [],
108
- lg_thinq: [],
109
- zigbee: [],
91
+ axios.get.mockImplementation((url) => ({
92
+ status: 200,
93
+ data: {},
94
+ }));
95
+ await act(async () => {
96
+ await renderer.create(wrapComponent(route));
97
+ });
98
+
99
+ expect(axios.get).toHaveBeenCalledWith(detailUnitApiUrl, {
100
+ headers: {
101
+ 'Cache-Control': 'no-cache',
110
102
  },
111
- stations: [],
112
- user_id: 119,
113
103
  });
104
+ });
114
105
 
115
- route.params.isSuccessfullyConnected = true;
106
+ test('fetch unit detail no network then load from cache', async () => {
107
+ axios.get.mockImplementation((url) => ({
108
+ status: 200,
109
+ data: {},
110
+ }));
116
111
  await act(async () => {
117
- tree = await renderer.create(wrapComponent(route));
112
+ await renderer.create(wrapComponent(route, account));
113
+ });
114
+
115
+ axios.get.mockImplementation((url) => {
116
+ if (url === detailUnitApiUrl) {
117
+ throw {};
118
+ }
119
+ return { status: 200, data: [] };
118
120
  });
119
- mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(new Error('Network Error'));
120
- const scrollView = tree.root.findByType(ParallaxScrollView);
121
- const refreshControl = scrollView.props.refreshControl;
122
121
  await act(async () => {
123
- refreshControl.props.onRefresh();
122
+ await renderer.create(wrapComponent(route, account));
124
123
  });
125
- const instance = tree.root;
126
- const PreventAccesss = instance.findByType(PreventAccess);
127
- expect(PreventAccesss).toBeDefined();
128
- });
129
124
 
130
- test('fetch unit detail no network then load from cache', async () => {
131
- mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(500, []);
132
- await act(async () => {
133
- tree = await renderer.create(wrapComponent(route, account));
125
+ expect(axios.get).toHaveBeenCalledWith(detailUnitApiUrl, {
126
+ headers: {
127
+ 'Cache-Control': 'no-cache',
128
+ },
134
129
  });
135
- const instance = tree.root;
136
- const PreventAccesss = instance.findByType(PreventAccess);
137
- expect(PreventAccesss).toBeDefined();
138
130
  });
139
131
 
140
- test('fetch unit detail error 404', async () => {
141
- mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(404, {});
132
+ test('fetch unit detail no network and fail load from cache', async () => {
133
+ axios.get.mockImplementation((url) => {
134
+ throw {};
135
+ });
142
136
  await act(async () => {
143
- tree = await renderer.create(wrapComponent(route));
137
+ await renderer.create(wrapComponent(route, account));
138
+ });
139
+
140
+ expect(axios.get).toHaveBeenCalledWith(detailUnitApiUrl, {
141
+ headers: {
142
+ 'Cache-Control': 'no-cache',
143
+ },
144
144
  });
145
- const instance = tree.root;
146
- const button1 = instance.find(
147
- (el) => el.props.testID === TESTID.BUTTON_PREVENT_ACCESS
148
- );
149
- expect(button1.props.isVisible).toBeTruthy();
150
145
  });
151
146
 
152
147
  test('fetch unit summary empty', async () => {
153
- mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200);
148
+ axios.get.mockImplementation((url) => {
149
+ if (url === summaryUnitApiUrl) {
150
+ return {
151
+ status: 200,
152
+ data: [],
153
+ };
154
+ }
155
+
156
+ return {
157
+ status: 200,
158
+ data: {},
159
+ };
160
+ });
154
161
  await act(async () => {
155
- tree = await renderer.create(wrapComponent(route, account));
162
+ await renderer.create(wrapComponent(route, account));
156
163
  });
157
- const instance = tree.root;
158
- const PreventAccesss = instance.findByType(PreventAccess);
159
- expect(PreventAccesss).toBeDefined();
164
+
165
+ expect(axios.get).toHaveBeenCalledWith(summaryUnitApiUrl, {});
160
166
  });
161
167
 
162
168
  test('fetch unit summary has data', async () => {
163
- mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200, [{}]);
169
+ axios.get.mockImplementation((url) => {
170
+ if (url === summaryUnitApiUrl) {
171
+ return {
172
+ status: 200,
173
+ data: [{}],
174
+ };
175
+ }
176
+
177
+ return {
178
+ status: 200,
179
+ data: {},
180
+ };
181
+ });
164
182
  await act(async () => {
165
- tree = await renderer.create(wrapComponent(route, account));
183
+ await renderer.create(wrapComponent(route, account));
166
184
  });
167
- const instance = tree.root;
168
- const PreventAccesss = instance.findByType(PreventAccess);
169
- expect(PreventAccesss).toBeDefined();
185
+
186
+ expect(axios.get).toHaveBeenCalledWith(summaryUnitApiUrl, {});
170
187
  });
171
188
 
172
189
  test('not fetch unit summary if not focus', async () => {
173
190
  useIsFocused.mockImplementation(() => false);
174
- mock.onGet(summaryUnitApiUrl).reply(200);
191
+ axios.get.mockImplementation((url) => {
192
+ if (url === summaryUnitApiUrl) {
193
+ return {
194
+ status: 200,
195
+ data: [{}],
196
+ };
197
+ }
198
+
199
+ return {
200
+ status: 200,
201
+ data: {},
202
+ };
203
+ });
175
204
  await act(async () => {
176
- tree = await renderer.create(wrapComponent(route, account));
205
+ await renderer.create(wrapComponent(route, account));
206
+ });
207
+
208
+ expect(axios.get).not.toHaveBeenCalledWith(summaryUnitApiUrl, {
209
+ headers: {
210
+ 'Cache-Control': 'no-cache',
211
+ },
177
212
  });
178
- const instance = tree.root;
179
- const PreventAccesss = instance.findByType(PreventAccess);
180
- expect(PreventAccesss).toBeDefined();
181
213
  });
182
214
 
183
215
  test('fetch unit detail when refresh', async () => {
184
216
  await act(async () => {
185
217
  tree = await renderer.create(wrapComponent(route, account));
186
218
  });
219
+ axios.get.mockClear();
187
220
  const scrollView = tree.root.findByType(ParallaxScrollView);
188
221
  const refreshControl = scrollView.props.refreshControl;
189
222
  await act(async () => {
190
223
  refreshControl.props.onRefresh();
191
224
  });
192
- expect(refreshControl).toBeDefined();
225
+ expect(axios.get).toHaveBeenCalledWith(detailUnitApiUrl, {
226
+ headers: {
227
+ 'Cache-Control': 'no-cache',
228
+ },
229
+ });
193
230
  });
194
231
 
195
232
  test('when unit has google home action then connect to google home', async () => {
@@ -204,12 +241,21 @@ describe('Test UnitDetail', () => {
204
241
  ],
205
242
  },
206
243
  };
244
+ jest.useFakeTimers();
245
+
246
+ createConnection.mockImplementation(async () => ({
247
+ subscribeEvents: jest.fn(),
248
+ addEventListener: jest.fn(),
249
+ }));
250
+
207
251
  await act(async () => {
208
252
  renderer.create(
209
253
  wrapComponent({ params: { ...route.params, unitData } }, account)
210
254
  );
211
255
  });
212
- expect(mockConnectGoogleHome).toBeCalled();
256
+
257
+ expect(createConnection).toHaveBeenCalled();
258
+ expect(getStates).toHaveBeenCalled();
213
259
  });
214
260
 
215
261
  test('when unit has bluetooth action then scan for devices', async () => {
@@ -287,9 +333,24 @@ describe('Test UnitDetail', () => {
287
333
  ],
288
334
  };
289
335
  jest.useFakeTimers();
290
- mock.onGet(summaryUnitApiUrl).reply(200, []);
291
- mock.onGet(sensorStatusApiUrl).reply(200, []);
292
- mock.onGet(detailUnitApiUrl).reply(200, unitData);
336
+ axios.get.mockImplementation((url) => {
337
+ if (url === summaryUnitApiUrl) {
338
+ return {
339
+ status: 200,
340
+ data: [],
341
+ };
342
+ } else if (url === sensorStatusApiUrl) {
343
+ return {
344
+ status: 200,
345
+ data: [],
346
+ };
347
+ }
348
+
349
+ return {
350
+ status: 200,
351
+ data: unitData,
352
+ };
353
+ });
293
354
 
294
355
  await act(async () => {
295
356
  tree = await renderer.create(
@@ -297,6 +358,9 @@ describe('Test UnitDetail', () => {
297
358
  );
298
359
  });
299
360
  const instance = tree.root;
361
+ const stationViews = instance.findAllByType(ShortDetailSubUnit);
362
+ expect(stationViews).toHaveLength(1);
363
+
300
364
  const icon = await instance.findAll(
301
365
  (el) =>
302
366
  el.props.testID === TESTID.NAVBAR_ICON_BARS &&
@@ -315,6 +379,55 @@ describe('Test UnitDetail', () => {
315
379
  expect(menu[0].props.isVisible).toEqual(true);
316
380
  });
317
381
 
382
+ test('when unit has google home action then connect to lg thinq', async () => {
383
+ const unitData = {
384
+ remote_control_options: {
385
+ lg_thinq: [
386
+ {
387
+ id: 1,
388
+ lg_devices: [
389
+ {
390
+ id: 1,
391
+ sensor_id: 2,
392
+ device_id: 'DEVICE_ID',
393
+ configs: [
394
+ {
395
+ id: 1,
396
+ name: 'windStrength',
397
+ },
398
+ ],
399
+ },
400
+ ],
401
+ },
402
+ ],
403
+ },
404
+ };
405
+
406
+ const responseGet = {
407
+ status: 200,
408
+ data: {
409
+ airFlow: {
410
+ windStrength: 'AUTO',
411
+ },
412
+ },
413
+ };
414
+ axios.get.mockImplementation(async () => {
415
+ return responseGet;
416
+ });
417
+
418
+ jest.useFakeTimers();
419
+ await act(async () => {
420
+ tree = await renderer.create(
421
+ wrapComponent({ params: { ...route.params, unitData } }, account)
422
+ );
423
+ });
424
+ await act(async () => {
425
+ await jest.runOnlyPendingTimers();
426
+ });
427
+ // TODO Called but can not expect
428
+ // expect(axios.get).toHaveBeenCalledWith(API.IOT.LG.DEVICE_STATUS(2));
429
+ });
430
+
318
431
  test('render subunit camera devices', async () => {
319
432
  const unitData = {
320
433
  stations: [
@@ -346,7 +459,7 @@ describe('Test UnitDetail', () => {
346
459
  });
347
460
  const instance = tree.root;
348
461
  const CameraDeviceViews = instance.findAllByType(CameraDevice);
349
- expect(CameraDeviceViews).toHaveLength(0);
462
+ expect(CameraDeviceViews).toHaveLength(1);
350
463
 
351
464
  const fullCamera = tree.root.findAll(
352
465
  (el) =>
@@ -359,7 +472,6 @@ describe('Test UnitDetail', () => {
359
472
  expect(fullView).toHaveLength(1);
360
473
  expect(fullView[0].props.isVisible).toEqual(false);
361
474
  });
362
-
363
475
  test('onPress subunit camera devices', async () => {
364
476
  const unitData = {
365
477
  stations: [
@@ -391,20 +503,19 @@ describe('Test UnitDetail', () => {
391
503
  });
392
504
  const instance = tree.root;
393
505
  const CameraDeviceViews = instance.findAllByType(CameraDevice);
394
- expect(CameraDeviceViews).toHaveLength(0);
506
+ expect(CameraDeviceViews).toHaveLength(1);
395
507
  const goDetailButton = tree.root.findAll(
396
508
  (el) =>
397
509
  el.props.testID === TESTID.SUB_UNIT_GO_DETAIL &&
398
510
  el.type === TouchableOpacity
399
511
  );
400
512
 
401
- expect(goDetailButton).toHaveLength(1);
513
+ expect(goDetailButton).toHaveLength(2);
402
514
  await act(async () => {
403
515
  await goDetailButton[0].props.onPress();
404
516
  });
405
- expect(mockedNavigate).not.toHaveBeenCalled();
517
+ expect(mockedNavigate).toHaveBeenCalled();
406
518
  });
407
-
408
519
  test('render subunit favorites', async () => {
409
520
  const unitData = {
410
521
  stations: [
@@ -423,12 +534,7 @@ describe('Test UnitDetail', () => {
423
534
  const favorites = instance.findAllByType(SubUnitFavorites);
424
535
  expect(favorites).toHaveLength(1);
425
536
  });
426
-
427
537
  test('render navbar', async () => {
428
- mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
429
- stations: [],
430
- });
431
-
432
538
  const unitData = {
433
539
  stations: [
434
540
  {
@@ -437,10 +543,10 @@ describe('Test UnitDetail', () => {
437
543
  },
438
544
  ],
439
545
  };
440
- route.params.isAddSubUnit = true;
441
- route.params.unitData = unitData;
442
546
  await act(async () => {
443
- tree = await renderer.create(wrapComponent(route, account));
547
+ tree = await renderer.create(
548
+ wrapComponent({ params: { ...route.params, unitData } }, account)
549
+ );
444
550
  });
445
551
  const instance = tree.root;
446
552
  const navBar = instance.find(
@@ -448,14 +554,9 @@ describe('Test UnitDetail', () => {
448
554
  );
449
555
 
450
556
  await act(() => {
451
- navBar.props.onSnapToItem({}, 1);
557
+ navBar.props.onSnapToItem();
452
558
  });
453
559
 
454
560
  expect(navBar).toBeDefined();
455
- const viewAutomate = instance.findAll(
456
- (el) =>
457
- el.props.testID === TESTID.VIEW_SUB_UNIT_AUTOMATE && el.type === View
458
- );
459
- expect(viewAutomate).toHaveLength(1);
460
561
  });
461
562
  });
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
- import MockAdapter from 'axios-mock-adapter';
4
- import Toast from 'react-native-toast-message';
3
+ import axios from 'axios';
5
4
 
6
5
  import { ToastBottomHelper } from '../../../utils/Utils';
7
6
  import { TESTID } from '../../../configs/Constants';
@@ -9,11 +8,8 @@ import { TESTID } from '../../../configs/Constants';
9
8
  import ManageUnit from '../ManageUnit';
10
9
  import { SCProvider } from '../../../context';
11
10
  import { mockSCStore } from '../../../context/mockStore';
12
- import api from '../../../utils/Apis/axios';
13
- import { API } from '../../../configs';
14
- import { getTranslate } from '../../../utils/I18n';
15
11
 
16
- const mock = new MockAdapter(api.axiosInstance);
12
+ jest.mock('axios');
17
13
 
18
14
  const mockNavigate = jest.fn();
19
15
  jest.mock('@react-navigation/native', () => {
@@ -59,6 +55,7 @@ describe('Test Manage Unit', () => {
59
55
 
60
56
  beforeEach(() => {
61
57
  mockNavigate.mockClear();
58
+ axios.get.mockClear();
62
59
  });
63
60
 
64
61
  const getElement = (instance) => {
@@ -119,28 +116,33 @@ describe('Test Manage Unit', () => {
119
116
  await act(async () => {
120
117
  tree = create(wrapComponent(route));
121
118
  });
119
+
122
120
  const instance = tree.root;
123
121
  const { changeName, inputRename } = getElement(instance);
122
+
124
123
  await act(async () => {
125
124
  await changeName[0].props.onPress();
126
125
  });
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
- mock.onPatch(API.UNIT.MANAGE_UNIT(1)).reply(200, {});
132
+
133
+ const response = {
134
+ data: {},
135
+ };
136
+ axios.patch.mockImplementation(async () => {
137
+ return response;
138
+ });
139
+
133
140
  await act(async () => {
134
141
  await inputRename[0].props.onChange('input station');
135
142
  await bottomButton.props.onPress();
136
143
  });
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
- });
144
+
145
+ expect(axios.patch).toBeCalled();
144
146
  });
145
147
 
146
148
  test('remove Unit success', async () => {
@@ -160,10 +162,23 @@ describe('Test Manage Unit', () => {
160
162
  item.props.testID ===
161
163
  `${TESTID.PREFIX.MANAGE_UNIT_ALERT}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
162
164
  );
165
+
163
166
  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
+
164
178
  await act(async () => {
165
179
  await bottomButton.props.onPress();
166
180
  });
181
+
167
182
  expect(mockedDispatch).not.toBeCalled();
168
183
  });
169
184
 
@@ -185,19 +200,29 @@ describe('Test Manage Unit', () => {
185
200
  item.props.testID ===
186
201
  `${TESTID.PREFIX.MANAGE_UNIT}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
187
202
  );
188
- mock.onPatch(API.UNIT.MANAGE_UNIT(1)).reply(200);
203
+
204
+ const response = {
205
+ status: 200,
206
+ success: true,
207
+ data: {},
208
+ };
209
+
210
+ axios.patch.mockImplementation(async () => {
211
+ return response;
212
+ });
189
213
 
190
214
  await act(async () => {
191
215
  await inputRename[0].props.onChange('input station');
192
216
  await bottomButton.props.onPress();
193
217
  });
194
218
 
219
+ expect(axios.patch).toBeCalled();
220
+
195
221
  expect(mockedDispatch).not.toBeCalled();
196
222
  expect(spyToast).toBeCalled();
197
223
  spyToast.mockReset();
198
224
  spyToast.mockRestore();
199
225
  });
200
-
201
226
  test('test onPress onUpdateImage', async () => {
202
227
  await act(async () => {
203
228
  tree = create(wrapComponent(route));
@@ -218,9 +243,9 @@ describe('Test Manage Unit', () => {
218
243
  imagePicker.props.setImageUrl('abc');
219
244
  });
220
245
 
246
+ expect(axios.patch).toBeCalled();
221
247
  expect(imagePicker.props.showImagePicker).toBeTruthy();
222
248
  });
223
-
224
249
  test('test onPress goSelectLocation', async () => {
225
250
  await act(async () => {
226
251
  tree = create(wrapComponent(route));
@@ -236,7 +261,6 @@ describe('Test Manage Unit', () => {
236
261
  });
237
262
  expect(mockNavigate).toBeCalled();
238
263
  });
239
-
240
264
  test('test onPress goToManageSubUnit', async () => {
241
265
  await act(async () => {
242
266
  tree = create(wrapComponent(route));