@eohjsc/react-native-smart-city 0.3.29 → 0.3.32

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 (404) hide show
  1. package/package.json +7 -5
  2. package/src/Images/DevMode/close.png +0 -0
  3. package/src/Images/DevMode/close@2x.png +0 -0
  4. package/src/Images/DevMode/close@3x.png +0 -0
  5. package/src/Images/DevMode/plus.png +0 -0
  6. package/src/Images/DevMode/plus@2x.png +0 -0
  7. package/src/Images/DevMode/plus@3x.png +0 -0
  8. package/src/Images/DevMode/remove_circle.png +0 -0
  9. package/src/Images/DevMode/remove_circle@2x.png +0 -0
  10. package/src/Images/DevMode/remove_circle@3x.png +0 -0
  11. package/src/commons/Action/ItemQuickAction.js +2 -2
  12. package/src/commons/Action/__test__/ItemQuickAction.test.js +17 -9
  13. package/src/commons/ActionGroup/ColorPickerTemplate.js +36 -17
  14. package/src/commons/ActionGroup/CurtainButtonTemplate.js +6 -6
  15. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +18 -13
  16. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/ButtonWrapper.js +5 -2
  17. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +10 -4
  18. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/index.js +4 -4
  19. package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLock.js +38 -45
  20. package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLockStyle.js +1 -0
  21. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
  22. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/index.test.js +2 -2
  23. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/index.js +2 -2
  24. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/ButtonWrapper.js +2 -2
  25. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +12 -6
  26. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/index.js +8 -4
  27. package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +9 -10
  28. package/src/commons/ActionGroup/OnOffTemplate/index.js +2 -2
  29. package/src/commons/ActionGroup/OneBigButtonTemplate.js +5 -5
  30. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +38 -22
  31. package/src/commons/ActionGroup/SliderRangeTemplate.js +24 -16
  32. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +25 -9
  33. package/src/commons/ActionGroup/SmartTiviActionTemplate/__test__/ControlPlay.test.js +13 -7
  34. package/src/commons/ActionGroup/SmartTiviActionTemplate/__test__/RectangleButton.test.js +9 -5
  35. package/src/commons/ActionGroup/SmartTiviActionTemplate/__test__/SmartTiviActionTemplate.test.js +25 -9
  36. package/src/commons/ActionGroup/SmartTiviActionTemplate/component/CircleButton.js +16 -6
  37. package/src/commons/ActionGroup/SmartTiviActionTemplate/component/ControlPlay.js +10 -4
  38. package/src/commons/ActionGroup/SmartTiviActionTemplate/component/RectangleButton.js +7 -3
  39. package/src/commons/ActionGroup/StatesGridActionTemplate.js +2 -2
  40. package/src/commons/ActionGroup/ThreeButtonTemplate.js +50 -60
  41. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +135 -133
  42. package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +7 -7
  43. package/src/commons/ActionGroup/__test__/OnOffSmartLock.test.js +3 -3
  44. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +3 -3
  45. package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +9 -5
  46. package/src/commons/ActionGroup/__test__/index.test.js +7 -5
  47. package/src/commons/ActionGroup/index.js +35 -10
  48. package/src/commons/AlertAction/index.js +2 -2
  49. package/src/commons/Auth/AccountItem.js +9 -3
  50. package/src/commons/Auth/__test__/AccountItem.test.js +6 -3
  51. package/src/commons/Automate/ItemAutomate.js +13 -3
  52. package/src/commons/BackDefault/index.js +2 -2
  53. package/src/commons/BottomButtonView/index.js +4 -4
  54. package/src/commons/Button/index.js +2 -2
  55. package/src/commons/ButtonPopup/index.js +3 -3
  56. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +3 -2
  57. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +4 -2
  58. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +6 -3
  59. package/src/commons/Dashboard/MyUnit/index.js +5 -3
  60. package/src/commons/DevMode/CardDevMode.js +42 -0
  61. package/src/commons/DevMode/EmptyComponent.js +18 -0
  62. package/src/commons/DevMode/Item.js +21 -0
  63. package/src/commons/DevMode/Styles/CardStyles.js +40 -0
  64. package/src/commons/DevMode/Styles/EmptyComponentStyles.js +15 -0
  65. package/src/commons/DevMode/Styles/ItemStyles.js +27 -0
  66. package/src/commons/DevMode/Styles/TextWithLabelStyles.js +36 -0
  67. package/src/commons/DevMode/TextWithLabel.js +30 -0
  68. package/src/commons/DevMode/index.js +5 -1
  69. package/src/commons/Device/ConnectedViewHeader.js +2 -2
  70. package/src/commons/Device/DeviceAlertStatus.js +3 -3
  71. package/src/commons/Device/DisconnectedView.js +2 -2
  72. package/src/commons/Device/Emergency/EmergencyButton.js +2 -2
  73. package/src/commons/Device/Emergency/EmergencyDetail.js +1 -1
  74. package/src/commons/Device/Emergency/__test__/EmergencyButton.test.js +3 -2
  75. package/src/commons/Device/FlatListItems.js +2 -2
  76. package/src/commons/Device/ItemAddNew/index.js +10 -11
  77. package/src/commons/Device/ItemDevice.js +27 -20
  78. package/src/commons/Device/PMSensor/PMSensorIndicatior.js +1 -1
  79. package/src/commons/Device/RainningSensor/CurrentRainSensor.js +1 -1
  80. package/src/commons/Device/SensorConnectedStatus.js +5 -2
  81. package/src/commons/Device/WindDirection/Compass/index.js +6 -3
  82. package/src/commons/Device/WindSpeed/Anemometer/index.js +1 -1
  83. package/src/commons/Device/__test__/DeviceAlertStatus.test.js +8 -4
  84. package/src/commons/Device/__test__/FlatListItems.test.js +3 -2
  85. package/src/commons/Device/__test__/SensorConnectedStatus.test.js +4 -2
  86. package/src/commons/Explore/ActivityIndicator/index.js +5 -2
  87. package/src/commons/Explore/SearchBox/__test__/SearchBox.test.js +3 -3
  88. package/src/commons/Explore/SearchBox/index.js +2 -2
  89. package/src/commons/FieldTemplate/ChooseUserField/ChoosePopup.js +4 -4
  90. package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +11 -8
  91. package/src/commons/FieldTemplate/ChooseUserField/index.js +2 -2
  92. package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +3 -2
  93. package/src/commons/FieldTemplate/PasscodeField/index.js +2 -2
  94. package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +12 -7
  95. package/src/commons/Form/TextInput.js +2 -2
  96. package/src/commons/Form/TextInputPassword.js +2 -2
  97. package/src/commons/GroupCheckBox/__test__/GroupCheckBox.test.js +5 -3
  98. package/src/commons/GroupCheckBox/index.js +2 -2
  99. package/src/commons/Header/HeaderCustom.js +8 -2
  100. package/src/commons/HeaderAni/index.js +2 -3
  101. package/src/commons/MediaPlayerDetail/index.js +2 -2
  102. package/src/commons/MenuActionList/index.js +2 -2
  103. package/src/commons/MenuActionMore/index.js +6 -5
  104. package/src/commons/NavBar/index.js +4 -4
  105. package/src/commons/OneTapTemplate/NumberUpDownActionTemplate.js +11 -5
  106. package/src/commons/OneTapTemplate/OptionsDropdownActionTemplate.js +7 -3
  107. package/src/commons/OneTapTemplate/StatesGridActionTemplate.js +4 -2
  108. package/src/commons/OneTapTemplate/__test__/NumberUpDownActionTemplate.test.js +11 -8
  109. package/src/commons/OneTapTemplate/__test__/OptionsDropdownActionTemplate.test.js +9 -5
  110. package/src/commons/OneTapTemplate/__test__/StatesGridActionTemplate.test.js +5 -3
  111. package/src/commons/Popover/index.js +2 -12
  112. package/src/commons/PreventAccess/__test__/PreventAccess.test.js +5 -3
  113. package/src/commons/PreventAccess/index.js +3 -3
  114. package/src/commons/{Connecting → Processing}/__test__/Connecting.test.js +5 -4
  115. package/src/commons/Processing/index.js +93 -0
  116. package/src/commons/{Connecting → Processing}/styles.js +9 -1
  117. package/src/commons/SelectGateway/index.js +105 -0
  118. package/src/commons/SelectGateway/styles.js +55 -0
  119. package/src/commons/SelectSubUnit/__test__/SelectSubUnit.test.js +106 -0
  120. package/src/commons/SelectSubUnit/index.js +124 -0
  121. package/src/commons/SelectSubUnit/styles.js +55 -0
  122. package/src/commons/SelectUnit/__test__/SelectUnit.test.js +120 -0
  123. package/src/commons/SelectUnit/index.js +106 -0
  124. package/src/commons/SelectUnit/styles.js +54 -0
  125. package/src/commons/Sharing/WrapHeaderScrollable.js +6 -4
  126. package/src/commons/SubUnit/OneTap/ItemOneTap.js +7 -4
  127. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +25 -10
  128. package/src/commons/SubUnit/OneTap/index.js +9 -4
  129. package/src/commons/SubUnit/ShortDetail.js +11 -29
  130. package/src/commons/SubUnit/__test__/ShortDetail.test.js +15 -10
  131. package/src/commons/SummaryItem/index.js +2 -2
  132. package/src/commons/Unit/HeaderUnit/index.js +4 -5
  133. package/src/commons/Unit/SharedUnit.js +10 -8
  134. package/src/commons/Unit/__test__/HeaderUnit.test.js +13 -5
  135. package/src/commons/Unit/__test__/SharedUnit.test.js +30 -11
  136. package/src/commons/UnitSummary/AirQuality/__test__/index.test.js +13 -8
  137. package/src/commons/UnitSummary/AirQuality/index.js +7 -3
  138. package/src/commons/UnitSummary/TotalPowerBox.js +2 -2
  139. package/src/commons/UnitSummary/TotalPowerConsumption/index.js +2 -2
  140. package/src/commons/UnitSummary/__test__/TotalPowerBox.test.js +3 -2
  141. package/src/commons/UnitSummary/__test__/TotalPowerConsumption.test.js +4 -2
  142. package/src/commons/ViewButtonBottom/index.js +4 -4
  143. package/src/commons/WheelDateTimePicker/index.js +5 -3
  144. package/src/commons/WrapParallaxScrollView/index.js +2 -1
  145. package/src/configs/API.js +12 -14
  146. package/src/configs/AccessibilityLabel.js +608 -0
  147. package/src/configs/Colors.js +4 -0
  148. package/src/configs/Constants.js +1 -593
  149. package/src/configs/Images.js +3 -0
  150. package/src/context/actionType.ts +19 -3
  151. package/src/context/mockStore.ts +18 -3
  152. package/src/context/reducer.ts +66 -9
  153. package/src/hoc/withRemoteControl.js +1 -0
  154. package/src/hooks/Common/index.js +2 -2
  155. package/src/hooks/Common/useDevicesStatus.js +1 -1
  156. package/src/hooks/Common/{useGGHomeDeviceConnected.js → useHomeAssistantDeviceConnected.js} +3 -3
  157. package/src/hooks/Common/usePopover.js +6 -1
  158. package/src/hooks/IoT/__test__/{useGGHomeConnection.test.js → useHomeAssistantConnection.test.js} +18 -18
  159. package/src/hooks/IoT/__test__/useRemoteControl.test.js +17 -12
  160. package/src/hooks/IoT/index.js +2 -2
  161. package/src/hooks/IoT/useHomeAssistantConnection.js +91 -0
  162. package/src/hooks/IoT/useRemoteControl.js +6 -6
  163. package/src/hooks/IoT/useValueEvaluation.js +10 -19
  164. package/src/iot/RemoteControl/{GoogleHome.js → HomeAssistant.js} +27 -23
  165. package/src/iot/RemoteControl/LG.js +2 -1
  166. package/src/iot/RemoteControl/__test__/{GoogleHome.test.js → HomeAssistant.test.js} +30 -30
  167. package/src/navigations/AddDeviceStack.js +0 -14
  168. package/src/navigations/AddGatewayStack.js +51 -21
  169. package/src/navigations/Main.js +28 -4
  170. package/src/navigations/SmartIrStack.js +3 -3
  171. package/src/navigations/UnitStack.js +5 -8
  172. package/src/screens/AQIGuide/__test__/AQIGuide.test.js +5 -3
  173. package/src/screens/AQIGuide/index.js +5 -3
  174. package/src/screens/ActivityLog/FilterPopup.js +2 -2
  175. package/src/screens/ActivityLog/__test__/FilterPopup.test.js +2 -2
  176. package/src/screens/ActivityLog/__test__/index.test.js +3 -2
  177. package/src/screens/ActivityLog/index.js +3 -3
  178. package/src/screens/AddCommon/SelectSubUnit.js +44 -191
  179. package/src/screens/AddCommon/SelectUnit.js +51 -204
  180. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +7 -50
  181. package/src/screens/AddCommon/__test__/SelectUnit.test.js +28 -26
  182. package/src/screens/AddLocationMaps/__test__/index.test.js +13 -7
  183. package/src/screens/AddLocationMaps/index.js +3 -3
  184. package/src/screens/AddNewAction/Device/index.js +5 -1
  185. package/src/screens/AddNewAction/SelectAction.js +36 -20
  186. package/src/screens/AddNewAction/SelectSensorDevices.js +3 -3
  187. package/src/screens/AddNewAction/__test__/SelectAction.test.js +3 -2
  188. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +8 -3
  189. package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +11 -7
  190. package/src/screens/AddNewAutoSmart/index.js +11 -12
  191. package/src/screens/AddNewDevice/ConnectingDevices.js +1 -1
  192. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +7 -4
  193. package/src/screens/AddNewDevice/index.js +4 -4
  194. package/src/screens/AddNewGateway/ConnectingDevice.js +40 -0
  195. package/src/screens/AddNewGateway/ConnectingModbusDevice.js +61 -0
  196. package/src/screens/AddNewGateway/ConnectingWifiDevice.js +70 -0
  197. package/src/screens/AddNewGateway/ConnectingZigbeeDevice.js +60 -0
  198. package/src/screens/AddNewGateway/PlugAndPlay/FirstWarning.js +21 -8
  199. package/src/screens/AddNewGateway/PlugAndPlay/__test__/FirstWarning.test.js +23 -4
  200. package/src/screens/AddNewGateway/RenameNewDevices.js +141 -0
  201. package/src/screens/AddNewGateway/RenameNewDevicesStyles.js +75 -0
  202. package/src/screens/AddNewGateway/ScanGatewayQR.js +57 -0
  203. package/src/screens/AddNewGateway/ScanModbusQR.js +53 -0
  204. package/src/screens/AddNewGateway/ScanWifiDeviceQR.js +55 -0
  205. package/src/screens/AddNewGateway/SelectDeviceSubUnit.js +31 -0
  206. package/src/screens/AddNewGateway/SelectDeviceType.js +52 -0
  207. package/src/screens/AddNewGateway/SelectDeviceUnit.js +29 -0
  208. package/src/screens/AddNewGateway/SelectModbusGateway.js +34 -0
  209. package/src/screens/AddNewGateway/SelectZigbeeGateway.js +34 -0
  210. package/src/screens/AddNewGateway/ShareWifiPassword.js +302 -0
  211. package/src/screens/AddNewGateway/ShareWifiPasswordStyles.js +44 -0
  212. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +7 -4
  213. package/src/screens/AddNewGateway/__test__/ConnectingModbusDevice.test.js +63 -0
  214. package/src/screens/AddNewGateway/__test__/{SelectGateway.test.js → ConnectingWifiDevice.test.js} +15 -10
  215. package/src/screens/AddNewGateway/__test__/ConnectingZigbeeDevice.test.js +62 -0
  216. package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +191 -0
  217. package/src/screens/AddNewGateway/__test__/ScanGatewayQR.test.js +73 -0
  218. package/src/screens/AddNewGateway/__test__/ScanModbusQR.test.js +75 -0
  219. package/src/screens/AddNewGateway/__test__/ScanWifiDeviceQR.test.js +73 -0
  220. package/src/screens/AddNewGateway/__test__/SelectDeviceSubUnit.test.js +47 -0
  221. package/src/screens/AddNewGateway/__test__/SelectDeviceType.test.js +89 -0
  222. package/src/screens/AddNewGateway/__test__/SelectDeviceUnit.test.js +48 -0
  223. package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +77 -0
  224. package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +77 -0
  225. package/src/screens/AddNewGateway/__test__/ShareWifiPassword.test.js +294 -0
  226. package/src/screens/AddNewGateway/hooks/__Tests__/index.test.js +27 -0
  227. package/src/screens/AddNewGateway/index.js +4 -4
  228. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +5 -4
  229. package/src/screens/AddNewOneTap/index.js +4 -4
  230. package/src/screens/Automate/__test__/index.test.js +2 -2
  231. package/src/screens/Automate/index.js +6 -2
  232. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +3 -2
  233. package/src/screens/ConfirmUnitDeletion/index.js +3 -3
  234. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +5 -5
  235. package/src/screens/Device/EditDevice/index.js +3 -3
  236. package/src/screens/Device/__test__/detail.test.js +38 -22
  237. package/src/screens/Device/components/DetailHistoryChart.js +7 -5
  238. package/src/screens/Device/components/SensorConnectStatusViewHeader.js +16 -17
  239. package/src/screens/Device/components/SensorDisplayItem.js +51 -26
  240. package/src/screens/Device/detail.js +65 -38
  241. package/src/screens/Device/hooks/useEvaluateValue.js +0 -2
  242. package/src/screens/Device/hooks/useFavoriteDevice.js +4 -2
  243. package/src/screens/DeviceInfo/__test__/index.test.js +8 -4
  244. package/src/screens/DeviceInfo/index.js +10 -6
  245. package/src/screens/Drawer/index.js +30 -13
  246. package/src/screens/EmergencyContacts/EmergencyContactsAddNew.js +11 -7
  247. package/src/screens/EmergencyContacts/EmergencyContactsList.js +1 -1
  248. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +9 -10
  249. package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +9 -5
  250. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +7 -3
  251. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +7 -3
  252. package/src/screens/EmergencySetting/__test__/DropDownItem.test.js +3 -2
  253. package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
  254. package/src/screens/EnterPassword/__test__/EnterPassword.test.js +6 -3
  255. package/src/screens/EnterPassword/index.js +5 -3
  256. package/src/screens/GuestInfo/__test__/index.test.js +18 -12
  257. package/src/screens/GuestInfo/components/AccessScheduleItem.js +2 -2
  258. package/src/screens/GuestInfo/components/AccessScheduleSheet.js +3 -3
  259. package/src/screens/GuestInfo/components/HeaderGuestInfo.js +2 -2
  260. package/src/screens/GuestInfo/components/RecurringDetail.js +4 -4
  261. package/src/screens/GuestInfo/components/TemporaryDetail.js +3 -3
  262. package/src/screens/GuestInfo/index.js +1 -1
  263. package/src/screens/HanetCamera/Detail.js +10 -4
  264. package/src/screens/HanetCamera/ManageAccess.js +4 -4
  265. package/src/screens/HanetCamera/MemberInfo.js +1 -1
  266. package/src/screens/HanetCamera/__test__/Detail.test.js +5 -3
  267. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +10 -4
  268. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +4 -2
  269. package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +2 -2
  270. package/src/screens/ManageAccess/index.js +1 -1
  271. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +4 -4
  272. package/src/screens/MoveToAnotherSubUnit/index.js +2 -2
  273. package/src/screens/Notification/__test__/NotificationItem.test.js +6 -30
  274. package/src/screens/Notification/components/NotificationItem.js +3 -19
  275. package/src/screens/PlayBackCamera/__test__/index.test.js +9 -6
  276. package/src/screens/PlayBackCamera/index.js +6 -6
  277. package/src/screens/ScanChipQR/components/QRScan/__test__/QRScan.test.js +1 -1
  278. package/src/screens/ScanChipQR/components/QRScan/index.js +10 -3
  279. package/src/screens/ScriptDetail/__test__/index.test.js +8 -4
  280. package/src/screens/ScriptDetail/index.js +7 -5
  281. package/src/screens/SelectUnit/__test__/index.test.js +4 -3
  282. package/src/screens/SelectUnit/index.js +3 -3
  283. package/src/screens/SetSchedule/index.js +1 -1
  284. package/src/screens/Sharing/Components/SensorItem.js +6 -3
  285. package/src/screens/Sharing/Components/Styles/SensorItemStyles.js +4 -0
  286. package/src/screens/Sharing/Components/Styles/TitleCheckBoxStyles.js +4 -0
  287. package/src/screens/Sharing/Components/TitleCheckBox.js +17 -8
  288. package/src/screens/Sharing/Components/__test__/SensorItem.test.js +4 -2
  289. package/src/screens/Sharing/InfoMemberUnit.js +7 -6
  290. package/src/screens/Sharing/MemberList.js +4 -4
  291. package/src/screens/Sharing/SelectPermission.js +9 -4
  292. package/src/screens/Sharing/SelectUser.js +9 -5
  293. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +3 -2
  294. package/src/screens/Sharing/__test__/SelectUser.test.js +7 -4
  295. package/src/screens/SideMenuDetail/__test__/index.test.js +11 -7
  296. package/src/screens/SideMenuDetail/index.js +2 -2
  297. package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +4 -2
  298. package/src/screens/SmartIr/__test__/SelectDeviceType.test.js +5 -5
  299. package/src/screens/SmartIr/__test__/SmartIr.test.js +14 -6
  300. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +4 -2
  301. package/src/screens/SmartIr/components/{SelectDeviceType.js → SelectIrDeviceType.js} +2 -2
  302. package/src/screens/SmartIr/index.js +1 -1
  303. package/src/screens/SubUnit/AddSubUnit.js +7 -3
  304. package/src/screens/SubUnit/Detail.js +6 -6
  305. package/src/screens/SubUnit/EditSubUnit.js +10 -6
  306. package/src/screens/SubUnit/ManageSubUnit.js +2 -2
  307. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +6 -3
  308. package/src/screens/SubUnit/__test__/Detail.test.js +5 -3
  309. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +9 -5
  310. package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +3 -2
  311. package/src/screens/SyncLGDevice/AddLGDevice.js +4 -4
  312. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +7 -4
  313. package/src/screens/TDSGuide/__test__/TDSGuide.test.js +4 -2
  314. package/src/screens/TDSGuide/index.js +2 -2
  315. package/src/screens/Template/EditTemplate.js +152 -0
  316. package/src/screens/Template/GatewayList.js +51 -0
  317. package/src/screens/Template/Information.js +41 -0
  318. package/src/screens/Template/Styles/EditTemplateStyle.js +109 -0
  319. package/src/screens/Template/Styles/GatewayStyles.js +46 -0
  320. package/src/screens/Template/Styles/InformationStyles.js +16 -0
  321. package/src/screens/Template/Styles/detailStyles.js +35 -0
  322. package/src/screens/Template/Styles/indexStyles.js +2 -33
  323. package/src/screens/Template/__test__/EditTemplate.test.js +89 -0
  324. package/src/screens/Template/__test__/GatewayList.test.js +26 -0
  325. package/src/screens/Template/__test__/Information.test.js +16 -0
  326. package/src/screens/Template/__test__/detail.test.js +68 -0
  327. package/src/screens/Template/__test__/index.test.js +26 -1
  328. package/src/screens/Template/detail.js +154 -0
  329. package/src/screens/Template/index.js +38 -32
  330. package/src/screens/UVIndexGuide/__test__/UVIndexGuide.test.js +3 -2
  331. package/src/screens/UVIndexGuide/index.js +2 -2
  332. package/src/screens/Unit/AddMenu.js +6 -20
  333. package/src/screens/Unit/ChooseLocation.js +1 -1
  334. package/src/screens/Unit/Detail.js +14 -9
  335. package/src/screens/Unit/ManageUnit.js +21 -15
  336. package/src/screens/Unit/MyAllUnit/index.js +1 -1
  337. package/src/screens/Unit/SelectAddToFavorites.js +11 -2
  338. package/src/screens/Unit/SelectAddress.js +4 -4
  339. package/src/screens/Unit/SmartAccount.js +1 -1
  340. package/src/screens/Unit/SmartAccountItem.js +3 -3
  341. package/src/screens/Unit/Station/__test__/index.test.js +19 -3
  342. package/src/screens/Unit/Station/index.js +2 -2
  343. package/src/screens/Unit/Summaries.js +2 -2
  344. package/src/screens/Unit/__test__/CheckSendEmail.test.js +6 -6
  345. package/src/screens/Unit/__test__/Detail.test.js +90 -55
  346. package/src/screens/Unit/__test__/ManageUnit.test.js +40 -18
  347. package/src/screens/Unit/__test__/SelectAddress.test.js +15 -8
  348. package/src/screens/Unit/__test__/SmartAccount.test.js +42 -25
  349. package/src/screens/Unit/__test__/SmartAccountItem.test.js +4 -3
  350. package/src/screens/Unit/components/AutomateScript/index.js +8 -2
  351. package/src/screens/Unit/components/ListMyAllUnit/index.js +1 -1
  352. package/src/screens/Unit/components/MyAllUnit/__test__/Header.test.js +9 -5
  353. package/src/screens/Unit/components/MyAllUnit/index.js +1 -1
  354. package/src/screens/Unit/components/MyUnitDevice/index.js +8 -5
  355. package/src/screens/Unit/components/SharedUnit/index.js +12 -6
  356. package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +2 -2
  357. package/src/screens/Unit/components/__test__/SharedUnit.test.js +24 -9
  358. package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +25 -11
  359. package/src/screens/UnitSummary/__test__/index.test.js +4 -2
  360. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +4 -2
  361. package/src/screens/UnitSummary/components/3PPowerConsumption/index.js +2 -2
  362. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +4 -2
  363. package/src/screens/UnitSummary/components/PowerConsumption/index.js +2 -2
  364. package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +5 -4
  365. package/src/screens/UnitSummary/components/RunningDevices/index.js +6 -3
  366. package/src/screens/UnitSummary/components/TotalPowerBox/index.js +2 -2
  367. package/src/screens/UnitSummary/components/TotalPowerConsumption/index.js +2 -2
  368. package/src/screens/UnitSummary/components/__test__/TotalPowerBox.test.js +3 -2
  369. package/src/screens/UnitSummary/components/__test__/TotalPowerConsumption.test.js +4 -2
  370. package/src/screens/UnitSummary/index.js +10 -8
  371. package/src/screens/WaterQualityGuide/__test__/index.test.js +17 -12
  372. package/src/screens/WaterQualityGuide/index.js +26 -10
  373. package/src/utils/Apis/axios.js +1 -0
  374. package/src/utils/I18n/translations/en.json +25 -10
  375. package/src/utils/I18n/translations/vi.json +22 -9
  376. package/src/utils/Route/index.js +22 -10
  377. package/src/commons/Connecting/index.js +0 -67
  378. package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +0 -28
  379. package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +0 -41
  380. package/src/commons/ConnectingProcess/__test__/Connecting.test.js +0 -163
  381. package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +0 -19
  382. package/src/commons/ConnectingProcess/index.js +0 -213
  383. package/src/commons/ConnectingProcess/styles.js +0 -69
  384. package/src/hooks/IoT/useGGHomeConnection.js +0 -91
  385. package/src/iot/RemoteControl/index.js +0 -55
  386. package/src/screens/AddNewDevice/ConnectDevices.js +0 -184
  387. package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -131
  388. package/src/screens/AddNewGateway/ConnectedGateway.js +0 -139
  389. package/src/screens/AddNewGateway/ConnectingGateway.js +0 -137
  390. package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +0 -214
  391. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +0 -307
  392. package/src/screens/AddNewGateway/PlugAndPlay/__test__/ConnectWifiWarning.test.js +0 -75
  393. package/src/screens/AddNewGateway/PlugAndPlay/__test__/GatewayWifiList.test.js +0 -130
  394. package/src/screens/AddNewGateway/SelectGateway.js +0 -133
  395. package/src/screens/AddNewGateway/SetupGatewayWifi.js +0 -207
  396. package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -71
  397. package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +0 -96
  398. package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -120
  399. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +0 -115
  400. package/src/screens/ScanChipQR/hooks/index.js +0 -120
  401. package/src/screens/ScanChipQR/index.js +0 -29
  402. package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +0 -111
  403. package/src/screens/ScanSensorQR/hooks/index.js +0 -40
  404. package/src/screens/ScanSensorQR/index.js +0 -39
@@ -1,96 +0,0 @@
1
- import React from 'react';
2
- import { act, create } from 'react-test-renderer';
3
- import MockAdapter from 'axios-mock-adapter';
4
-
5
- import ConnectingGateway from '../ConnectingGateway';
6
- import Text from '../../../commons/Text';
7
- import API from '../../../configs/API';
8
- import Routes from '../../../utils/Route';
9
- import { getTranslate } from '../../../utils/I18n';
10
- import { SCProvider } from '../../../context';
11
- import { mockSCStore } from '../../../context/mockStore';
12
- import api from '../../../utils/Apis/axios';
13
-
14
- const mock = new MockAdapter(api.axiosInstance);
15
-
16
- const mockedNavigate = jest.fn();
17
- jest.mock('@react-navigation/native', () => {
18
- return {
19
- ...jest.requireActual('@react-navigation/native'),
20
- useNavigation: () => ({
21
- navigate: mockedNavigate,
22
- }),
23
- };
24
- });
25
-
26
- const wrapComponent = (route) => (
27
- <SCProvider initState={mockSCStore({})}>
28
- <ConnectingGateway route={route} />
29
- </SCProvider>
30
- );
31
-
32
- describe('Test ConnectingGateway', () => {
33
- let tree;
34
- let route;
35
-
36
- afterEach(() => {
37
- mockedNavigate.mockClear();
38
- });
39
-
40
- beforeEach(() => {
41
- route = {
42
- params: {
43
- new_chip: {
44
- id: 1,
45
- },
46
- },
47
- };
48
- });
49
-
50
- test('create', async () => {
51
- await act(async () => {
52
- tree = await create(wrapComponent(route));
53
- });
54
- const instance = tree.root;
55
- const texts = instance.findAllByType(Text);
56
- expect(texts).toHaveLength(8);
57
- expect(texts[0].props.children).toEqual(
58
- getTranslate('en', 'connecting_your_gateway')
59
- );
60
- expect(texts[1].props.children).toEqual(
61
- getTranslate('en', 'dont_turn_off_the_device_or_close_this_app')
62
- );
63
- });
64
-
65
- test('call setInterval api success', async () => {
66
- jest.useFakeTimers();
67
- mock.onGet(API.CHIP.CHECK_FINALIZED()).reply(200, {});
68
- await act(async () => {
69
- tree = await create(wrapComponent(route));
70
- });
71
- await act(async () => {
72
- await jest.runOnlyPendingTimers();
73
- });
74
- expect(setInterval).toHaveBeenCalled();
75
- expect(mockedNavigate).not.toHaveBeenCalledWith(
76
- Routes.ConnectedGateway,
77
- route.params
78
- );
79
- });
80
-
81
- test('call setInterval api fail', async () => {
82
- jest.useFakeTimers();
83
- mock.onGet(API.CHIP.CHECK_FINALIZED()).reply(400);
84
- await act(async () => {
85
- tree = await create(wrapComponent(route));
86
- });
87
- await act(async () => {
88
- await jest.runOnlyPendingTimers();
89
- });
90
- expect(setInterval).toHaveBeenCalled();
91
- expect(mockedNavigate).not.toHaveBeenCalledWith(
92
- Routes.ConnectedGateway,
93
- route.params
94
- );
95
- });
96
- });
@@ -1,120 +0,0 @@
1
- import React from 'react';
2
- import { act, create } from 'react-test-renderer';
3
-
4
- import { TESTID } from '../../../configs/Constants';
5
- import { SCProvider } from '../../../context';
6
- import { mockSCStore } from '../../../context/mockStore';
7
- import SetupGatewayWifi from '../SetupGatewayWifi';
8
- import DisplayChecking from '../../../commons/DisplayChecking';
9
- import _TextInputPassword from '../../../commons/Form/TextInputPassword';
10
- import _TextInput from '../../../commons/Form/TextInput';
11
-
12
- const wrapComponent = (route) => (
13
- <SCProvider initState={mockSCStore({})}>
14
- <SetupGatewayWifi route={route} />
15
- </SCProvider>
16
- );
17
-
18
- jest.mock('react', () => {
19
- return { ...jest.requireActual('react'), memo: (x) => x };
20
- });
21
-
22
- const mockedNavigate = jest.fn();
23
- const mockedGoBack = jest.fn();
24
-
25
- jest.mock('@react-navigation/native', () => {
26
- return {
27
- ...jest.requireActual('@react-navigation/native'),
28
- useNavigation: () => ({
29
- navigate: mockedNavigate,
30
- goBack: mockedGoBack,
31
- }),
32
- useIsFocused: () => ({}),
33
- };
34
- });
35
-
36
- jest.mock('../../../iot/RemoteControl/Bluetooth', () => {
37
- const device = {
38
- name: '1234567',
39
- cancelConnection: jest.fn(),
40
- connect: async () => ({
41
- discoverAllServicesAndCharacteristics: async () => ({
42
- writeCharacteristicWithResponseForService: async () => ({}),
43
- monitorCharacteristicForService: async (x) => x,
44
- }),
45
- }),
46
- monitorCharacteristicForService: async (x) => x,
47
- };
48
- return {
49
- ...jest.requireActual('../../../iot/RemoteControl/Bluetooth'),
50
- getDeviceByName: (x) => device,
51
- };
52
- });
53
-
54
- describe('Test SetupGatewayWifi', () => {
55
- let tree;
56
- let route;
57
-
58
- afterEach(() => {
59
- mockedNavigate.mockClear();
60
- });
61
-
62
- beforeEach(() => {
63
- route = {
64
- params: {
65
- unit_id: 1,
66
- },
67
- };
68
- });
69
-
70
- const getText = (instance, id) => {
71
- return instance.find((el) => el.props.testID === id);
72
- };
73
- test('check displayLoadingConnect', async () => {
74
- await act(async () => {
75
- tree = await create(wrapComponent(route));
76
- });
77
- const instance = tree.root;
78
- const rightButton = getText(
79
- instance,
80
- TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON
81
- );
82
- await act(async () => {
83
- await rightButton.props.onPress();
84
- });
85
- const displayLoadingConnect = instance.findByType(DisplayChecking);
86
- expect(displayLoadingConnect.props.visible).toBeTruthy();
87
-
88
- const ButtonPopup = instance.find(
89
- (el) => el.props.testID === TESTID.SET_UP_GATEWAY_WIFI.BUTTON_ALERT
90
- );
91
-
92
- await act(() => {
93
- ButtonPopup.props.hideModal();
94
- });
95
- await act(() => {
96
- ButtonPopup.props.leftButtonClick();
97
- });
98
-
99
- expect(ButtonPopup).toBeDefined();
100
- });
101
-
102
- test('onChange TextInputPassword', async () => {
103
- await act(async () => {
104
- tree = await create(wrapComponent(route));
105
- });
106
-
107
- const instance = tree.root;
108
- const textInputPassword = instance.findAllByType(_TextInputPassword);
109
- await act(async () => {
110
- await textInputPassword[0].props.onChange();
111
- });
112
- expect(textInputPassword).toHaveLength(1);
113
-
114
- const textInput = instance.findAllByType(_TextInput);
115
- await act(async () => {
116
- await textInput[0].props.onChange();
117
- });
118
- expect(textInput).toHaveLength(1);
119
- });
120
- });
@@ -1,115 +0,0 @@
1
- import React from 'react';
2
- import { create, act } from 'react-test-renderer';
3
- import MockAdapter from 'axios-mock-adapter';
4
-
5
- import { SCProvider } from '../../../context';
6
- import { mockSCStore } from '../../../context/mockStore';
7
- import ScanChipQR from '..';
8
- import QRScan from '../components/QRScan';
9
- import Routes from '../../../utils/Route';
10
- import api from '../../../utils/Apis/axios';
11
- import { API } from '../../../configs';
12
-
13
- const wrapComponent = (route) => (
14
- <SCProvider initState={mockSCStore({})}>
15
- <ScanChipQR route={route} />
16
- </SCProvider>
17
- );
18
-
19
- const mockedNavigate = jest.fn();
20
- const mockedGoBack = jest.fn();
21
-
22
- const mock = new MockAdapter(api.axiosInstance);
23
-
24
- jest.mock('react', () => {
25
- return { ...jest.requireActual('react'), memo: (x) => x };
26
- });
27
-
28
- jest.mock('@react-navigation/native', () => {
29
- return {
30
- ...jest.requireActual('@react-navigation/native'),
31
- useIsFocused: jest.fn(),
32
- useNavigation: () => ({
33
- navigate: mockedNavigate,
34
- goBack: mockedGoBack,
35
- }),
36
- };
37
- });
38
-
39
- describe('test ScanChipQR', () => {
40
- let route;
41
-
42
- beforeEach(() => {
43
- route = {
44
- params: {
45
- station_id: 1,
46
- phoneNumber: '0909123456',
47
- chipName: 'Chip name',
48
- isNewFlow: true,
49
- },
50
- };
51
- });
52
-
53
- test('create ScanChipQR', async () => {
54
- let tree;
55
- await act(async () => {
56
- tree = await create(wrapComponent(route));
57
- });
58
- const instance = tree.root;
59
- const qrScan = instance.findAllByType(QRScan);
60
- expect(qrScan).toHaveLength(1);
61
- expect(qrScan[0].props.loading).toEqual(false);
62
- });
63
-
64
- test('onScan addDeviceNewFlow success', async () => {
65
- const new_chip = {
66
- id: 1,
67
- name: 'ABC',
68
- };
69
-
70
- mock.onPost(API.UNIT.CHIP_SCAN_GET_WIFI_INFO()).reply(200, new_chip);
71
-
72
- let tree;
73
- const body = { id: 1, imei: 'SENSOR-X341241', name: 'New Chip' };
74
- await act(async () => {
75
- tree = await create(wrapComponent(route));
76
- });
77
- const instance = tree.root;
78
- const qrScan = instance.findByType(QRScan);
79
- expect(qrScan.props.loading).toEqual(false);
80
- await act(async () => {
81
- qrScan.props.onScan(JSON.stringify(body));
82
- });
83
- expect(qrScan.props.loading).toEqual(true);
84
- expect(mockedNavigate).toHaveBeenCalledWith(Routes.AddDeviceStack, {
85
- params: {
86
- scan_sensor_data: { id: 1, imei: 'SENSOR-X341241', name: 'New Chip' },
87
- addType: 'AddDeviceNewFlow',
88
- devicePrefixName: 'SENSOR',
89
- unit_id: undefined,
90
- },
91
- screen: 'AddGatewaySelectGateway',
92
- });
93
- });
94
-
95
- test('onScan failed', async () => {
96
- const new_chip = {
97
- id: 1,
98
- name: 'ABC',
99
- };
100
- mock.onPost(API.UNIT.CHIP_SCAN_GET_WIFI_INFO()).reply(200, new_chip);
101
- let tree;
102
- const body = { id: 1, imei: 'IMEI_X', name: 'New Chip' };
103
- await act(async () => {
104
- tree = await create(wrapComponent(route));
105
- });
106
- const instance = tree.root;
107
- const qrScan = instance.findByType(QRScan);
108
- expect(qrScan.props.loading).toEqual(false);
109
- await act(async () => {
110
- qrScan.props.onScan(JSON.stringify(body));
111
- });
112
- expect(qrScan.props.loading).toEqual(true);
113
- expect(mockedGoBack).toHaveBeenCalled();
114
- });
115
- });
@@ -1,120 +0,0 @@
1
- import { useNavigation } from '@react-navigation/native';
2
- import API from '../../../configs/API';
3
- import { useCallback, useState } from 'react';
4
- import { axiosPost } from '../../../utils/Apis/axios';
5
- import Routes from '../../../utils/Route';
6
- import { ToastBottomHelper } from '../../../utils/Utils';
7
-
8
- const useChipScan = (route) => {
9
- const {
10
- unit_id,
11
- unit_name,
12
- imei,
13
- isNewFlow,
14
- phoneNumber,
15
- chipName,
16
- wifiName,
17
- wifiPass,
18
- station,
19
- } = route.params;
20
- const navigation = useNavigation();
21
- const [loading, setLoading] = useState(false);
22
-
23
- const onChipScan = useCallback(
24
- async (data) => {
25
- setLoading(true);
26
- const body = JSON.parse(data);
27
- if (isNewFlow) {
28
- const devicePrefixName = body?.imei.split('-')[0];
29
- switch (devicePrefixName) {
30
- case 'SENSOR':
31
- navigation.navigate(Routes.AddDeviceStack, {
32
- screen: Routes.AddGatewaySelectGateway,
33
- params: {
34
- scan_sensor_data: { ...body },
35
- addType: 'AddDeviceNewFlow',
36
- unit_id: unit_id,
37
- devicePrefixName,
38
- },
39
- });
40
- break;
41
- case 'ROBOT':
42
- case 'LITE':
43
- {
44
- const { success, data: new_chip } = await axiosPost(
45
- API.UNIT.CHIP_SCAN_GET_WIFI_INFO(),
46
- {
47
- imei: imei || body.imei,
48
- qr_code: body.imei,
49
- }
50
- );
51
- if (success) {
52
- navigation.navigate(Routes.ConnectWifiWarning, {
53
- wifi_ssid: new_chip.wifi_ssid,
54
- wifi_pass: new_chip.wifi_pass,
55
- chip_id: new_chip.id,
56
- unit_id: unit_id,
57
- unit_name: unit_name,
58
- devicePrefixName,
59
- body,
60
- });
61
- } else {
62
- ToastBottomHelper.error(
63
- 'Fail to fetch wifi info',
64
- devicePrefixName
65
- );
66
- navigation.goBack();
67
- }
68
- }
69
- break;
70
- default:
71
- ToastBottomHelper.error('Invalid QR prefix', devicePrefixName);
72
- navigation.goBack();
73
- break;
74
- }
75
- } else {
76
- const { success, data: new_chip } = await axiosPost(
77
- API.UNIT.CHIP_SCAN(unit_id),
78
- {
79
- imei: imei,
80
- qr_code: body.imei,
81
- phone: phoneNumber,
82
- name: chipName,
83
- station: station,
84
- wifi_ssid: wifiName,
85
- wifi_pass: wifiPass,
86
- }
87
- );
88
- if (success) {
89
- navigation.navigate(Routes.ConnectingGateway, {
90
- new_chip,
91
- ...route.params,
92
- });
93
- } else {
94
- navigation.goBack();
95
- }
96
- }
97
- },
98
- [
99
- chipName,
100
- imei,
101
- isNewFlow,
102
- navigation,
103
- phoneNumber,
104
- route.params,
105
- station,
106
- unit_id,
107
- unit_name,
108
- wifiName,
109
- wifiPass,
110
- ]
111
- );
112
-
113
- return {
114
- onChipScan,
115
- loading,
116
- setLoading,
117
- };
118
- };
119
-
120
- export { useChipScan };
@@ -1,29 +0,0 @@
1
- import React, { memo, useCallback } from 'react';
2
- import { View, StyleSheet } from 'react-native';
3
- import QRScan from './components/QRScan';
4
- import { useChipScan } from './hooks';
5
-
6
- const ScanChipQR = memo(({ route }) => {
7
- const { onChipScan, loading, setLoading } = useChipScan(route);
8
-
9
- const onScan = useCallback(
10
- (data) => {
11
- onChipScan(data);
12
- },
13
- [onChipScan]
14
- );
15
-
16
- return (
17
- <View style={styles.container}>
18
- <QRScan onScan={onScan} loading={loading} setLoading={setLoading} />
19
- </View>
20
- );
21
- });
22
-
23
- export default ScanChipQR;
24
-
25
- const styles = StyleSheet.create({
26
- container: {
27
- flex: 1,
28
- },
29
- });
@@ -1,111 +0,0 @@
1
- import React from 'react';
2
- import { create, act } from 'react-test-renderer';
3
- import MockAdapter from 'axios-mock-adapter';
4
-
5
- import { SCProvider } from '../../../context';
6
- import { mockSCStore } from '../../../context/mockStore';
7
- import ScanSensorQR from '..';
8
- import QRScan from '../../ScanChipQR/components/QRScan';
9
- import API from '../../../configs/API';
10
- import Routes from '../../../utils/Route';
11
- import api from '../../../utils/Apis/axios';
12
-
13
- const wrapComponent = (route) => (
14
- <SCProvider initState={mockSCStore({})}>
15
- <ScanSensorQR route={route} />
16
- </SCProvider>
17
- );
18
-
19
- const mock = new MockAdapter(api.axiosInstance);
20
-
21
- const mockedNavigate = jest.fn();
22
- const mockedGoBack = jest.fn();
23
-
24
- jest.mock('react', () => {
25
- return { ...jest.requireActual('react'), memo: (x) => x };
26
- });
27
-
28
- jest.mock('@react-navigation/native', () => {
29
- return {
30
- ...jest.requireActual('@react-navigation/native'),
31
- useIsFocused: jest.fn(),
32
- useNavigation: () => ({
33
- navigate: mockedNavigate,
34
- goBack: mockedGoBack,
35
- }),
36
- };
37
- });
38
-
39
- describe('test ScanSensorQR', () => {
40
- let route;
41
-
42
- beforeEach(() => {
43
- route = {
44
- params: {
45
- station_id: 1,
46
- unit_id: 1,
47
- unit_name: 'Unit name',
48
- },
49
- };
50
- });
51
-
52
- test('create ScanSensorQR', async () => {
53
- let tree;
54
- await act(async () => {
55
- tree = await create(wrapComponent(route));
56
- });
57
- const instance = tree.root;
58
- const qrScan = instance.findAllByType(QRScan);
59
- expect(qrScan).toHaveLength(1);
60
- expect(qrScan[0].props.loading).toEqual(false);
61
- });
62
-
63
- test('onScan success', async () => {
64
- const new_sensor = {
65
- id: 1,
66
- name: 'ABC',
67
- };
68
-
69
- mock.onPost(API.SUB_UNIT.SENSOR_SCAN(1)).reply(200, new_sensor);
70
-
71
- let tree;
72
- const body = { id: 1, imei: 'IMEI_X', name: 'New Chip' };
73
- await act(async () => {
74
- tree = await create(wrapComponent(route));
75
- });
76
- const instance = tree.root;
77
- const qrScan = instance.findByType(QRScan);
78
- expect(qrScan.props.loading).toEqual(false);
79
- await act(async () => {
80
- qrScan.props.onScan(JSON.stringify(body));
81
- });
82
- expect(qrScan.props.loading).toEqual(true);
83
- expect(mockedNavigate).toHaveBeenCalledWith(Routes.ConnectingDevices, {
84
- new_sensor,
85
- station_id: 1,
86
- unit_id: 1,
87
- unit_name: 'Unit name',
88
- });
89
- });
90
-
91
- test('onScan failed', async () => {
92
- const new_chip = {
93
- id: 1,
94
- name: 'ABC',
95
- };
96
- mock.onPost(API.SUB_UNIT.SENSOR_SCAN(1)).reply(200, new_chip);
97
- let tree;
98
- const body = { id: 1, imei: 'IMEI_X', name: 'New Chip' };
99
- await act(async () => {
100
- tree = await create(wrapComponent(route));
101
- });
102
- const instance = tree.root;
103
- const qrScan = instance.findByType(QRScan);
104
- expect(qrScan.props.loading).toEqual(false);
105
- await act(async () => {
106
- qrScan.props.onScan(JSON.stringify(body));
107
- });
108
- expect(qrScan.props.loading).toEqual(true);
109
- expect(mockedGoBack).not.toHaveBeenCalled();
110
- });
111
- });
@@ -1,40 +0,0 @@
1
- import { useCallback, useState } from 'react';
2
- import { useNavigation } from '@react-navigation/native';
3
- import { axiosPost } from '../../../utils/Apis/axios';
4
- import Routes from '../../../utils/Route';
5
- import { API } from '../../../configs';
6
-
7
- const useSensorScan = (station_id, unit_id, unit_name) => {
8
- const navigation = useNavigation();
9
- const [loading, setLoading] = useState(false);
10
-
11
- const onSensorScan = useCallback(
12
- async (data) => {
13
- setLoading(true);
14
- const body = JSON.parse(data);
15
- const { success, data: new_sensor } = await axiosPost(
16
- API.SUB_UNIT.SENSOR_SCAN(station_id),
17
- body
18
- );
19
- if (success) {
20
- navigation.navigate(Routes.ConnectingDevices, {
21
- new_sensor: new_sensor,
22
- station_id: station_id,
23
- unit_id: unit_id,
24
- unit_name: unit_name,
25
- });
26
- } else {
27
- navigation.goBack();
28
- }
29
- },
30
- [navigation, station_id, unit_id, unit_name]
31
- );
32
-
33
- return {
34
- onSensorScan,
35
- loading,
36
- setLoading,
37
- };
38
- };
39
-
40
- export { useSensorScan };
@@ -1,39 +0,0 @@
1
- import React, { memo, useCallback } from 'react';
2
- import { View, StyleSheet } from 'react-native';
3
- import QRScan from '../ScanChipQR/components/QRScan';
4
- import { useSensorScan } from './hooks';
5
-
6
- const ScanSensorQR = memo(({ route }) => {
7
- const { station_id, unit_id, unit_name } = route.params;
8
- const { onSensorScan, loading, setLoading } = useSensorScan(
9
- station_id,
10
- unit_id,
11
- unit_name
12
- );
13
-
14
- const onScan = useCallback(
15
- (data) => {
16
- onSensorScan(data);
17
- },
18
- [onSensorScan]
19
- );
20
-
21
- return (
22
- <View style={styles.container}>
23
- <QRScan
24
- style={styles.scanScreen}
25
- onScan={onScan}
26
- loading={loading}
27
- setLoading={setLoading}
28
- />
29
- </View>
30
- );
31
- });
32
-
33
- export default ScanSensorQR;
34
-
35
- const styles = StyleSheet.create({
36
- container: {
37
- flex: 1,
38
- },
39
- });