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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/README.md +35 -14
  2. package/package.json +4 -2
  3. package/src/commons/Action/ItemQuickAction.js +5 -2
  4. package/src/commons/ActionGroup/ColorPickerTemplate.js +1 -1
  5. package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
  6. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +12 -4
  7. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
  8. package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLock.js +7 -4
  9. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
  10. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +24 -0
  11. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +14 -0
  12. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/index.js +1 -0
  13. package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplate.js +10 -10
  14. package/src/commons/ActionGroup/OnOffTemplate/index.js +18 -15
  15. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +9 -3
  16. package/src/commons/ActionGroup/SliderRangeTemplate.js +1 -1
  17. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +4 -1
  18. package/src/commons/ActionGroup/StatesGridActionTemplate.js +22 -8
  19. package/src/commons/ActionGroup/TimerActionTemplate.js +11 -3
  20. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +13 -9
  21. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
  22. package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +14 -14
  23. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +53 -78
  24. package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +36 -20
  25. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
  26. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
  27. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
  28. package/src/commons/ActionGroup/__test__/index.test.js +135 -0
  29. package/src/commons/Auth/AccountList.js +1 -1
  30. package/src/commons/Automate/ItemAutomate.js +1 -3
  31. package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
  32. package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
  33. package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
  34. package/src/commons/ConnectingProcess/index.js +1 -1
  35. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
  36. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
  37. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
  38. package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
  39. package/src/commons/Device/HistoryChart.js +4 -0
  40. package/src/commons/Device/LinearChart.js +15 -0
  41. package/src/commons/Device/PMSensor/PMSensorIndicatior.js +16 -12
  42. package/src/commons/Device/PMSensor/PMSensorIndicatorStyles.js +3 -0
  43. package/src/commons/Device/WaterQualitySensor/ListQualityIndicator.js +1 -0
  44. package/src/commons/Explore/__test__/CityItem.test.js +33 -54
  45. package/src/commons/FieldTemplate/ChooseUserField/ChooseFieldStyles.js +25 -0
  46. package/src/commons/FieldTemplate/ChooseUserField/ChoosePopup.js +96 -0
  47. package/src/commons/FieldTemplate/ChooseUserField/ChoosePopupStyles.js +39 -0
  48. package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +118 -0
  49. package/src/commons/FieldTemplate/ChooseUserField/index.js +62 -0
  50. package/src/commons/FieldTemplate/PasscodeField/PasscodeFieldStyles.js +30 -0
  51. package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +90 -0
  52. package/src/commons/FieldTemplate/PasscodeField/index.js +43 -0
  53. package/src/commons/FieldTemplate/ScheduleField/ScheduleFieldStyles.js +13 -0
  54. package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +179 -0
  55. package/src/commons/FieldTemplate/ScheduleField/index.js +176 -0
  56. package/src/commons/FullLoading/index.js +2 -1
  57. package/src/commons/MenuActionAddnew/index.js +1 -0
  58. package/src/commons/MenuActionList/index.js +1 -0
  59. package/src/commons/MenuActionMore/index.js +1 -1
  60. package/src/commons/PreventAccess/__test__/PreventAccess.test.js +62 -0
  61. package/src/commons/PreventAccess/index.js +9 -1
  62. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
  63. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
  64. package/src/commons/SubUnit/OneTap/index.js +1 -2
  65. package/src/commons/Unit/SharedUnit.js +1 -0
  66. package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
  67. package/src/commons/WheelDateTimePicker/index.js +2 -1
  68. package/src/configs/API.js +87 -138
  69. package/src/configs/Constants.js +27 -1
  70. package/src/configs/SCConfig.js +2 -0
  71. package/src/iot/RemoteControl/__test__/GoogleHome.test.js +8 -30
  72. package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
  73. package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
  74. package/src/navigations/UnitStack.js +8 -0
  75. package/src/screens/AQIGuide/index.js +1 -1
  76. package/src/screens/ActivityLog/FilterPopup.js +2 -0
  77. package/src/screens/ActivityLog/__test__/index.test.js +38 -23
  78. package/src/screens/ActivityLog/hooks/__test__/index.test.js +51 -90
  79. package/src/screens/ActivityLog/index.js +2 -2
  80. package/src/screens/AddCommon/SelectSubUnit.js +1 -0
  81. package/src/screens/AddCommon/SelectUnit.js +1 -0
  82. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
  83. package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
  84. package/src/screens/AddLocationMaps/index.js +4 -1
  85. package/src/screens/AddNewAction/SelectSensorDevices.js +8 -2
  86. package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
  87. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
  88. package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +3 -1
  89. package/src/screens/AddNewAutoSmart/index.js +5 -2
  90. package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
  91. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -33
  92. package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
  93. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +21 -21
  94. package/src/screens/AddNewDevice/index.js +1 -0
  95. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +4 -1
  96. package/src/screens/AddNewGateway/SelectGateway.js +1 -0
  97. package/src/screens/AddNewGateway/SetupGatewayWifi.js +1 -0
  98. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
  99. package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
  100. package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
  101. package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
  102. package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
  103. package/src/screens/AddNewGateway/index.js +1 -0
  104. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +10 -24
  105. package/src/screens/AddNewOneTap/index.js +3 -2
  106. package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
  107. package/src/screens/Automate/__test__/index.test.js +7 -12
  108. package/src/screens/Automate/index.js +2 -0
  109. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
  110. package/src/screens/ConfirmUnitDeletion/index.js +7 -1
  111. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
  112. package/src/screens/Device/__test__/detail.test.js +23 -84
  113. package/src/screens/Device/detail.js +31 -8
  114. package/src/screens/Device/hooks/useFavoriteDevice.js +5 -9
  115. package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
  116. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +6 -3
  117. package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
  118. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +20 -2
  119. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +40 -23
  120. package/src/screens/EmergencySetting/index.js +4 -1
  121. package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
  122. package/src/screens/Explore/index.js +2 -0
  123. package/src/screens/GuestInfo/__test__/index.test.js +14 -41
  124. package/src/screens/GuestInfo/components/RecurringDetail.js +1 -0
  125. package/src/screens/GuestInfo/components/TemporaryDetail.js +2 -2
  126. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +8 -12
  127. package/src/screens/HanetCamera/__test__/Detail.test.js +27 -42
  128. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +8 -5
  129. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -32
  130. package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +43 -35
  131. package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
  132. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +33 -22
  133. package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +44 -45
  134. package/src/screens/ManageAccess/index.js +2 -1
  135. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
  136. package/src/screens/MoveToAnotherSubUnit/index.js +5 -5
  137. package/src/screens/Notification/__test__/Notification.test.js +14 -25
  138. package/src/screens/Notification/__test__/NotificationItem.test.js +4 -3
  139. package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
  140. package/src/screens/PlayBackCamera/index.js +19 -3
  141. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
  142. package/src/screens/ScanChipQR/components/QRScan/index.js +1 -0
  143. package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +8 -24
  144. package/src/screens/ScriptDetail/__test__/index.test.js +17 -86
  145. package/src/screens/ScriptDetail/index.js +5 -4
  146. package/src/screens/SelectUnit/__test__/index.test.js +12 -55
  147. package/src/screens/SelectUnit/index.js +5 -2
  148. package/src/screens/SetSchedule/index.js +6 -2
  149. package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
  150. package/src/screens/SharedUnit/index.js +2 -0
  151. package/src/screens/Sharing/InfoMemberUnit.js +1 -1
  152. package/src/screens/Sharing/MemberList.js +12 -11
  153. package/src/screens/Sharing/SelectPermission.js +107 -70
  154. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
  155. package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
  156. package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
  157. package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
  158. package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
  159. package/src/screens/Sharing/hooks/index.js +3 -0
  160. package/src/screens/SideMenuDetail/SideMenuDetailStyles.js +28 -0
  161. package/src/screens/SideMenuDetail/__test__/index.test.js +154 -0
  162. package/src/screens/SideMenuDetail/index.js +149 -0
  163. package/src/screens/SmartIr/components/SelectBrand.js +1 -1
  164. package/src/screens/SubUnit/ManageSubUnit.js +1 -0
  165. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +21 -67
  166. package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
  167. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
  168. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +47 -44
  169. package/src/screens/SyncLGDevice/AddLGDevice.js +1 -0
  170. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +14 -90
  171. package/src/screens/TDSGuide/index.js +4 -1
  172. package/src/screens/UVIndexGuide/index.js +1 -1
  173. package/src/screens/Unit/ChooseLocation.js +1 -1
  174. package/src/screens/Unit/ManageUnit.js +1 -0
  175. package/src/screens/Unit/SelectAddress.js +4 -1
  176. package/src/screens/Unit/Station/index.js +1 -0
  177. package/src/screens/Unit/Summaries.js +1 -1
  178. package/src/screens/Unit/__test__/CheckSendEmail.test.js +15 -28
  179. package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
  180. package/src/screens/Unit/__test__/Detail.test.js +83 -185
  181. package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
  182. package/src/screens/Unit/__test__/SelectAddress.test.js +13 -39
  183. package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
  184. package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
  185. package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
  186. package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
  187. package/src/screens/Unit/components/SharedUnit/index.js +1 -0
  188. package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
  189. package/src/screens/UnitSummary/__test__/index.test.js +38 -31
  190. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
  191. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
  192. package/src/screens/WaterQualityGuide/index.js +1 -1
  193. package/src/utils/Apis/axios.js +37 -13
  194. package/src/utils/I18n/translations/en.json +1 -0
  195. package/src/utils/I18n/translations/vi.json +1 -0
  196. package/src/utils/Route/index.js +1 -0
  197. package/src/utils/Utils.js +6 -6
@@ -1,7 +1,7 @@
1
1
  import React, { useState } from 'react';
2
2
  import { FlatList, TouchableOpacity } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
- import axios from 'axios';
4
+ import MockAdapter from 'axios-mock-adapter';
5
5
 
6
6
  import Automate from '../';
7
7
  import { SCProvider } from '../../../context';
@@ -10,8 +10,10 @@ import ItemOneTap from '../../../commons/SubUnit/OneTap/ItemOneTap';
10
10
  import ItemAddNew from '../../../commons/Device/ItemAddNew';
11
11
  import Routes from '../../../utils/Route';
12
12
  import { TESTID } from '../../../configs/Constants';
13
+ import api from '../../../utils/Apis/axios';
14
+ import { API } from '../../../configs';
13
15
 
14
- jest.mock('axios');
16
+ const mock = new MockAdapter(api.axiosInstance);
15
17
  const mockedNavigate = jest.fn();
16
18
  const mockSetState = jest.fn();
17
19
 
@@ -46,7 +48,6 @@ describe('Test Automate', () => {
46
48
  let tree;
47
49
 
48
50
  beforeEach(() => {
49
- axios.get.mockClear();
50
51
  mockedNavigate.mockClear();
51
52
  mockSetState.mockClear();
52
53
  });
@@ -86,9 +87,7 @@ describe('Test Automate', () => {
86
87
  },
87
88
  ],
88
89
  };
89
- await axios.get.mockImplementation(async () => {
90
- return response;
91
- });
90
+ mock.onGet(API.AUTOMATE.GET_SMART()).reply(200, response.data);
92
91
 
93
92
  useState.mockImplementation(() => [false, mockSetState]);
94
93
  useState.mockImplementation(() => [response.data, mockSetState]);
@@ -141,9 +140,7 @@ describe('Test Automate', () => {
141
140
  { automates: [], unit_id: 3, unit_name: 'La Vida' },
142
141
  ],
143
142
  };
144
- await axios.get.mockImplementation(async () => {
145
- return response;
146
- });
143
+ mock.onGet(API.AUTOMATE.GET_SMART()).reply(200, response.data);
147
144
 
148
145
  useState.mockImplementation(() => [false, mockSetState]);
149
146
  useState.mockImplementation(() => [response.data, mockSetState]);
@@ -199,9 +196,7 @@ describe('Test Automate', () => {
199
196
  { automates: [], unit_id: 3, unit_name: 'La Vida' },
200
197
  ],
201
198
  };
202
- await axios.get.mockImplementation(async () => {
203
- return response;
204
- });
199
+ mock.onGet(API.AUTOMATE.GET_SMART()).reply(200, response.data);
205
200
 
206
201
  useState.mockImplementation(() => [false, mockSetState]);
207
202
  useState.mockImplementation(() => [response.data, mockSetState]);
@@ -147,6 +147,7 @@ const Automate = () => {
147
147
  showsHorizontalScrollIndicator={false}
148
148
  contentContainerStyle={styles.contentContainerStyle2}
149
149
  ListFooterComponent={renderListFooterComponent(type, unit_id)}
150
+ scrollIndicatorInsets={{ right: 1 }}
150
151
  />
151
152
  </View>
152
153
  );
@@ -189,6 +190,7 @@ const Automate = () => {
189
190
  contentContainerStyle={styles.contentContainerStyle}
190
191
  refreshing={false}
191
192
  onRefresh={getAutomates}
193
+ scrollIndicatorInsets={{ right: 1 }}
192
194
  />
193
195
  </View>
194
196
  );
@@ -1,43 +1,49 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
- import axios from 'axios';
4
3
 
5
4
  import { SCProvider } from '../../../context';
6
5
  import { mockSCStore } from '../../../context/mockStore';
7
6
  import ConfirmUnitDeletion from '../index';
8
7
  import _TextInput from '../../../commons/Form/TextInput';
8
+ import { TouchableOpacity } from 'react-native';
9
+ import { TESTID } from '../../../configs/Constants';
10
+ import API from '../../../configs/API';
11
+ import api from '../../../utils/Apis/axios';
12
+ import MockAdapter from 'axios-mock-adapter';
9
13
 
14
+ const mock = new MockAdapter(api.axiosInstance);
10
15
  const wrapComponent = (route, navigation) => (
11
16
  <SCProvider initState={mockSCStore({})}>
12
17
  <ConfirmUnitDeletion route={route} />
13
18
  </SCProvider>
14
19
  );
15
20
 
16
- const mockedNavigate = jest.fn();
17
-
21
+ const mockNavigate = jest.fn();
22
+ const mockGoBack = jest.fn();
18
23
  jest.mock('@react-navigation/native', () => {
19
24
  return {
20
25
  ...jest.requireActual('@react-navigation/native'),
21
26
  useNavigation: () => ({
22
- goBack: mockedNavigate,
27
+ navigate: mockNavigate,
28
+ goBack: mockGoBack,
23
29
  }),
24
30
  };
25
31
  });
26
32
 
33
+ const mockSetState = jest.fn();
27
34
  jest.mock('react', () => {
28
35
  return {
29
36
  ...jest.requireActual('react'),
37
+ useState: jest.fn((init) => [init, mockSetState]),
30
38
  memo: (x) => x,
31
39
  };
32
40
  });
33
41
 
34
- jest.mock('axios');
35
42
  describe('Test ConfirmUnitDeletion', () => {
36
43
  let tree;
37
44
  let route;
38
45
 
39
46
  beforeAll(() => {
40
- axios.get.mockClear();
41
47
  route = {
42
48
  params: {
43
49
  unit: {
@@ -48,14 +54,36 @@ describe('Test ConfirmUnitDeletion', () => {
48
54
  });
49
55
 
50
56
  test('test render ConfirmUnitDeletion', async () => {
57
+ useState.mockImplementationOnce((init) => ['new_name', mockSetState]);
58
+ await act(async () => {
59
+ tree = await renderer.create(wrapComponent(route));
60
+ });
61
+ const instance = tree.root;
62
+
63
+ const textInput = instance.findByType(_TextInput);
64
+ await act(async () => {
65
+ textInput.props.onChange();
66
+ });
67
+ });
68
+ test('Onpress button ConfirmUnitDeletion ', async () => {
69
+ useState.mockImplementationOnce((init) => ['YES', mockSetState]);
51
70
  await act(async () => {
52
71
  tree = await renderer.create(wrapComponent(route));
53
72
  });
54
73
  const instance = tree.root;
55
74
 
75
+ const touchableOpacity = instance.find(
76
+ (el) =>
77
+ el.props.testID === TESTID.CONFIRM_UNIT_DELETION_BUTTON &&
78
+ el.type === TouchableOpacity
79
+ );
56
80
  const textInput = instance.findByType(_TextInput);
57
81
  await act(async () => {
58
- textInput.props.onChange('new_name');
82
+ touchableOpacity.props.onPress();
83
+ });
84
+ await act(async () => {
85
+ textInput.props.onChange();
59
86
  });
87
+ mock.onDelete(API.UNIT.MANAGE_UNIT(1)).reply(204);
60
88
  });
61
89
  });
@@ -12,6 +12,7 @@ import { Button } from '../../commons';
12
12
  import Routes from '../../utils/Route';
13
13
  import { axiosDelete } from '../../utils/Apis/axios';
14
14
  import { ToastBottomHelper } from '../../utils/Utils';
15
+ import { TESTID } from '../../configs/Constants';
15
16
 
16
17
  const ConfirmUnitDeletion = ({ route }) => {
17
18
  const t = useTranslations();
@@ -55,7 +56,12 @@ const ConfirmUnitDeletion = ({ route }) => {
55
56
  textInputStyle={styles.textInput}
56
57
  />
57
58
  <View style={styles.buttonWrap}>
58
- <Button type="auth" title={t('done')} onPress={onSendPress} />
59
+ <Button
60
+ type="auth"
61
+ title={t('done')}
62
+ onPress={onSendPress}
63
+ testID={TESTID.CONFIRM_UNIT_DELETION_BUTTON}
64
+ />
59
65
  </View>
60
66
  </WrapHeaderScrollable>
61
67
  );
@@ -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(() => {
@@ -192,6 +185,7 @@ describe('test DeviceDetail', () => {
192
185
  type: 'action',
193
186
  },
194
187
  ],
188
+ side_menu_items: [{ id: 1, order: 1, name: 'Setup generate passcode' }],
195
189
  };
196
190
  test('render DeviceDetail render SensorDisplayItem', async () => {
197
191
  const responseDisplay = {
@@ -225,12 +219,6 @@ describe('test DeviceDetail', () => {
225
219
  tree = await create(wrapComponent(store, account, route));
226
220
  });
227
221
  const instance = tree.root;
228
- expect(axios.get).toHaveBeenCalledTimes(4);
229
- expect(axios.get).toHaveBeenCalledWith(API.SENSOR.DISPLAY(1), {});
230
- expect(axios.get).toHaveBeenCalledWith(
231
- API.SENSOR.REMOTE_CONTROL_OPTIONS(1),
232
- {}
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
  });