@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
@@ -12,7 +12,7 @@ import { get } from 'lodash';
12
12
  import { useSelector } from 'react-redux';
13
13
  import { IconFill, IconOutline } from '@ant-design/icons-react-native';
14
14
  import { Icon } from '@ant-design/react-native';
15
-
15
+ import Routes from '../../utils/Route';
16
16
  import { useCountUp } from './hooks/useCountUp';
17
17
  import { getData as getLocalData } from '../../utils/Storage';
18
18
  import { API, Colors } from '../../configs';
@@ -35,7 +35,7 @@ import Text from '../../commons/Text';
35
35
  import { transformDatetime } from '../../utils/Converter/time';
36
36
  import { AlertAction, ButtonPopup, MenuActionMore } from '../../commons';
37
37
  import { TESTID } from '../../configs/Constants';
38
- import Routes from '../../utils/Route';
38
+
39
39
  import { usePopover } from '../../hooks/Common';
40
40
  import { useConfigGlobalState } from '../../iot/states';
41
41
  import { useNavigation } from '@react-navigation/native';
@@ -82,7 +82,7 @@ const DeviceDetail = ({ route }) => {
82
82
  displayTemplate: true,
83
83
  });
84
84
  const [serverDown, setServerDown] = useState(false);
85
-
85
+ const [sideMenu, setSideMenu] = useState([]);
86
86
  const isNetworkConnected = useSCContextSelector(
87
87
  (state) => state.app.isNetworkConnected
88
88
  );
@@ -131,10 +131,8 @@ const DeviceDetail = ({ route }) => {
131
131
  [display.items]
132
132
  );
133
133
 
134
- const { isFavorite, addToFavorites, removeFromFavorites } = useFavoriteDevice(
135
- unit,
136
- sensor
137
- );
134
+ const { isFavorite, addToFavorites, removeFromFavorites } =
135
+ useFavoriteDevice(sensor);
138
136
 
139
137
  const currentUserId = useSelector((state) =>
140
138
  get(state, 'auth.account.user.id', 0)
@@ -191,6 +189,7 @@ const DeviceDetail = ({ route }) => {
191
189
  {},
192
190
  true
193
191
  );
192
+
194
193
  if (success) {
195
194
  setDisplay(data);
196
195
  setServerDown(false);
@@ -210,6 +209,9 @@ const DeviceDetail = ({ route }) => {
210
209
  }
211
210
  }
212
211
  }
212
+ if (data?.side_menu_items?.length) {
213
+ setSideMenu(data.side_menu_items);
214
+ }
213
215
  }
214
216
  setLoading((preState) => ({ ...preState, displayTemplate: false }));
215
217
 
@@ -305,6 +307,19 @@ const DeviceDetail = ({ route }) => {
305
307
  text: t('activity_log'),
306
308
  });
307
309
  }
310
+
311
+ sideMenu.forEach((el) => {
312
+ menuItems.push({
313
+ route: Routes.SideMenuDetail,
314
+ data: {
315
+ unit,
316
+ sensor,
317
+ side_menu: el,
318
+ },
319
+ text: el.name,
320
+ });
321
+ });
322
+
308
323
  menuItems.push({
309
324
  route: Routes.DeviceInfo,
310
325
  text: t('device_info'),
@@ -321,6 +336,13 @@ const DeviceDetail = ({ route }) => {
321
336
  text: t('auto_lock'),
322
337
  });
323
338
  }
339
+ menuItems.push({
340
+ route: Routes.SmartLockStack,
341
+ data: {
342
+ screen: Routes.SetupGeneratePasscode,
343
+ },
344
+ text: t('setup_generate_passcode'),
345
+ });
324
346
  if (isOwner && isShowSetUpSmartLock) {
325
347
  menuItems.push({
326
348
  route: Routes.SmartLockStack,
@@ -361,6 +383,7 @@ const DeviceDetail = ({ route }) => {
361
383
  sensor,
362
384
  unit,
363
385
  sensorName,
386
+ sideMenu,
364
387
  station,
365
388
  emergencyDeviceId,
366
389
  addToFavorites,
@@ -370,7 +393,7 @@ const DeviceDetail = ({ route }) => {
370
393
  const { countUpStr } = useCountUp(lastEvent.reportedAt);
371
394
 
372
395
  useEffect(() => {
373
- if (controlOptions.bluetooth) {
396
+ if (controlOptions?.bluetooth) {
374
397
  const bluetooth = controlOptions.bluetooth;
375
398
  scanBluetoothDevices([bluetooth.address]);
376
399
  }
@@ -4,7 +4,7 @@ import { SCContext, useSCContextSelector } from '../../../context';
4
4
  import { Action } from '../../../context/actionType';
5
5
  import { axiosPost } from '../../../utils/Apis/axios';
6
6
 
7
- export const useFavoriteDevice = (unit, device) => {
7
+ export const useFavoriteDevice = (device) => {
8
8
  const { setAction } = useContext(SCContext);
9
9
  const favoriteDeviceIds = useSCContextSelector(
10
10
  (state) => state.unit.favoriteDeviceIds
@@ -14,21 +14,17 @@ export const useFavoriteDevice = (unit, device) => {
14
14
 
15
15
  const addToFavorites = useCallback(async () => {
16
16
  const { success } = await axiosPost(
17
- API.SENSOR.ADD_TO_FAVOURITES(unit?.id, device?.station?.id, device?.id)
17
+ API.DEVICE.ADD_TO_FAVOURITES(device?.id)
18
18
  );
19
19
  success && setAction(Action.ADD_DEVICE_TO_FAVORITES, device.id);
20
- }, [unit, device, setAction]);
20
+ }, [device, setAction]);
21
21
 
22
22
  const removeFromFavorites = useCallback(async () => {
23
23
  const { success } = await axiosPost(
24
- API.SENSOR.REMOVE_FROM_FAVOURITES(
25
- unit?.id,
26
- device?.station?.id,
27
- device?.id
28
- )
24
+ API.DEVICE.REMOVE_FROM_FAVOURITES(device?.id)
29
25
  );
30
26
  success && setAction(Action.REMOVE_DEVICE_FROM_FAVORITES, device.id);
31
- }, [unit, device, setAction]);
27
+ }, [device, setAction]);
32
28
 
33
29
  return {
34
30
  isFavorite,
@@ -7,8 +7,6 @@ import { View } from 'react-native';
7
7
  import { SCProvider } from '../../../context';
8
8
  import { mockSCStore } from '../../../context/mockStore';
9
9
 
10
- jest.mock('axios');
11
-
12
10
  jest.mock('@react-navigation/core', () => {
13
11
  return {
14
12
  ...jest.requireActual('@react-navigation/core'),
@@ -1,5 +1,5 @@
1
1
  import React, { useCallback, useEffect, useState } from 'react';
2
- import { SafeAreaView, StyleSheet, View } from 'react-native';
2
+ import { SafeAreaView, StyleSheet, View, Platform } from 'react-native';
3
3
  import { IconOutline } from '@ant-design/icons-react-native';
4
4
  import { useNavigation } from '@react-navigation/native';
5
5
  import { useTranslations } from '../../hooks/Common/useTranslations';
@@ -71,11 +71,11 @@ export const EmergencyContactsSelectContacts = ({ route }) => {
71
71
  return (
72
72
  <SafeAreaView style={styles.container}>
73
73
  <WrapHeaderScrollable title={t('select_contacts')} loading={loading}>
74
- <Section type={'border'}>
74
+ <Section type={'border'} style={styles.section}>
75
75
  {dataContact.map((contact, index) => (
76
76
  <RowUser
77
77
  key={contact.id.toString()}
78
- testID={TESTID.EMERGENCY_SELECT_CONTACT}
78
+ testID={TESTID.EMERGENCY_SELECT_CONTACT + index}
79
79
  index={index}
80
80
  leftIcon={
81
81
  <IconOutline name={'user'} size={20} color={Colors.White} />
@@ -116,6 +116,9 @@ const styles = StyleSheet.create({
116
116
  flex: 1,
117
117
  backgroundColor: Colors.Gray2,
118
118
  },
119
+ section: {
120
+ marginTop: Platform.OS === 'ios' ? 40 : 0,
121
+ },
119
122
  buttonRemove: {
120
123
  height: 40,
121
124
  width: 40,
@@ -2,13 +2,15 @@ import React from 'react';
2
2
  import { TextInput } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
4
  import { EmergencyContactsAddNew } from '../EmergencyContactsAddNew';
5
- import axios from 'axios';
5
+ import MockAdapter from 'axios-mock-adapter';
6
6
  import Toast from 'react-native-toast-message';
7
7
  import { ViewButtonBottom } from '../../../commons';
8
8
  import { TESTID } from '../../../configs/Constants';
9
9
  import { getTranslate } from '../../../utils/I18n';
10
10
  import { SCProvider } from '../../../context';
11
11
  import { mockSCStore } from '../../../context/mockStore';
12
+ import api from '../../../utils/Apis/axios';
13
+ import { API } from '../../../configs';
12
14
 
13
15
  const wrapComponent = (route) => (
14
16
  <SCProvider initState={mockSCStore({})}>
@@ -20,7 +22,7 @@ jest.mock('react-native-toast-message');
20
22
 
21
23
  const mockedGoBack = jest.fn();
22
24
 
23
- jest.mock('axios');
25
+ const mock = new MockAdapter(api.axiosInstance);
24
26
 
25
27
  jest.mock('@react-navigation/native', () => {
26
28
  return {
@@ -105,13 +107,7 @@ describe('test EmergencyContactAddNew', () => {
105
107
  });
106
108
 
107
109
  test('onSave success', async () => {
108
- const response = {
109
- status: 200,
110
- data: {},
111
- };
112
- axios.post.mockImplementation(async () => {
113
- return response;
114
- });
110
+ mock.onPost(API.EMERGENCY_BUTTON.CREATE_CONTACT()).reply(200);
115
111
 
116
112
  await act(async () => {
117
113
  tree = await create(wrapComponent(route));
@@ -127,22 +123,14 @@ describe('test EmergencyContactAddNew', () => {
127
123
  });
128
124
 
129
125
  test('onSave fail', async () => {
130
- const response = {
131
- data: {},
132
- };
133
- axios.post.mockImplementation(async () => {
134
- return response;
135
- });
136
-
137
126
  await act(async () => {
138
127
  tree = await create(wrapComponent(route));
139
128
  });
140
129
  const instance = tree.root;
141
130
  const viewButtonBottom = instance.findByType(ViewButtonBottom);
142
131
 
143
- await act(async () => {
144
- await viewButtonBottom.props.onRightClick();
145
- });
132
+ mock.onPost(API.EMERGENCY_BUTTON.CREATE_CONTACT()).reply(400);
133
+ await viewButtonBottom.props.onRightClick();
146
134
  expect(Toast.show).toHaveBeenCalledWith({
147
135
  type: 'error',
148
136
  position: 'bottom',
@@ -1,13 +1,19 @@
1
1
  import React from 'react';
2
2
  import { TouchableOpacity } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
+ import MockAdapter from 'axios-mock-adapter';
5
+
4
6
  import Routes from '../../../utils/Route';
7
+ import { API } from '../../../configs';
5
8
  import { AlertAction } from '../../../commons';
6
9
  import { EmergencyContactsList } from '../EmergencyContactsList';
7
10
  import { TESTID } from '../../../configs/Constants';
8
11
  import { getTranslate } from '../../../utils/I18n';
9
12
  import { SCProvider } from '../../../context';
10
13
  import { mockSCStore } from '../../../context/mockStore';
14
+ import api from '../../../utils/Apis/axios';
15
+
16
+ const mock = new MockAdapter(api.axiosInstance);
11
17
 
12
18
  const wrapComponent = (route) => (
13
19
  <SCProvider initState={mockSCStore({})}>
@@ -23,7 +29,7 @@ jest.mock('@react-navigation/native', () => {
23
29
  useNavigation: () => ({
24
30
  navigate: mockedNavigate,
25
31
  }),
26
- useIsFocused: jest.fn(),
32
+ useIsFocused: () => true,
27
33
  };
28
34
  });
29
35
 
@@ -50,11 +56,23 @@ describe('test EmergencyContactList', () => {
50
56
  });
51
57
  const instance = tree.root;
52
58
  const alertAction = instance.findByType(AlertAction);
53
-
59
+ mock.onDelete(API.EMERGENCY_BUTTON.REMOVE_CONTACTS()).reply(204);
54
60
  act(() => {
55
61
  alertAction.props.rightButtonClick();
56
62
  });
63
+ expect(alertAction.props.visible).toBe(false);
64
+ });
57
65
 
66
+ test('handleRemove failure', async () => {
67
+ act(() => {
68
+ tree = create(wrapComponent(route));
69
+ });
70
+ const instance = tree.root;
71
+ const alertAction = instance.findByType(AlertAction);
72
+ mock.onDelete(API.EMERGENCY_BUTTON.REMOVE_CONTACTS()).reply(400);
73
+ act(() => {
74
+ alertAction.props.rightButtonClick();
75
+ });
58
76
  expect(alertAction.props.visible).toBe(false);
59
77
  });
60
78
 
@@ -1,14 +1,18 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
- import axios from 'axios';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+ import Toast from 'react-native-toast-message';
5
+
4
6
  import { EmergencyContactsSelectContacts } from '../EmergencyContactsSelectContacts';
5
7
  import { TESTID } from '../../../configs/Constants';
6
8
  import { SCProvider } from '../../../context';
7
9
  import { mockSCStore } from '../../../context/mockStore';
8
10
  import { API } from '../../../configs';
9
11
  import { ViewButtonBottom } from '../../../commons';
12
+ import api from '../../../utils/Apis/axios';
13
+ import { getTranslate } from '../../../utils/I18n';
10
14
 
11
- jest.mock('axios');
15
+ const mock = new MockAdapter(api.axiosInstance);
12
16
 
13
17
  const mockedNavigate = jest.fn();
14
18
  jest.mock('@react-navigation/native', () => {
@@ -45,7 +49,6 @@ describe('test EmergencyContactsSelectContacts', () => {
45
49
  tree = create(wrapComponent(route));
46
50
  });
47
51
  const instance = tree.root;
48
-
49
52
  const rowUser = instance.findAllByProps(
50
53
  (item) => item.props.testID === TESTID.EMERGENCY_SELECT_CONTACT
51
54
  );
@@ -54,32 +57,41 @@ describe('test EmergencyContactsSelectContacts', () => {
54
57
 
55
58
  test('render emergencyContactsSelectContacts success', async () => {
56
59
  jest.useFakeTimers();
57
- const response = {
58
- status: 200,
59
- data: {
60
- data: {},
61
- },
62
- };
63
- axios.get.mockImplementation(() => Promise.resolve(response));
64
-
65
- act(() => {
66
- tree = create(wrapComponent(route));
60
+ mock.onGet(API.SHARE.UNITS_MEMBERS(1, 1)).reply(200, {
61
+ id: 1,
62
+ name: 'test',
63
+ phone_number: 1,
67
64
  });
68
65
  act(() => {
69
- jest.runOnlyPendingTimers();
66
+ tree = create(wrapComponent(route));
70
67
  });
71
- expect(axios.get).toHaveBeenCalled();
72
- expect(axios.get).toHaveBeenCalledWith(API.SHARE.UNITS_MEMBERS(1, 1), {});
68
+ const instance = tree.root;
69
+ const rowUser = instance.findAllByProps(
70
+ (item) => item.props.testID === TESTID.EMERGENCY_SELECT_CONTACT + 0
71
+ );
72
+ expect(rowUser[0]).toBeDefined();
73
73
  });
74
74
 
75
75
  test('test onSave emergencyContactsSelectContacts', async () => {
76
- const response = {
77
- status: 200,
78
- success: true,
79
- };
80
- axios.post.mockImplementation(async () => {
81
- return response;
76
+ mock.onPost(API.EMERGENCY_BUTTON.CREATE_BATCH()).reply(200);
77
+ act(() => {
78
+ tree = create(wrapComponent(route));
79
+ });
80
+ const instance = tree.root;
81
+ const viewButtonBottom = instance.findByType(ViewButtonBottom);
82
+ await act(async () => {
83
+ viewButtonBottom.props.onRightClick();
84
+ });
85
+ expect(Toast.show).toBeCalledWith({
86
+ type: 'success',
87
+ position: 'bottom',
88
+ text1: getTranslate('en', 'saving_contact_successful'),
89
+ visibilityTime: 1000,
82
90
  });
91
+ });
92
+
93
+ test('test onSave emergencyContactsSelectContacts fail', async () => {
94
+ mock.onPost(API.EMERGENCY_BUTTON.CREATE_BATCH()).reply(500);
83
95
  act(() => {
84
96
  tree = create(wrapComponent(route));
85
97
  });
@@ -89,6 +101,11 @@ describe('test EmergencyContactsSelectContacts', () => {
89
101
  await act(async () => {
90
102
  viewButtonBottom.props.onRightClick();
91
103
  });
92
- expect(axios.post).toHaveBeenCalled();
104
+ expect(Toast.show).toBeCalledWith({
105
+ type: 'error',
106
+ position: 'bottom',
107
+ text1: getTranslate('en', 'create_contact_failed'),
108
+ visibilityTime: 1000,
109
+ });
93
110
  });
94
111
  });
@@ -63,7 +63,10 @@ const EmergencySetting = () => {
63
63
  <View style={styles.wrap}>
64
64
  <HeaderCustom title={t('setting')} isShowSeparator />
65
65
 
66
- <ScrollView contentContainerStyle={styles.contentContainerStyle}>
66
+ <ScrollView
67
+ contentContainerStyle={styles.contentContainerStyle}
68
+ scrollIndicatorInsets={{ right: 1 }}
69
+ >
67
70
  {listData.map((item, index) => (
68
71
  <DropDownItem
69
72
  {...item}
@@ -1,15 +1,16 @@
1
1
  import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
3
  import { TouchableOpacity } from 'react-native';
4
- import axios from 'axios';
4
+ import MockAdapter from 'axios-mock-adapter';
5
5
 
6
6
  import { SCProvider } from '../../../context';
7
7
  import { mockSCStore } from '../../../context/mockStore';
8
8
  import EnterPassword from '../index';
9
9
  import { TESTID } from '../../../configs/Constants';
10
10
  import { API } from '../../../configs';
11
+ import api from '../../../utils/Apis/axios';
11
12
 
12
- jest.mock('axios');
13
+ const mock = new MockAdapter(api.axiosInstance);
13
14
 
14
15
  const wrapComponent = (route) => (
15
16
  <SCProvider initState={mockSCStore({})}>
@@ -37,20 +38,11 @@ describe('Test EnterPassword', () => {
37
38
  el.type === TouchableOpacity
38
39
  );
39
40
  };
40
- const mockAxios = (response, method) => {
41
- switch (method) {
42
- case 'get':
43
- return axios.get.mockImplementation(async () => {
44
- return response;
45
- });
46
- case 'put':
47
- return axios.put.mockImplementation(async () => {
48
- return response;
49
- });
50
- default:
51
- return '';
52
- }
53
- };
41
+
42
+ beforeEach(() => {
43
+ mockNavigate.mockClear();
44
+ });
45
+
54
46
  test('test render EnterPassword button done', () => {
55
47
  const route = {
56
48
  params: { dataParams: {}, type: '' },
@@ -63,6 +55,16 @@ describe('Test EnterPassword', () => {
63
55
  expect(button).toHaveLength(1);
64
56
  });
65
57
 
58
+ test('test render EnterPassword has not params', () => {
59
+ const route = {};
60
+ act(() => {
61
+ tree = create(wrapComponent(route));
62
+ });
63
+ const instance = tree.root;
64
+ const button = buttonDone(instance);
65
+ expect(button).toHaveLength(1);
66
+ });
67
+
66
68
  test('test render EnterPassword text input password', () => {
67
69
  const route = {
68
70
  params: { dataParams: {}, type: '' },
@@ -102,11 +104,7 @@ describe('Test EnterPassword', () => {
102
104
  type: 'infoMemberUnit',
103
105
  },
104
106
  };
105
- const responsePut = {
106
- status: 200,
107
- data: { id: 1, user_id: 1 },
108
- };
109
- await mockAxios(responsePut, 'put');
107
+ mock.onPut(API.UNIT.CHANGE_OWNER(1)).reply(200, { id: 1, user_id: 1 });
110
108
  await act(async () => {
111
109
  tree = await create(wrapComponent(route));
112
110
  });
@@ -115,10 +113,28 @@ describe('Test EnterPassword', () => {
115
113
  await act(async () => {
116
114
  await button[0].props.onPress();
117
115
  });
118
- expect(axios.put).toHaveBeenCalledTimes(1);
119
- expect(axios.put).toHaveBeenCalledWith(API.UNIT.CHANGE_OWNER(1), {
120
- confirm_password: '',
121
- new_owner: 1,
116
+ expect(mockNavigate).toBeCalled();
117
+ });
118
+
119
+ test('test EnterPassword button failure', async () => {
120
+ const route = {
121
+ params: {
122
+ dataParams: {
123
+ unit_id: 1,
124
+ member: { id: 1 },
125
+ },
126
+ type: 'infoMemberUnit',
127
+ },
128
+ };
129
+ await act(async () => {
130
+ tree = await create(wrapComponent(route));
131
+ });
132
+ const instance = tree.root;
133
+ const button = buttonDone(instance);
134
+ mock.onPut(API.UNIT.CHANGE_OWNER(1)).reply(400);
135
+ await act(async () => {
136
+ await button[0].props.onPress();
122
137
  });
138
+ expect(mockNavigate).not.toBeCalled();
123
139
  });
124
140
  });
@@ -92,6 +92,7 @@ const Explore = ({ navigation }) => {
92
92
  horizontal={true}
93
93
  contentContainerStyle={styles.locationContent}
94
94
  showsHorizontalScrollIndicator={false}
95
+ scrollIndicatorInsets={{ right: 1 }}
95
96
  >
96
97
  {!!unitsNearMe &&
97
98
  unitsNearMe.map((item) => (
@@ -134,6 +135,7 @@ const Explore = ({ navigation }) => {
134
135
  onEndReachedThreshold={0.01}
135
136
  onMomentumScrollBegin={() => setOnEndReached(false)}
136
137
  onEndReached={handleEndReachUnitPublic}
138
+ scrollIndicatorInsets={{ right: 1 }}
137
139
  />
138
140
  </Animated.View>
139
141
  </SafeAreaView>
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
2
  import { TouchableOpacity } from 'react-native';
3
3
  import { create, act } from 'react-test-renderer';
4
- import axios from 'axios';
4
+ import MockAdapter from 'axios-mock-adapter';
5
+
5
6
  import { SCProvider } from '../../../context';
6
7
  import { mockSCStore } from '../../../context/mockStore';
7
8
  import GuestInfo from '..';
@@ -11,6 +12,7 @@ import WheelDateTimePicker from '../../../commons/WheelDateTimePicker';
11
12
  import Text from '../../../commons/Text';
12
13
  import { TESTID } from '../../../configs/Constants';
13
14
  import { API } from '../../../configs';
15
+ import api from '../../../utils/Apis/axios';
14
16
 
15
17
  const wrapComponent = (route) => (
16
18
  <SCProvider initState={mockSCStore({})}>
@@ -35,7 +37,7 @@ jest.mock('@react-navigation/native', () => {
35
37
  };
36
38
  });
37
39
 
38
- jest.mock('axios');
40
+ const mock = new MockAdapter(api.axiosInstance);
39
41
 
40
42
  const getButton = (instance, testID, many = false) => {
41
43
  if (many) {
@@ -54,8 +56,6 @@ describe('Test GuestInfo', () => {
54
56
  let data;
55
57
 
56
58
  beforeEach(() => {
57
- axios.get.mockClear();
58
- axios.put.mockClear();
59
59
  mockGoBack.mockClear();
60
60
  route = {
61
61
  params: { id: 1 },
@@ -76,23 +76,14 @@ describe('Test GuestInfo', () => {
76
76
  });
77
77
 
78
78
  test('test render GuestInfo', async () => {
79
- const response = {
80
- status: 200,
81
- data: data,
82
- };
83
- axios.get.mockImplementation(async () => {
84
- return response;
85
- });
79
+ mock.onGet(API.SHARED_SENSOR.ACCESS(1)).reply(200, data);
86
80
  await act(async () => {
87
81
  tree = await create(wrapComponent(route));
88
82
  });
89
83
  const instance = tree.root;
90
-
91
- expect(axios.get).toHaveBeenCalledWith(API.SHARED_SENSOR.ACCESS(1), {});
92
84
  const texts = instance.findAllByType(Text);
93
85
  expect(texts[4].props.children).toBe(data.user.id);
94
86
  expect(texts[6].props.children).toBe('Always');
95
-
96
87
  const accessScheduleItems = instance.findAllByType(AccessScheduleItem);
97
88
  const radioButtons = getButton(
98
89
  instance,
@@ -101,21 +92,18 @@ describe('Test GuestInfo', () => {
101
92
  );
102
93
  expect(accessScheduleItems).toHaveLength(3);
103
94
  expect(radioButtons).toHaveLength(3);
104
-
105
95
  const always = accessScheduleItems[0];
106
96
  const recurring = accessScheduleItems[1];
107
97
  const temporary = accessScheduleItems[2];
108
98
  expect(always.props.isSelected).toBeTruthy();
109
99
  expect(recurring.props.isSelected).toBeFalsy();
110
100
  expect(temporary.props.isSelected).toBeFalsy();
111
-
112
101
  await act(async () => {
113
102
  await radioButtons[1].props.onPress();
114
103
  });
115
104
  expect(always.props.isSelected).toBeFalsy();
116
105
  expect(recurring.props.isSelected).toBeTruthy();
117
106
  expect(temporary.props.isSelected).toBeFalsy();
118
-
119
107
  await act(async () => {
120
108
  await radioButtons[2].props.onPress();
121
109
  });
@@ -125,13 +113,7 @@ describe('Test GuestInfo', () => {
125
113
  });
126
114
 
127
115
  test('test open and close 2 modal', async () => {
128
- const response = {
129
- status: 200,
130
- data: data,
131
- };
132
- axios.get.mockImplementation(async () => {
133
- return response;
134
- });
116
+ mock.onGet(API.SHARED_SENSOR.ACCESS(1)).reply(200, data);
135
117
  await act(async () => {
136
118
  tree = await create(wrapComponent(route));
137
119
  });
@@ -152,7 +134,7 @@ describe('Test GuestInfo', () => {
152
134
  );
153
135
  const dateTimePickerDone = getButton(
154
136
  instance,
155
- `${TESTID.WHEEL_DATE_TIME_PICKER}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
137
+ `${TESTID.WHEEL_DATE_TIME_PICKER_BUTTON}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
156
138
  );
157
139
 
158
140
  // show AccessScheduleSheet
@@ -197,13 +179,7 @@ describe('Test GuestInfo', () => {
197
179
 
198
180
  test('test save', async () => {
199
181
  data.access_schedule = 'recurring';
200
- const response = {
201
- status: 200,
202
- data: data,
203
- };
204
- axios.get.mockImplementation(async () => {
205
- return response;
206
- });
182
+ mock.onGet(API.SHARED_SENSOR.ACCESS(1)).reply(200, data);
207
183
  await act(async () => {
208
184
  tree = await create(wrapComponent(route));
209
185
  });
@@ -213,17 +189,14 @@ describe('Test GuestInfo', () => {
213
189
  el.props.testID === TESTID.SAVE_ACCESS_SCHEDULE &&
214
190
  el.type === TouchableOpacity
215
191
  );
216
- axios.put.mockImplementation(async () => {
217
- return { status: 200 };
218
- });
192
+ mock.onPut(API.SHARED_SENSOR.ACCESS(1)).reply(200);
219
193
  await act(async () => {
220
194
  await saveButton.props.onPress();
221
195
  });
222
- expect(axios.put).toHaveBeenCalledWith(API.SHARED_SENSOR.ACCESS(1), {
223
- access_schedule: 'recurring',
224
- recurring_time_start: '07:00:00',
225
- recurring_time_end: '07:00:00',
226
- recurring_time_repeat: [0, 1, 2],
227
- });
196
+ const accessScheduleSheetDone = getButton(
197
+ instance,
198
+ `${TESTID.ACCESS_SCHEDULE_SHEET}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
199
+ );
200
+ expect(accessScheduleSheetDone.props.isVisible).toBeFalsy();
228
201
  });
229
202
  });