@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
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { TouchableOpacity } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
4
  import Text from '../../../commons/Text';
5
+ import { TESTID } from '../../../configs/Constants';
5
6
  import { watchMultiConfigs } from '../../../iot/Monitor';
6
7
  import NumberUpDownActionTemplate from '../NumberUpDownActionTemplate';
7
8
 
@@ -30,7 +31,7 @@ describe('Test NumberUpDownActionTemplate', () => {
30
31
  watchMultiConfigs.mockClear();
31
32
  actionGroup = {
32
33
  configuration: {
33
- keep_track_config: false,
34
+ allow_config_store_value: false,
34
35
  config: 5,
35
36
  action_data,
36
37
  min_value: 16,
@@ -57,28 +58,10 @@ describe('Test NumberUpDownActionTemplate', () => {
57
58
 
58
59
  const touchs = instance.findAllByType(TouchableOpacity);
59
60
  expect(touchs).toHaveLength(2);
60
- });
61
-
62
- test('do action call watchConfigs', async () => {
63
- actionGroup.configuration.keep_track_config = true;
64
- const mockDoAction = jest.fn();
65
- await act(async () => {
66
- wrapper = await create(
67
- <NumberUpDownActionTemplate
68
- actionGroup={actionGroup}
69
- doAction={mockDoAction}
70
- sensor={{ is_managed_by_backend: true }}
71
- />
72
- );
73
- });
74
- const instance = wrapper.root;
75
- const touchs = instance.findAllByType(TouchableOpacity);
76
- expect(touchs).toHaveLength(2);
77
61
 
78
62
  await act(async () => {
79
63
  await touchs[0].props.onPress();
80
64
  });
81
-
82
65
  expect(watchMultiConfigs).toBeCalled();
83
66
  });
84
67
 
@@ -104,8 +87,9 @@ describe('Test NumberUpDownActionTemplate', () => {
104
87
  expect(watchMultiConfigs).not.toBeCalled();
105
88
  });
106
89
 
107
- test('do action not call watchConfigs cause keep track config false', async () => {
90
+ test('do action watchConfigs cause allow_config_store_value true', async () => {
108
91
  const mockDoAction = jest.fn();
92
+ actionGroup.configuration.allow_config_store_value = true;
109
93
  await act(async () => {
110
94
  wrapper = await create(
111
95
  <NumberUpDownActionTemplate
@@ -123,11 +107,11 @@ describe('Test NumberUpDownActionTemplate', () => {
123
107
  await touchs[0].props.onPress();
124
108
  });
125
109
 
126
- expect(watchMultiConfigs).not.toBeCalled();
110
+ expect(watchMultiConfigs).toBeCalled();
127
111
  });
128
112
 
129
113
  test('action down without config', async () => {
130
- actionGroup.configuration.keep_track_config = true;
114
+ actionGroup.configuration.allow_config_store_value = true;
131
115
  actionGroup.configuration.config = undefined;
132
116
  const mockDoAction = jest.fn();
133
117
  await act(async () => {
@@ -150,8 +134,10 @@ describe('Test NumberUpDownActionTemplate', () => {
150
134
  expect(watchMultiConfigs).not.toBeCalled();
151
135
  });
152
136
 
153
- test('action down without keep track config', async () => {
137
+ test('action down allow_config_store_value true', async () => {
154
138
  const mockDoAction = jest.fn();
139
+ actionGroup.configuration.allow_config_store_value = true;
140
+ actionGroup.configuration.config = null;
155
141
  await act(async () => {
156
142
  wrapper = await create(
157
143
  <NumberUpDownActionTemplate
@@ -162,19 +148,23 @@ describe('Test NumberUpDownActionTemplate', () => {
162
148
  );
163
149
  });
164
150
  const instance = wrapper.root;
165
- const touchs = instance.findAllByType(TouchableOpacity);
166
- expect(touchs).toHaveLength(2);
167
-
151
+ const touchs = instance.find(
152
+ (el) =>
153
+ el.props.testID === TESTID.NUMBER_ACTION_DOWN &&
154
+ el.type === TouchableOpacity
155
+ );
168
156
  await act(async () => {
169
- await touchs[0].props.onPress();
157
+ await touchs.props.onPress();
170
158
  });
171
159
 
172
160
  const text = instance.findByType(Text);
173
- expect(text.props.children).toEqual('24 *C');
161
+ expect(text.props.children).toEqual('27 *C');
174
162
  });
175
163
 
176
- test('action up without keep track config', async () => {
164
+ test('action up allow_config_store_value true', async () => {
177
165
  const mockDoAction = jest.fn();
166
+ actionGroup.configuration.allow_config_store_value = true;
167
+ actionGroup.configuration.config = null;
178
168
  await act(async () => {
179
169
  wrapper = await create(
180
170
  <NumberUpDownActionTemplate
@@ -185,19 +175,21 @@ describe('Test NumberUpDownActionTemplate', () => {
185
175
  );
186
176
  });
187
177
  const instance = wrapper.root;
188
- const touchs = instance.findAllByType(TouchableOpacity);
189
- expect(touchs).toHaveLength(2);
190
-
178
+ const touchs = instance.find(
179
+ (el) =>
180
+ el.props.testID === TESTID.NUMBER_ACTION_UP &&
181
+ el.type === TouchableOpacity
182
+ );
191
183
  await act(async () => {
192
- await touchs[1].props.onPress();
184
+ await touchs.props.onPress();
193
185
  });
194
-
195
- const text = instance.findByType(Text);
196
- expect(text.props.children).toEqual('26 *C');
186
+ const text = instance.find(
187
+ (el) => el.props.testID === 'abcd' && el.type === Text
188
+ );
189
+ expect(text.props.children).toEqual('29 *C');
197
190
  });
198
191
 
199
- test('action down with keep track config', async () => {
200
- actionGroup.configuration.keep_track_config = true;
192
+ test('action down with allow_config_store_value false', async () => {
201
193
  const mockDoAction = jest.fn();
202
194
  await act(async () => {
203
195
  wrapper = await create(
@@ -209,19 +201,21 @@ describe('Test NumberUpDownActionTemplate', () => {
209
201
  );
210
202
  });
211
203
  const instance = wrapper.root;
212
- const touchs = instance.findAllByType(TouchableOpacity);
213
- expect(touchs).toHaveLength(2);
204
+ const touchs = instance.find(
205
+ (el) =>
206
+ el.props.testID === TESTID.NUMBER_ACTION_DOWN &&
207
+ el.type === TouchableOpacity
208
+ );
214
209
 
215
210
  await act(async () => {
216
- await touchs[0].props.onPress();
211
+ await touchs.props.onPress();
217
212
  });
218
213
 
219
214
  const text = instance.findByType(Text);
220
- expect(text.props.children).toEqual('25 *C'); // TODO should 24, configValues make changes again
215
+ expect(text.props.children).toEqual('24 *C'); // TODO should 24, configValues make changes again
221
216
  });
222
217
 
223
- test('action up with keep track config', async () => {
224
- actionGroup.configuration.keep_track_config = true;
218
+ test('action up with allow_config_store_value false', async () => {
225
219
  const mockDoAction = jest.fn();
226
220
  await act(async () => {
227
221
  wrapper = await create(
@@ -233,15 +227,18 @@ describe('Test NumberUpDownActionTemplate', () => {
233
227
  );
234
228
  });
235
229
  const instance = wrapper.root;
236
- const touchs = instance.findAllByType(TouchableOpacity);
237
- expect(touchs).toHaveLength(2);
230
+ const touchs = instance.find(
231
+ (el) =>
232
+ el.props.testID === TESTID.NUMBER_ACTION_UP &&
233
+ el.type === TouchableOpacity
234
+ );
238
235
 
239
236
  await act(async () => {
240
- await touchs[1].props.onPress();
237
+ await touchs.props.onPress();
241
238
  });
242
239
 
243
240
  const text = instance.findByType(Text);
244
- expect(text.props.children).toEqual('25 *C'); // TODO should 26, configValues make changes again
241
+ expect(text.props.children).toEqual('26 *C'); // TODO should 26, configValues make changes again
245
242
  });
246
243
 
247
244
  test('action down limit ', async () => {
@@ -0,0 +1,77 @@
1
+ import React from 'react';
2
+ import { TouchableOpacity } from 'react-native';
3
+ import { act, create } from 'react-test-renderer';
4
+ import Text from '../../Text';
5
+ import StatesGridActionTemplate from '../StatesGridActionTemplate';
6
+
7
+ const mockDoAction = jest.fn();
8
+ const mockActionData = jest.fn();
9
+
10
+ describe('Test StatesGridActionTemplate', () => {
11
+ let tree;
12
+ const actionGroup = {
13
+ configuration: {
14
+ options: [
15
+ {
16
+ config: true,
17
+ active: false,
18
+ text: 'item 1',
19
+ icon_kit_data: 'icon_kit_data',
20
+ icon: '123',
21
+ icon_outlined: 'icon_outlined',
22
+ action_data: mockActionData,
23
+ },
24
+ {
25
+ config: false,
26
+ active: true,
27
+ text: 'item 2',
28
+ icon_kit_data: 'icon_kit_data',
29
+ icon: 'icon',
30
+ icon_outlined: 'icon_outlined',
31
+ action_data: mockActionData,
32
+ },
33
+ ],
34
+ is_on_value: true,
35
+ },
36
+ title: 'Title',
37
+ };
38
+ const sensor = {
39
+ is_managed_by_backend: true,
40
+ device_type: '',
41
+ name: 'Sensor name',
42
+ };
43
+
44
+ test('test render without params', async () => {
45
+ await act(async () => {
46
+ tree = await create(<StatesGridActionTemplate />);
47
+ });
48
+ const instance = tree.root;
49
+ const Texts = instance.findAllByType(Text);
50
+ expect(Texts).toHaveLength(1);
51
+ });
52
+
53
+ test('test render with params', async () => {
54
+ await act(async () => {
55
+ tree = await create(
56
+ <StatesGridActionTemplate
57
+ doAction={mockDoAction}
58
+ sensor={sensor}
59
+ actionGroup={actionGroup}
60
+ />
61
+ );
62
+ });
63
+ const instance = tree.root;
64
+ const Texts = instance.findAllByType(Text);
65
+ expect(Texts).toHaveLength(3);
66
+ const TouchableOpacities = instance.findAllByType(TouchableOpacity);
67
+ expect(TouchableOpacities).toHaveLength(2);
68
+ await TouchableOpacities[0].props.onPress();
69
+ expect(mockDoAction).toBeCalledWith(
70
+ mockActionData,
71
+ null,
72
+ `${sensor.name} ${actionGroup.title.toLowerCase()} ${
73
+ actionGroup.configuration.options[0].text
74
+ }`
75
+ );
76
+ });
77
+ });
@@ -1,8 +1,10 @@
1
1
  import React from 'react';
2
- import { Switch } from 'react-native';
2
+ import { Switch, TouchableOpacity } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
4
  import TimerActionTemplate from '../TimerActionTemplate';
5
5
  import DateTimePickerModal from 'react-native-modal-datetime-picker';
6
+ import ScrollPicker from 'react-native-wheel-scrollview-picker';
7
+
6
8
  import moment from 'moment';
7
9
  import Text from '../../Text';
8
10
  import { watchMultiConfigs } from '../../../iot/Monitor';
@@ -15,12 +17,14 @@ jest.mock('../../../iot/states', () => ({
15
17
  useConfigGlobalState: () => [{ 5: 18, 6: 30 }, null],
16
18
  }));
17
19
 
18
- const wrapComponent = (actionGroup, mockDoAction, is_managed_by_backend) => (
20
+ const mockDoAction = jest.fn();
21
+
22
+ const wrapComponent = (actionGroup, sensor) => (
19
23
  <SCProvider initState={mockSCStore({})}>
20
24
  <TimerActionTemplate
21
25
  actionGroup={actionGroup}
22
26
  doAction={mockDoAction}
23
- sensor={{ is_managed_by_backend }}
27
+ sensor={sensor}
24
28
  />
25
29
  </SCProvider>
26
30
  );
@@ -39,6 +43,7 @@ describe('Test TimerActionTemplate success with config value', () => {
39
43
 
40
44
  let actionGroup;
41
45
  let wrapper;
46
+ let sensor;
42
47
 
43
48
  beforeEach(() => {
44
49
  watchMultiConfigs.mockClear();
@@ -50,12 +55,24 @@ describe('Test TimerActionTemplate success with config value', () => {
50
55
  config_minute: 6,
51
56
  },
52
57
  };
58
+ sensor = {
59
+ is_managed_by_backend: true,
60
+ device_type: '',
61
+ };
62
+ });
63
+
64
+ test('render without params', async () => {
65
+ await act(async () => {
66
+ wrapper = await create(wrapComponent());
67
+ });
68
+ const instance = wrapper.root;
69
+ const texts = instance.findAllByType(Text);
70
+ expect(texts).toHaveLength(6);
53
71
  });
54
72
 
55
73
  test('render template', async () => {
56
- const mockDoAction = jest.fn();
57
74
  await act(async () => {
58
- wrapper = await create(wrapComponent(actionGroup, mockDoAction, true));
75
+ wrapper = await create(wrapComponent(actionGroup, sensor));
59
76
  });
60
77
  const instance = wrapper.root;
61
78
 
@@ -66,11 +83,46 @@ describe('Test TimerActionTemplate success with config value', () => {
66
83
 
67
84
  const switchButton = instance.findByType(Switch);
68
85
  expect(switchButton.props.value).toBeTruthy();
86
+ await switchButton.props.onValueChange();
87
+ expect(mockDoAction).toBeCalled();
88
+
89
+ const bottomScrollPicker = instance.findByType(ScrollPicker);
90
+ expect(bottomScrollPicker).toBeDefined();
91
+ const TouchableOpacities = instance.findAllByType(TouchableOpacity);
92
+ await TouchableOpacities[0].props.onPress();
69
93
 
70
94
  const dateTimePicker = instance.findByType(DateTimePickerModal);
71
- expect(dateTimePicker.props.isVisible).toBeFalsy();
95
+ expect(dateTimePicker.props.isVisible).toBeTruthy();
72
96
  expect(dateTimePicker.props.date).toEqual(
73
97
  moment('18:30', 'HH:mm').valueOf()
74
98
  );
75
99
  });
100
+
101
+ test('render template with config_hour', async () => {
102
+ actionGroup = {
103
+ ...actionGroup,
104
+ configuration: {
105
+ ...actionGroup.configuration,
106
+ config_hour: 5,
107
+ config_minute: null,
108
+ },
109
+ };
110
+ await act(async () => {
111
+ wrapper = await create(wrapComponent(actionGroup, sensor));
112
+ });
113
+ const instance = wrapper.root;
114
+
115
+ const bottomScrollPicker = instance.findByType(ScrollPicker);
116
+ expect(bottomScrollPicker).toBeDefined();
117
+
118
+ const dateTimePicker = instance.findByType(DateTimePickerModal);
119
+ expect(dateTimePicker.props.isVisible).toBeFalsy();
120
+ await dateTimePicker.props.onConfirm();
121
+
122
+ const TouchableOpacities = instance.findAllByType(TouchableOpacity);
123
+ expect(TouchableOpacities).toHaveLength(3);
124
+ await TouchableOpacities[0].props.onPress();
125
+ await TouchableOpacities[2].props.onPress(3);
126
+ expect(mockDoAction).toBeCalled();
127
+ });
76
128
  });
@@ -1,6 +1,7 @@
1
1
  import React, { useState } from 'react';
2
2
  import { TouchableOpacity } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
+ import { DEVICE_TYPE } from '../../../configs/Constants';
4
5
  import TwoButtonTemplate from '../TwoButtonTemplate';
5
6
 
6
7
  jest.mock('react', () => ({
@@ -31,6 +32,10 @@ describe('Test TwoButtonTemplate', () => {
31
32
  key: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
32
33
  };
33
34
 
35
+ const sensor = {
36
+ device_type: DEVICE_TYPE.LG_THINQ,
37
+ is_managed_by_backend: true,
38
+ };
34
39
  const actionGroup = {
35
40
  configuration: {
36
41
  button1: {
@@ -41,6 +46,9 @@ describe('Test TwoButtonTemplate', () => {
41
46
  icon_on: 'poweroff',
42
47
  text_on: 'ON',
43
48
  config: 621,
49
+ is_on_value: [true],
50
+ action_on_data,
51
+ action_off_data,
44
52
  },
45
53
  button2: {
46
54
  action_off: 'f49e1577-493d-4bae-a9ab-3b0f96a4ec52',
@@ -50,6 +58,9 @@ describe('Test TwoButtonTemplate', () => {
50
58
  icon_on: 'caret-right',
51
59
  text_on: 'START',
52
60
  config: 621,
61
+ is_on_value: [true],
62
+ action_on_data,
63
+ action_off_data,
53
64
  },
54
65
  },
55
66
  };
@@ -102,7 +113,44 @@ describe('Test TwoButtonTemplate', () => {
102
113
  const mockDoAction = jest.fn();
103
114
  await act(() => {
104
115
  wrapper = create(
105
- <TwoButtonTemplate actionGroup={actionGroup} doAction={mockDoAction} />
116
+ <TwoButtonTemplate
117
+ actionGroup={actionGroup}
118
+ doAction={mockDoAction}
119
+ sensor={sensor}
120
+ />
121
+ );
122
+ });
123
+ const instance = wrapper.root;
124
+ const touchableOpacities = instance.findAllByType(TouchableOpacity);
125
+ expect(touchableOpacities.length).toEqual(2);
126
+ await touchableOpacities[0].props.onPress();
127
+ await touchableOpacities[1].props.onPress();
128
+ expect(mockDoAction).toBeCalled();
129
+ });
130
+
131
+ test('render TouchableOpacity TwoButtonTemplate without is_on_value', async () => {
132
+ const mockDoAction = jest.fn();
133
+ let new_actionGroup = {
134
+ ...actionGroup,
135
+ configuration: {
136
+ ...actionGroup.configuration,
137
+ button1: {
138
+ ...actionGroup.configuration.button1,
139
+ is_on_value: null,
140
+ },
141
+ button2: {
142
+ ...actionGroup.configuration.button2,
143
+ is_on_value: null,
144
+ },
145
+ },
146
+ };
147
+ await act(() => {
148
+ wrapper = create(
149
+ <TwoButtonTemplate
150
+ actionGroup={new_actionGroup}
151
+ doAction={mockDoAction}
152
+ sensor={sensor}
153
+ />
106
154
  );
107
155
  });
108
156
  const instance = wrapper.root;
@@ -356,8 +356,8 @@ describe('Test ActionGroup', () => {
356
356
  text_format: '{number} *C',
357
357
  },
358
358
  };
359
- await act(() => {
360
- wrapper = renderer.create(
359
+ await act(async () => {
360
+ wrapper = await renderer.create(
361
361
  wrapComponent(actionGroup, mockDoAction, sensor)
362
362
  );
363
363
  });
@@ -464,4 +464,139 @@ describe('Test ActionGroup', () => {
464
464
  moment('2021-09-09T10:00:00.000Z').valueOf()
465
465
  );
466
466
  });
467
+
468
+ test('render OnOffSmartLock', async () => {
469
+ Date.now = jest.fn(() => new Date('2021-09-09T10:00:00.000Z'));
470
+ const actionGroup = {
471
+ template: 'OnOffSmartLockActionTemplate',
472
+ title: 'Timer',
473
+ configuration: {
474
+ action_off_data: jest.fn(),
475
+ action_on_data: jest.fn(),
476
+ },
477
+ };
478
+ const mockDoAction = jest.fn();
479
+ await act(() => {
480
+ wrapper = renderer.create(
481
+ wrapComponent(actionGroup, mockDoAction, sensor)
482
+ );
483
+ });
484
+ const instance = wrapper.root;
485
+ const texts = instance.findAllByType(Text);
486
+ expect(texts).toHaveLength(5);
487
+ });
488
+
489
+ test('render OptionsDropdownActionTemplate', async () => {
490
+ Date.now = jest.fn(() => new Date('2021-09-09T10:00:00.000Z'));
491
+ const actionGroup = {
492
+ template: 'OptionsDropdownActionTemplate',
493
+ title: 'Timer',
494
+ configuration: {
495
+ action_data: jest.fn(),
496
+ options: [],
497
+ icon_kit_data: 'icon_kit_data',
498
+ icon: '',
499
+ icon_outlined: 'icon_outlined',
500
+ },
501
+ };
502
+ const mockDoAction = jest.fn();
503
+ await act(() => {
504
+ wrapper = renderer.create(
505
+ wrapComponent(actionGroup, mockDoAction, sensor)
506
+ );
507
+ });
508
+ const instance = wrapper.root;
509
+ const texts = instance.findAllByType(Text);
510
+ expect(texts).toHaveLength(7);
511
+ });
512
+
513
+ test('render CurtainButtonTemplate', async () => {
514
+ Date.now = jest.fn(() => new Date('2021-09-09T10:00:00.000Z'));
515
+ const actionGroup = {
516
+ template: 'curtain_action_template',
517
+ title: 'Timer',
518
+ configuration: {},
519
+ };
520
+ const mockDoAction = jest.fn();
521
+ await act(() => {
522
+ wrapper = renderer.create(
523
+ wrapComponent(actionGroup, mockDoAction, sensor)
524
+ );
525
+ });
526
+ const instance = wrapper.root;
527
+ const texts = instance.findAllByType(Text);
528
+ expect(texts).toHaveLength(2);
529
+ });
530
+
531
+ test('render SmartTiviActionTemplate', async () => {
532
+ Date.now = jest.fn(() => new Date('2021-09-09T10:00:00.000Z'));
533
+ const actionGroup = {
534
+ template: 'SmartTiviActionTemplate',
535
+ title: 'Timer',
536
+ configuration: {},
537
+ };
538
+ const mockDoAction = jest.fn();
539
+ await act(() => {
540
+ wrapper = renderer.create(
541
+ wrapComponent(actionGroup, mockDoAction, sensor)
542
+ );
543
+ });
544
+ const instance = wrapper.root;
545
+ const texts = instance.findAllByType(Text);
546
+ expect(texts).toHaveLength(4);
547
+ });
548
+
549
+ test('render ColorPickerTemplate', async () => {
550
+ Date.now = jest.fn(() => new Date('2021-09-09T10:00:00.000Z'));
551
+ const actionGroup = {
552
+ template: 'color_picker_template',
553
+ title: 'Timer',
554
+ configuration: {},
555
+ };
556
+ const mockDoAction = jest.fn();
557
+ await act(() => {
558
+ wrapper = renderer.create(
559
+ wrapComponent(actionGroup, mockDoAction, sensor)
560
+ );
561
+ });
562
+ const instance = wrapper.root;
563
+ const texts = instance.findAllByType(Text);
564
+ expect(texts).toHaveLength(2);
565
+ });
566
+
567
+ test('render SliderRangeTemplate', async () => {
568
+ Date.now = jest.fn(() => new Date('2021-09-09T10:00:00.000Z'));
569
+ const actionGroup = {
570
+ template: 'slider_range_template',
571
+ title: 'Timer',
572
+ configuration: {},
573
+ };
574
+ const mockDoAction = jest.fn();
575
+ await act(() => {
576
+ wrapper = renderer.create(
577
+ wrapComponent(actionGroup, mockDoAction, sensor)
578
+ );
579
+ });
580
+ const instance = wrapper.root;
581
+ const texts = instance.findAllByType(Text);
582
+ expect(texts).toHaveLength(4);
583
+ });
584
+
585
+ test('render TwoButtonTemplate', async () => {
586
+ Date.now = jest.fn(() => new Date('2021-09-09T10:00:00.000Z'));
587
+ const actionGroup = {
588
+ template: 'two_button_action_template',
589
+ title: 'Timer',
590
+ configuration: {},
591
+ };
592
+ const mockDoAction = jest.fn();
593
+ await act(() => {
594
+ wrapper = renderer.create(
595
+ wrapComponent(actionGroup, mockDoAction, sensor)
596
+ );
597
+ });
598
+ const instance = wrapper.root;
599
+ const texts = instance.findAllByType(Text);
600
+ expect(texts).toHaveLength(5);
601
+ });
467
602
  });
@@ -35,9 +35,7 @@ const ItemAutomate = ({
35
35
  style={[styles.wrap, isSelected && styles.active]}
36
36
  >
37
37
  <View style={styles.row}>
38
- <View style={styles.wrapIcon}>
39
- <Icon />
40
- </View>
38
+ <View style={styles.wrapIcon}>{!!Icon && <Icon />}</View>
41
39
  <View style={styles.wrapTitle}>
42
40
  <Text type="H4" bold>
43
41
  {t(item?.title)}
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import renderer, { act } from 'react-test-renderer';
3
+ import CalendarComponent from '../';
4
+ import { Calendar } from 'react-native-calendars';
5
+ // eslint-disable-next-line no-unused-vars
6
+ import BottomSheet from '../../BottomSheet';
7
+ import { SCProvider } from '../../../context';
8
+ import { mockSCStore } from '../../../context/mockStore';
9
+
10
+ const mockSetState = jest.fn();
11
+ jest.mock('react', () => {
12
+ return {
13
+ ...jest.requireActual('react'),
14
+ useState: jest.fn((init) => [init, mockSetState]),
15
+ };
16
+ });
17
+ const wrapComponent = (route, navigation) => (
18
+ <SCProvider initState={mockSCStore({})}>
19
+ <CalendarComponent route={route} />
20
+ </SCProvider>
21
+ );
22
+ describe('Test Calendar component', () => {
23
+ let tree;
24
+
25
+ test('create Calendar', () => {
26
+ act(() => {
27
+ tree = renderer.create(wrapComponent());
28
+ });
29
+ const instance = tree.root;
30
+ const calendar = instance.findAllByType(Calendar);
31
+ expect(calendar).toHaveLength(1);
32
+ });
33
+ });