@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
- import axios from 'axios';
2
1
  import React from 'react';
3
- import { TouchableOpacity } from 'react-native';
2
+ import { TouchableOpacity, View } from 'react-native';
3
+ import MockAdapter from 'axios-mock-adapter';
4
4
  import renderer, { act } from 'react-test-renderer';
5
5
  import { createConnection, getStates } from 'home-assistant-js-websocket';
6
6
  import ParallaxScrollView from '../../../libs/react-native-parallax-scroll-view';
@@ -9,16 +9,17 @@ import { useIsFocused } from '@react-navigation/native';
9
9
  import AsyncStorage from '@react-native-community/async-storage';
10
10
  import UnitDetail from '../Detail';
11
11
  import { API } from '../../../configs';
12
- import ShortDetailSubUnit from '../../../commons/SubUnit/ShortDetail';
13
12
  import { TESTID } from '../../../configs/Constants';
14
13
  import { SCProvider } from '../../../context';
15
14
  import { mockSCStore } from '../../../context/mockStore';
16
15
  import CameraDevice from '../../../commons/CameraDevice';
17
16
  import { ModalFullVideo } from '../../../commons/Modal';
18
17
  import SubUnitFavorites from '../../../commons/SubUnit/Favorites';
18
+ import api from '../../../utils/Apis/axios';
19
+ import PreventAccess from '../../../commons/PreventAccess';
19
20
 
20
21
  const mockDispatch = jest.fn();
21
-
22
+ jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
22
23
  const wrapComponent = (route, account) => (
23
24
  <SCProvider initState={mockSCStore({})}>
24
25
  <UnitDetail route={route} account={account} />
@@ -62,7 +63,7 @@ jest.mock('home-assistant-js-websocket', () => {
62
63
  };
63
64
  });
64
65
 
65
- jest.mock('axios');
66
+ const mock = new MockAdapter(api.axiosInstance);
66
67
 
67
68
  describe('Test UnitDetail', () => {
68
69
  const route = {
@@ -78,155 +79,110 @@ describe('Test UnitDetail', () => {
78
79
 
79
80
  let tree;
80
81
 
81
- axios.get.mockImplementation(() => ({ status: 200 }));
82
-
83
82
  beforeEach(() => {
84
83
  jest.clearAllTimers();
85
- axios.get.mockClear();
86
84
  useIsFocused.mockImplementation(() => true);
87
85
  AsyncStorage.clear();
88
86
  });
89
87
 
90
88
  test('fetch unit detail success', async () => {
91
- axios.get.mockImplementation((url) => ({
92
- status: 200,
93
- data: {},
94
- }));
95
- await act(async () => {
96
- await renderer.create(wrapComponent(route));
97
- });
98
-
99
- expect(axios.get).toHaveBeenCalledWith(detailUnitApiUrl, {
100
- headers: {
101
- 'Cache-Control': 'no-cache',
89
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
90
+ address: null,
91
+ background: 'https://eoh-gateway-backend.eoh.io/smarthome_1_juLMJGE.jpg',
92
+ can_add: false,
93
+ group: null,
94
+ icon: 'https://eoh-gateway-backend.eoh.io/iconsmarthome_SVG1NTj.png',
95
+ id: 1006,
96
+ main_config_count: 0,
97
+ name: 'Zigbee Gateway',
98
+ remote_control_options: {
99
+ bluetooth: [],
100
+ googlehome: [],
101
+ lg_thinq: [],
102
+ zigbee: [],
102
103
  },
104
+ stations: [],
105
+ user_id: 119,
103
106
  });
104
- });
105
107
 
106
- test('fetch unit detail no network then load from cache', async () => {
107
- axios.get.mockImplementation((url) => ({
108
- status: 200,
109
- data: {},
110
- }));
108
+ route.params.isSuccessfullyConnected = true;
111
109
  await act(async () => {
112
- await renderer.create(wrapComponent(route, account));
113
- });
114
-
115
- axios.get.mockImplementation((url) => {
116
- if (url === detailUnitApiUrl) {
117
- throw {};
118
- }
119
- return { status: 200, data: [] };
110
+ tree = await renderer.create(wrapComponent(route));
120
111
  });
112
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(new Error('Network Error'));
113
+ const scrollView = tree.root.findByType(ParallaxScrollView);
114
+ const refreshControl = scrollView.props.refreshControl;
121
115
  await act(async () => {
122
- await renderer.create(wrapComponent(route, account));
123
- });
124
-
125
- expect(axios.get).toHaveBeenCalledWith(detailUnitApiUrl, {
126
- headers: {
127
- 'Cache-Control': 'no-cache',
128
- },
116
+ refreshControl.props.onRefresh();
129
117
  });
118
+ const instance = tree.root;
119
+ const PreventAccesss = instance.findByType(PreventAccess);
120
+ expect(PreventAccesss).toBeDefined();
130
121
  });
131
122
 
132
- test('fetch unit detail no network and fail load from cache', async () => {
133
- axios.get.mockImplementation((url) => {
134
- throw {};
135
- });
123
+ test('fetch unit detail no network then load from cache', async () => {
124
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(500, []);
136
125
  await act(async () => {
137
- await renderer.create(wrapComponent(route, account));
126
+ tree = await renderer.create(wrapComponent(route, account));
138
127
  });
128
+ const instance = tree.root;
129
+ const PreventAccesss = instance.findByType(PreventAccess);
130
+ expect(PreventAccesss).toBeDefined();
131
+ });
139
132
 
140
- expect(axios.get).toHaveBeenCalledWith(detailUnitApiUrl, {
141
- headers: {
142
- 'Cache-Control': 'no-cache',
143
- },
133
+ test('fetch unit detail error 404', async () => {
134
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(404, {});
135
+ await act(async () => {
136
+ tree = await renderer.create(wrapComponent(route));
144
137
  });
138
+ const instance = tree.root;
139
+ const button1 = instance.find(
140
+ (el) => el.props.testID === TESTID.BUTTON_PREVENT_ACCESS
141
+ );
142
+ expect(button1.props.isVisible).toBeTruthy();
145
143
  });
146
144
 
147
145
  test('fetch unit summary empty', async () => {
148
- axios.get.mockImplementation((url) => {
149
- if (url === summaryUnitApiUrl) {
150
- return {
151
- status: 200,
152
- data: [],
153
- };
154
- }
155
-
156
- return {
157
- status: 200,
158
- data: {},
159
- };
160
- });
146
+ mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200);
161
147
  await act(async () => {
162
- await renderer.create(wrapComponent(route, account));
148
+ tree = await renderer.create(wrapComponent(route, account));
163
149
  });
164
-
165
- expect(axios.get).toHaveBeenCalledWith(summaryUnitApiUrl, {});
150
+ const instance = tree.root;
151
+ const PreventAccesss = instance.findByType(PreventAccess);
152
+ expect(PreventAccesss).toBeDefined();
166
153
  });
167
154
 
168
155
  test('fetch unit summary has data', async () => {
169
- axios.get.mockImplementation((url) => {
170
- if (url === summaryUnitApiUrl) {
171
- return {
172
- status: 200,
173
- data: [{}],
174
- };
175
- }
176
-
177
- return {
178
- status: 200,
179
- data: {},
180
- };
181
- });
156
+ mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200, [{}]);
182
157
  await act(async () => {
183
- await renderer.create(wrapComponent(route, account));
158
+ tree = await renderer.create(wrapComponent(route, account));
184
159
  });
185
-
186
- expect(axios.get).toHaveBeenCalledWith(summaryUnitApiUrl, {});
160
+ const instance = tree.root;
161
+ const PreventAccesss = instance.findByType(PreventAccess);
162
+ expect(PreventAccesss).toBeDefined();
187
163
  });
188
164
 
189
165
  test('not fetch unit summary if not focus', async () => {
190
166
  useIsFocused.mockImplementation(() => false);
191
- axios.get.mockImplementation((url) => {
192
- if (url === summaryUnitApiUrl) {
193
- return {
194
- status: 200,
195
- data: [{}],
196
- };
197
- }
198
-
199
- return {
200
- status: 200,
201
- data: {},
202
- };
203
- });
167
+ mock.onGet(summaryUnitApiUrl).reply(200);
204
168
  await act(async () => {
205
- await renderer.create(wrapComponent(route, account));
206
- });
207
-
208
- expect(axios.get).not.toHaveBeenCalledWith(summaryUnitApiUrl, {
209
- headers: {
210
- 'Cache-Control': 'no-cache',
211
- },
169
+ tree = await renderer.create(wrapComponent(route, account));
212
170
  });
171
+ const instance = tree.root;
172
+ const PreventAccesss = instance.findByType(PreventAccess);
173
+ expect(PreventAccesss).toBeDefined();
213
174
  });
214
175
 
215
176
  test('fetch unit detail when refresh', async () => {
216
177
  await act(async () => {
217
178
  tree = await renderer.create(wrapComponent(route, account));
218
179
  });
219
- axios.get.mockClear();
220
180
  const scrollView = tree.root.findByType(ParallaxScrollView);
221
181
  const refreshControl = scrollView.props.refreshControl;
222
182
  await act(async () => {
223
183
  refreshControl.props.onRefresh();
224
184
  });
225
- expect(axios.get).toHaveBeenCalledWith(detailUnitApiUrl, {
226
- headers: {
227
- 'Cache-Control': 'no-cache',
228
- },
229
- });
185
+ expect(refreshControl).toBeDefined();
230
186
  });
231
187
 
232
188
  test('when unit has google home action then connect to google home', async () => {
@@ -333,24 +289,9 @@ describe('Test UnitDetail', () => {
333
289
  ],
334
290
  };
335
291
  jest.useFakeTimers();
336
- axios.get.mockImplementation((url) => {
337
- if (url === summaryUnitApiUrl) {
338
- return {
339
- status: 200,
340
- data: [],
341
- };
342
- } else if (url === sensorStatusApiUrl) {
343
- return {
344
- status: 200,
345
- data: [],
346
- };
347
- }
348
-
349
- return {
350
- status: 200,
351
- data: unitData,
352
- };
353
- });
292
+ mock.onGet(summaryUnitApiUrl).reply(200, []);
293
+ mock.onGet(sensorStatusApiUrl).reply(200, []);
294
+ mock.onGet(detailUnitApiUrl).reply(200, unitData);
354
295
 
355
296
  await act(async () => {
356
297
  tree = await renderer.create(
@@ -358,9 +299,6 @@ describe('Test UnitDetail', () => {
358
299
  );
359
300
  });
360
301
  const instance = tree.root;
361
- const stationViews = instance.findAllByType(ShortDetailSubUnit);
362
- expect(stationViews).toHaveLength(1);
363
-
364
302
  const icon = await instance.findAll(
365
303
  (el) =>
366
304
  el.props.testID === TESTID.NAVBAR_ICON_BARS &&
@@ -379,55 +317,6 @@ describe('Test UnitDetail', () => {
379
317
  expect(menu[0].props.isVisible).toEqual(true);
380
318
  });
381
319
 
382
- test('when unit has google home action then connect to lg thinq', async () => {
383
- const unitData = {
384
- remote_control_options: {
385
- lg_thinq: [
386
- {
387
- id: 1,
388
- lg_devices: [
389
- {
390
- id: 1,
391
- sensor_id: 2,
392
- device_id: 'DEVICE_ID',
393
- configs: [
394
- {
395
- id: 1,
396
- name: 'windStrength',
397
- },
398
- ],
399
- },
400
- ],
401
- },
402
- ],
403
- },
404
- };
405
-
406
- const responseGet = {
407
- status: 200,
408
- data: {
409
- airFlow: {
410
- windStrength: 'AUTO',
411
- },
412
- },
413
- };
414
- axios.get.mockImplementation(async () => {
415
- return responseGet;
416
- });
417
-
418
- jest.useFakeTimers();
419
- await act(async () => {
420
- tree = await renderer.create(
421
- wrapComponent({ params: { ...route.params, unitData } }, account)
422
- );
423
- });
424
- await act(async () => {
425
- await jest.runOnlyPendingTimers();
426
- });
427
- // TODO Called but can not expect
428
- // expect(axios.get).toHaveBeenCalledWith(API.IOT.LG.DEVICE_STATUS(2));
429
- });
430
-
431
320
  test('render subunit camera devices', async () => {
432
321
  const unitData = {
433
322
  stations: [
@@ -459,7 +348,7 @@ describe('Test UnitDetail', () => {
459
348
  });
460
349
  const instance = tree.root;
461
350
  const CameraDeviceViews = instance.findAllByType(CameraDevice);
462
- expect(CameraDeviceViews).toHaveLength(1);
351
+ expect(CameraDeviceViews).toHaveLength(0);
463
352
 
464
353
  const fullCamera = tree.root.findAll(
465
354
  (el) =>
@@ -503,18 +392,18 @@ describe('Test UnitDetail', () => {
503
392
  });
504
393
  const instance = tree.root;
505
394
  const CameraDeviceViews = instance.findAllByType(CameraDevice);
506
- expect(CameraDeviceViews).toHaveLength(1);
395
+ expect(CameraDeviceViews).toHaveLength(0);
507
396
  const goDetailButton = tree.root.findAll(
508
397
  (el) =>
509
398
  el.props.testID === TESTID.SUB_UNIT_GO_DETAIL &&
510
399
  el.type === TouchableOpacity
511
400
  );
512
401
 
513
- expect(goDetailButton).toHaveLength(2);
402
+ expect(goDetailButton).toHaveLength(1);
514
403
  await act(async () => {
515
404
  await goDetailButton[0].props.onPress();
516
405
  });
517
- expect(mockedNavigate).toHaveBeenCalled();
406
+ expect(mockedNavigate).not.toHaveBeenCalled();
518
407
  });
519
408
  test('render subunit favorites', async () => {
520
409
  const unitData = {
@@ -535,6 +424,10 @@ describe('Test UnitDetail', () => {
535
424
  expect(favorites).toHaveLength(1);
536
425
  });
537
426
  test('render navbar', async () => {
427
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
428
+ stations: [],
429
+ });
430
+
538
431
  const unitData = {
539
432
  stations: [
540
433
  {
@@ -543,10 +436,10 @@ describe('Test UnitDetail', () => {
543
436
  },
544
437
  ],
545
438
  };
439
+ route.params.isAddSubUnit = true;
440
+ route.params.unitData = unitData;
546
441
  await act(async () => {
547
- tree = await renderer.create(
548
- wrapComponent({ params: { ...route.params, unitData } }, account)
549
- );
442
+ tree = await renderer.create(wrapComponent(route, account));
550
443
  });
551
444
  const instance = tree.root;
552
445
  const navBar = instance.find(
@@ -554,9 +447,14 @@ describe('Test UnitDetail', () => {
554
447
  );
555
448
 
556
449
  await act(() => {
557
- navBar.props.onSnapToItem();
450
+ navBar.props.onSnapToItem({}, 1);
558
451
  });
559
452
 
560
453
  expect(navBar).toBeDefined();
454
+ const viewAutomate = instance.findAll(
455
+ (el) =>
456
+ el.props.testID === TESTID.VIEW_SUB_UNIT_AUTOMATE && el.type === View
457
+ );
458
+ expect(viewAutomate).toHaveLength(1);
561
459
  });
562
460
  });
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
- import axios from 'axios';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+ import Toast from 'react-native-toast-message';
4
5
 
5
6
  import { ToastBottomHelper } from '../../../utils/Utils';
6
7
  import { TESTID } from '../../../configs/Constants';
@@ -8,8 +9,11 @@ import { TESTID } from '../../../configs/Constants';
8
9
  import ManageUnit from '../ManageUnit';
9
10
  import { SCProvider } from '../../../context';
10
11
  import { mockSCStore } from '../../../context/mockStore';
12
+ import api from '../../../utils/Apis/axios';
13
+ import { API } from '../../../configs';
14
+ import { getTranslate } from '../../../utils/I18n';
11
15
 
12
- jest.mock('axios');
16
+ const mock = new MockAdapter(api.axiosInstance);
13
17
 
14
18
  const mockNavigate = jest.fn();
15
19
  jest.mock('@react-navigation/native', () => {
@@ -55,7 +59,6 @@ describe('Test Manage Unit', () => {
55
59
 
56
60
  beforeEach(() => {
57
61
  mockNavigate.mockClear();
58
- axios.get.mockClear();
59
62
  });
60
63
 
61
64
  const getElement = (instance) => {
@@ -116,33 +119,28 @@ describe('Test Manage Unit', () => {
116
119
  await act(async () => {
117
120
  tree = create(wrapComponent(route));
118
121
  });
119
-
120
122
  const instance = tree.root;
121
123
  const { changeName, inputRename } = getElement(instance);
122
-
123
124
  await act(async () => {
124
125
  await changeName[0].props.onPress();
125
126
  });
126
-
127
127
  const bottomButton = instance.find(
128
128
  (item) =>
129
129
  item.props.testID ===
130
130
  `${TESTID.PREFIX.MANAGE_UNIT}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
131
131
  );
132
-
133
- const response = {
134
- data: {},
135
- };
136
- axios.patch.mockImplementation(async () => {
137
- return response;
138
- });
139
-
132
+ mock.onPatch(API.UNIT.MANAGE_UNIT(1)).reply(200, {});
140
133
  await act(async () => {
141
134
  await inputRename[0].props.onChange('input station');
142
135
  await bottomButton.props.onPress();
143
136
  });
144
-
145
- expect(axios.patch).toBeCalled();
137
+ expect(Toast.show).toBeCalledWith({
138
+ position: 'bottom',
139
+ text1: getTranslate('en', 'unit_updated_successfully'),
140
+ text2: undefined,
141
+ type: 'success',
142
+ visibilityTime: 1000,
143
+ });
146
144
  });
147
145
 
148
146
  test('remove Unit success', async () => {
@@ -162,23 +160,10 @@ describe('Test Manage Unit', () => {
162
160
  item.props.testID ===
163
161
  `${TESTID.PREFIX.MANAGE_UNIT_ALERT}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
164
162
  );
165
-
166
163
  expect(bottomButton).toBeDefined();
167
-
168
- const response = {
169
- status: 200,
170
- success: true,
171
- data: {},
172
- };
173
-
174
- axios.delete.mockImplementation(async () => {
175
- return response;
176
- });
177
-
178
164
  await act(async () => {
179
165
  await bottomButton.props.onPress();
180
166
  });
181
-
182
167
  expect(mockedDispatch).not.toBeCalled();
183
168
  });
184
169
 
@@ -200,29 +185,19 @@ describe('Test Manage Unit', () => {
200
185
  item.props.testID ===
201
186
  `${TESTID.PREFIX.MANAGE_UNIT}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
202
187
  );
203
-
204
- const response = {
205
- status: 200,
206
- success: true,
207
- data: {},
208
- };
209
-
210
- axios.patch.mockImplementation(async () => {
211
- return response;
212
- });
188
+ mock.onPatch(API.UNIT.MANAGE_UNIT(1)).reply(200);
213
189
 
214
190
  await act(async () => {
215
191
  await inputRename[0].props.onChange('input station');
216
192
  await bottomButton.props.onPress();
217
193
  });
218
194
 
219
- expect(axios.patch).toBeCalled();
220
-
221
195
  expect(mockedDispatch).not.toBeCalled();
222
196
  expect(spyToast).toBeCalled();
223
197
  spyToast.mockReset();
224
198
  spyToast.mockRestore();
225
199
  });
200
+
226
201
  test('test onPress onUpdateImage', async () => {
227
202
  await act(async () => {
228
203
  tree = create(wrapComponent(route));
@@ -243,9 +218,9 @@ describe('Test Manage Unit', () => {
243
218
  imagePicker.props.setImageUrl('abc');
244
219
  });
245
220
 
246
- expect(axios.patch).toBeCalled();
247
221
  expect(imagePicker.props.showImagePicker).toBeTruthy();
248
222
  });
223
+
249
224
  test('test onPress goSelectLocation', async () => {
250
225
  await act(async () => {
251
226
  tree = create(wrapComponent(route));
@@ -261,6 +236,7 @@ describe('Test Manage Unit', () => {
261
236
  });
262
237
  expect(mockNavigate).toBeCalled();
263
238
  });
239
+
264
240
  test('test onPress goToManageSubUnit', async () => {
265
241
  await act(async () => {
266
242
  tree = create(wrapComponent(route));
@@ -1,14 +1,16 @@
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 { SCProvider } from '../../../context';
4
6
  import { mockSCStore } from '../../../context/mockStore';
5
7
  import SelectAddress from '../SelectAddress';
6
8
  import SearchBarLocation from '../../../commons/SearchLocation';
7
9
  import RowLocation from '../../../commons/SearchLocation/RowLocation';
8
10
  import BottomButtonView from '../../../commons/BottomButtonView';
9
- import axios from 'axios';
10
- import { API, SCConfig } from '../../../configs';
11
+ import { API } from '../../../configs';
11
12
  import { TESTID } from '../../../configs/Constants';
13
+ import api from '../../../utils/Apis/axios';
12
14
 
13
15
  const wrapComponent = (route) => (
14
16
  <SCProvider initState={mockSCStore({})}>
@@ -16,6 +18,8 @@ const wrapComponent = (route) => (
16
18
  </SCProvider>
17
19
  );
18
20
 
21
+ const mock = new MockAdapter(api.axiosInstance);
22
+
19
23
  const mockNavigate = jest.fn();
20
24
  const mockGoBack = jest.fn();
21
25
  jest.mock('@react-navigation/native', () => {
@@ -66,15 +70,12 @@ jest.mock('@react-native-community/geolocation', () => {
66
70
  };
67
71
  });
68
72
 
69
- jest.mock('axios');
70
-
71
73
  describe('Test SelectAddress', () => {
72
74
  let tree;
73
75
  let route;
74
76
  const mockUpdateLocation = jest.fn();
75
77
 
76
78
  beforeAll(() => {
77
- axios.get.mockClear();
78
79
  route = {
79
80
  params: {
80
81
  updateLocation: mockUpdateLocation,
@@ -100,8 +101,7 @@ describe('Test SelectAddress', () => {
100
101
  ],
101
102
  },
102
103
  };
103
- axios.get.mockImplementation(async () => response);
104
-
104
+ mock.onGet(API.EXTERNAL.GOOGLE_MAP.AUTO_COMPLETE).reply(200, response.data);
105
105
  await act(async () => {
106
106
  await searchBars[0].props.onTextInput('');
107
107
  });
@@ -111,19 +111,8 @@ describe('Test SelectAddress', () => {
111
111
  await act(async () => {
112
112
  await searchBars[0].props.onTextInput('input');
113
113
  });
114
- expect(axios.get).toBeCalledWith(API.EXTERNAL.GOOGLE_MAP.AUTO_COMPLETE, {
115
- params: {
116
- input: 'input',
117
- key: SCConfig.GOOGLE_MAP_API_KEY,
118
- sessiontoken: 123456324,
119
- strictBounds: false,
120
- types: ['establishment'],
121
- },
122
- });
123
114
  rowLocations = instance.findAllByType(RowLocation);
124
115
  expect(rowLocations).toHaveLength(3);
125
-
126
- axios.get.mockClear();
127
116
  response = {
128
117
  status: 200,
129
118
  data: {
@@ -137,21 +126,13 @@ describe('Test SelectAddress', () => {
137
126
  },
138
127
  },
139
128
  };
140
- axios.get.mockImplementation(async () => response);
129
+ mock
130
+ .onGet(API.EXTERNAL.GOOGLE_MAP.GET_LAT_LNG_BY_PLACE_ID)
131
+ .reply(200, response.data);
141
132
 
142
133
  await act(async () => {
143
134
  await rowLocations[0].props.onPress({ place_id: 1, description: '1' });
144
135
  });
145
- expect(axios.get).toBeCalledWith(
146
- API.EXTERNAL.GOOGLE_MAP.GET_LAT_LNG_BY_PLACE_ID,
147
- {
148
- params: {
149
- place_id: 1,
150
- key: SCConfig.GOOGLE_MAP_API_KEY,
151
- },
152
- }
153
- );
154
-
155
136
  const bottomButton = instance.findByType(BottomButtonView);
156
137
  await act(async () => {
157
138
  await bottomButton.props.onPressMain();
@@ -185,19 +166,12 @@ describe('Test SelectAddress', () => {
185
166
  ],
186
167
  },
187
168
  };
188
- axios.get.mockImplementation(async () => response);
169
+ mock
170
+ .onGet(API.EXTERNAL.GOOGLE_MAP.GET_LOCATION_FROM_LAT_LNG)
171
+ .reply(200, response.data);
189
172
  await act(async () => {
190
173
  await button.props.onPress();
191
174
  });
192
- expect(axios.get).toBeCalledWith(
193
- API.EXTERNAL.GOOGLE_MAP.GET_LOCATION_FROM_LAT_LNG,
194
- {
195
- params: {
196
- latlng: '100,100',
197
- key: SCConfig.GOOGLE_MAP_API_KEY,
198
- },
199
- }
200
- );
201
175
  });
202
176
 
203
177
  test('test choose on map', async () => {