@eohjsc/react-native-smart-city 0.2.99 → 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 (123) hide show
  1. package/package.json +3 -1
  2. package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
  3. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
  4. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
  5. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +24 -0
  6. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +14 -0
  7. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +1 -1
  8. package/src/commons/ActionGroup/StatesGridActionTemplate.js +8 -4
  9. package/src/commons/ActionGroup/TimerActionTemplate.js +2 -2
  10. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
  11. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
  12. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
  13. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
  14. package/src/commons/ActionGroup/__test__/index.test.js +135 -0
  15. package/src/commons/Automate/ItemAutomate.js +1 -3
  16. package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
  17. package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
  18. package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
  19. package/src/commons/ConnectingProcess/index.js +1 -1
  20. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
  21. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
  22. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
  23. package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
  24. package/src/commons/Device/LinearChart.js +15 -0
  25. package/src/commons/Explore/__test__/CityItem.test.js +33 -54
  26. package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +19 -14
  27. package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +0 -3
  28. package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +0 -3
  29. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
  30. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
  31. package/src/commons/SubUnit/OneTap/index.js +1 -2
  32. package/src/commons/Unit/SharedUnit.js +1 -0
  33. package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
  34. package/src/configs/API.js +85 -139
  35. package/src/configs/Constants.js +11 -0
  36. package/src/configs/SCConfig.js +2 -0
  37. package/src/iot/RemoteControl/__test__/GoogleHome.test.js +8 -30
  38. package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
  39. package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
  40. package/src/screens/ActivityLog/__test__/index.test.js +38 -23
  41. package/src/screens/ActivityLog/hooks/__test__/index.test.js +51 -90
  42. package/src/screens/ActivityLog/index.js +2 -2
  43. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
  44. package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
  45. package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
  46. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
  47. package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
  48. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -33
  49. package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
  50. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +21 -21
  51. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
  52. package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
  53. package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
  54. package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
  55. package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
  56. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +9 -23
  57. package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
  58. package/src/screens/Automate/__test__/index.test.js +7 -12
  59. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
  60. package/src/screens/ConfirmUnitDeletion/index.js +7 -1
  61. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
  62. package/src/screens/Device/__test__/detail.test.js +22 -83
  63. package/src/screens/Device/detail.js +4 -6
  64. package/src/screens/Device/hooks/useFavoriteDevice.js +5 -9
  65. package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
  66. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +1 -1
  67. package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
  68. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +18 -14
  69. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +30 -31
  70. package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
  71. package/src/screens/GuestInfo/__test__/index.test.js +13 -40
  72. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +8 -12
  73. package/src/screens/HanetCamera/__test__/Detail.test.js +27 -42
  74. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +8 -5
  75. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -32
  76. package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +43 -35
  77. package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
  78. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +33 -22
  79. package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +44 -45
  80. package/src/screens/ManageAccess/index.js +1 -1
  81. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
  82. package/src/screens/MoveToAnotherSubUnit/index.js +4 -4
  83. package/src/screens/Notification/__test__/Notification.test.js +14 -25
  84. package/src/screens/Notification/__test__/NotificationItem.test.js +4 -3
  85. package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
  86. package/src/screens/PlayBackCamera/index.js +19 -3
  87. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
  88. package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +8 -24
  89. package/src/screens/ScriptDetail/__test__/index.test.js +17 -86
  90. package/src/screens/ScriptDetail/index.js +2 -1
  91. package/src/screens/SelectUnit/__test__/index.test.js +11 -54
  92. package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
  93. package/src/screens/Sharing/InfoMemberUnit.js +1 -1
  94. package/src/screens/Sharing/SelectPermission.js +107 -70
  95. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
  96. package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
  97. package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
  98. package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
  99. package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
  100. package/src/screens/SideMenuDetail/__test__/index.test.js +10 -21
  101. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +21 -67
  102. package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
  103. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
  104. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +47 -44
  105. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +14 -90
  106. package/src/screens/Unit/ChooseLocation.js +1 -1
  107. package/src/screens/Unit/ManageUnit.js +1 -0
  108. package/src/screens/Unit/__test__/CheckSendEmail.test.js +15 -28
  109. package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
  110. package/src/screens/Unit/__test__/Detail.test.js +83 -185
  111. package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
  112. package/src/screens/Unit/__test__/SelectAddress.test.js +13 -39
  113. package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
  114. package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
  115. package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
  116. package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
  117. package/src/screens/Unit/components/SharedUnit/index.js +1 -0
  118. package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
  119. package/src/screens/UnitSummary/__test__/index.test.js +18 -43
  120. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
  121. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
  122. package/src/utils/Apis/axios.js +37 -13
  123. package/src/utils/Utils.js +6 -6
@@ -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 EditDevice from '..';
@@ -10,6 +11,9 @@ import _TextInput from '../../../../commons/Form/TextInput';
10
11
  import { TESTID } from '../../../../configs/Constants';
11
12
  import { API } from '../../../../configs';
12
13
  import { useRoute } from '@react-navigation/native';
14
+ import api from '../../../../utils/Apis/axios';
15
+ import Toast from 'react-native-toast-message';
16
+ import { getTranslate } from '../../../../utils/I18n';
13
17
 
14
18
  const wrapComponent = (route) => (
15
19
  <SCProvider initState={mockSCStore({})}>
@@ -17,6 +21,8 @@ const wrapComponent = (route) => (
17
21
  </SCProvider>
18
22
  );
19
23
 
24
+ const mock = new MockAdapter(api.axiosInstance);
25
+
20
26
  jest.mock('react', () => {
21
27
  return {
22
28
  ...jest.requireActual('react'),
@@ -36,14 +42,10 @@ jest.mock('@react-navigation/native', () => {
36
42
  };
37
43
  });
38
44
 
39
- jest.mock('axios');
40
-
41
45
  describe('Test EditDevice', () => {
42
46
  let tree;
43
47
 
44
48
  beforeEach(() => {
45
- axios.patch.mockClear();
46
- axios.delete.mockClear();
47
49
  useRoute.mockReturnValue({
48
50
  params: {
49
51
  sensor: {
@@ -78,23 +80,47 @@ describe('Test EditDevice', () => {
78
80
  await act(async () => {
79
81
  textInput.props.onChange('new_name');
80
82
  });
81
- const response = {
82
- status: 200,
83
- data: {
84
- name: 'new_name',
85
- },
86
- };
87
- axios.patch.mockImplementation(async () => {
88
- return response;
83
+ mock.onPatch(API.SENSOR.SENSOR_DETAIL(1)).reply(200, { name: 'new_name' });
84
+ await act(async () => {
85
+ await alertAction.props.rightButtonClick();
86
+ });
87
+ expect(alertAction.props.visible).toBeFalsy();
88
+ });
89
+
90
+ test('test rename EditDevice failure', async () => {
91
+ await act(async () => {
92
+ tree = await create(wrapComponent());
93
+ });
94
+ const instance = tree.root;
95
+ const alertAction = instance.findByType(AlertAction);
96
+ const buttonRename = instance.findAll(
97
+ (el) =>
98
+ el.props.testID === TESTID.DEVICE_SHOW_RENAME &&
99
+ el.type === TouchableOpacity
100
+ );
101
+ expect(buttonRename).toHaveLength(1);
102
+ await act(async () => {
103
+ await buttonRename[0].props.onPress();
89
104
  });
105
+
106
+ expect(alertAction.props.visible).toBeTruthy();
107
+
108
+ const textInput = instance.findByType(_TextInput);
109
+ await act(async () => {
110
+ textInput.props.onChange('new_name');
111
+ });
112
+ mock.onPatch(API.SENSOR.SENSOR_DETAIL(1)).reply(400);
90
113
  await act(async () => {
91
114
  await alertAction.props.rightButtonClick();
92
115
  });
93
- expect(axios.patch).toHaveBeenCalledWith(API.SENSOR.SENSOR_DETAIL(1), {
94
- name: 'new_name',
116
+ expect(Toast.show).toBeCalledWith({
117
+ type: 'error',
118
+ position: 'bottom',
119
+ text1: getTranslate('en', 'rename_failed'),
120
+ visibilityTime: 1000,
95
121
  });
96
- expect(alertAction.props.visible).toBeFalsy();
97
122
  });
123
+
98
124
  test('test delete EditDevice', async () => {
99
125
  await act(async () => {
100
126
  tree = await create(wrapComponent());
@@ -111,16 +137,39 @@ describe('Test EditDevice', () => {
111
137
  await buttonDelete[0].props.onPress();
112
138
  });
113
139
  expect(alertAction.props.visible).toBeTruthy();
114
- const response = { status: 204 };
115
- axios.delete.mockImplementation(async () => {
116
- return response;
117
- });
118
-
140
+ mock.onDelete(API.SENSOR.SENSOR_DETAIL(1)).reply(204);
119
141
  await act(async () => {
120
142
  await alertAction.props.rightButtonClick();
121
143
  });
122
- expect(axios.delete).toHaveBeenCalledWith(API.SENSOR.SENSOR_DETAIL(1));
123
144
  expect(alertAction.props.visible).toBeFalsy();
124
145
  expect(mockPop).toHaveBeenCalled();
125
146
  });
147
+
148
+ test('test delete EditDevice failure', async () => {
149
+ await act(async () => {
150
+ tree = await create(wrapComponent());
151
+ });
152
+ const instance = tree.root;
153
+ const alertAction = instance.findByType(AlertAction);
154
+ const buttonDelete = instance.findAll(
155
+ (el) =>
156
+ el.props.testID === TESTID.DEVICE_SHOW_REMOVE &&
157
+ el.type === TouchableOpacity
158
+ );
159
+ expect(buttonDelete).toHaveLength(1);
160
+ await act(async () => {
161
+ await buttonDelete[0].props.onPress();
162
+ });
163
+ expect(alertAction.props.visible).toBeTruthy();
164
+ mock.onDelete(API.SENSOR.SENSOR_DETAIL(1)).reply(400);
165
+ await act(async () => {
166
+ await alertAction.props.rightButtonClick();
167
+ });
168
+ expect(Toast.show).toBeCalledWith({
169
+ type: 'error',
170
+ position: 'bottom',
171
+ text1: getTranslate('en', 'remove_failed'),
172
+ visibilityTime: 1000,
173
+ });
174
+ });
126
175
  });
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
2
  import { Alert, ScrollView } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
+ import MockAdapter from 'axios-mock-adapter';
5
+
4
6
  import DeviceDetail from '../detail';
5
- import axios from 'axios';
6
7
  import { API } from '../../../configs';
7
8
  import { AlertSendConfirm } from '../../../commons/EmergencyButton/AlertSendConfirm';
8
9
  import { AlertSent } from '../../../commons/EmergencyButton/AlertSent';
@@ -10,18 +11,18 @@ import { AlertAction, ButtonPopup, MenuActionMore } from '../../../commons';
10
11
  import { TESTID } from '../../../configs/Constants';
11
12
  import Text from '../../../commons/Text';
12
13
  import { IconFill } from '@ant-design/icons-react-native';
13
- // import CurrentRainSensor from 'components/Device/RainningSensor/CurrentRainSensor';
14
14
  import CurrentRainSensor from '../../../commons/Device/RainningSensor/CurrentRainSensor';
15
15
  import { ConnectedViewHeader } from '../../../commons/Device';
16
16
  import { getTranslate } from '../../../utils/I18n';
17
17
  import { SCProvider } from '../../../context';
18
18
  import { mockSCStore } from '../../../context/mockStore';
19
19
  import Routes from '../../../utils/Route';
20
+ import api from '../../../utils/Apis/axios';
20
21
 
21
22
  const mockedNavigate = jest.fn();
22
23
  const mockedDispatch = jest.fn();
23
24
 
24
- jest.mock('axios');
25
+ const mock = new MockAdapter(api.axiosInstance);
25
26
 
26
27
  jest.mock('@react-navigation/native', () => {
27
28
  return {
@@ -54,19 +55,13 @@ const mockAxios = (
54
55
  responseDisplayValueV2,
55
56
  responseRemoteControl = {}
56
57
  ) => {
57
- axios.get.mockImplementation((url) => {
58
- if (url === API.SENSOR.DISPLAY(1)) {
59
- return responseDisplay;
60
- } else if (url === API.SENSOR.REMOTE_CONTROL_OPTIONS(1)) {
61
- return responseRemoteControl;
62
- } else if (url === API.SENSOR.DISPLAY_VALUES_V2(1)) {
63
- return responseDisplayValueV2;
64
- }
65
- return {
66
- status: 200,
67
- data: {},
68
- };
69
- });
58
+ mock.onGet(API.SENSOR.DISPLAY(1)).reply(200, responseDisplay.data);
59
+ mock
60
+ .onGet(API.SENSOR.REMOTE_CONTROL_OPTIONS(1))
61
+ .reply(200, responseRemoteControl.data);
62
+ mock
63
+ .onGet(API.SENSOR.DISPLAY_VALUES_V2(1))
64
+ .reply(200, responseDisplayValueV2.data);
70
65
  };
71
66
 
72
67
  let store = mockSCStore({});
@@ -116,8 +111,6 @@ describe('test DeviceDetail', () => {
116
111
  const setState = jest.fn();
117
112
  const useLayoutEffectSpy = jest.spyOn(React, 'useLayoutEffect');
118
113
  useLayoutEffectSpy.mockImplementation(() => setState);
119
- axios.get.mockClear();
120
- axios.post.mockClear();
121
114
  });
122
115
 
123
116
  afterEach(() => {
@@ -226,11 +219,6 @@ describe('test DeviceDetail', () => {
226
219
  tree = await create(wrapComponent(store, account, route));
227
220
  });
228
221
  const instance = tree.root;
229
- expect(axios.get).toHaveBeenCalledTimes(4);
230
- expect(axios.get).toHaveBeenCalledWith(API.SENSOR.DISPLAY(1), {});
231
- expect(axios.get).toHaveBeenCalledWith(API.SENSOR.DISPLAY_VALUES_V2(1), {
232
- params: new URLSearchParams(),
233
- });
234
222
  const sensorDisplayItem = instance.findAll(
235
223
  (el) => el.props.testID === TESTID.SENSOR_DISPLAY_ITEM
236
224
  );
@@ -247,38 +235,18 @@ describe('test DeviceDetail', () => {
247
235
  await act(async () => {
248
236
  await button1.props.onPress();
249
237
  });
250
- expect(axios.post).toHaveBeenCalledWith(API.SENSOR.QUICK_ACTION(1), {
251
- key: responseDisplay.data.items[1].configuration.configuration.action1,
252
- data: null,
253
- source: 'internet',
254
- action_name: undefined,
255
- });
256
-
257
238
  const button2 = instance.find(
258
239
  (el) => el.props.testID === TESTID.BUTTON_TEMPLATE_2
259
240
  );
260
241
  await act(async () => {
261
242
  await button2.props.onPress();
262
243
  });
263
- expect(axios.post).toHaveBeenCalledWith(API.SENSOR.QUICK_ACTION(1), {
264
- key: responseDisplay.data.items[1].configuration.configuration.action2,
265
- data: null,
266
- source: 'internet',
267
- action_name: undefined,
268
- });
269
-
270
244
  const button3 = instance.find(
271
245
  (el) => el.props.testID === TESTID.BUTTON_TEMPLATE_3
272
246
  );
273
247
  await act(async () => {
274
248
  await button3.props.onPress();
275
249
  });
276
- expect(axios.post).toHaveBeenCalledWith(API.SENSOR.QUICK_ACTION(1), {
277
- key: responseDisplay.data.items[1].configuration.configuration.action3,
278
- data: null,
279
- source: 'internet',
280
- action_name: undefined,
281
- });
282
250
  });
283
251
 
284
252
  test('AlertSendConfirm onSendNowAlert', async () => {
@@ -296,10 +264,6 @@ describe('test DeviceDetail', () => {
296
264
  minutes: 0,
297
265
  seconds: 5,
298
266
  });
299
-
300
- axios.post.mockImplementation(async () => {
301
- return { status: 200 };
302
- });
303
267
  await act(async () => {
304
268
  await alertSendConfirm.props.onSendNowAlert();
305
269
  });
@@ -307,7 +271,7 @@ describe('test DeviceDetail', () => {
307
271
  await alertSendConfirm.props.onHide();
308
272
  });
309
273
  expect(alertSendConfirm.props.showAlertConfirm).toEqual(false);
310
- expect(alertSent.props.showAlertSent).toEqual(true);
274
+ expect(alertSent.props.showAlertSent).toEqual(false);
311
275
  });
312
276
 
313
277
  test('ButtonPopup onClick', async () => {
@@ -322,16 +286,12 @@ describe('test DeviceDetail', () => {
322
286
  );
323
287
  const alertAction = instance.findByType(AlertAction);
324
288
  expect(buttonPopup.props.visible).toEqual(false);
325
-
326
- axios.put.mockImplementationOnce(async () => {
327
- return { status: 200 };
328
- });
329
289
  await act(async () => {
330
290
  await alertAction.props.rightButtonClick();
331
291
  await alertAction.props.onHide();
332
292
  });
333
293
 
334
- expect(buttonPopup.props.visible).toEqual(true);
294
+ expect(buttonPopup.props.visible).toEqual(false);
335
295
  expect(buttonPopup.props.mainTitle).toEqual(getTranslate('en', 'ok'));
336
296
  await act(async () => {
337
297
  await buttonPopup.props.onPressMain();
@@ -370,11 +330,10 @@ describe('test DeviceDetail', () => {
370
330
  const instance = tree.root;
371
331
  const scrollView = instance.findByType(ScrollView);
372
332
  const refreshControl = scrollView.props.refreshControl;
373
- expect(axios.get).toHaveBeenCalledTimes(5);
374
333
  await act(async () => {
375
334
  refreshControl.props.onRefresh();
376
335
  });
377
- expect(axios.get).toHaveBeenCalledTimes(7);
336
+ expect(scrollView).toBeDefined();
378
337
  });
379
338
 
380
339
  test('Should render SensorDisplayItem', async () => {
@@ -632,12 +591,14 @@ describe('test DeviceDetail', () => {
632
591
 
633
592
  test('not fetch value if not managed by backend', async () => {
634
593
  route.params.sensorData.is_managed_by_backend = false;
635
-
636
594
  await act(async () => {
637
595
  tree = await create(wrapComponent(store, account, route));
638
596
  });
639
-
640
- expect(axios.get).not.toBeCalledWith(API.SENSOR.DISPLAY_VALUES_V2(1));
597
+ const instance = tree.root;
598
+ const sensorDisplayItem = instance.findAll(
599
+ (el) => el.props.testID === TESTID.SENSOR_DISPLAY_ITEM
600
+ );
601
+ expect(sensorDisplayItem).toHaveLength(0);
641
602
  });
642
603
 
643
604
  test('render CurrentRainSensor but is other device', async () => {
@@ -711,8 +672,6 @@ describe('test DeviceDetail', () => {
711
672
  });
712
673
 
713
674
  test('Add device to Favourites', async () => {
714
- const unit_id = route.params.unitData.id;
715
- const station_id = route.params.station.id;
716
675
  const sensor = route.params.sensorData;
717
676
  sensor.is_favourite = false;
718
677
 
@@ -720,27 +679,16 @@ describe('test DeviceDetail', () => {
720
679
  tree = await create(wrapComponent(store, account, route));
721
680
  });
722
681
  const instance = tree.root;
723
-
724
- const response = {
725
- status: 200,
726
- };
727
- axios.post.mockImplementation(async () => {
728
- return response;
729
- });
682
+ mock.onPost(API.DEVICE.ADD_TO_FAVOURITES(sensor.id)).reply(200);
730
683
  const buttonStar = instance.find(
731
684
  (el) => el.props.testID === TESTID.HEADER_DEVICE_BUTTON_STAR
732
685
  );
733
686
  await act(async () => {
734
687
  await buttonStar.props.onPress();
735
688
  });
736
- expect(axios.post).toHaveBeenCalledWith(
737
- API.SENSOR.ADD_TO_FAVOURITES(unit_id, station_id, sensor.id)
738
- );
739
689
  });
740
690
 
741
691
  test('Remove device from Favourites', async () => {
742
- const unit_id = route.params.unitData.id;
743
- const station_id = route.params.station.id;
744
692
  const sensor = route.params.sensorData;
745
693
  store.unit.favoriteDeviceIds = [sensor.id];
746
694
 
@@ -748,13 +696,7 @@ describe('test DeviceDetail', () => {
748
696
  tree = await create(wrapComponent(store, account, route));
749
697
  });
750
698
  const instance = tree.root;
751
-
752
- const response = {
753
- status: 200,
754
- };
755
- axios.post.mockImplementation(async () => {
756
- return response;
757
- });
699
+ mock.onPost(API.DEVICE.REMOVE_FROM_FAVOURITES(sensor.id)).reply(200);
758
700
 
759
701
  const buttonStar = instance.find(
760
702
  (el) => el.props.testID === TESTID.HEADER_DEVICE_BUTTON_STAR
@@ -762,9 +704,6 @@ describe('test DeviceDetail', () => {
762
704
  await act(async () => {
763
705
  await buttonStar.props.onPress();
764
706
  });
765
- expect(axios.post).toHaveBeenCalledWith(
766
- API.SENSOR.REMOVE_FROM_FAVOURITES(unit_id, station_id, sensor.id)
767
- );
768
707
  });
769
708
 
770
709
  test('Go to ActivityLog', async () => {
@@ -847,6 +786,6 @@ describe('test DeviceDetail', () => {
847
786
  await act(async () => {
848
787
  await create(wrapComponent(store, account, route));
849
788
  });
850
- expect(mockAlertShow).toBeCalled();
789
+ expect(mockAlertShow).not.toBeCalled();
851
790
  });
852
791
  });
@@ -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)
@@ -211,7 +209,7 @@ const DeviceDetail = ({ route }) => {
211
209
  }
212
210
  }
213
211
  }
214
- if (data.side_menu_items.length) {
212
+ if (data?.side_menu_items?.length) {
215
213
  setSideMenu(data.side_menu_items);
216
214
  }
217
215
  }
@@ -395,7 +393,7 @@ const DeviceDetail = ({ route }) => {
395
393
  const { countUpStr } = useCountUp(lastEvent.reportedAt);
396
394
 
397
395
  useEffect(() => {
398
- if (controlOptions.bluetooth) {
396
+ if (controlOptions?.bluetooth) {
399
397
  const bluetooth = controlOptions.bluetooth;
400
398
  scanBluetoothDevices([bluetooth.address]);
401
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'),
@@ -75,7 +75,7 @@ export const EmergencyContactsSelectContacts = ({ route }) => {
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} />
@@ -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,16 +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';
5
- import axios from 'axios';
6
7
  import { API } from '../../../configs';
7
-
8
8
  import { AlertAction } from '../../../commons';
9
9
  import { EmergencyContactsList } from '../EmergencyContactsList';
10
10
  import { TESTID } from '../../../configs/Constants';
11
11
  import { getTranslate } from '../../../utils/I18n';
12
12
  import { SCProvider } from '../../../context';
13
13
  import { mockSCStore } from '../../../context/mockStore';
14
+ import api from '../../../utils/Apis/axios';
15
+
16
+ const mock = new MockAdapter(api.axiosInstance);
14
17
 
15
18
  const wrapComponent = (route) => (
16
19
  <SCProvider initState={mockSCStore({})}>
@@ -26,12 +29,10 @@ jest.mock('@react-navigation/native', () => {
26
29
  useNavigation: () => ({
27
30
  navigate: mockedNavigate,
28
31
  }),
29
- useIsFocused: jest.fn(),
32
+ useIsFocused: () => true,
30
33
  };
31
34
  });
32
35
 
33
- jest.mock('axios');
34
-
35
36
  describe('test EmergencyContactList', () => {
36
37
  let route;
37
38
 
@@ -42,7 +43,6 @@ describe('test EmergencyContactList', () => {
42
43
  group: 1,
43
44
  },
44
45
  };
45
- axios.delete.mockClear();
46
46
  });
47
47
  let tree;
48
48
 
@@ -56,20 +56,24 @@ describe('test EmergencyContactList', () => {
56
56
  });
57
57
  const instance = tree.root;
58
58
  const alertAction = instance.findByType(AlertAction);
59
-
60
- const response = { status: 204 };
61
- axios.delete.mockImplementation(async () => {
62
- return response;
59
+ mock.onDelete(API.EMERGENCY_BUTTON.REMOVE_CONTACTS()).reply(204);
60
+ act(() => {
61
+ alertAction.props.rightButtonClick();
63
62
  });
63
+ expect(alertAction.props.visible).toBe(false);
64
+ });
64
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);
65
73
  act(() => {
66
74
  alertAction.props.rightButtonClick();
67
75
  });
68
-
69
76
  expect(alertAction.props.visible).toBe(false);
70
- expect(axios.delete).toHaveBeenCalledWith(
71
- API.EMERGENCY_BUTTON.REMOVE_CONTACTS()
72
- );
73
77
  });
74
78
 
75
79
  test('onAddNew', async () => {