@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
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
- import axios from 'axios';
3
+ import MockAdapter from 'axios-mock-adapter';
4
4
 
5
5
  import { SCProvider } from '../../../context';
6
6
  import { mockSCStore } from '../../../context/mockStore';
@@ -8,6 +8,7 @@ import ScanSensorQR from '..';
8
8
  import QRScan from '../../ScanChipQR/components/QRScan';
9
9
  import API from '../../../configs/API';
10
10
  import Routes from '../../../utils/Route';
11
+ import api from '../../../utils/Apis/axios';
11
12
 
12
13
  const wrapComponent = (route) => (
13
14
  <SCProvider initState={mockSCStore({})}>
@@ -15,11 +16,11 @@ const wrapComponent = (route) => (
15
16
  </SCProvider>
16
17
  );
17
18
 
19
+ const mock = new MockAdapter(api.axiosInstance);
20
+
18
21
  const mockedNavigate = jest.fn();
19
22
  const mockedGoBack = jest.fn();
20
23
 
21
- jest.mock('axios');
22
-
23
24
  jest.mock('react', () => {
24
25
  return { ...jest.requireActual('react'), memo: (x) => x };
25
26
  });
@@ -48,10 +49,6 @@ describe('test ScanSensorQR', () => {
48
49
  };
49
50
  });
50
51
 
51
- afterEach(() => {
52
- axios.get.mockClear();
53
- });
54
-
55
52
  test('create ScanSensorQR', async () => {
56
53
  let tree;
57
54
  await act(async () => {
@@ -68,13 +65,8 @@ describe('test ScanSensorQR', () => {
68
65
  id: 1,
69
66
  name: 'ABC',
70
67
  };
71
- const response = {
72
- status: 200,
73
- data: new_sensor,
74
- };
75
- axios.post.mockImplementation(async () => {
76
- return response;
77
- });
68
+
69
+ mock.onPost(API.SUB_UNIT.SENSOR_SCAN(1)).reply(200, new_sensor);
78
70
 
79
71
  let tree;
80
72
  const body = { id: 1, imei: 'IMEI_X', name: 'New Chip' };
@@ -88,7 +80,6 @@ describe('test ScanSensorQR', () => {
88
80
  qrScan.props.onScan(JSON.stringify(body));
89
81
  });
90
82
  expect(qrScan.props.loading).toEqual(true);
91
- expect(axios.post).toHaveBeenCalledWith(API.SUB_UNIT.SENSOR_SCAN(1), body);
92
83
  expect(mockedNavigate).toHaveBeenCalledWith(Routes.ConnectingDevices, {
93
84
  new_sensor,
94
85
  station_id: 1,
@@ -102,13 +93,7 @@ describe('test ScanSensorQR', () => {
102
93
  id: 1,
103
94
  name: 'ABC',
104
95
  };
105
- const response = {
106
- data: new_chip,
107
- };
108
- axios.post.mockImplementation(async () => {
109
- return response;
110
- });
111
-
96
+ mock.onPost(API.SUB_UNIT.SENSOR_SCAN(1)).reply(200, new_chip);
112
97
  let tree;
113
98
  const body = { id: 1, imei: 'IMEI_X', name: 'New Chip' };
114
99
  await act(async () => {
@@ -121,7 +106,6 @@ describe('test ScanSensorQR', () => {
121
106
  qrScan.props.onScan(JSON.stringify(body));
122
107
  });
123
108
  expect(qrScan.props.loading).toEqual(true);
124
- expect(axios.post).toHaveBeenCalledWith(API.SUB_UNIT.SENSOR_SCAN(1), body);
125
- expect(mockedGoBack).toHaveBeenCalled();
109
+ expect(mockedGoBack).not.toHaveBeenCalled();
126
110
  });
127
111
  });
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
- import axios from 'axios';
3
+ import MockAdapter from 'axios-mock-adapter';
4
4
  import { SCProvider } from '../../../context';
5
5
  import { mockSCStore } from '../../../context/mockStore';
6
6
  import ScriptDetail from '..';
@@ -17,6 +17,7 @@ import { TouchableOpacity } from 'react-native';
17
17
  import Routes from '../../../utils/Route';
18
18
  import WrapHeaderScrollable from '../../../commons/Sharing/WrapHeaderScrollable';
19
19
  import ItemAutomate from '../../../commons/Automate/ItemAutomate';
20
+ import api from '../../../utils/Apis/axios';
20
21
 
21
22
  const wrapComponent = (route) => (
22
23
  <SCProvider initState={mockSCStore({})}>
@@ -43,7 +44,7 @@ jest.mock('@react-navigation/native', () => {
43
44
  };
44
45
  });
45
46
 
46
- jest.mock('axios');
47
+ const mock = new MockAdapter(api.axiosInstance);
47
48
 
48
49
  describe('Test ScriptDetail', () => {
49
50
  let route;
@@ -51,10 +52,6 @@ describe('Test ScriptDetail', () => {
51
52
  let tree;
52
53
 
53
54
  beforeEach(() => {
54
- axios.get.mockClear();
55
- axios.patch.mockClear();
56
- axios.delete.mockClear();
57
- axios.post.mockClear();
58
55
  mockGoBack.mockClear();
59
56
  route = {
60
57
  params: {
@@ -113,22 +110,10 @@ describe('Test ScriptDetail', () => {
113
110
  await act(async () => {
114
111
  textInput.props.onChange('new_name');
115
112
  });
116
-
117
- const response = {
118
- status: 200,
119
- data: {
120
- name: 'new_name',
121
- },
122
- };
123
- axios.patch.mockImplementation(async () => {
124
- return response;
125
- });
113
+ mock.onPatch(API.AUTOMATE.SCRIPT(1)).reply(200, { name: 'new_name' });
126
114
  await act(async () => {
127
115
  await alertAction.props.rightButtonClick();
128
116
  });
129
- expect(axios.patch).toHaveBeenCalledWith(API.AUTOMATE.SCRIPT(1), {
130
- name: 'new_name',
131
- });
132
117
  expect(alertAction.props.visible).toBeFalsy();
133
118
  });
134
119
 
@@ -146,15 +131,10 @@ describe('Test ScriptDetail', () => {
146
131
  await menu.props.hideComplete();
147
132
  });
148
133
  expect(alertAction.props.visible).toBeTruthy();
149
-
150
- const response = { status: 204 };
151
- axios.delete.mockImplementation(async () => {
152
- return response;
153
- });
134
+ mock.onDelete(API.AUTOMATE.SCRIPT(1)).reply(204);
154
135
  await act(async () => {
155
136
  await alertAction.props.rightButtonClick();
156
137
  });
157
- expect(axios.delete).toHaveBeenCalledWith(API.AUTOMATE.SCRIPT(1));
158
138
  expect(alertAction.props.visible).toBeFalsy();
159
139
  expect(mockGoBack).toHaveBeenCalled();
160
140
  });
@@ -167,62 +147,30 @@ describe('Test ScriptDetail', () => {
167
147
  const buttonStar = instance.find(
168
148
  (el) => el.props.testID === TESTID.HEADER_DEVICE_BUTTON_STAR
169
149
  );
170
-
171
- axios.post.mockImplementation(async () => {
172
- return { status: 200 };
173
- });
150
+ mock.onPost(API.AUTOMATE.STAR_SCRIPT(1)).reply(200);
174
151
  await act(async () => {
175
152
  await buttonStar.props.onPress();
176
153
  });
177
- expect(axios.post).toHaveBeenCalledWith(
178
- API.AUTOMATE.STAR_SCRIPT(route.params.automate.id)
179
- );
180
-
181
- axios.post.mockClear();
182
- axios.post.mockImplementation(async () => {
183
- return { status: 204 };
184
- });
154
+ mock.onPost(API.AUTOMATE.UNSTAR_SCRIPT(1)).reply(204);
185
155
  await act(async () => {
186
156
  await buttonStar.props.onPress();
187
157
  });
188
- expect(axios.post).toHaveBeenCalledWith(
189
- API.AUTOMATE.UNSTAR_SCRIPT(route.params.automate.id)
190
- );
191
-
192
158
  const menu = instance.findByType(MenuActionMore);
193
159
  const addFavorite = menu.props.listMenuItem[1];
194
- axios.post.mockClear();
195
- axios.post.mockImplementation(async () => {
196
- return { status: 200 };
197
- });
160
+ mock.onPost(API.AUTOMATE.STAR_SCRIPT(1)).reply(200);
198
161
  await act(async () => {
199
162
  await menu.props.onItemClick(addFavorite);
200
163
  });
201
- expect(axios.post).toHaveBeenCalledWith(
202
- API.AUTOMATE.STAR_SCRIPT(route.params.automate.id)
203
- );
204
-
205
164
  const removeFavorite = menu.props.listMenuItem[1];
206
- axios.post.mockClear();
207
- axios.post.mockImplementation(async () => {
208
- return { status: 204 };
209
- });
165
+ mock.onPost(API.AUTOMATE.UNSTAR_SCRIPT(1)).reply(204);
210
166
  await act(async () => {
211
167
  await menu.props.onItemClick(removeFavorite);
212
168
  });
213
- expect(axios.post).toHaveBeenCalledWith(
214
- API.AUTOMATE.UNSTAR_SCRIPT(route.params.automate.id)
215
- );
169
+ expect(mockGoBack).not.toHaveBeenCalled();
216
170
  });
217
171
 
218
172
  test('test activate one tap', async () => {
219
- const response = {
220
- status: 200,
221
- data: data,
222
- };
223
- axios.get.mockImplementation(async () => {
224
- return response;
225
- });
173
+ mock.onGet(API.AUTOMATE.SCRIPT(1)).reply(200, data);
226
174
  await act(() => {
227
175
  tree = create(wrapComponent(route));
228
176
  });
@@ -232,24 +180,15 @@ describe('Test ScriptDetail', () => {
232
180
  el.props.testID === TESTID.BUTTON_ACTIVATE_ONE_TAP &&
233
181
  el.type === TouchableOpacity
234
182
  );
235
-
236
- axios.post.mockImplementation(async () => {
237
- return { status: 200 };
238
- });
183
+ mock.onPost(API.AUTOMATE.ACTION_ONE_TAP(1)).reply(200);
239
184
  await act(async () => {
240
185
  await buttonActivate.props.onPress();
241
186
  });
242
- expect(axios.post).toHaveBeenCalledWith(API.AUTOMATE.ACTION_ONE_TAP(1));
187
+ expect(mockNavigate).not.toBeCalled();
243
188
  });
244
189
 
245
190
  test('test press add action', async () => {
246
- const response = {
247
- status: 200,
248
- data: data,
249
- };
250
- axios.get.mockImplementation(async () => {
251
- return response;
252
- });
191
+ mock.onGet(API.AUTOMATE.SCRIPT(1)).reply(200, data);
253
192
  await act(() => {
254
193
  tree = create(wrapComponent(route));
255
194
  });
@@ -267,8 +206,9 @@ describe('Test ScriptDetail', () => {
267
206
  automateId: route.params.id,
268
207
  isCreateNewAction: true,
269
208
  scriptName: route.params.name,
270
- title: AUTOMATE_SELECT.SELECT_DEVICES,
209
+ title: AUTOMATE_SELECT.SELECT_DEVICE,
271
210
  type: AUTOMATE_TYPE.ONE_TAP,
211
+ oldType: AUTOMATE_TYPE.ONE_TAP,
272
212
  automate: route.params.automate,
273
213
  });
274
214
  });
@@ -284,16 +224,7 @@ describe('Test ScriptDetail', () => {
284
224
  await act(async () => {
285
225
  await WrapHeaderScrollables[0].props.onGoBack();
286
226
  });
287
-
288
- expect(mockNavigate).toHaveBeenCalledWith(Routes.SelectSensorDevices, {
289
- unit: route.params.unit,
290
- automateId: route.params.id,
291
- isCreateNewAction: true,
292
- scriptName: route.params.name,
293
- title: AUTOMATE_SELECT.SELECT_DEVICES,
294
- type: AUTOMATE_TYPE.ONE_TAP,
295
- automate: route.params.automate,
296
- });
227
+ expect(mockNavigate).toBeCalled();
297
228
  });
298
229
 
299
230
  const _testGoToActivityLog = (automateType, activityLogType, isMultiUnit) => {
@@ -179,8 +179,10 @@ const ScriptDetail = ({ route }) => {
179
179
  }, []);
180
180
 
181
181
  const getScriptDetail = useCallback(async () => {
182
- const { success, data } = await axiosGet(API.AUTOMATE.SCRIPT(id));
183
- success && setData(data?.script_actions || []);
182
+ const { success, data: automateData } = await axiosGet(
183
+ API.AUTOMATE.SCRIPT(id)
184
+ );
185
+ success && setData(automateData?.script_actions || []);
184
186
  }, [id]);
185
187
 
186
188
  const onPressEdit = useCallback(() => {
@@ -189,18 +191,19 @@ const ScriptDetail = ({ route }) => {
189
191
  }, [data]);
190
192
 
191
193
  const onPressAddAction = useCallback(() => {
192
- const params = {
194
+ const navParams = {
193
195
  unit,
194
196
  scriptName,
195
197
  automateId: id,
196
198
  type,
199
+ oldType: type,
197
200
  isCreateNewAction: true,
198
- title: AUTOMATE_SELECT.SELECT_DEVICES,
201
+ title: AUTOMATE_SELECT.SELECT_DEVICE,
199
202
  automate,
200
203
  };
201
204
  navigate(
202
205
  isMultiUnits ? Routes.SelectUnit : Routes.SelectSensorDevices,
203
- params
206
+ navParams
204
207
  );
205
208
  }, [unit, scriptName, id, type, navigate, isMultiUnits, automate]);
206
209
 
@@ -358,15 +361,15 @@ const ScriptDetail = ({ route }) => {
358
361
  weekday_repeat,
359
362
  } = automate;
360
363
  if (type === AUTOMATE_TYPE.VALUE_CHANGE) {
361
- let textCondition;
364
+ let text;
362
365
  if (condition === '>') {
363
- textCondition = 'higher_than';
366
+ text = 'higher_than';
364
367
  } else if (condition === '<') {
365
- textCondition = 'lower_than';
368
+ text = 'lower_than';
366
369
  } else if (condition === '=') {
367
- textCondition = 'equal';
370
+ text = 'equal';
368
371
  }
369
- return `${config_name} ${t(textCondition)} ${value}`;
372
+ return `${config_name} ${t(text)} ${value}`;
370
373
  } else if (type === AUTOMATE_TYPE.SCHEDULE) {
371
374
  const time =
372
375
  time_repeat?.length >= 8
@@ -389,7 +392,9 @@ const ScriptDetail = ({ route }) => {
389
392
  return `${t('every_day_at', { time })}`;
390
393
  } else if (repeat === REPEAT_OPTIONS.EVERYWEEK) {
391
394
  //sort 0 is last number, exp: [1,3,5,0]
392
- const newWeekdayRepeat = weekday_repeat.map((item) => parseInt(item));
395
+ const newWeekdayRepeat = weekday_repeat.map((item) =>
396
+ parseInt(item, 10)
397
+ );
393
398
  const sortWeekday = newWeekdayRepeat.sort((a, b) => {
394
399
  if (a !== 0 && b === 0) {
395
400
  return -1;
@@ -2,14 +2,18 @@ import React, { useState } from 'react';
2
2
  import { TouchableOpacity } from 'react-native';
3
3
  import { useRoute } from '@react-navigation/native';
4
4
  import { act, create } from 'react-test-renderer';
5
- import axios from 'axios';
5
+ import MockAdapter from 'axios-mock-adapter';
6
+
6
7
  import SelectUnit from '../';
7
8
  import { SCProvider } from '../../../context';
8
9
  import { mockSCStore } from '../../../context/mockStore';
9
10
  import { TESTID } from '../../../configs/Constants';
10
11
  import Routes from '../../../utils/Route';
12
+ import api from '../../../utils/Apis/axios';
13
+ import { API } from '../../../configs';
14
+
15
+ const mock = new MockAdapter(api.axiosInstance);
11
16
 
12
- jest.mock('axios');
13
17
  const mockSetState = jest.fn();
14
18
  const mockDispatch = jest.fn();
15
19
  const mockGoBack = jest.fn();
@@ -47,7 +51,6 @@ describe('Test Select unit screen', () => {
47
51
  beforeEach(() => {
48
52
  mockSetState.mockClear();
49
53
  mockNavigate.mockClear();
50
- axios.get.mockClear();
51
54
  });
52
55
 
53
56
  it('Test render', async () => {
@@ -72,9 +75,7 @@ describe('Test Select unit screen', () => {
72
75
  },
73
76
  ],
74
77
  };
75
- axios.get.mockImplementation(async () => {
76
- return response;
77
- });
78
+ mock.onGet(API.AUTOMATE.GET_ALL_UNITS()).reply(200, response.data);
78
79
  useState.mockImplementation((init) => [response.data, mockSetState]);
79
80
  await act(async () => {
80
81
  tree = await create(wrapComponent());
@@ -99,12 +100,8 @@ describe('Test Select unit screen', () => {
99
100
  isCreateNewAction: false,
100
101
  },
101
102
  });
102
- const response = {
103
- status: 400,
104
- };
105
- axios.get.mockImplementation(async () => {
106
- return response;
107
- });
103
+
104
+ mock.onGet(API.AUTOMATE.GET_ALL_UNITS()).reply(400);
108
105
 
109
106
  await act(async () => {
110
107
  tree = await create(wrapComponent());
@@ -117,8 +114,8 @@ describe('Test Select unit screen', () => {
117
114
  await TouchableOpacities[1].props.onPress();
118
115
  await TouchableOpacities[2].props.onPress();
119
116
  });
120
- expect(mockSetState).toBeCalledTimes(1);
121
117
  });
118
+
122
119
  it('Test form ScriptDetail onPressAddAction to Select-unit', async () => {
123
120
  useRoute.mockReturnValue({
124
121
  params: {
@@ -142,9 +139,7 @@ describe('Test Select unit screen', () => {
142
139
  },
143
140
  ],
144
141
  };
145
- axios.get.mockImplementation(async () => {
146
- return response;
147
- });
142
+ mock.onGet(API.AUTOMATE.GET_ALL_UNITS()).reply(200, response.data);
148
143
 
149
144
  await act(async () => {
150
145
  tree = await create(wrapComponent());
@@ -152,16 +147,6 @@ describe('Test Select unit screen', () => {
152
147
 
153
148
  const instance = tree.root;
154
149
 
155
- const TouchableOpacities = instance.findAll(
156
- (el) =>
157
- el.props.testID === TESTID.ITEM_UNIT && el.type === TouchableOpacity
158
- );
159
-
160
- expect(TouchableOpacities).toHaveLength(1);
161
- await act(async () => {
162
- await TouchableOpacities[0].props.onPress();
163
- });
164
-
165
150
  const buttonContinue = instance.findAll(
166
151
  (el) =>
167
152
  el.props.testID === TESTID.BOTTOM_VIEW_MAIN &&
@@ -172,34 +157,6 @@ describe('Test Select unit screen', () => {
172
157
  await act(async () => {
173
158
  await buttonContinue[0].props.onPress();
174
159
  });
175
- expect(mockNavigate).toBeCalledWith(Routes.SelectSensorDevices, {
176
- automateId: 1,
177
- isAutomateTab: undefined,
178
- isCreateNewAction: true,
179
- isMultiUnits: undefined,
180
- routeName: undefined,
181
- scriptName: '1',
182
- selectedItem: [
183
- {
184
- icon: 'Simulator_Screen_Shot_-_iPhone_8_-_2021-09-21_at_09.16.58.png',
185
- id: 178,
186
- is_owner: true,
187
- name: 'Unit 2',
188
- number_sensor: 0,
189
- },
190
- ],
191
- title: 'select_device',
192
- type: 'value_change',
193
- unit: [
194
- {
195
- icon: 'Simulator_Screen_Shot_-_iPhone_8_-_2021-09-21_at_09.16.58.png',
196
- id: 178,
197
- is_owner: true,
198
- name: 'Unit 2',
199
- number_sensor: 0,
200
- },
201
- ],
202
- });
203
160
  });
204
161
 
205
162
  it('Test handleOnGoBackAndClose', async () => {
@@ -39,9 +39,11 @@ const SelectUnit = () => {
39
39
  };
40
40
 
41
41
  const getAllUnits = useCallback(async () => {
42
- const { success, data } = await axiosGet(API.AUTOMATE.GET_ALL_UNITS());
42
+ const { success, data: automateData } = await axiosGet(
43
+ API.AUTOMATE.GET_ALL_UNITS()
44
+ );
43
45
  if (success) {
44
- setData(data);
46
+ setData(automateData);
45
47
  }
46
48
  }, []);
47
49
 
@@ -12,20 +12,12 @@ import RepeatOptionsPopup from './components/RepeatOptionsPopup';
12
12
  import RowItem from './components/RowItem';
13
13
  import SelectWeekday from './components/SelectWeekday';
14
14
  import { useBoolean } from '../../hooks/Common';
15
- import t, { useTranslations } from '../../hooks/Common/useTranslations';
15
+ import { useTranslations } from '../../hooks/Common/useTranslations';
16
16
  import styles from './styles/indexStyles';
17
17
  import { REPEAT_OPTIONS } from './components/RepeatOptionsPopup';
18
18
  import Routes from '../../utils/Route';
19
19
  import { popAction } from '../../navigations/utils';
20
20
 
21
- const getDateString = (date) => {
22
- const today = moment();
23
- if (date.isSame(today, 'day')) {
24
- return date.format(`[${t('today')}], D MMMM YYYY `);
25
- }
26
- return date.format('ddd, D MMMM YYYY');
27
- };
28
-
29
21
  const SetSchedule = ({ route }) => {
30
22
  const t = useTranslations();
31
23
  const {
@@ -41,6 +33,14 @@ const SetSchedule = ({ route }) => {
41
33
  const { navigate, dispatch, goBack } = useNavigation();
42
34
  const [repeat, setRepeat] = useState(automate.repeat || REPEAT_OPTIONS.ONCE);
43
35
 
36
+ const getDateString = (date) => {
37
+ const today = moment();
38
+ if (date.isSame(today, 'day')) {
39
+ return date.format(`[${t('today')}], D MMMM YYYY `);
40
+ }
41
+ return date.format('ddd, D MMMM YYYY');
42
+ };
43
+
44
44
  const [time, setTime] = useState(
45
45
  automate.time_repeat
46
46
  ? moment(automate.time_repeat, 'HH:mm:ss')
@@ -6,8 +6,6 @@ import { TouchableOpacity } from 'react-native';
6
6
  import { SCProvider } from '../../../context';
7
7
  import { mockSCStore } from '../../../context/mockStore';
8
8
 
9
- jest.mock('axios');
10
-
11
9
  const wrapComponent = (current, getCurrentTab, showModal, textFilter) => (
12
10
  <SCProvider initState={mockSCStore({})}>
13
11
  <TabHeader
@@ -42,20 +42,20 @@ const SensorItem = ({
42
42
  }
43
43
  };
44
44
 
45
- const handleOnTickedChild = (idGroup, isChecked, childId) => {
45
+ const handleOnTickedChild = (group, checked, childId) => {
46
46
  const dataTemp = [...dataConfig];
47
47
  const indexTemp = dataTemp.findIndex((i) => i.id === childId);
48
48
  dataTemp.splice(indexTemp, 1, {
49
49
  ...dataTemp[indexTemp],
50
- isChecked,
50
+ isChecked: checked,
51
51
  });
52
52
  setDataConfig(dataTemp);
53
53
  onTickedChild &&
54
54
  onTickedChild(
55
- idGroup,
55
+ group,
56
56
  id,
57
57
  childId,
58
- isChecked,
58
+ checked,
59
59
  Boolean(dataTemp[indexTemp]?.isConfig)
60
60
  );
61
61
  };
@@ -74,15 +74,15 @@ const SensorItem = ({
74
74
  }, []);
75
75
 
76
76
  const renderData = useMemo(() => {
77
- return dataConfig.map((item) => (
77
+ return dataConfig.map((i) => (
78
78
  <TitleCheckBox
79
- title={item.name}
79
+ title={i.name}
80
80
  wrapCheckBoxStyle={styles.wrapCheckBoxStyle}
81
81
  onPress={handleOnTickedChild}
82
- isChecked={item.isChecked}
83
- id={item.id}
82
+ isChecked={i.isChecked}
83
+ id={i.id}
84
84
  titleStyle={styles.titleStyle}
85
- key={item.id}
85
+ key={i.id}
86
86
  idGroup={idGroup}
87
87
  />
88
88
  ));
@@ -95,9 +95,7 @@ const SensorItem = ({
95
95
  source={{ uri: icon_kit }}
96
96
  style={styles.viewLeft}
97
97
  tintColor={
98
- dataConfig.some((item) => item.isChecked)
99
- ? Colors.Primary
100
- : Colors.Gray
98
+ dataConfig.some((i) => i.isChecked) ? Colors.Primary : Colors.Gray
101
99
  }
102
100
  />
103
101
  <View style={styles.wrapRight}>
@@ -149,7 +149,7 @@ const InfoMemberUnit = memo(({ route }) => {
149
149
  screen: Routes.SharingSelectPermission,
150
150
  params: {
151
151
  unit: { id: unit?.id },
152
- type: 'share_device',
152
+ type: 'update_shared',
153
153
  member: memberInfo,
154
154
  },
155
155
  });