@eohjsc/react-native-smart-city 0.2.97 → 0.3.0

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 (197) hide show
  1. package/README.md +35 -14
  2. package/package.json +4 -2
  3. package/src/commons/Action/ItemQuickAction.js +5 -2
  4. package/src/commons/ActionGroup/ColorPickerTemplate.js +1 -1
  5. package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
  6. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +12 -4
  7. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
  8. package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLock.js +7 -4
  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/OnOffSmartLock/SetupGeneratePasscode/index.js +1 -0
  13. package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplate.js +10 -10
  14. package/src/commons/ActionGroup/OnOffTemplate/index.js +18 -15
  15. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +9 -3
  16. package/src/commons/ActionGroup/SliderRangeTemplate.js +1 -1
  17. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +4 -1
  18. package/src/commons/ActionGroup/StatesGridActionTemplate.js +22 -8
  19. package/src/commons/ActionGroup/TimerActionTemplate.js +11 -3
  20. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +13 -9
  21. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
  22. package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +14 -14
  23. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +53 -78
  24. package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +36 -20
  25. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
  26. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
  27. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
  28. package/src/commons/ActionGroup/__test__/index.test.js +135 -0
  29. package/src/commons/Auth/AccountList.js +1 -1
  30. package/src/commons/Automate/ItemAutomate.js +1 -3
  31. package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
  32. package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
  33. package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
  34. package/src/commons/ConnectingProcess/index.js +1 -1
  35. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
  36. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
  37. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
  38. package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
  39. package/src/commons/Device/HistoryChart.js +4 -0
  40. package/src/commons/Device/LinearChart.js +15 -0
  41. package/src/commons/Device/PMSensor/PMSensorIndicatior.js +16 -12
  42. package/src/commons/Device/PMSensor/PMSensorIndicatorStyles.js +3 -0
  43. package/src/commons/Device/WaterQualitySensor/ListQualityIndicator.js +1 -0
  44. package/src/commons/Explore/__test__/CityItem.test.js +33 -54
  45. package/src/commons/FieldTemplate/ChooseUserField/ChooseFieldStyles.js +25 -0
  46. package/src/commons/FieldTemplate/ChooseUserField/ChoosePopup.js +96 -0
  47. package/src/commons/FieldTemplate/ChooseUserField/ChoosePopupStyles.js +39 -0
  48. package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +118 -0
  49. package/src/commons/FieldTemplate/ChooseUserField/index.js +62 -0
  50. package/src/commons/FieldTemplate/PasscodeField/PasscodeFieldStyles.js +30 -0
  51. package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +90 -0
  52. package/src/commons/FieldTemplate/PasscodeField/index.js +43 -0
  53. package/src/commons/FieldTemplate/ScheduleField/ScheduleFieldStyles.js +13 -0
  54. package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +179 -0
  55. package/src/commons/FieldTemplate/ScheduleField/index.js +176 -0
  56. package/src/commons/FullLoading/index.js +2 -1
  57. package/src/commons/MenuActionAddnew/index.js +1 -0
  58. package/src/commons/MenuActionList/index.js +1 -0
  59. package/src/commons/MenuActionMore/index.js +1 -1
  60. package/src/commons/PreventAccess/__test__/PreventAccess.test.js +62 -0
  61. package/src/commons/PreventAccess/index.js +9 -1
  62. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
  63. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
  64. package/src/commons/SubUnit/OneTap/index.js +1 -2
  65. package/src/commons/Unit/SharedUnit.js +1 -0
  66. package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
  67. package/src/commons/WheelDateTimePicker/index.js +2 -1
  68. package/src/configs/API.js +87 -138
  69. package/src/configs/Constants.js +27 -1
  70. package/src/configs/SCConfig.js +2 -0
  71. package/src/iot/RemoteControl/__test__/GoogleHome.test.js +8 -30
  72. package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
  73. package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
  74. package/src/navigations/UnitStack.js +8 -0
  75. package/src/screens/AQIGuide/index.js +1 -1
  76. package/src/screens/ActivityLog/FilterPopup.js +2 -0
  77. package/src/screens/ActivityLog/__test__/index.test.js +38 -23
  78. package/src/screens/ActivityLog/hooks/__test__/index.test.js +51 -90
  79. package/src/screens/ActivityLog/index.js +2 -2
  80. package/src/screens/AddCommon/SelectSubUnit.js +1 -0
  81. package/src/screens/AddCommon/SelectUnit.js +1 -0
  82. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
  83. package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
  84. package/src/screens/AddLocationMaps/index.js +4 -1
  85. package/src/screens/AddNewAction/SelectSensorDevices.js +8 -2
  86. package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
  87. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
  88. package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +3 -1
  89. package/src/screens/AddNewAutoSmart/index.js +5 -2
  90. package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
  91. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -33
  92. package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
  93. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +21 -21
  94. package/src/screens/AddNewDevice/index.js +1 -0
  95. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +4 -1
  96. package/src/screens/AddNewGateway/SelectGateway.js +1 -0
  97. package/src/screens/AddNewGateway/SetupGatewayWifi.js +1 -0
  98. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
  99. package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
  100. package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
  101. package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
  102. package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
  103. package/src/screens/AddNewGateway/index.js +1 -0
  104. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +10 -24
  105. package/src/screens/AddNewOneTap/index.js +3 -2
  106. package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
  107. package/src/screens/Automate/__test__/index.test.js +7 -12
  108. package/src/screens/Automate/index.js +2 -0
  109. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
  110. package/src/screens/ConfirmUnitDeletion/index.js +7 -1
  111. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
  112. package/src/screens/Device/__test__/detail.test.js +23 -84
  113. package/src/screens/Device/detail.js +31 -8
  114. package/src/screens/Device/hooks/useFavoriteDevice.js +5 -9
  115. package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
  116. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +6 -3
  117. package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
  118. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +20 -2
  119. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +40 -23
  120. package/src/screens/EmergencySetting/index.js +4 -1
  121. package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
  122. package/src/screens/Explore/index.js +2 -0
  123. package/src/screens/GuestInfo/__test__/index.test.js +14 -41
  124. package/src/screens/GuestInfo/components/RecurringDetail.js +1 -0
  125. package/src/screens/GuestInfo/components/TemporaryDetail.js +2 -2
  126. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +8 -12
  127. package/src/screens/HanetCamera/__test__/Detail.test.js +27 -42
  128. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +8 -5
  129. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -32
  130. package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +43 -35
  131. package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
  132. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +33 -22
  133. package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +44 -45
  134. package/src/screens/ManageAccess/index.js +2 -1
  135. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
  136. package/src/screens/MoveToAnotherSubUnit/index.js +5 -5
  137. package/src/screens/Notification/__test__/Notification.test.js +14 -25
  138. package/src/screens/Notification/__test__/NotificationItem.test.js +4 -3
  139. package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
  140. package/src/screens/PlayBackCamera/index.js +19 -3
  141. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
  142. package/src/screens/ScanChipQR/components/QRScan/index.js +1 -0
  143. package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +8 -24
  144. package/src/screens/ScriptDetail/__test__/index.test.js +17 -86
  145. package/src/screens/ScriptDetail/index.js +5 -4
  146. package/src/screens/SelectUnit/__test__/index.test.js +12 -55
  147. package/src/screens/SelectUnit/index.js +5 -2
  148. package/src/screens/SetSchedule/index.js +6 -2
  149. package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
  150. package/src/screens/SharedUnit/index.js +2 -0
  151. package/src/screens/Sharing/InfoMemberUnit.js +1 -1
  152. package/src/screens/Sharing/MemberList.js +12 -11
  153. package/src/screens/Sharing/SelectPermission.js +107 -70
  154. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
  155. package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
  156. package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
  157. package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
  158. package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
  159. package/src/screens/Sharing/hooks/index.js +3 -0
  160. package/src/screens/SideMenuDetail/SideMenuDetailStyles.js +28 -0
  161. package/src/screens/SideMenuDetail/__test__/index.test.js +154 -0
  162. package/src/screens/SideMenuDetail/index.js +149 -0
  163. package/src/screens/SmartIr/components/SelectBrand.js +1 -1
  164. package/src/screens/SubUnit/ManageSubUnit.js +1 -0
  165. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +21 -67
  166. package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
  167. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
  168. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +47 -44
  169. package/src/screens/SyncLGDevice/AddLGDevice.js +1 -0
  170. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +14 -90
  171. package/src/screens/TDSGuide/index.js +4 -1
  172. package/src/screens/UVIndexGuide/index.js +1 -1
  173. package/src/screens/Unit/ChooseLocation.js +1 -1
  174. package/src/screens/Unit/ManageUnit.js +1 -0
  175. package/src/screens/Unit/SelectAddress.js +4 -1
  176. package/src/screens/Unit/Station/index.js +1 -0
  177. package/src/screens/Unit/Summaries.js +1 -1
  178. package/src/screens/Unit/__test__/CheckSendEmail.test.js +15 -28
  179. package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
  180. package/src/screens/Unit/__test__/Detail.test.js +83 -185
  181. package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
  182. package/src/screens/Unit/__test__/SelectAddress.test.js +13 -39
  183. package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
  184. package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
  185. package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
  186. package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
  187. package/src/screens/Unit/components/SharedUnit/index.js +1 -0
  188. package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
  189. package/src/screens/UnitSummary/__test__/index.test.js +38 -31
  190. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
  191. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
  192. package/src/screens/WaterQualityGuide/index.js +1 -1
  193. package/src/utils/Apis/axios.js +37 -13
  194. package/src/utils/I18n/translations/en.json +1 -0
  195. package/src/utils/I18n/translations/vi.json +1 -0
  196. package/src/utils/Route/index.js +1 -0
  197. package/src/utils/Utils.js +6 -6
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useEffect, useMemo, useState } from 'react';
1
+ import React, { memo, useCallback, useEffect, useMemo, useState } from 'react';
2
2
  import {
3
3
  SafeAreaView,
4
4
  View,
@@ -32,8 +32,12 @@ const SelectPermission = ({ route }) => {
32
32
  const [isTickAllDevices, setIsTickAllDevices] = useState(false);
33
33
  const [activeItemId, setActiveItemId] = useState(-1);
34
34
  const [loading, setLoading] = useState(true);
35
- const [dataDeviceShared, setDataDeviceShared] = useState([]);
36
35
  const [hasDataChecked, setHasDataChecked] = useState(false);
36
+ const [dataDeviceShared, setDataDeviceShared] = useState([]);
37
+
38
+ const isUpdateSharedDevice = useMemo(() => {
39
+ return type === 'update_shared';
40
+ }, [type]);
37
41
 
38
42
  const onTickTitle = (idGroup, isChecked, id) => {
39
43
  if (!idGroup) {
@@ -98,6 +102,10 @@ const SelectPermission = ({ route }) => {
98
102
  sensor.actions.some((i) => !i.isChecked)
99
103
  );
100
104
 
105
+ stationCheck(data);
106
+ };
107
+
108
+ const stationCheck = (data) => {
101
109
  for (let station of data) {
102
110
  if (station.sensors.length) {
103
111
  station.isChecked = !station.sensors.some((i) => !i.isChecked);
@@ -115,51 +123,80 @@ const SelectPermission = ({ route }) => {
115
123
 
116
124
  sensor.isChecked = isChecked;
117
125
 
118
- for (let station of data) {
119
- if (station.sensors.length) {
120
- station.isChecked = !station.sensors.some((i) => !i.isChecked);
121
- }
122
- }
123
- setIsTickAllDevices(!dataStationTemp.some((i) => !i.isChecked));
124
- dataStationTemp = data;
125
- setDataStations(data);
126
+ stationCheck(data);
126
127
  };
127
128
 
128
129
  const autoCheckedGroup = useCallback(async () => {
129
- if (type === 'share_device') {
130
+ if (isUpdateSharedDevice) {
130
131
  if (hasDataChecked) {
131
132
  const stationIds = object_Ids(dataDeviceShared)?.stationIds;
132
133
  const sensorIds = object_Ids(dataDeviceShared)?.sensorIds;
133
134
  const actionIds = object_Ids(dataDeviceShared)?.actionIds;
134
135
  const configIds = object_Ids(dataDeviceShared)?.configIds;
135
- const data = dataStations?.map((i) => ({
136
- ...i,
137
- isChecked: stationIds.includes(i.id),
138
- }));
139
- for (let station in data) {
140
- for (let item in data[station].sensors) {
141
- const itemTemp = data[station].sensors[item];
142
- data[station].sensors[item] = {
136
+ const sensor_checked = [];
137
+ const action_checked = [];
138
+ const config_checked = [];
139
+ const action_temp = [];
140
+ const config_temp = [];
141
+ for (let station in dataStations) {
142
+ for (let item in dataStations[station].sensors) {
143
+ const itemTemp = dataStations[station].sensors[item];
144
+ dataStations[station].sensors[item] = {
143
145
  ...itemTemp,
144
146
  isChecked: sensorIds.includes(itemTemp?.id),
145
- actions: itemTemp.actions.map((i) => ({
146
- ...i,
147
- isChecked: actionIds?.includes(i.id),
148
- })),
149
- read_configs: itemTemp.read_configs.map((i) => ({
150
- ...i,
151
- isChecked: configIds?.includes(i.id),
152
- })),
147
+ actions: itemTemp.actions.map((i) => {
148
+ if (actionIds?.includes(i.id)) {
149
+ action_checked.push(i);
150
+ }
151
+ action_temp.push(i);
152
+ return {
153
+ ...i,
154
+ isChecked: actionIds?.includes(i.id),
155
+ };
156
+ }),
157
+ read_configs: itemTemp.read_configs.map((i) => {
158
+ if (configIds?.includes(i.id)) {
159
+ config_checked.push(i);
160
+ }
161
+ config_temp.push(i);
162
+ return {
163
+ ...i,
164
+ isChecked: configIds?.includes(i.id),
165
+ };
166
+ }),
153
167
  };
168
+ if (dataStations[station].sensors[item]?.isChecked) {
169
+ sensor_checked.push(dataStations[station].sensors[item]);
170
+ }
154
171
  }
155
172
  }
173
+ const check_action_config = () => {
174
+ return (
175
+ action_checked?.length === action_temp?.length &&
176
+ config_checked?.length === config_temp?.length
177
+ );
178
+ };
179
+ const data = dataStations?.map((i) => {
180
+ return {
181
+ ...i,
182
+ isChecked:
183
+ check_action_config() &&
184
+ i?.sensors?.length === sensor_checked?.length &&
185
+ stationIds.includes(i.id),
186
+ };
187
+ });
156
188
  const sensorIdsDefault = object_Ids(data)?.sensorIds;
189
+ const stationIdsDefault = object_Ids(data)?.stationIds;
157
190
  setDataStations(data);
158
- setIsTickAllDevices(sensorIdsDefault?.length === sensorIds?.length);
191
+ setIsTickAllDevices(
192
+ check_action_config() &&
193
+ sensorIdsDefault?.length === sensorIds?.length &&
194
+ stationIdsDefault?.length === stationIds?.length
195
+ );
159
196
  setHasDataChecked(false);
160
197
  }
161
198
  }
162
- }, [dataDeviceShared, dataStations, hasDataChecked, type]);
199
+ }, [dataDeviceShared, dataStations, hasDataChecked, isUpdateSharedDevice]);
163
200
 
164
201
  const GroupSenSorItem = ({ item = {}, index }) => {
165
202
  const { name = '', sensors = [], isChecked, id = '' } = item;
@@ -174,11 +211,11 @@ const SelectPermission = ({ route }) => {
174
211
  idGroup={id}
175
212
  />
176
213
  <View style={styles.wrapSensor}>
177
- {sensors.map((i, index) => (
214
+ {sensors?.map((i, index) => (
178
215
  <SensorItem
179
216
  item={i}
180
217
  key={i.id}
181
- isRenderSeparated={index !== sensors.length - 1}
218
+ isRenderSeparated={index !== sensors?.length - 1}
182
219
  onTickedChild={onTickedChild}
183
220
  onTickedSensor={onTickedSensor}
184
221
  titleGroup={name}
@@ -199,6 +236,7 @@ const SelectPermission = ({ route }) => {
199
236
  for (let item of station.sensors) {
200
237
  let arrIdControlTemp = [],
201
238
  arrIdReadTemp = [];
239
+
202
240
  for (let i of item.actions) {
203
241
  i.isChecked && arrIdControlTemp.push(i.id);
204
242
  }
@@ -219,18 +257,18 @@ const SelectPermission = ({ route }) => {
219
257
  Alert.alert('', t('choose_at_least_one'));
220
258
  return;
221
259
  }
222
- if (type === 'share_device') {
260
+ if (isUpdateSharedDevice) {
223
261
  const phone =
224
262
  member?.phone_number && member?.email
225
263
  ? member?.phone_number
226
264
  : member?.phone_number || '';
227
265
  const email = member?.phone_number ? '' : member?.email || '';
228
-
229
266
  const { success } = await axiosPost(API.SHARE.SHARE(), {
230
267
  phone,
231
268
  email,
232
269
  unit: unit?.id,
233
270
  permissions: { read_permissions, control_permissions },
271
+ is_remove_old_permission: true,
234
272
  });
235
273
  if (success) {
236
274
  navigation.goBack();
@@ -249,48 +287,47 @@ const SelectPermission = ({ route }) => {
249
287
 
250
288
  const renderFlatList = useMemo(() => {
251
289
  return (
252
- Boolean(dataStations.length) && (
253
- <FlatList
254
- keyExtractor={(item) => item.id}
255
- extraData={dataStations}
256
- data={dataStations}
257
- renderItem={renderGroupItem}
258
- ListHeaderComponent={
259
- Boolean(dataStations?.length) && (
260
- <TitleCheckBox
261
- title={t('text_all_devices')}
262
- wrapStyle={styles.wrapAllDevices}
263
- onPress={onTickTitle}
264
- titleStyle={styles.textAllDevice}
265
- isChecked={isTickAllDevices}
266
- />
267
- )
268
- }
269
- />
270
- )
290
+ <FlatList
291
+ keyExtractor={(item) => item.id}
292
+ extraData={dataStations}
293
+ data={dataStations}
294
+ renderItem={renderGroupItem}
295
+ ListHeaderComponent={
296
+ dataStations?.length > 0 ? (
297
+ <TitleCheckBox
298
+ title={t('text_all_devices')}
299
+ wrapStyle={styles.wrapAllDevices}
300
+ onPress={onTickTitle}
301
+ titleStyle={styles.textAllDevice}
302
+ isChecked={isTickAllDevices}
303
+ />
304
+ ) : (
305
+ <></>
306
+ )
307
+ }
308
+ scrollIndicatorInsets={{ right: 1 }}
309
+ />
271
310
  );
311
+
272
312
  // eslint-disable-next-line react-hooks/exhaustive-deps
273
313
  }, [dataStations, isTickAllDevices, activeItemId]);
274
314
 
275
- const getShareUnitPermission = useCallback(async () => {
276
- if (type === 'share_device') {
277
- if (dataStations?.length > 0) {
278
- const response = await axiosGet(
279
- API.SHARE.UNIT_MEMBER_SHARE_DEVICE(unit?.id, member?.id)
280
- );
281
- if (response.success) {
282
- setDataDeviceShared(response.data);
283
- setHasDataChecked(true);
284
- }
285
- }
286
- setLoading(false);
287
- }
288
- }, [dataStations?.length, member?.id, type, unit?.id]);
289
-
290
315
  useEffect(() => {
291
316
  autoCheckedGroup();
292
317
  }, [autoCheckedGroup]);
293
318
 
319
+ const getShareUnitPermission = useCallback(async () => {
320
+ if (isUpdateSharedDevice && dataStations?.length > 0) {
321
+ const response = await axiosGet(
322
+ API.SHARE.UNIT_MEMBER_SHARE_DEVICE(unit?.id, member?.id)
323
+ );
324
+ if (response?.success) {
325
+ setDataDeviceShared(response?.data);
326
+ setHasDataChecked(true);
327
+ }
328
+ }
329
+ }, [dataStations?.length, isUpdateSharedDevice, member?.id, unit?.id]);
330
+
294
331
  useEffect(() => {
295
332
  getShareUnitPermission();
296
333
  }, [getShareUnitPermission]);
@@ -309,7 +346,7 @@ const SelectPermission = ({ route }) => {
309
346
  }
310
347
  setLoading(false);
311
348
  })();
312
- }, [unit]);
349
+ }, [dataStations?.length, isUpdateSharedDevice, member?.id, unit]);
313
350
 
314
351
  useEffect(() => {
315
352
  dataStationTemp = dataStations;
@@ -341,7 +378,7 @@ const SelectPermission = ({ route }) => {
341
378
  testIDPrefix={TESTID.PREFIX.SHARING_SELECT_PERMISSION}
342
379
  leftTitle={t('cancel')}
343
380
  onLeftClick={() => navigation.goBack()}
344
- rightTitle={type === 'share_device' ? t('done') : t('next')}
381
+ rightTitle={isUpdateSharedDevice ? t('done') : t('next')}
345
382
  rightDisabled={false}
346
383
  onRightClick={onPressBottom}
347
384
  />
@@ -350,4 +387,4 @@ const SelectPermission = ({ route }) => {
350
387
  );
351
388
  };
352
389
 
353
- export default SelectPermission;
390
+ export default memo(SelectPermission);
@@ -1,14 +1,18 @@
1
1
  import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
3
  import { TouchableOpacity } from 'react-native';
4
+ import MockAdapter from 'axios-mock-adapter';
5
+
4
6
  import InfoMemberUnit from '../InfoMemberUnit';
5
7
  import { HeaderCustom } from '../../../commons/Header';
6
- import axios from 'axios';
7
8
  import { SCProvider } from '../../../context';
8
9
  import { mockSCStore } from '../../../context/mockStore';
9
10
  import { AlertAction } from '../../../commons';
10
11
  import API from '../../../configs/API';
11
12
  import { TESTID } from '../../../configs/Constants';
13
+ import api from '../../../utils/Apis/axios';
14
+
15
+ const mock = new MockAdapter(api.axiosInstance);
12
16
 
13
17
  jest.mock('../../../hooks/Common', () => {
14
18
  return {
@@ -24,20 +28,20 @@ jest.mock('react', () => {
24
28
  };
25
29
  });
26
30
 
31
+ const mockGoBack = jest.fn();
32
+
27
33
  jest.mock('@react-navigation/native', () => {
28
34
  return {
29
35
  ...jest.requireActual('@react-navigation/native'),
30
36
  useRoute: jest.fn(),
31
37
  useNavigation: () => ({
32
- goBack: jest.fn(),
38
+ goBack: mockGoBack,
33
39
  navigate: mockedNavigate,
34
40
  }),
35
41
  useIsFocused: () => mockUseIsFocused,
36
42
  };
37
43
  });
38
44
 
39
- jest.mock('axios');
40
-
41
45
  const wrapComponent = (route) => (
42
46
  <SCProvider initState={mockSCStore({})}>
43
47
  <InfoMemberUnit route={route} />
@@ -49,7 +53,6 @@ describe('Test InfoMemberUnit', () => {
49
53
  let route;
50
54
 
51
55
  beforeEach(() => {
52
- axios.get.mockClear();
53
56
  mockedNavigate.mockClear();
54
57
  route = {
55
58
  params: {
@@ -65,23 +68,17 @@ describe('Test InfoMemberUnit', () => {
65
68
  },
66
69
  };
67
70
  });
68
- it('render InfoMemberUnit', async () => {
69
- mockUseIsFocused.mockImplementation(() => true);
70
- const response = {
71
- status: 200,
72
- data: {
73
- id: 1,
74
- identity: 'owner',
75
- phone_number: '88888',
76
- name: 'user',
77
- email: 'abc@gmail.com',
78
- },
79
- };
80
- axios.get.mockImplementation(async () => {
81
- return response;
71
+
72
+ it('render InfoMemberUnit without params', async () => {
73
+ mock.onGet(API.SHARE.UNIT_MEMBER_INFO(1, 1)).reply(200, {
74
+ id: 1,
75
+ identity: 'owner',
76
+ phone_number: '88888',
77
+ name: 'user',
78
+ email: 'abc@gmail.com',
82
79
  });
83
80
  await act(async () => {
84
- tree = await create(wrapComponent(route));
81
+ tree = await create(wrapComponent({}));
85
82
  });
86
83
  const instance = tree.root;
87
84
  const header = instance.findAllByType(HeaderCustom);
@@ -92,13 +89,35 @@ describe('Test InfoMemberUnit', () => {
92
89
  alertAction[0].props.rightButtonClick();
93
90
  });
94
91
  });
92
+
93
+ it('render InfoMemberUnit', async () => {
94
+ mock.onGet(API.SHARE.UNIT_MEMBER_INFO(1, 1)).reply(200, {
95
+ id: 1,
96
+ identity: 'owner',
97
+ phone_number: '88888',
98
+ name: 'user',
99
+ email: 'abc@gmail.com',
100
+ });
101
+ await act(async () => {
102
+ tree = await create(wrapComponent(route));
103
+ });
104
+ const instance = tree.root;
105
+ const header = instance.findAllByType(HeaderCustom);
106
+ const alertAction = instance.findAllByType(AlertAction);
107
+ await act(async () => {
108
+ alertAction[0].props.rightButtonClick();
109
+ });
110
+ expect(header).toHaveLength(1);
111
+ expect(alertAction).toHaveLength(1);
112
+ });
113
+
95
114
  it('render InfoMemberUnit delete member', async () => {
96
- mockUseIsFocused.mockImplementation(() => true);
97
- const response = {
98
- status: 200,
99
- };
100
- axios.delete.mockImplementation(async () => {
101
- return response;
115
+ mock.onGet(API.SHARE.UNIT_MEMBER_INFO(1, 1)).reply(200, {
116
+ id: 1,
117
+ identity: 'owner',
118
+ phone_number: '88888',
119
+ name: 'user',
120
+ email: 'abc@gmail.com',
102
121
  });
103
122
  await act(async () => {
104
123
  tree = await create(wrapComponent(route));
@@ -111,11 +130,10 @@ describe('Test InfoMemberUnit', () => {
111
130
  );
112
131
  expect(header).toHaveLength(1);
113
132
  expect(buttonRemove).toHaveLength(1);
133
+ mock.onDelete(API.SHARE.UNITS_MEMBER_DETAIL(1)).reply(200);
114
134
  await act(async () => {
115
135
  buttonRemove[0].props.onPress();
116
136
  });
117
- expect(axios.delete).toHaveBeenCalledWith(
118
- API.SHARE.UNITS_MEMBER_DETAIL(1, undefined)
119
- );
137
+ expect(mockGoBack).toBeCalled();
120
138
  });
121
139
  });
@@ -1,26 +1,26 @@
1
- /* eslint-disable promise/prefer-await-to-callbacks */
2
1
  import React from 'react';
3
2
  import { create, act } from 'react-test-renderer';
4
- import axios from 'axios';
3
+
5
4
  import MemberList from '../MemberList';
6
5
  import { AlertAction } from '../../../commons';
7
- import API from '../../../configs/API';
8
- import { TESTID } from '../../../configs/Constants';
9
- import { TouchableOpacity } from 'react-native';
10
6
  import { SCProvider } from '../../../context';
11
7
  import { mockSCStore } from '../../../context/mockStore';
8
+ import { TouchableOpacity } from 'react-native';
12
9
  import Routes from '../../../utils/Route';
13
10
 
11
+ jest.mock('../../../hooks/Common', () => {
12
+ return {
13
+ useIsOwnerOfUnit: () => ({ isOwner: true }),
14
+ };
15
+ });
16
+
14
17
  const mockedNavigate = jest.fn();
15
- const mockedDispatch = jest.fn();
16
- const mockedAddListener = jest.fn();
17
18
  const mockUseIsFocused = jest.fn();
18
19
 
19
20
  jest.mock('@react-navigation/native', () => {
20
21
  return {
21
22
  ...jest.requireActual('@react-navigation/native'),
22
23
  useNavigation: () => ({
23
- addListener: mockedAddListener,
24
24
  navigate: mockedNavigate,
25
25
  }),
26
26
  useIsFocused: () => ({
@@ -29,22 +29,8 @@ jest.mock('@react-navigation/native', () => {
29
29
  };
30
30
  });
31
31
 
32
- jest.mock('axios');
33
- jest.mock('react-native-toast-message');
34
-
35
- jest.mock('react-redux', () => {
36
- return {
37
- ...jest.requireActual('react-redux'),
38
- useDispatch: () => mockedDispatch,
39
- useSelector: jest.fn(),
40
- connect: () => {
41
- return (component) => component;
42
- },
43
- };
44
- });
45
-
46
32
  const wrapComponent = (route, state) => (
47
- <SCProvider initState={mockSCStore(state)}>
33
+ <SCProvider initState={mockSCStore({})}>
48
34
  <MemberList route={route} />
49
35
  </SCProvider>
50
36
  );
@@ -74,17 +60,6 @@ describe('test MemberList', () => {
74
60
  };
75
61
  });
76
62
 
77
- afterEach(() => {
78
- axios.get.mockClear();
79
- });
80
-
81
- test('render MemberList', async () => {
82
- await act(async () => {
83
- await create(wrapComponent(route, localState));
84
- });
85
- expect(axios.get).toHaveBeenCalledWith(API.SHARE.UNITS_MEMBERS(1), {});
86
- });
87
-
88
63
  test('AlertAction rightButtonClick', async () => {
89
64
  let tree;
90
65
  await act(async () => {
@@ -95,100 +70,11 @@ describe('test MemberList', () => {
95
70
  await act(async () => {
96
71
  alertAction.props.rightButtonClick();
97
72
  });
98
- });
99
-
100
- test('get dataMembers', async () => {
101
- const response = {
102
- status: 200,
103
- data: [
104
- {
105
- id: 1,
106
- name: 'a',
107
- share_id: 1,
108
- },
109
- ],
110
- };
111
- axios.get.mockImplementation(async () => {
112
- return response;
113
- });
114
-
115
- let tree;
116
- await act(async () => {
117
- tree = await create(wrapComponent(route, localState));
118
- });
119
- const instance = tree.root;
120
- const sharingMember = instance.findAll(
121
- (el) => el.props.testID === TESTID.SHARING_MEMBER
122
- );
123
- expect(sharingMember).toHaveLength(1);
124
- expect(axios.get).toHaveBeenCalledWith(API.SHARE.UNITS_MEMBERS(1), {});
125
- });
126
-
127
- test('WrapHeaderScrollable rightHeader', async () => {
128
- const response = {
129
- status: 200,
130
- data: [
131
- {
132
- id: 1,
133
- name: 'a',
134
- },
135
- ],
136
- };
137
- axios.get.mockImplementation(async () => {
138
- return response;
139
- });
140
-
141
- let tree;
142
- await act(async () => {
143
- tree = await create(wrapComponent(route, localState));
144
- });
145
- const instance = tree.root;
146
- const button = instance.find(
147
- (el) =>
148
- el.props.testID === TESTID.MEMBER_LIST_RIGHT_HEADER_TOUCH &&
149
- el.type === TouchableOpacity
150
- );
151
- await act(async () => {
152
- await button.props.onPress();
153
- });
154
- expect(axios.get).toHaveBeenCalledWith(API.SHARE.UNITS_MEMBERS(1), {});
155
- expect(mockedNavigate).toHaveBeenCalledWith(Routes.AddMemberStack, {
73
+ const MemberListButtons = instance.findAllByType(TouchableOpacity);
74
+ await MemberListButtons[1].props.onPress();
75
+ expect(mockedNavigate).toBeCalledWith(Routes.AddMemberStack, {
156
76
  screen: Routes.SharingSelectPermission,
157
- params: { unit: { id: route.params.unitId } },
158
- });
159
- });
160
-
161
- test('WrapHeaderScrollable rightHeader but not owner', async () => {
162
- route.params.unit.user_id = 1;
163
- const response = {
164
- status: 200,
165
- data: [
166
- {
167
- id: 1,
168
- name: 'a',
169
- },
170
- ],
171
- };
172
- axios.get.mockImplementation(async () => {
173
- return response;
174
- });
175
-
176
- let tree;
177
- await act(async () => {
178
- tree = await create(wrapComponent(route, localState));
179
- });
180
- const instance = tree.root;
181
- const button = instance.find(
182
- (el) =>
183
- el.props.testID === TESTID.MEMBER_LIST_RIGHT_HEADER_TOUCH &&
184
- el.type === TouchableOpacity
185
- );
186
- const alertAction = instance.findByType(AlertAction);
187
- expect(alertAction.props.visible).toEqual(false);
188
- await act(async () => {
189
- await button.props.onPress();
77
+ params: { unit: { id: 1 } },
190
78
  });
191
- expect(alertAction.props.visible).toEqual(true);
192
- expect(axios.get).toHaveBeenCalledWith(API.SHARE.UNITS_MEMBERS(1), {});
193
79
  });
194
80
  });
@@ -0,0 +1,80 @@
1
+ import React from 'react';
2
+ import { create, act } from 'react-test-renderer';
3
+
4
+ import MemberList from '../MemberList';
5
+ import { AlertAction } from '../../../commons';
6
+ import { SCProvider } from '../../../context';
7
+ import { mockSCStore } from '../../../context/mockStore';
8
+ import { TouchableOpacity } from 'react-native';
9
+ import Routes from '../../../utils/Route';
10
+
11
+ jest.mock('../../../hooks/Common', () => {
12
+ return {
13
+ useIsOwnerOfUnit: () => ({ isOwner: false }),
14
+ };
15
+ });
16
+
17
+ const mockedNavigate = jest.fn();
18
+ const mockUseIsFocused = jest.fn();
19
+
20
+ jest.mock('@react-navigation/native', () => {
21
+ return {
22
+ ...jest.requireActual('@react-navigation/native'),
23
+ useNavigation: () => ({
24
+ navigate: mockedNavigate,
25
+ }),
26
+ useIsFocused: () => ({
27
+ isFocused: mockUseIsFocused,
28
+ }),
29
+ };
30
+ });
31
+
32
+ const wrapComponent = (route, state) => (
33
+ <SCProvider initState={mockSCStore({})}>
34
+ <MemberList route={route} />
35
+ </SCProvider>
36
+ );
37
+
38
+ describe('test MemberList', () => {
39
+ let route;
40
+ let localState = {
41
+ auth: {
42
+ account: {
43
+ user: {
44
+ id: 2,
45
+ },
46
+ },
47
+ },
48
+ };
49
+
50
+ beforeEach(() => {
51
+ route = {
52
+ params: {
53
+ unitId: 1,
54
+ unit: {
55
+ id: 1,
56
+ user_id: 2,
57
+ name: '',
58
+ },
59
+ },
60
+ };
61
+ });
62
+
63
+ test('AlertAction rightButtonClick', async () => {
64
+ let tree;
65
+ await act(async () => {
66
+ tree = await create(wrapComponent(route, localState));
67
+ });
68
+ const instance = tree.root;
69
+ const alertAction = instance.findByType(AlertAction);
70
+ await act(async () => {
71
+ alertAction.props.rightButtonClick();
72
+ });
73
+ const MemberListButtons = instance.findAllByType(TouchableOpacity);
74
+ await MemberListButtons[1].props.onPress();
75
+ expect(mockedNavigate).not.toBeCalledWith(Routes.AddMemberStack, {
76
+ screen: Routes.SharingSelectPermission,
77
+ params: { unit: { id: 1 } },
78
+ });
79
+ });
80
+ });