@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,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import renderer, { 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,8 @@ import ListSmartAccount from '../SmartAccount';
8
8
  import { SmartAccountItem } from '../SmartAccountItem';
9
9
  import { AlertAction, MenuActionMore } from '../../../commons';
10
10
  import Routes from '../../../utils/Route';
11
+ import api from '../../../utils/Apis/axios';
12
+ import { API } from '../../../configs';
11
13
 
12
14
  const wrapComponent = (route, navigation) => (
13
15
  <SCProvider initState={mockSCStore({})}>
@@ -15,6 +17,8 @@ const wrapComponent = (route, navigation) => (
15
17
  </SCProvider>
16
18
  );
17
19
 
20
+ const mock = new MockAdapter(api.axiosInstance);
21
+
18
22
  const mockNavigate = jest.fn();
19
23
  jest.mock('@react-navigation/native', () => {
20
24
  return {
@@ -33,7 +37,6 @@ jest.mock('react', () => {
33
37
  };
34
38
  });
35
39
 
36
- jest.mock('axios');
37
40
  describe('Test SmartAccount', () => {
38
41
  let tree;
39
42
  let route = {
@@ -42,7 +45,7 @@ describe('Test SmartAccount', () => {
42
45
  },
43
46
  };
44
47
  test('test render SmartAccount', async () => {
45
- const reponse = {
48
+ const response = {
46
49
  status: 200,
47
50
  data: [
48
51
  {
@@ -65,7 +68,9 @@ describe('Test SmartAccount', () => {
65
68
  },
66
69
  ],
67
70
  };
68
- axios.get.mockImplementationOnce(() => reponse);
71
+ mock
72
+ .onGet(API.SMART_ACCOUNT.LIST_SMART_ACCOUNT())
73
+ .reply(response.status, response.data);
69
74
  await act(async () => {
70
75
  tree = await renderer.create(wrapComponent(route));
71
76
  });
@@ -74,13 +79,16 @@ describe('Test SmartAccount', () => {
74
79
  const smartAccountItem = instance.findAllByType(SmartAccountItem);
75
80
  expect(smartAccountItem.length).toEqual(3);
76
81
  act(() => {
77
- smartAccountItem[0].props.gotoSmartAccountDetail(reponse.data[0]);
78
- smartAccountItem[0].props.onShowMenuMore(reponse.data[0]);
82
+ smartAccountItem[0].props.gotoSmartAccountDetail(response.data[0]);
83
+ smartAccountItem[0].props.onShowMenuMore(response.data[0]);
79
84
  });
85
+ const alertAction = instance.findAllByType(AlertAction);
86
+ mock.onDelete(API.SMART_ACCOUNT.REMOVE_SMART_ACCOUNT(1)).reply(200);
87
+ await alertAction[0].props.leftButtonClick();
80
88
  expect(mockNavigate).toBeCalledWith(Routes.ListDeviceSmartAccount, {
81
- username: reponse.data[0].username,
82
- brand: reponse.data[0].brand,
83
- smart_account_id: reponse.data[0].id,
89
+ username: response.data[0].username,
90
+ brand: response.data[0].brand,
91
+ smart_account_id: response.data[0].id,
84
92
  unit_id: route.params.unitId,
85
93
  });
86
94
  });
@@ -37,7 +37,6 @@ jest.mock('react', () => {
37
37
  };
38
38
  });
39
39
 
40
- jest.mock('axios');
41
40
  describe('Test SmartAccountItem', () => {
42
41
  let tree;
43
42
  test('test render SmartAccountItem', async () => {
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { SafeAreaView } from 'react-native';
3
+ import { act, create } from 'react-test-renderer';
4
+ import MyAllUnit from '../index';
5
+ import { SCProvider } from '../../../../../context';
6
+ import { mockSCStore } from '../../../../../context/mockStore';
7
+
8
+ const wrapComponent = (route) => (
9
+ <SCProvider initState={mockSCStore({})}>
10
+ <MyAllUnit route={route} />
11
+ </SCProvider>
12
+ );
13
+ describe('Test MyAllUnit', () => {
14
+ let tree;
15
+ test('render MyAllUnit', async () => {
16
+ const route = {
17
+ params: {
18
+ myUnits: [
19
+ {
20
+ background: '',
21
+ name: '',
22
+ stations: [
23
+ { id: 1, name: 'station', sensors: [{ id: 1, name: 'sensor' }] },
24
+ ],
25
+ },
26
+ ],
27
+ },
28
+ };
29
+ act(() => {
30
+ tree = create(wrapComponent(route));
31
+ });
32
+ const instance = tree.root;
33
+ const safeAreaView = instance.findAllByType(SafeAreaView);
34
+ expect(safeAreaView).toHaveLength(1);
35
+ });
36
+ });
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+ import { act, create } from 'react-test-renderer';
3
+ import MyAllUnit from '../index';
4
+ import Header from '../../Header';
5
+ import { SCProvider } from '../../../../../context';
6
+ import { mockSCStore } from '../../../../../context/mockStore';
7
+
8
+ const wrapComponent = (props) => (
9
+ <SCProvider initState={mockSCStore({})}>
10
+ <MyAllUnit {...props} />
11
+ </SCProvider>
12
+ );
13
+
14
+ test('test MyAllUnit', () => {
15
+ let tree, props;
16
+ let mockGoBack = jest.fn();
17
+
18
+ props = {
19
+ route: {
20
+ params: {
21
+ myUnits: [
22
+ {
23
+ background: '',
24
+ name: 'name',
25
+ stations: [
26
+ {
27
+ name: 'station',
28
+ sensors: [
29
+ {
30
+ name: 'sensor',
31
+ },
32
+ ],
33
+ },
34
+ ],
35
+ },
36
+ ],
37
+ },
38
+ },
39
+ navigation: {
40
+ goBack: mockGoBack,
41
+ },
42
+ };
43
+
44
+ act(() => {
45
+ tree = create(wrapComponent(props));
46
+ });
47
+
48
+ const instance = tree.root;
49
+ const header = instance.findByType(Header);
50
+ act(() => {
51
+ header.props.goBack();
52
+ });
53
+ expect(mockGoBack).toBeCalled();
54
+ });
@@ -39,6 +39,7 @@ const SharedUnit = ({
39
39
  }, [renewItem, index, unit, item]);
40
40
  const addPinSharedUnit = useCallback(async () => {
41
41
  const { success } = await axiosPost(API.UNIT.PIN_UNIT(unit.id));
42
+
42
43
  if (success) {
43
44
  item.is_pin = true;
44
45
  renewItem(index);
@@ -2,15 +2,16 @@ import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
3
  import moment from 'moment';
4
4
  import { useNavigation } from '@react-navigation/native';
5
- import axios from 'axios';
5
+ import MockAdapter from 'axios-mock-adapter';
6
6
  import SharedUnit from '../SharedUnit';
7
7
  import { TESTID } from '../../../../configs/Constants';
8
8
  import { API } from '../../../../configs';
9
9
  import Routes from '../../../../utils/Route';
10
10
  import { SCProvider } from '../../../../context';
11
11
  import { mockSCStore } from '../../../../context/mockStore';
12
+ import api from '../../../../utils/Apis/axios';
12
13
 
13
- jest.mock('axios');
14
+ const mock = new MockAdapter(api.axiosInstance);
14
15
 
15
16
  const mockRenewItem = jest.fn();
16
17
  const wrapComponent = (item, navigation) => (
@@ -37,10 +38,6 @@ jest.mock('@react-navigation/native', () => {
37
38
  describe('Test SharedUnit', () => {
38
39
  let tree;
39
40
 
40
- beforeEach(() => {
41
- axios.post.mockClear();
42
- });
43
-
44
41
  let unit = {
45
42
  background: '',
46
43
  icon: '',
@@ -60,14 +57,8 @@ describe('Test SharedUnit', () => {
60
57
 
61
58
  test('test create SharedUnit unit is not pin, not star', async () => {
62
59
  const navigation = useNavigation();
63
- const response = {
64
- status: 200,
65
- success: true,
66
- };
67
- axios.post.mockImplementation(async () => {
68
- return response;
69
- });
70
-
60
+ mock.onPost(API.UNIT.PIN_UNIT(3)).reply(200);
61
+ mock.onPost(API.UNIT.STAR_UNIT(3)).reply(200);
71
62
  await act(async () => {
72
63
  tree = await create(wrapComponent(item, navigation));
73
64
  });
@@ -85,41 +76,50 @@ describe('Test SharedUnit', () => {
85
76
  unitData: unit,
86
77
  },
87
78
  });
88
-
89
79
  const iconRemovePinSharedUnit = instance.findAll(
90
80
  (el) => el.props.testID === TESTID.ICON_REMOVE_PIN_SHARED_UNIT
91
81
  );
92
- expect(iconRemovePinSharedUnit).toHaveLength(0);
93
-
94
82
  const iconAddPinSharedUnit = instance.find(
95
83
  (el) => el.props.testID === TESTID.ICON_ADD_PIN_SHARED_UNIT
96
84
  );
97
85
  act(() => {
98
86
  iconAddPinSharedUnit.props.onPress();
99
87
  });
100
- expect(axios.post).toHaveBeenCalledWith(API.UNIT.PIN_UNIT(3));
101
-
102
88
  const iconAddStarSharedUnit = instance.find(
103
89
  (el) => el.props.testID === TESTID.ICON_ADD_STAR_SHARED_UNIT
104
90
  );
105
91
  act(() => {
106
92
  iconAddStarSharedUnit.props.onPress();
107
93
  });
108
- expect(axios.post).toHaveBeenCalledWith(API.UNIT.STAR_UNIT(3));
94
+ expect(iconRemovePinSharedUnit).toHaveLength(0);
109
95
  });
110
96
 
111
97
  test('test create SharedUnit unit is pin, is star', async () => {
112
98
  const navigation = useNavigation();
113
99
  item.is_pin = true;
114
100
  item.is_star = true;
115
- const response = {
116
- status: 200,
117
- success: true,
118
- };
119
- axios.post.mockImplementation(async () => {
120
- return response;
101
+ await act(async () => {
102
+ tree = await create(wrapComponent(item, navigation));
121
103
  });
104
+ const instance = tree.root;
105
+ const iconRemovePinSharedUnit = instance.find(
106
+ (el) => el.props.testID === TESTID.ICON_REMOVE_PIN_SHARED_UNIT
107
+ );
108
+ mock.onPost(API.UNIT.UNPIN_UNIT(3)).reply(200);
109
+ await iconRemovePinSharedUnit.props.onPress();
122
110
 
111
+ const iconRemoveStarSharedUnit = instance.find(
112
+ (el) => el.props.testID === TESTID.ICON_REMOVE_STAR_SHARED_UNIT
113
+ );
114
+ mock.onPost(API.UNIT.UNSTAR_UNIT(3)).reply(200);
115
+ await iconRemoveStarSharedUnit.props.onPress();
116
+ expect(mockRenewItem).toBeCalled();
117
+ });
118
+
119
+ test('test create SharedUnit unit is pin, is star with call api failure', async () => {
120
+ const navigation = useNavigation();
121
+ item.is_pin = true;
122
+ item.is_star = true;
123
123
  await act(async () => {
124
124
  tree = await create(wrapComponent(item, navigation));
125
125
  });
@@ -127,17 +127,14 @@ describe('Test SharedUnit', () => {
127
127
  const iconRemovePinSharedUnit = instance.find(
128
128
  (el) => el.props.testID === TESTID.ICON_REMOVE_PIN_SHARED_UNIT
129
129
  );
130
- act(() => {
131
- iconRemovePinSharedUnit.props.onPress();
132
- });
133
- expect(axios.post).toHaveBeenCalledWith(API.UNIT.UNPIN_UNIT(3));
130
+ mock.onPost(API.UNIT.UNPIN_UNIT(3)).reply(400);
131
+ await iconRemovePinSharedUnit.props.onPress();
134
132
 
135
133
  const iconRemoveStarSharedUnit = instance.find(
136
134
  (el) => el.props.testID === TESTID.ICON_REMOVE_STAR_SHARED_UNIT
137
135
  );
138
- act(() => {
139
- iconRemoveStarSharedUnit.props.onPress();
140
- });
141
- expect(axios.post).toHaveBeenCalledWith(API.UNIT.UNSTAR_UNIT(3));
136
+ mock.onPost(API.UNIT.UNSTAR_UNIT(3)).reply(200);
137
+ await iconRemoveStarSharedUnit.props.onPress();
138
+ expect(mockRenewItem).toBeCalled();
142
139
  });
143
140
  });
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+
3
5
  import Routes from '../../../utils/Route';
4
6
  import UnitSummary from '..';
5
- import axios from 'axios';
6
7
  import { API } from '../../../configs';
7
8
  import { RefreshControl } from 'react-native';
8
9
  import { TESTID } from '../../../configs/Constants';
@@ -16,8 +17,9 @@ import UvIndex from '../components/UvIndex';
16
17
  import WaterQuality from '../components/WaterQuality';
17
18
  import { SCProvider } from '../../../context';
18
19
  import { mockSCStore } from '../../../context/mockStore';
20
+ import api from '../../../utils/Apis/axios';
19
21
 
20
- jest.mock('axios');
22
+ const mock = new MockAdapter(api.axiosInstance);
21
23
 
22
24
  const mockedNavigate = jest.fn();
23
25
 
@@ -43,6 +45,7 @@ describe('Test UnitSummary', () => {
43
45
  Date.now = jest.fn(() => new Date('2021-01-24T12:00:00.000Z'));
44
46
  route = {
45
47
  params: {
48
+ unitId: 1,
46
49
  unitData: {
47
50
  id: 1,
48
51
  },
@@ -57,6 +60,7 @@ describe('Test UnitSummary', () => {
57
60
  let tree;
58
61
 
59
62
  test('onRefresh', async () => {
63
+ mock.onGet(API.UNIT.UNIT_SUMMARY_DETAIL(1, 1)).reply(200);
60
64
  act(() => {
61
65
  tree = create(wrapComponent(route));
62
66
  });
@@ -65,53 +69,56 @@ describe('Test UnitSummary', () => {
65
69
  act(() => {
66
70
  refreshControl.props.onRefresh();
67
71
  });
68
- expect(axios.get).toHaveBeenCalled();
69
- expect(axios.get).toHaveBeenCalledWith(
70
- API.UNIT.UNIT_SUMMARY_DETAIL(1, 1),
71
- {}
72
- );
72
+ expect(refreshControl).toBeDefined();
73
73
  });
74
74
 
75
75
  test('render fetchSummaryDetail failed', async () => {
76
- const response = {
77
- status: 400,
78
- data: {
79
- data: {},
80
- },
81
- };
82
- axios.get.mockImplementation(() => Promise.resolve(response));
83
-
76
+ mock.onGet(API.UNIT.UNIT_SUMMARY_DETAIL(1, 1)).reply(200, {});
84
77
  act(() => {
85
78
  tree = create(wrapComponent(route));
86
79
  });
87
- expect(axios.get).toHaveBeenCalled();
88
- expect(axios.get).toHaveBeenCalledWith(
89
- API.UNIT.UNIT_SUMMARY_DETAIL(1, 1),
90
- {}
91
- );
80
+ const instance = tree.root;
81
+ const refreshControl = instance.findByType(RefreshControl);
82
+ expect(refreshControl).toBeDefined();
92
83
  });
93
84
 
94
85
  test('render fetchSummaryDetail success', async () => {
95
86
  jest.useFakeTimers();
96
- const response = {
97
- status: 200,
98
- data: {
99
- data: {},
87
+ mock.onGet(API.UNIT.UNIT_SUMMARY_DETAIL(1, 1)).reply(200);
88
+ act(() => {
89
+ tree = create(wrapComponent(route));
90
+ });
91
+ act(() => {
92
+ jest.runOnlyPendingTimers();
93
+ });
94
+ const instance = tree.root;
95
+ const refreshControl = instance.findByType(RefreshControl);
96
+ expect(refreshControl).toBeDefined();
97
+ });
98
+
99
+ test('render fetchUnitDetail success', async () => {
100
+ route = {
101
+ params: {
102
+ unitId: 1,
103
+ unitData: null,
104
+ summaryData: {
105
+ id: 1,
106
+ name: '',
107
+ screen: Routes.AirQuality,
108
+ },
100
109
  },
101
110
  };
102
- axios.get.mockImplementation(() => Promise.resolve(response));
103
-
111
+ jest.useFakeTimers();
112
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {});
104
113
  act(() => {
105
114
  tree = create(wrapComponent(route));
106
115
  });
107
116
  act(() => {
108
117
  jest.runOnlyPendingTimers();
109
118
  });
110
- expect(axios.get).toHaveBeenCalled();
111
- expect(axios.get).toHaveBeenCalledWith(
112
- API.UNIT.UNIT_SUMMARY_DETAIL(1, 1),
113
- {}
114
- );
119
+ const instance = tree.root;
120
+ const refreshControl = instance.findByType(RefreshControl);
121
+ expect(refreshControl).toBeDefined();
115
122
  });
116
123
 
117
124
  let list_value = [
@@ -1,11 +1,14 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+ import moment from 'moment';
5
+
3
6
  import ConfigHistoryChart from '../';
4
7
  import { SCProvider } from '../../../../../context';
5
8
  import { mockSCStore } from '../../../../../context/mockStore';
6
9
  import HistoryChart from '../../../../../commons/Device/HistoryChart';
7
- import axios from 'axios';
8
- import moment from 'moment';
10
+ import api from '../../../../../utils/Apis/axios';
11
+ import { API } from '../../../../../configs';
9
12
 
10
13
  jest.mock('react', () => {
11
14
  return {
@@ -14,7 +17,7 @@ jest.mock('react', () => {
14
17
  };
15
18
  });
16
19
 
17
- jest.mock('axios');
20
+ const mock = new MockAdapter(api.axiosInstance);
18
21
 
19
22
  const wrapComponent = (configs = []) => (
20
23
  <SCProvider initState={mockSCStore({})}>
@@ -48,7 +51,7 @@ describe('Test HistoryChart', () => {
48
51
  },
49
52
  ],
50
53
  };
51
- axios.get.mockImplementation(async () => response);
54
+ mock.onGet(API.CONFIG.DISPLAY_HISTORY).reply(200, response.data);
52
55
  const configs = [{ id: 1 }];
53
56
  await act(async () => {
54
57
  tree = await create(wrapComponent(configs));
@@ -1,14 +1,17 @@
1
1
  import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+
3
5
  import { TESTID } from '../../../../../configs/Constants';
4
- import { Colors } from '../../../../../configs';
6
+ import { API, Colors } from '../../../../../configs';
5
7
  import ListQualityIndicator from '../../../../../commons/Device/WaterQualitySensor/ListQualityIndicator';
6
- import axios from 'axios';
7
8
  import PowerConsumption from '../index';
8
9
  import { SCProvider } from '../../../../../context';
9
10
  import { mockSCStore } from '../../../../../context/mockStore';
11
+ import api from '../../../../../utils/Apis/axios';
12
+ import { Today } from '../../../../../commons';
10
13
 
11
- jest.mock('axios');
14
+ const mock = new MockAdapter(api.axiosInstance);
12
15
 
13
16
  const wrapComponent = (summaryDetail) => (
14
17
  <SCProvider initState={mockSCStore({})}>
@@ -86,15 +89,13 @@ describe('Test PowerConsumption', () => {
86
89
  },
87
90
  };
88
91
 
89
- const response = {
90
- status: 200,
91
- };
92
- axios.get.mockImplementation(async (url) => response);
93
-
92
+ mock.onGet(API.VALUE_CONSUME.DISPLAY_HISTORY()).reply(200);
94
93
  await act(async () => {
95
94
  tree = await renderer.create(wrapComponent(summaryDetail));
96
95
  });
97
- expect(axios.get).toHaveBeenCalled();
96
+ const instance = tree.root;
97
+ const Todays = instance.findByType(Today);
98
+ expect(Todays).toBeDefined();
98
99
  });
99
100
 
100
101
  test('render with unsuccess fetch', async () => {
@@ -113,16 +114,13 @@ describe('Test PowerConsumption', () => {
113
114
  volt: 209,
114
115
  },
115
116
  };
116
-
117
- const response = {
118
- data: {},
119
- };
120
- axios.get.mockImplementation(async (url) => response);
121
-
117
+ mock.onGet(API.VALUE_CONSUME.DISPLAY_HISTORY()).reply(200, {});
122
118
  await act(async () => {
123
119
  tree = await renderer.create(wrapComponent(summaryDetail));
124
120
  });
125
- expect(axios.get).toHaveBeenCalled();
121
+ const instance = tree.root;
122
+ const Todays = instance.findByType(Today);
123
+ expect(Todays).toBeDefined();
126
124
  });
127
125
 
128
126
  test('render without value', async () => {
@@ -270,7 +270,7 @@ const WaterQualityGuide = memo(({ route }) => {
270
270
 
271
271
  return (
272
272
  <SafeAreaView style={styles.container}>
273
- <ScrollView style={styles.container}>
273
+ <ScrollView style={styles.container} scrollIndicatorInsets={{ right: 1 }}>
274
274
  <View style={styles.wrapScroll}>
275
275
  {titles.map((item, index) => {
276
276
  const { title, des } = item;
@@ -1,8 +1,15 @@
1
- import axios from 'axios';
2
- import { deleteData, getData, storeData } from '../Storage';
1
+ import { create } from 'apisauce';
2
+ import { getData, storeData } from '../Storage';
3
3
  import { ToastBottomHelper } from '../Utils';
4
4
  import NetInfo from '@react-native-community/netinfo';
5
5
 
6
+ const api = create({
7
+ headers: {
8
+ 'Content-Type': 'application/json',
9
+ },
10
+ timeout: 30000,
11
+ });
12
+
6
13
  export const replaceParams = (apiURL, params) => {
7
14
  let _result = apiURL;
8
15
  if (typeof params === 'object') {
@@ -16,7 +23,10 @@ export const replaceParams = (apiURL, params) => {
16
23
  const parseErrorResponse = async (error) => {
17
24
  let message;
18
25
  let data = {};
19
- if (
26
+ if (!error.response && error.data) {
27
+ data = error.data.error || error.data.message;
28
+ message = data instanceof Array ? data[0] : data;
29
+ } else if (
20
30
  error.response &&
21
31
  error.response.data &&
22
32
  error.response.data instanceof Object
@@ -28,8 +38,11 @@ const parseErrorResponse = async (error) => {
28
38
  if (message instanceof Array) {
29
39
  message = message[0];
30
40
  }
41
+ if (message.message) {
42
+ message = message.message;
43
+ }
31
44
  } else {
32
- message = error.message;
45
+ message = error.problem;
33
46
  }
34
47
 
35
48
  if (typeof message === 'string') {
@@ -83,25 +96,34 @@ export async function fetchWithCache(url, config = {}, updateMethod) {
83
96
  }
84
97
 
85
98
  export async function axiosGet(URL, config = {}, cache = false) {
86
- const cacheKey = `@CACHE_REQUEST_${URL}`;
87
99
  let response;
88
100
  try {
89
- response = await axios.get(URL, config);
101
+ response = await api.get(URL, config.params, config);
90
102
  } catch (error) {
91
103
  if (cache) {
92
- // only network error or server error
93
- if (!error.response || error.response.status >= 500) {
104
+ if (error.message === 'Network Error') {
105
+ return (
106
+ (await axiosCache(URL, 500)) || (await parseErrorResponse(error))
107
+ );
108
+ }
109
+ if (!error?.response || error?.response?.status >= 500) {
94
110
  return (
95
- (await axiosCache(URL, error.response.status)) ||
111
+ (await axiosCache(URL, error?.response?.status)) ||
96
112
  (await parseErrorResponse(error))
97
113
  );
98
- } else {
99
- await deleteData(cacheKey);
100
114
  }
101
115
  }
102
116
  return await parseErrorResponse(error);
103
117
  }
104
- const { data } = response;
118
+ const { data, problem } = response;
119
+ if (problem === 'NETWORK_ERROR') {
120
+ if (cache) {
121
+ return (
122
+ (await axiosCache(URL, 500)) || (await parseErrorResponse(response))
123
+ );
124
+ }
125
+ return await parseErrorResponse(response);
126
+ }
105
127
  if (response.status === 200) {
106
128
  if (cache) {
107
129
  await storeData(`@CACHE_REQUEST_${URL}`, JSON.stringify(data));
@@ -121,7 +143,7 @@ export async function axiosGet(URL, config = {}, cache = false) {
121
143
  async function axiosCall(method, ...args) {
122
144
  let response;
123
145
  try {
124
- response = await axios[method](...args);
146
+ response = await api[method](...args);
125
147
  } catch (error) {
126
148
  return await parseErrorResponse(error);
127
149
  }
@@ -186,3 +208,5 @@ export function createFormData(data, list_file_field) {
186
208
 
187
209
  return formData;
188
210
  }
211
+
212
+ export default api;
@@ -985,5 +985,6 @@
985
985
  "you_need_to_enter_password": "You need to enter password to perform this action",
986
986
  "note": "Note",
987
987
  "back": "Back",
988
+ "invaild_data": "Invaild data",
988
989
  "This {name} was removed!" : "This {name} was removed!"
989
990
  }
@@ -985,5 +985,6 @@
985
985
  "maxmium_contacts": "Địa chỉ liên hệ tối đa",
986
986
  "note": "Lưu ý ",
987
987
  "back": "Quay lại",
988
+ "invaild_data": "Dữ liệu không hợp lệ",
988
989
  "This {name} was removed!" : "{Name} này đã bị xóa!"
989
990
  }
@@ -136,6 +136,7 @@ const Routes = {
136
136
  SmartAccount: 'SmartAccount',
137
137
  SmartHomeDashboard: 'SmartHomeDashboard',
138
138
  SetupGeneratePasscode: 'SetupGeneratePasscode',
139
+ SideMenuDetail: 'SideMenuDetail',
139
140
  SelectDeviceType: 'SelectDeviceType',
140
141
  SelectBrand: 'SelectBrand',
141
142
  GroupButtonByType: 'GroupButtonByType',