@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
package/README.md CHANGED
@@ -159,7 +159,7 @@ export const MyFunctionalComponent = () => {
159
159
  - sendRemoteCommand user needs to `have permission to control the device`, you pass in the `sensor and action` to it and it will run after calling render.
160
160
  - `sensor` is a device in your Unit and action is the `action` key of the device..
161
161
  - You can take out the sensor and action from your Unit when calling the `API.UNIT.UNIT_DETAIL(unitId)` it will return all devices in 1 unit.
162
- - Or get sensor from `API.SENSOR.DISPLAY(sensor.id)` returns all actions of 1 device.
162
+ - Or get sensor from `API.DEVICE.DISPLAY(sensor.id)` returns all actions of 1 device.
163
163
  - Refer YourProjectPath /node_modules/@eohjsc/react-native-smart-city/src/screens/Unit/Detail.js
164
164
 
165
165
  ## Sync file to EoH source
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eohjsc/react-native-smart-city",
3
3
  "title": "React Native Smart Home",
4
- "version": "0.2.99",
4
+ "version": "0.3.02",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -18,7 +18,7 @@
18
18
  "ios": "react-native run-ios",
19
19
  "start": "react-native start",
20
20
  "test": "yarn run lint && yarn run jest",
21
- "lint": "eslint . --ext js --ext ts --ext tsx",
21
+ "lint": "eslint . --ext js --ext ts --ext tsx --max-warnings 5",
22
22
  "lint-fix": "eslint . --fix",
23
23
  "type-check": "npx tsc",
24
24
  "pod": "cd ios && pod install",
@@ -74,6 +74,7 @@
74
74
  "@types/react": "^17.0.0",
75
75
  "@types/react-native": "^0.63.43",
76
76
  "@types/react-test-renderer": "^17.0.0",
77
+ "axios-mock-adapter": "^1.21.1",
77
78
  "babel-jest": "^26.6.3",
78
79
  "detox": "^18.3.1",
79
80
  "eslint": "7.14.0",
@@ -99,7 +100,7 @@
99
100
  "@ant-design/icons-react-native": "^2.2.1",
100
101
  "@ant-design/react-native": "^4.0.5",
101
102
  "@babel/helper-environment-visitor": "^7.16.7",
102
- "@eohjsc/highcharts": "^1.0.8",
103
+ "@eohjsc/highcharts": "^1.0.9",
103
104
  "@eohjsc/react-native-keyboard-aware-scroll-view": "^0.9.5",
104
105
  "@formatjs/intl-getcanonicallocales": "^1.4.5",
105
106
  "@formatjs/intl-numberformat": "^5.6.2",
@@ -124,6 +125,7 @@
124
125
  "@react-navigation/stack": "^5.7.0",
125
126
  "@sentry/react-native": "^1.7.1",
126
127
  "@testing-library/react-hooks": "^6.0.0",
128
+ "apisauce": "^2.1.5",
127
129
  "axios": "^0.19.2",
128
130
  "dotenv": "^8.2.0",
129
131
  "google-libphonenumber": "^3.2.10",
@@ -174,7 +176,7 @@
174
176
  "react-native-pager-view": "^5.4.1",
175
177
  "react-native-parallax-scroll-view": "^0.21.3",
176
178
  "react-native-parsed-text": "^0.0.22",
177
- "react-native-permissions": "^2.1.5",
179
+ "react-native-permissions": "3.0.3",
178
180
  "react-native-popover-view": "^4.0.3",
179
181
  "react-native-progress": "^5.0.0",
180
182
  "react-native-reanimated": "1.10.1",
@@ -22,6 +22,7 @@ Pod::Spec.new do |s|
22
22
  s.requires_arc = true
23
23
 
24
24
  s.dependency "React"
25
+ s.dependency "react-native-permissions"
25
26
  # ...
26
27
  # s.dependency "..."
27
28
  end
@@ -3,7 +3,7 @@ import { TouchableOpacity, View } from 'react-native';
3
3
  import { TESTID } from '../../configs/Constants';
4
4
  import { useSCContextSelector } from '../../context';
5
5
  import { watchMultiConfigs } from '../../iot/Monitor';
6
- import { sendRemoteCommand } from '../../iot/RemoteControl';
6
+ import { useRemoteControl } from '../../hooks/IoT';
7
7
  import { useConfigGlobalState } from '../../iot/states';
8
8
  import IconComponent from '../IconComponent';
9
9
 
@@ -13,6 +13,8 @@ const ItemQuickAction = memo(({ sensor, wrapperStyle, setStatus, unit }) => {
13
13
  // eslint-disable-next-line no-unused-vars
14
14
  const [configValues, _] = useConfigGlobalState('configValues');
15
15
 
16
+ const sendRemoteCommand = useRemoteControl();
17
+
16
18
  const revertActionUpdate = useCallback(
17
19
  (value, on_action, on_status, off_action, off_status) => {
18
20
  setIsSendingCommand(false);
@@ -81,7 +83,14 @@ const ItemQuickAction = memo(({ sensor, wrapperStyle, setStatus, unit }) => {
81
83
  statusCallback(action.id === sensor.quick_action.on_action.id);
82
84
  }, sensor.quick_action.interval);
83
85
  }
84
- }, [sensor, action, userId, revertActionUpdate, statusCallback]);
86
+ }, [
87
+ sensor,
88
+ action,
89
+ userId,
90
+ revertActionUpdate,
91
+ statusCallback,
92
+ sendRemoteCommand,
93
+ ]);
85
94
 
86
95
  if (!action) {
87
96
  return <View />;
@@ -5,7 +5,6 @@ import ItemQuickAction from '../ItemQuickAction';
5
5
  import { Colors } from '../../../configs';
6
6
  import { TESTID } from '../../../configs/Constants';
7
7
  import { factory } from 'factory-girl';
8
- import { sendRemoteCommand } from '../../../iot/RemoteControl';
9
8
 
10
9
  class Sensor {}
11
10
 
@@ -21,7 +20,13 @@ jest.mock('react', () => {
21
20
 
22
21
  useState.mockImplementation((init) => [init, mockSetState]);
23
22
 
24
- jest.mock('../../../iot/RemoteControl');
23
+ const mockSendRemoteControl = jest.fn();
24
+ jest.mock('../../../hooks/IoT', () => {
25
+ return {
26
+ ...jest.requireActual('../../../hooks/IoT'),
27
+ useRemoteControl: () => mockSendRemoteControl,
28
+ };
29
+ });
25
30
 
26
31
  jest.mock('../../../iot/states', () => ({
27
32
  useConfigGlobalState: () => [{}, null],
@@ -83,9 +88,9 @@ describe('Test ItemQuickAction', () => {
83
88
  };
84
89
 
85
90
  test('render with no action', async () => {
86
- const sensor = await factory.build('Sensor');
91
+ const newSensor = await factory.build('Sensor');
87
92
  act(() => {
88
- tree = create(<ItemQuickAction sensor={sensor} />);
93
+ tree = create(<ItemQuickAction sensor={newSensor} />);
89
94
  });
90
95
  const instance = tree.root;
91
96
  const buttonOnActionPress = instance.findAll(
@@ -121,7 +126,7 @@ describe('Test ItemQuickAction', () => {
121
126
  act(() => {
122
127
  buttonOnActionPress.props.onPress();
123
128
  });
124
- expect(sendRemoteCommand).toBeCalled();
129
+ expect(mockSendRemoteControl).toBeCalled();
125
130
  expect(mockSetState).toBeCalledTimes(1);
126
131
 
127
132
  jest.runAllTimers();
@@ -154,7 +159,7 @@ describe('Test ItemQuickAction', () => {
154
159
  act(() => {
155
160
  buttonOnActionPress.props.onPress();
156
161
  });
157
- expect(sendRemoteCommand).toBeCalled();
162
+ expect(mockSendRemoteControl).toBeCalled();
158
163
  expect(mockSetState).toBeCalledTimes(1);
159
164
 
160
165
  jest.runAllTimers();
@@ -17,6 +17,11 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
17
17
  close_action_data,
18
18
  action_off_data,
19
19
  action_on_data,
20
+ is_display_lock,
21
+ text1,
22
+ text2,
23
+ text3,
24
+ text_door_lock,
20
25
  } = configuration || {};
21
26
  const [lock, setLock] = useState(false);
22
27
 
@@ -52,21 +57,21 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
52
57
  {
53
58
  style: styles.buttonActionCurtain,
54
59
  icon: Images.buttonLeftCurtain,
55
- text: configuration.text1,
60
+ text: text1,
56
61
  onPress: onButtonOpenPress,
57
62
  testID: TESTID.BUTTON_TEMPLATE_1,
58
63
  },
59
64
  {
60
65
  style: styles.buttonActionCurtainCenter,
61
66
  icon: Images.buttonPauseCurtain,
62
- text: configuration.text2,
67
+ text: text2,
63
68
  onPress: onButtonStopPress,
64
69
  testID: TESTID.BUTTON_TEMPLATE_2,
65
70
  },
66
71
  {
67
72
  style: styles.buttonActionCurtain,
68
73
  icon: Images.buttonRightCurtain,
69
- text: configuration.text3,
74
+ text: text3,
70
75
  onPress: onButtonClosePress,
71
76
  testID: TESTID.BUTTON_TEMPLATE_3,
72
77
  },
@@ -96,7 +101,7 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
96
101
  style={styles.textLockDoor}
97
102
  testID={TESTID.TEXT_DOOR_LOOK_ON_OFF}
98
103
  >
99
- {configuration.text_door_lock}{' '}
104
+ {text_door_lock}{' '}
100
105
  </Text>
101
106
  </View>
102
107
  <Switch
@@ -115,7 +120,7 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
115
120
  <RenderThreeButtonActions />
116
121
  </View>
117
122
  <View style={styles.lockSwitch}>
118
- {configuration.is_display_lock &&
123
+ {is_display_lock &&
119
124
  itemLock(
120
125
  lock ? 'lock' : 'unlock',
121
126
  lock ? Colors.Primary : Colors.Gray6
@@ -7,6 +7,7 @@ import Text from '../Text';
7
7
  import { useConfigGlobalState } from '../../iot/states';
8
8
  import styles from './NumberUpDownActionTemplateStyle';
9
9
  import { watchMultiConfigs } from '../../iot/Monitor';
10
+ import { TESTID } from '../../configs/Constants';
10
11
 
11
12
  const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
12
13
  const { configuration, title } = actionGroup;
@@ -15,39 +16,39 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
15
16
  max_value,
16
17
  min_value,
17
18
  text_format,
18
- keep_track_config,
19
19
  config,
20
+ allow_config_store_value,
20
21
  } = configuration;
21
22
 
22
23
  // eslint-disable-next-line no-unused-vars
23
24
  const [configValues, setConfigValues] = useConfigGlobalState('configValues');
24
- const [value, setValue] = useState((config && configValues[config]) || 28);
25
+ const [value, setValue] = useState();
26
+ const valueDefault = 28;
25
27
 
26
28
  useEffect(() => {
27
- if (!keep_track_config) {
28
- return;
29
- }
30
29
  if (!config) {
30
+ setValue(valueDefault);
31
31
  return;
32
32
  }
33
33
 
34
34
  const configValue = configValues[config];
35
35
  if (configValue !== null && configValue !== undefined) {
36
36
  setValue(configValue);
37
+ } else {
38
+ setValue(valueDefault);
37
39
  }
38
- }, [configValues, config, keep_track_config]);
40
+ // eslint-disable-next-line react-hooks/exhaustive-deps
41
+ }, []);
39
42
 
40
43
  const doActionAndWatchConfig = useCallback(
41
44
  async (actionData, actionValue, actionName) => {
42
- await doAction(
43
- actionData,
44
- JSON.stringify({ temperature: actionValue }),
45
- actionName
46
- );
47
- if (!sensor?.is_managed_by_backend) {
48
- return;
45
+ const data = { temperature: actionValue };
46
+ if (allow_config_store_value && config) {
47
+ data.config_id = config;
48
+ data.value = actionValue;
49
49
  }
50
- if (!keep_track_config) {
50
+ await doAction(actionData, JSON.stringify(data), actionName);
51
+ if (!sensor?.is_managed_by_backend) {
51
52
  return;
52
53
  }
53
54
  if (!config) {
@@ -59,11 +60,11 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
59
60
  watchMultiConfigs([config]);
60
61
  },
61
62
  [
62
- config,
63
63
  doAction,
64
- keep_track_config,
65
- sensor.is_managed_by_backend,
64
+ sensor?.is_managed_by_backend,
66
65
  sensor.device_type,
66
+ allow_config_store_value,
67
+ config,
67
68
  ]
68
69
  );
69
70
 
@@ -103,13 +104,23 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
103
104
  )}
104
105
 
105
106
  <View style={styles.controlPannel}>
106
- <TouchableOpacity style={styles.downButton} onPress={doActionDown}>
107
+ <TouchableOpacity
108
+ style={styles.downButton}
109
+ onPress={doActionDown}
110
+ testID={TESTID.NUMBER_ACTION_DOWN}
111
+ >
107
112
  <IconOutline name="down" size={32} color={Colors.Primary} />
108
113
  </TouchableOpacity>
109
114
 
110
- <Text type="H2">{text_format.replace('{number}', value)}</Text>
115
+ <Text testID={'abcd'} type="H2">
116
+ {text_format.replace('{number}', value)}
117
+ </Text>
111
118
 
112
- <TouchableOpacity style={styles.upButton} onPress={doActionUp}>
119
+ <TouchableOpacity
120
+ style={styles.upButton}
121
+ onPress={doActionUp}
122
+ testID={TESTID.NUMBER_ACTION_UP}
123
+ >
113
124
  <IconOutline name="up" size={32} color={Colors.Primary} />
114
125
  </TouchableOpacity>
115
126
  </View>
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
+ import { Switch } from 'react-native';
3
4
 
4
5
  import AutoLock from '../index';
5
6
  import { mockSCStore } from '../../../../../context/mockStore';
@@ -38,6 +39,9 @@ describe('Test AutoLock', () => {
38
39
  });
39
40
 
40
41
  const instance = tree.root;
42
+ const switchs = instance.findByType(Switch);
43
+ await switchs.props.onValueChange();
44
+
41
45
  const { buttonEnable, buttonInstant, buttonRelockTiming } =
42
46
  getElement(instance);
43
47
 
@@ -19,7 +19,7 @@ const ButtonWrapper = ({ item, textHeadline }) => {
19
19
  };
20
20
 
21
21
  const ItemPasscode = memo(({ route }) => {
22
- const { item } = route.params;
22
+ const { item = {} } = route.params || {};
23
23
 
24
24
  return (
25
25
  <SafeAreaView style={styles.container}>
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { TouchableOpacity } from 'react-native';
3
+ import { act, create } from 'react-test-renderer';
4
+ import { SCProvider } from '../../../../../context';
5
+ import { mockSCStore } from '../../../../../context/mockStore';
6
+ import ItemPasscode from '../ItemPasscode';
7
+
8
+ const wrapComponent = (route = {}) => (
9
+ <SCProvider initState={mockSCStore({})}>
10
+ <ItemPasscode route={route} />
11
+ </SCProvider>
12
+ );
13
+
14
+ describe('Test ItemPasscode', () => {
15
+ let tree;
16
+ test('test render without params', async () => {
17
+ await act(async () => {
18
+ tree = await create(wrapComponent());
19
+ });
20
+ const instance = tree.root;
21
+ const TouchableOpacities = instance.findAllByType(TouchableOpacity);
22
+ expect(TouchableOpacities).toHaveLength(2);
23
+ });
24
+ });
@@ -40,6 +40,7 @@ describe('Test SetupGeneratePasscode', () => {
40
40
  const changeDuration = instance.findAll(
41
41
  (item) => item.props.testID === TESTID.GENERATE_PASSCODE_SET_DURATION
42
42
  );
43
+
43
44
  return {
44
45
  changeName,
45
46
  changeTime,
@@ -58,5 +59,18 @@ describe('Test SetupGeneratePasscode', () => {
58
59
  expect(changeName[0]).toBeDefined();
59
60
  expect(changeTime[0]).toBeDefined();
60
61
  expect(changeDuration[0]).toBeDefined();
62
+
63
+ await changeDuration[0].props.onPressSetMinute();
64
+ await changeDuration[0].props.onPressSelectCircle();
65
+ await changeTime[0].props.onPressSetTime();
66
+
67
+ const wheelDateTimePicker = instance.findAll(
68
+ (item) =>
69
+ item.props.testID ===
70
+ `${TESTID.WHEEL_DATE_TIME_PICKER_BUTTON}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
71
+ );
72
+ await wheelDateTimePicker[5].props.onClick();
73
+ await wheelDateTimePicker[11].props.onClick();
74
+ await wheelDateTimePicker[17].props.onClick();
61
75
  });
62
76
  });
@@ -92,7 +92,7 @@ const OptionsDropdownActionTemplate = ({ actionGroup, doAction, sensor }) => {
92
92
  return t('not_available');
93
93
  }
94
94
  return selectedOption.text;
95
- }, [configuration.config, selectedOption.text, t]);
95
+ }, [configuration?.config, selectedOption?.text, t]);
96
96
 
97
97
  const iconSvg = useMemo(() => {
98
98
  switch (icon) {
@@ -1,5 +1,5 @@
1
1
  import React, { memo, useCallback } from 'react';
2
- import { View, ScrollView, Alert } from 'react-native';
2
+ import { View, ScrollView } from 'react-native';
3
3
 
4
4
  import styles from './SmartTiviActionTemplateStyles';
5
5
  import Text from '../../Text';
@@ -22,6 +22,7 @@ import {
22
22
  Youtube,
23
23
  Netflix,
24
24
  } from './component/Icon';
25
+ import { notImplemented } from '../../../utils/Utils';
25
26
 
26
27
  const SmartTiviActionTemplate = memo(
27
28
  ({ actionGroup, doAction, scrollEnabled = true }) => {
@@ -68,7 +69,7 @@ const SmartTiviActionTemplate = memo(
68
69
  case SMART_TIVI_BUTTON.HOME_BUTTON:
69
70
  case SMART_TIVI_BUTTON.BACK_BUTTON:
70
71
  case SMART_TIVI_BUTTON.CHANNEL_BUTTON:
71
- return Alert.alert(t('feature_under_development'));
72
+ return notImplemented(t);
72
73
  default:
73
74
  return <></>;
74
75
  }
@@ -105,15 +105,19 @@ const GridItem = ({ item, index, length, doAction, sensor, title }) => {
105
105
  );
106
106
  };
107
107
 
108
- const StatesGridActionTemplate = ({ actionGroup, doAction, sensor }) => {
109
- const { configuration, title } = actionGroup;
108
+ const StatesGridActionTemplate = ({
109
+ actionGroup = {},
110
+ doAction,
111
+ sensor = {},
112
+ }) => {
113
+ const { configuration = {}, title } = actionGroup;
110
114
 
111
115
  // eslint-disable-next-line no-unused-vars
112
116
  const [configValues, setConfigValues] = useConfigGlobalState('configValues');
113
117
 
114
118
  const options = useMemo(() => {
115
- return configuration.options.map((option) => {
116
- if (configValues[option.config] === option.is_on_value) {
119
+ return (configuration?.options || []).map((option) => {
120
+ if (configValues[option?.config] === option?.is_on_value) {
117
121
  return {
118
122
  ...option,
119
123
  active: true,
@@ -14,9 +14,9 @@ import { Colors } from '../../configs';
14
14
  import { useConfigGlobalState } from '../../iot/states';
15
15
  import BottomScrollPicker from '../BottomScrollPicker';
16
16
 
17
- const TimerActionTemplate = ({ actionGroup, doAction, sensor }) => {
17
+ const TimerActionTemplate = ({ actionGroup = {}, doAction, sensor = {} }) => {
18
18
  const t = useTranslations();
19
- const { configuration, title } = actionGroup;
19
+ const { configuration = {}, title } = actionGroup;
20
20
  const [showTime, setShowTime] = useState(false);
21
21
  const [showHour, setShowHour] = useState(false);
22
22
 
@@ -14,7 +14,6 @@ const TwoButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
14
14
  const { button1, button2 } = configuration;
15
15
  const [isOn, setIsOn] = useState(true);
16
16
  const [isStart, setIsStart] = useState(true);
17
- // eslint-disable-next-line no-unused-vars
18
17
  const [configValues] = useConfigGlobalState('configValues');
19
18
  const isLight = false;
20
19
 
@@ -1,20 +1,37 @@
1
1
  import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
- import { TouchableOpacity } from 'react-native';
3
+ import { TouchableOpacity, Switch } from 'react-native';
4
4
 
5
5
  import CurtainButtonTemplate from '../CurtainButtonTemplate';
6
6
  import { SCProvider } from '../../../context';
7
7
  import { mockSCStore } from '../../../context/mockStore';
8
8
 
9
- const wrapComponent = (actionGroup) => (
9
+ const mockDoAction = jest.fn();
10
+ const mockActionOffData = jest.fn();
11
+ const mockActionOnData = jest.fn();
12
+ const mockCloseActionData = jest.fn();
13
+
14
+ const wrapComponent = (actionGroup = {}, sensor = {}) => (
10
15
  <SCProvider initState={mockSCStore({})}>
11
- <CurtainButtonTemplate actionGroup={actionGroup} doAction={jest.fn()} />
16
+ <CurtainButtonTemplate
17
+ actionGroup={actionGroup}
18
+ doAction={mockDoAction}
19
+ sensor={sensor}
20
+ />
12
21
  </SCProvider>
13
22
  );
14
23
 
15
24
  describe('Test CurtainButtonTemplate', () => {
25
+ const sensor = {
26
+ name: 'test',
27
+ };
16
28
  const actionGroup = {
17
29
  configuration: {
30
+ text_open: 'open',
31
+ is_display_lock: true,
32
+ action_off_data: mockActionOffData,
33
+ action_on_data: mockActionOnData,
34
+ close_action_data: mockCloseActionData,
18
35
  action1: '2b949045-8e03-4c07-a855-7794ade2e69c',
19
36
  action1_data: {
20
37
  color: '#00979D',
@@ -61,12 +78,44 @@ describe('Test CurtainButtonTemplate', () => {
61
78
 
62
79
  let wrapper;
63
80
 
81
+ test('render without params', async () => {
82
+ await act(() => {
83
+ wrapper = renderer.create(wrapComponent());
84
+ });
85
+ const instance = wrapper.root;
86
+ const touchableOpacities = instance.findAllByType(TouchableOpacity);
87
+ expect(touchableOpacities.length).toEqual(3);
88
+ });
89
+
64
90
  test('render CurtainButtonTemplate', async () => {
65
91
  await act(() => {
66
- wrapper = renderer.create(wrapComponent(actionGroup));
92
+ wrapper = renderer.create(wrapComponent(actionGroup, sensor));
67
93
  });
68
94
  const instance = wrapper.root;
69
95
  const touchableOpacities = instance.findAllByType(TouchableOpacity);
70
96
  expect(touchableOpacities.length).toEqual(3);
97
+ await touchableOpacities[0].props.onPress();
98
+ await touchableOpacities[1].props.onPress();
99
+ await touchableOpacities[2].props.onPress();
100
+ expect(mockDoAction).toBeCalledWith(
101
+ mockCloseActionData,
102
+ null,
103
+ sensor?.name + ' undefined'
104
+ );
105
+
106
+ const Switchs = instance.findAllByType(Switch);
107
+ expect(Switchs).toHaveLength(1);
108
+ await Switchs[0].props.onValueChange();
109
+ expect(mockDoAction).toBeCalledWith(
110
+ mockActionOnData,
111
+ null,
112
+ `${sensor.name} lock`
113
+ );
114
+ await Switchs[0].props.onValueChange();
115
+ expect(mockDoAction).toBeCalledWith(
116
+ mockActionOffData,
117
+ null,
118
+ `${sensor.name} unlock`
119
+ );
71
120
  });
72
121
  });