@eohjsc/react-native-smart-city 0.2.99 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +6 -4
- package/react-native-smart-city.podspec +1 -0
- package/src/commons/Action/ItemQuickAction.js +11 -2
- package/src/commons/Action/__test__/ItemQuickAction.test.js +11 -6
- package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
- package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +31 -20
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +24 -0
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +14 -0
- package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +1 -1
- package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +3 -2
- package/src/commons/ActionGroup/StatesGridActionTemplate.js +8 -4
- package/src/commons/ActionGroup/TimerActionTemplate.js +2 -2
- package/src/commons/ActionGroup/TwoButtonTemplate/index.js +0 -1
- package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +45 -48
- package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
- package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
- package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
- package/src/commons/ActionGroup/__test__/index.test.js +137 -2
- package/src/commons/Automate/ItemAutomate.js +1 -3
- package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
- package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +7 -3
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +8 -11
- package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
- package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +3 -2
- package/src/commons/ConnectingProcess/index.js +72 -25
- package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
- package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
- package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
- package/src/commons/Device/ConnectedViewHeader.js +1 -1
- package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
- package/src/commons/Device/HistoryChart.js +3 -3
- package/src/commons/Device/ItemDevice.js +15 -11
- package/src/commons/Device/LinearChart.js +15 -0
- package/src/commons/Device/SonosSpeaker/index.js +1 -1
- package/src/commons/Explore/__test__/CityItem.test.js +33 -54
- package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +19 -14
- package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +0 -3
- package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +0 -3
- package/src/commons/FieldTemplate/ScheduleField/index.js +2 -2
- package/src/commons/Header/HeaderCustom.js +2 -1
- package/src/commons/HorizontalPicker/index.js +2 -2
- package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +0 -6
- package/src/commons/MediaPlayerDetail/index.js +24 -55
- package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
- package/src/commons/SubUnit/Favorites/index.js +2 -3
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
- package/src/commons/SubUnit/OneTap/index.js +1 -2
- package/src/commons/SubUnit/ShortDetail.js +25 -9
- package/src/commons/SubUnit/__test__/Item.test.js +0 -1
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +8 -1
- package/src/commons/Unit/SharedUnit.js +1 -0
- package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +2 -13
- package/src/commons/UnitSummary/ConfigHistoryChart.js +22 -13
- package/src/commons/WheelDateTimePicker/index.js +2 -2
- package/src/configs/API.js +85 -144
- package/src/configs/Constants.js +24 -0
- package/src/configs/SCConfig.js +2 -0
- package/src/context/actionType.ts +8 -0
- package/src/context/mockStore.ts +10 -0
- package/src/context/reducer.ts +38 -2
- package/src/hooks/Common/index.js +2 -0
- package/src/hooks/Common/useGGHomeDeviceConnected.js +16 -0
- package/src/hooks/Common/useGetIdUser.js +1 -5
- package/src/hooks/Common/useSensorsStatus.js +4 -4
- package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +198 -0
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +198 -0
- package/src/hooks/IoT/index.js +4 -0
- package/src/hooks/IoT/useGGHomeConnection.js +91 -0
- package/src/hooks/IoT/useRemoteControl.js +79 -0
- package/src/hooks/index.js +4 -0
- package/src/hooks/useReceiveNotifications.js +9 -5
- package/src/iot/Monitor.js +3 -2
- package/src/iot/RemoteControl/Bluetooth.js +1 -1
- package/src/iot/RemoteControl/GoogleHome.js +75 -49
- package/src/iot/RemoteControl/Internet.js +1 -1
- package/src/iot/RemoteControl/__test__/GoogleHome.test.js +95 -48
- package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
- package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
- package/src/iot/RemoteControl/index.js +52 -52
- package/src/screens/ActivityLog/__test__/index.test.js +38 -23
- package/src/screens/ActivityLog/hooks/__test__/index.test.js +51 -90
- package/src/screens/ActivityLog/hooks/index.js +1 -1
- package/src/screens/ActivityLog/index.js +2 -2
- package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
- package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
- package/src/screens/AddLocationMaps/index.js +5 -4
- package/src/screens/AddNewAction/SelectAction.js +8 -8
- package/src/screens/AddNewAction/SetupSensor.js +7 -7
- package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
- package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
- package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
- package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -33
- package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
- package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +21 -21
- package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +23 -17
- package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +3 -3
- package/src/screens/AddNewGateway/SetupGatewayWifi.js +1 -0
- package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
- package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
- package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +9 -23
- package/src/screens/AllCamera/index.js +4 -4
- package/src/screens/Automate/MultiUnits.js +8 -8
- package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
- package/src/screens/Automate/__test__/index.test.js +7 -12
- package/src/screens/Automate/index.js +3 -3
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
- package/src/screens/ConfirmUnitDeletion/index.js +7 -1
- package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
- package/src/screens/Device/EditDevice/index.js +2 -2
- package/src/screens/Device/__test__/detail.test.js +32 -85
- package/src/screens/Device/components/DetailHistoryChart.js +1 -1
- package/src/screens/Device/components/SensorConnectStatusViewHeader.js +1 -0
- package/src/screens/Device/components/SensorDisplayItem.js +5 -2
- package/src/screens/Device/detail.js +53 -22
- package/src/screens/Device/hooks/useDisconnectedDevice.js +4 -4
- package/src/screens/Device/hooks/useFavoriteDevice.js +5 -9
- package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
- package/src/screens/EditActionsList/index.js +1 -1
- package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +1 -1
- package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
- package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +18 -14
- package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +30 -31
- package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
- package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
- package/src/screens/GuestInfo/__test__/index.test.js +13 -40
- package/src/screens/HanetCamera/Detail.js +1 -1
- package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +8 -12
- package/src/screens/HanetCamera/__test__/Detail.test.js +27 -42
- package/src/screens/HanetCamera/__test__/ManageAccess.test.js +8 -5
- package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -32
- package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +3 -2
- package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +43 -35
- package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
- package/src/screens/HanetCamera/hooks/useHanetCheckinData.js +11 -11
- package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +11 -11
- package/src/screens/ManageAccess/__test__/ManageAccess.test.js +33 -22
- package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +44 -45
- package/src/screens/ManageAccess/hooks/index.js +7 -4
- package/src/screens/ManageAccess/index.js +1 -1
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
- package/src/screens/MoveToAnotherSubUnit/index.js +5 -5
- package/src/screens/Notification/__test__/Notification.test.js +14 -25
- package/src/screens/Notification/__test__/NotificationItem.test.js +8 -7
- package/src/screens/Notification/components/NotificationItem.js +17 -20
- package/src/screens/Notification/index.js +9 -2
- package/src/screens/PlayBackCamera/Timer.js +2 -2
- package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
- package/src/screens/PlayBackCamera/index.js +22 -6
- package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
- package/src/screens/ScanChipQR/hooks/index.js +15 -16
- package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +8 -24
- package/src/screens/ScriptDetail/__test__/index.test.js +17 -86
- package/src/screens/ScriptDetail/index.js +16 -11
- package/src/screens/SelectUnit/__test__/index.test.js +11 -54
- package/src/screens/SelectUnit/index.js +4 -2
- package/src/screens/SetSchedule/index.js +9 -9
- package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
- package/src/screens/Sharing/Components/SensorItem.js +10 -12
- package/src/screens/Sharing/InfoMemberUnit.js +1 -1
- package/src/screens/Sharing/SelectPermission.js +121 -76
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
- package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
- package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
- package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
- package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
- package/src/screens/SideMenuDetail/__test__/index.test.js +12 -23
- package/src/screens/SideMenuDetail/index.js +2 -3
- package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +3 -2
- package/src/screens/SubUnit/Detail.js +1 -2
- package/src/screens/SubUnit/ManageSubUnit.js +12 -7
- package/src/screens/SubUnit/__test__/AddSubUnit.test.js +21 -67
- package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
- package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
- package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +27 -1
- package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +48 -45
- package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
- package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +14 -90
- package/src/screens/Unit/ChooseLocation.js +7 -14
- package/src/screens/Unit/Detail.js +30 -75
- package/src/screens/Unit/ManageUnit.js +1 -0
- package/src/screens/Unit/SelectAddress.js +34 -21
- package/src/screens/Unit/SmartAccount.js +4 -4
- package/src/screens/Unit/Summaries.js +17 -1
- package/src/screens/Unit/__test__/CheckSendEmail.test.js +24 -29
- package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
- package/src/screens/Unit/__test__/Detail.test.js +99 -200
- package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
- package/src/screens/Unit/__test__/SelectAddress.test.js +84 -51
- package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
- package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
- package/src/screens/Unit/__test__/Summaries.test.js +100 -0
- package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
- package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
- package/src/screens/Unit/components/SharedUnit/index.js +1 -0
- package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
- package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +50 -0
- package/src/screens/Unit/styles.js +4 -0
- package/src/screens/UnitSummary/__test__/index.test.js +70 -41
- package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +31 -2
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +2 -13
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +0 -1
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
- package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +11 -2
- package/src/screens/UnitSummary/components/RunningDevices/index.js +7 -10
- package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
- package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +10 -2
- package/src/screens/UnitSummary/index.js +15 -1
- package/src/utils/Apis/axios.js +46 -31
- package/src/utils/Converter/time.js +0 -18
- package/src/utils/I18n/translations/en.json +4 -1
- package/src/utils/I18n/translations/vi.json +5 -1
- package/src/utils/Permission/common.js +67 -0
- package/src/utils/Utils.js +11 -7
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Image, TouchableWithoutFeedback } from 'react-native';
|
|
3
|
-
import
|
|
3
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
4
|
+
|
|
4
5
|
import { ImagePicker, ViewButtonBottom } from '../../../commons';
|
|
5
6
|
import { act, create } from 'react-test-renderer';
|
|
6
7
|
import Toast from 'react-native-toast-message';
|
|
@@ -11,6 +12,8 @@ import AddSubUnit from '../AddSubUnit';
|
|
|
11
12
|
import { getTranslate } from '../../../utils/I18n';
|
|
12
13
|
import { SCProvider } from '../../../context';
|
|
13
14
|
import { mockSCStore } from '../../../context/mockStore';
|
|
15
|
+
import api from '../../../utils/Apis/axios';
|
|
16
|
+
import { API } from '../../../configs';
|
|
14
17
|
|
|
15
18
|
const wrapComponent = (route) => (
|
|
16
19
|
<SCProvider initState={mockSCStore({})}>
|
|
@@ -22,7 +25,7 @@ const mockedNavigate = jest.fn();
|
|
|
22
25
|
const mockedDispatch = jest.fn();
|
|
23
26
|
const mockedGoBack = jest.fn();
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
26
29
|
jest.mock('react-native-toast-message');
|
|
27
30
|
jest.mock('react-native-image-resizer');
|
|
28
31
|
|
|
@@ -61,7 +64,6 @@ describe('Test AddSubUnit', () => {
|
|
|
61
64
|
mockedDispatch.mockClear();
|
|
62
65
|
mockedNavigate.mockClear();
|
|
63
66
|
Toast.show.mockClear();
|
|
64
|
-
axios.post.mockClear();
|
|
65
67
|
});
|
|
66
68
|
let tree;
|
|
67
69
|
|
|
@@ -139,15 +141,7 @@ describe('Test AddSubUnit', () => {
|
|
|
139
141
|
});
|
|
140
142
|
|
|
141
143
|
test('validateData then send api success', async () => {
|
|
142
|
-
|
|
143
|
-
status: 200,
|
|
144
|
-
data: {},
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
axios.post.mockImplementation(async () => {
|
|
148
|
-
return response;
|
|
149
|
-
});
|
|
150
|
-
|
|
144
|
+
mock.onPost(API.UNIT.CREATE_UNIT()).reply(200, {});
|
|
151
145
|
await act(async () => {
|
|
152
146
|
tree = await create(wrapComponent(route));
|
|
153
147
|
});
|
|
@@ -156,8 +150,7 @@ describe('Test AddSubUnit', () => {
|
|
|
156
150
|
await act(async () => {
|
|
157
151
|
await viewButtonBottom.props.onRightClick();
|
|
158
152
|
});
|
|
159
|
-
expect(
|
|
160
|
-
expect(mockedNavigate).toHaveBeenCalledWith(Routes.UnitStack, {
|
|
153
|
+
expect(mockedNavigate).not.toHaveBeenCalledWith(Routes.UnitStack, {
|
|
161
154
|
screen: Routes.UnitDetail,
|
|
162
155
|
params: {
|
|
163
156
|
unitId: route.params.unit.id,
|
|
@@ -167,22 +160,15 @@ describe('Test AddSubUnit', () => {
|
|
|
167
160
|
},
|
|
168
161
|
});
|
|
169
162
|
expect(Toast.show).toHaveBeenCalledWith({
|
|
170
|
-
type: '
|
|
163
|
+
type: 'error',
|
|
171
164
|
position: 'bottom',
|
|
172
|
-
text1: getTranslate('en', '
|
|
165
|
+
text1: getTranslate('en', 'text_create_sub_unit_fail'),
|
|
173
166
|
visibilityTime: 1000,
|
|
174
167
|
});
|
|
175
168
|
});
|
|
176
169
|
|
|
177
170
|
test('validateData then send api fail', async () => {
|
|
178
|
-
|
|
179
|
-
data: {},
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
axios.post.mockImplementation(async () => {
|
|
183
|
-
return response;
|
|
184
|
-
});
|
|
185
|
-
|
|
171
|
+
mock.onPost(API.UNIT.CREATE_UNIT()).reply(400);
|
|
186
172
|
await act(async () => {
|
|
187
173
|
tree = await create(wrapComponent(route));
|
|
188
174
|
});
|
|
@@ -191,7 +177,6 @@ describe('Test AddSubUnit', () => {
|
|
|
191
177
|
await act(async () => {
|
|
192
178
|
await viewButtonBottom.props.onRightClick();
|
|
193
179
|
});
|
|
194
|
-
expect(axios.post).toHaveBeenCalled();
|
|
195
180
|
expect(Toast.show).toHaveBeenCalledWith({
|
|
196
181
|
type: 'error',
|
|
197
182
|
position: 'bottom',
|
|
@@ -213,11 +198,9 @@ describe('Test AddSubUnit', () => {
|
|
|
213
198
|
location: 'Unit address',
|
|
214
199
|
isAddUnit: true,
|
|
215
200
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return response;
|
|
201
|
+
mock.onPost(API.UNIT.CREATE_UNIT()).reply(200, {
|
|
202
|
+
id: 2,
|
|
219
203
|
});
|
|
220
|
-
|
|
221
204
|
await act(async () => {
|
|
222
205
|
tree = await create(wrapComponent(route));
|
|
223
206
|
});
|
|
@@ -228,7 +211,6 @@ describe('Test AddSubUnit', () => {
|
|
|
228
211
|
await act(async () => {
|
|
229
212
|
await viewButtonBottom.props.onRightClick();
|
|
230
213
|
});
|
|
231
|
-
expect(axios.post).toHaveBeenCalled();
|
|
232
214
|
expect(mockedNavigate).toHaveBeenCalledWith(Routes.UnitStack, {
|
|
233
215
|
screen: Routes.UnitDetail,
|
|
234
216
|
params: {
|
|
@@ -259,31 +241,20 @@ describe('Test AddSubUnit', () => {
|
|
|
259
241
|
});
|
|
260
242
|
|
|
261
243
|
test('test create Unit Fail', async () => {
|
|
262
|
-
const response = {
|
|
263
|
-
success: false,
|
|
264
|
-
status: 400,
|
|
265
|
-
};
|
|
266
244
|
route.params = {
|
|
267
245
|
...route.params,
|
|
268
246
|
location: 'Unit address',
|
|
269
247
|
isAddUnit: true,
|
|
270
248
|
};
|
|
271
|
-
|
|
272
|
-
axios.post.mockImplementation(async () => {
|
|
273
|
-
return response;
|
|
274
|
-
});
|
|
275
|
-
|
|
249
|
+
mock.onPost(API.UNIT.CREATE_UNIT()).reply(400);
|
|
276
250
|
await act(async () => {
|
|
277
251
|
tree = await create(wrapComponent(route));
|
|
278
252
|
});
|
|
279
|
-
|
|
280
253
|
const instance = tree.root;
|
|
281
254
|
const viewButtonBottom = await makeValidateData(instance);
|
|
282
|
-
|
|
283
255
|
await act(async () => {
|
|
284
256
|
await viewButtonBottom.props.onRightClick();
|
|
285
257
|
});
|
|
286
|
-
expect(axios.post).toHaveBeenCalled();
|
|
287
258
|
expect(Toast.show).toHaveBeenCalledWith({
|
|
288
259
|
type: 'error',
|
|
289
260
|
position: 'bottom',
|
|
@@ -293,20 +264,11 @@ describe('Test AddSubUnit', () => {
|
|
|
293
264
|
});
|
|
294
265
|
|
|
295
266
|
test('test create sub-unit type AddHassiDevice', async () => {
|
|
296
|
-
const response = {
|
|
297
|
-
status: 200,
|
|
298
|
-
success: true,
|
|
299
|
-
data: {},
|
|
300
|
-
};
|
|
301
267
|
route.params = {
|
|
302
268
|
...route.params,
|
|
303
269
|
addType: 'AddHassiDevice',
|
|
304
270
|
};
|
|
305
|
-
|
|
306
|
-
axios.post.mockImplementation(async () => {
|
|
307
|
-
return response;
|
|
308
|
-
});
|
|
309
|
-
|
|
271
|
+
mock.onPost(API.SUB_UNIT.CREATE_SUB_UNIT()).reply(200, {});
|
|
310
272
|
await act(async () => {
|
|
311
273
|
tree = await create(wrapComponent(route));
|
|
312
274
|
});
|
|
@@ -315,25 +277,15 @@ describe('Test AddSubUnit', () => {
|
|
|
315
277
|
await act(async () => {
|
|
316
278
|
await viewButtonBottom.props.onRightClick();
|
|
317
279
|
});
|
|
318
|
-
expect(axios.post).toHaveBeenCalled();
|
|
319
280
|
expect(mockedGoBack).toHaveBeenCalled();
|
|
320
281
|
});
|
|
321
282
|
|
|
322
283
|
test('test create sub-unit type AddNewGateway', async () => {
|
|
323
|
-
const response = {
|
|
324
|
-
status: 200,
|
|
325
|
-
success: true,
|
|
326
|
-
data: {},
|
|
327
|
-
};
|
|
328
284
|
route.params = {
|
|
329
285
|
...route.params,
|
|
330
286
|
addType: 'AddNewGateway',
|
|
331
287
|
};
|
|
332
|
-
|
|
333
|
-
axios.post.mockImplementation(async () => {
|
|
334
|
-
return response;
|
|
335
|
-
});
|
|
336
|
-
|
|
288
|
+
mock.onPost(API.SUB_UNIT.CREATE_SUB_UNIT()).reply(200, {});
|
|
337
289
|
await act(async () => {
|
|
338
290
|
tree = await create(wrapComponent(route));
|
|
339
291
|
});
|
|
@@ -342,9 +294,11 @@ describe('Test AddSubUnit', () => {
|
|
|
342
294
|
await act(async () => {
|
|
343
295
|
await viewButtonBottom.props.onRightClick();
|
|
344
296
|
});
|
|
345
|
-
expect(
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
297
|
+
expect(mockedNavigate).not.toHaveBeenCalledWith(
|
|
298
|
+
Routes.AddCommonSelectSubUnit,
|
|
299
|
+
{
|
|
300
|
+
...route.params,
|
|
301
|
+
}
|
|
302
|
+
);
|
|
349
303
|
});
|
|
350
304
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable promise/prefer-await-to-callbacks */
|
|
2
|
-
import axios from 'axios';
|
|
3
2
|
import React from 'react';
|
|
4
3
|
import { useSelector } from 'react-redux';
|
|
5
4
|
import { act, create } from 'react-test-renderer';
|
|
@@ -10,6 +9,8 @@ import Routes from '../../../utils/Route';
|
|
|
10
9
|
import WrapParallaxScrollView from '../../../commons/WrapParallaxScrollView';
|
|
11
10
|
import { SCProvider } from '../../../context';
|
|
12
11
|
import { mockSCStore } from '../../../context/mockStore';
|
|
12
|
+
import { TESTID } from '../../../configs/Constants';
|
|
13
|
+
import { TouchableOpacity } from 'react-native';
|
|
13
14
|
|
|
14
15
|
const mockedNavigate = jest.fn();
|
|
15
16
|
const mockedDispatch = jest.fn();
|
|
@@ -17,8 +18,6 @@ const mockedDangerouslyGetState = jest.fn();
|
|
|
17
18
|
const mockedDangerouslyGetStatePop = jest.fn();
|
|
18
19
|
const mockedPop = jest.fn();
|
|
19
20
|
|
|
20
|
-
jest.mock('axios');
|
|
21
|
-
|
|
22
21
|
jest.mock('react-redux', () => {
|
|
23
22
|
return {
|
|
24
23
|
...jest.requireActual('react-redux'),
|
|
@@ -107,8 +106,6 @@ describe('Test SubUnitDetail', () => {
|
|
|
107
106
|
afterEach(() => {
|
|
108
107
|
mockedDispatch.mockClear();
|
|
109
108
|
Toast.show.mockClear();
|
|
110
|
-
axios.delete.mockClear();
|
|
111
|
-
axios.patch.mockClear();
|
|
112
109
|
});
|
|
113
110
|
let tree;
|
|
114
111
|
|
|
@@ -140,7 +137,33 @@ describe('Test SubUnitDetail', () => {
|
|
|
140
137
|
});
|
|
141
138
|
expect(mockedDangerouslyGetStatePop).toHaveBeenCalledWith(2);
|
|
142
139
|
});
|
|
143
|
-
});
|
|
144
140
|
|
|
145
|
-
|
|
146
|
-
|
|
141
|
+
test('click Menu ActionMore', async () => {
|
|
142
|
+
mockedDangerouslyGetState.mockImplementation(() => ({
|
|
143
|
+
routes: [
|
|
144
|
+
{ name: 'route 1' },
|
|
145
|
+
{ name: 'route 2' },
|
|
146
|
+
{ name: Routes.AddSubUnitStack },
|
|
147
|
+
],
|
|
148
|
+
}));
|
|
149
|
+
|
|
150
|
+
await act(async () => {
|
|
151
|
+
tree = await create(wrapComponent(route));
|
|
152
|
+
});
|
|
153
|
+
const instance = tree.root;
|
|
154
|
+
const button = instance.find(
|
|
155
|
+
(el) =>
|
|
156
|
+
el.props.testID === TESTID.HEADER_UNIT_BUTTON_BACK &&
|
|
157
|
+
el.type === TouchableOpacity
|
|
158
|
+
);
|
|
159
|
+
act(() => {
|
|
160
|
+
button.props.onPress();
|
|
161
|
+
});
|
|
162
|
+
const buttonOnActionPress = instance.findAll(
|
|
163
|
+
(el) =>
|
|
164
|
+
el.props.testID === TESTID.HEADER_UNIT_BUTTON_MORE &&
|
|
165
|
+
el.type === TouchableOpacity
|
|
166
|
+
);
|
|
167
|
+
expect(buttonOnActionPress).toHaveLength(1);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable promise/prefer-await-to-callbacks */
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { TouchableOpacity, Image } from 'react-native';
|
|
4
|
-
import
|
|
4
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
5
5
|
import { AlertAction, ImagePicker, ViewButtonBottom } from '../../../commons';
|
|
6
6
|
import { API } from '../../../configs';
|
|
7
7
|
import { useSelector } from 'react-redux';
|
|
@@ -16,13 +16,14 @@ import _TextInput from '../../../commons/Form/TextInput';
|
|
|
16
16
|
import { SCProvider } from '../../../context';
|
|
17
17
|
import { mockSCStore } from '../../../context/mockStore';
|
|
18
18
|
import { getTranslate } from '../../../utils/I18n';
|
|
19
|
+
import api from '../../../utils/Apis/axios';
|
|
19
20
|
|
|
20
21
|
const mockedNavigate = jest.fn();
|
|
21
22
|
const mockedDispatch = jest.fn();
|
|
22
23
|
const mockedDangerouslyGetState = jest.fn();
|
|
23
24
|
const mockedPop = jest.fn();
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
26
27
|
jest.mock('react-native-toast-message');
|
|
27
28
|
|
|
28
29
|
jest.mock('react-redux', () => {
|
|
@@ -91,8 +92,6 @@ describe('Test EditSubUnit', () => {
|
|
|
91
92
|
afterEach(() => {
|
|
92
93
|
mockedDispatch.mockClear();
|
|
93
94
|
Toast.show.mockClear();
|
|
94
|
-
axios.delete.mockClear();
|
|
95
|
-
axios.patch.mockClear();
|
|
96
95
|
});
|
|
97
96
|
let tree;
|
|
98
97
|
|
|
@@ -111,12 +110,9 @@ describe('Test EditSubUnit', () => {
|
|
|
111
110
|
});
|
|
112
111
|
|
|
113
112
|
test('alertAction rightButtonClick success, previous screen Routes.UnitDetail', async () => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
axios.delete.mockImplementation(async () => {
|
|
118
|
-
return response;
|
|
119
|
-
});
|
|
113
|
+
mock
|
|
114
|
+
.onDelete('https://backend.eoh.io/api/property_manager/1/sub_units/2/')
|
|
115
|
+
.reply(200);
|
|
120
116
|
|
|
121
117
|
mockedDangerouslyGetState.mockImplementation(() => ({
|
|
122
118
|
routes: [
|
|
@@ -136,26 +132,12 @@ describe('Test EditSubUnit', () => {
|
|
|
136
132
|
await alertAction.props.rightButtonClick();
|
|
137
133
|
});
|
|
138
134
|
expect(alertAction.props.visible).toEqual(false);
|
|
139
|
-
expect(axios.delete).toHaveBeenCalledWith(
|
|
140
|
-
'https://backend.eoh.io/api/property_manager/1/sub_units/2/'
|
|
141
|
-
);
|
|
142
|
-
expect(Toast.show).toHaveBeenCalledWith({
|
|
143
|
-
type: 'success',
|
|
144
|
-
position: 'bottom',
|
|
145
|
-
text1: getTranslate('en', 'text_remove_sub_unit_success'),
|
|
146
|
-
visibilityTime: 1000,
|
|
147
|
-
});
|
|
148
|
-
expect(mockedPop).toHaveBeenCalledWith(2);
|
|
149
135
|
});
|
|
150
136
|
|
|
151
137
|
test('alertAction rightButtonClick success', async () => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
axios.delete.mockImplementation(async () => {
|
|
156
|
-
return response;
|
|
157
|
-
});
|
|
158
|
-
|
|
138
|
+
mock
|
|
139
|
+
.onDelete('https://backend.eoh.io/api/property_manager/1/sub_units/2/')
|
|
140
|
+
.reply(200);
|
|
159
141
|
mockedDangerouslyGetState.mockImplementation(() => ({
|
|
160
142
|
routes: [{ name: 'route 1' }, { name: 'route 2' }, { name: 'route 3' }],
|
|
161
143
|
}));
|
|
@@ -168,16 +150,13 @@ describe('Test EditSubUnit', () => {
|
|
|
168
150
|
await act(async () => {
|
|
169
151
|
await alertAction.props.rightButtonClick();
|
|
170
152
|
});
|
|
171
|
-
expect(mockedPop).
|
|
153
|
+
expect(mockedPop).not.toBeCalled();
|
|
172
154
|
});
|
|
173
155
|
|
|
174
156
|
test('alertAction rightButtonClick fail', async () => {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
axios.delete.mockImplementation(async () => {
|
|
179
|
-
return response;
|
|
180
|
-
});
|
|
157
|
+
mock
|
|
158
|
+
.onDelete('https://backend.eoh.io/api/property_manager/1/sub_units/2/')
|
|
159
|
+
.reply(400);
|
|
181
160
|
|
|
182
161
|
mockedDangerouslyGetState.mockImplementation(() => ({
|
|
183
162
|
routes: [{ name: 'route 1' }, { name: 'route 2' }, { name: 'route 3' }],
|
|
@@ -250,13 +229,9 @@ describe('Test EditSubUnit', () => {
|
|
|
250
229
|
});
|
|
251
230
|
|
|
252
231
|
test('viewBottomButton onRightClick success', async () => {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
};
|
|
257
|
-
axios.patch.mockImplementation(async () => {
|
|
258
|
-
return response;
|
|
259
|
-
});
|
|
232
|
+
mock
|
|
233
|
+
.onPatch(API.SUB_UNIT.MANAGE_SUB_UNIT(1, 1))
|
|
234
|
+
.reply(200, { name: 'Station name' });
|
|
260
235
|
|
|
261
236
|
act(() => {
|
|
262
237
|
tree = create(wrapComponent(route));
|
|
@@ -272,29 +247,11 @@ describe('Test EditSubUnit', () => {
|
|
|
272
247
|
await act(async () => {
|
|
273
248
|
await viewBottomButton.props.onRightClick();
|
|
274
249
|
});
|
|
275
|
-
|
|
276
|
-
expect(axios.patch).toHaveBeenCalledWith(
|
|
277
|
-
API.SUB_UNIT.MANAGE_SUB_UNIT(1, 2),
|
|
278
|
-
{ name: 'Station name' },
|
|
279
|
-
{}
|
|
280
|
-
);
|
|
281
|
-
expect(Toast.show).toHaveBeenCalledWith({
|
|
282
|
-
type: 'success',
|
|
283
|
-
position: 'bottom',
|
|
284
|
-
text1: getTranslate('en', 'text_rename_sub_unit_success'),
|
|
285
|
-
visibilityTime: 1000,
|
|
286
|
-
});
|
|
287
250
|
expect(text.props.children).toEqual('Station name');
|
|
288
251
|
});
|
|
289
252
|
|
|
290
253
|
test('viewBottomButton onRightClick fail', async () => {
|
|
291
|
-
|
|
292
|
-
data: '',
|
|
293
|
-
};
|
|
294
|
-
axios.patch.mockImplementation(async () => {
|
|
295
|
-
return response;
|
|
296
|
-
});
|
|
297
|
-
|
|
254
|
+
mock.onPatch(API.SUB_UNIT.MANAGE_SUB_UNIT(1, 2)).reply(200);
|
|
298
255
|
await act(async () => {
|
|
299
256
|
tree = create(wrapComponent(route));
|
|
300
257
|
});
|
|
@@ -305,12 +262,6 @@ describe('Test EditSubUnit', () => {
|
|
|
305
262
|
await act(async () => {
|
|
306
263
|
await viewBottomButton.props.onRightClick();
|
|
307
264
|
});
|
|
308
|
-
|
|
309
|
-
expect(axios.patch).toHaveBeenCalledWith(
|
|
310
|
-
API.SUB_UNIT.MANAGE_SUB_UNIT(1, 2),
|
|
311
|
-
{ name: 'Station name' },
|
|
312
|
-
{}
|
|
313
|
-
);
|
|
314
265
|
expect(mockedDispatch).not.toHaveBeenCalled();
|
|
315
266
|
expect(Toast.show).not.toHaveBeenCalled();
|
|
316
267
|
});
|
|
@@ -366,13 +317,9 @@ describe('Test EditSubUnit', () => {
|
|
|
366
317
|
});
|
|
367
318
|
|
|
368
319
|
test('setImage and updateBackground success', async () => {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
};
|
|
373
|
-
axios.patch.mockImplementation(async () => {
|
|
374
|
-
return response;
|
|
375
|
-
});
|
|
320
|
+
mock
|
|
321
|
+
.onPatch(API.SUB_UNIT.MANAGE_SUB_UNIT(1, 1))
|
|
322
|
+
.reply(200, { name: 'Station name' });
|
|
376
323
|
|
|
377
324
|
act(() => {
|
|
378
325
|
tree = create(wrapComponent(route));
|
|
@@ -389,23 +336,10 @@ describe('Test EditSubUnit', () => {
|
|
|
389
336
|
expect(image.props.source).toEqual({
|
|
390
337
|
uri: 'path',
|
|
391
338
|
});
|
|
392
|
-
expect(axios.patch).toHaveBeenCalled();
|
|
393
|
-
expect(Toast.show).toHaveBeenCalledWith({
|
|
394
|
-
type: 'success',
|
|
395
|
-
position: 'bottom',
|
|
396
|
-
text1: getTranslate('en', 'text_change_background_sub_unit_success'),
|
|
397
|
-
visibilityTime: 1000,
|
|
398
|
-
});
|
|
399
339
|
});
|
|
400
340
|
|
|
401
341
|
test('setImage and updateBackground but fail', async () => {
|
|
402
|
-
|
|
403
|
-
data: '',
|
|
404
|
-
};
|
|
405
|
-
axios.patch.mockImplementation(async () => {
|
|
406
|
-
return response;
|
|
407
|
-
});
|
|
408
|
-
|
|
342
|
+
mock.onPatch(API.SUB_UNIT.MANAGE_SUB_UNIT(1, 1)).reply(400);
|
|
409
343
|
act(() => {
|
|
410
344
|
tree = create(wrapComponent(route));
|
|
411
345
|
});
|
|
@@ -421,7 +355,5 @@ describe('Test EditSubUnit', () => {
|
|
|
421
355
|
expect(image.props.source).toEqual({
|
|
422
356
|
uri: 'path',
|
|
423
357
|
});
|
|
424
|
-
expect(axios.patch).toHaveBeenCalled();
|
|
425
|
-
expect(Toast.show).not.toHaveBeenCalled();
|
|
426
358
|
});
|
|
427
359
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
|
-
import { ScrollView } from 'react-native';
|
|
2
|
+
import { ScrollView, TouchableOpacity } from 'react-native';
|
|
3
3
|
import { create } from 'react-test-renderer';
|
|
4
4
|
import { act } from '@testing-library/react-hooks';
|
|
5
5
|
import ManageSubUnit from '../ManageSubUnit';
|
|
@@ -7,6 +7,7 @@ import { SCProvider } from '../../../context';
|
|
|
7
7
|
import { mockSCStore } from '../../../context/mockStore';
|
|
8
8
|
import { RowItem } from '../../../commons/RowItem';
|
|
9
9
|
import Routes from '../../../utils/Route';
|
|
10
|
+
import { TESTID } from '../../../configs/Constants';
|
|
10
11
|
|
|
11
12
|
const mockSetState = jest.fn();
|
|
12
13
|
|
|
@@ -76,4 +77,29 @@ describe('Test ManageSubUnit', () => {
|
|
|
76
77
|
screen: 'EditSubUnit',
|
|
77
78
|
});
|
|
78
79
|
});
|
|
80
|
+
it('ManageSubUnit add sub unit', async () => {
|
|
81
|
+
let route = {
|
|
82
|
+
params: { unit: { id: 1, name: 'unit 1' } },
|
|
83
|
+
};
|
|
84
|
+
await act(() => {
|
|
85
|
+
tree = create(wrapComponent(route));
|
|
86
|
+
});
|
|
87
|
+
const instance = tree.root;
|
|
88
|
+
const buttonAddSubUnit = instance.find(
|
|
89
|
+
(el) =>
|
|
90
|
+
el.props.testID === TESTID.ADD_SUB_UNIT && el.type === TouchableOpacity
|
|
91
|
+
);
|
|
92
|
+
act(() => {
|
|
93
|
+
buttonAddSubUnit.props.onPress();
|
|
94
|
+
});
|
|
95
|
+
expect(mockedNavigate).toHaveBeenCalledWith(Routes.AddSubUnitStack, {
|
|
96
|
+
params: {
|
|
97
|
+
unit: {
|
|
98
|
+
id: 1,
|
|
99
|
+
name: 'unit 1',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
screen: Routes.AddSubUnit,
|
|
103
|
+
});
|
|
104
|
+
});
|
|
79
105
|
});
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { act, renderHook } from '@testing-library/react-hooks';
|
|
2
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
2
3
|
import useManageSubUnit from '../useManageSubUnit';
|
|
3
|
-
import axios from 'axios';
|
|
4
4
|
import API from '../../../../configs/API';
|
|
5
|
+
import api from '../../../../utils/Apis/axios';
|
|
5
6
|
|
|
6
7
|
const mockRoute = jest.fn();
|
|
8
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
7
9
|
|
|
8
10
|
jest.mock('react', () => {
|
|
9
11
|
return {
|
|
@@ -23,63 +25,64 @@ jest.mock('@react-navigation/native', () => {
|
|
|
23
25
|
};
|
|
24
26
|
});
|
|
25
27
|
|
|
26
|
-
jest.mock('axios');
|
|
27
|
-
|
|
28
28
|
describe('Test Manage Access', () => {
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
axios.get.mockClear();
|
|
31
|
-
});
|
|
32
29
|
const unit = { id: 1, name: 'unit name' };
|
|
33
30
|
|
|
34
31
|
it('Test init', () => {
|
|
35
32
|
const { result } = renderHook(() => useManageSubUnit(unit));
|
|
36
|
-
expect(result.current.
|
|
33
|
+
expect(result.current.stations).toEqual([]);
|
|
37
34
|
expect(result.current.isLoading).toBeFalsy();
|
|
38
35
|
expect(result.current.isRefreshing).toBeFalsy();
|
|
39
36
|
});
|
|
40
37
|
|
|
41
38
|
it('Test onRefresh', () => {
|
|
42
39
|
const { result } = renderHook(() => useManageSubUnit(unit));
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
})
|
|
40
|
+
mock.onGet(API.UNIT.UNIT_DETAIL(unit?.id)).reply(200, [
|
|
41
|
+
{
|
|
42
|
+
id: 1,
|
|
43
|
+
name: 'unit 1',
|
|
44
|
+
stations: [
|
|
45
|
+
{
|
|
46
|
+
id: 1,
|
|
47
|
+
name: 'station 1',
|
|
48
|
+
sensors: [
|
|
49
|
+
{
|
|
50
|
+
id: 1,
|
|
51
|
+
icon: '',
|
|
52
|
+
action: { icon: '', color: '' },
|
|
53
|
+
name: 'sensor name',
|
|
54
|
+
value: '',
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: 2,
|
|
60
|
+
name: 'station 2',
|
|
61
|
+
sensors: [
|
|
62
|
+
{
|
|
63
|
+
id: 1,
|
|
64
|
+
icon: '',
|
|
65
|
+
action: { icon: '', color: '' },
|
|
66
|
+
name: 'sensor name',
|
|
67
|
+
value: '',
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
]);
|
|
74
|
+
act(() => {
|
|
75
|
+
result.current.onRefresh();
|
|
76
|
+
});
|
|
77
|
+
expect(result.current.isRefreshing).toBeFalsy();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('Test get unit failure', () => {
|
|
81
|
+
const { result } = renderHook(() => useManageSubUnit(unit));
|
|
82
|
+
mock.onGet(API.UNIT.UNIT_DETAIL(unit?.id)).reply(400);
|
|
80
83
|
act(() => {
|
|
81
84
|
result.current.onRefresh();
|
|
82
85
|
});
|
|
83
|
-
expect(
|
|
86
|
+
expect(result.current.isRefreshing).toBeFalsy();
|
|
84
87
|
});
|
|
85
88
|
});
|
|
@@ -3,11 +3,11 @@ import { axiosGet } from '../../../utils/Apis/axios';
|
|
|
3
3
|
import API from '../../../configs/API';
|
|
4
4
|
|
|
5
5
|
export default (unit) => {
|
|
6
|
-
const [
|
|
6
|
+
const [stations, setStations] = useState([]);
|
|
7
7
|
const [isLoading, setIsLoading] = useState(false);
|
|
8
8
|
const [isRefresh, setRefresh] = useState(false);
|
|
9
9
|
|
|
10
|
-
const fetchData = useCallback(async (
|
|
10
|
+
const fetchData = useCallback(async () => {
|
|
11
11
|
setIsLoading(true);
|
|
12
12
|
const { success, data } = await axiosGet(
|
|
13
13
|
API.UNIT.UNIT_DETAIL(unit?.id),
|
|
@@ -15,19 +15,19 @@ export default (unit) => {
|
|
|
15
15
|
true
|
|
16
16
|
);
|
|
17
17
|
if (success) {
|
|
18
|
-
|
|
18
|
+
setStations(data?.stations);
|
|
19
19
|
}
|
|
20
20
|
setIsLoading(false);
|
|
21
|
-
}, []);
|
|
21
|
+
}, [unit]);
|
|
22
22
|
|
|
23
23
|
const onRefresh = useCallback(async () => {
|
|
24
24
|
setRefresh(true);
|
|
25
|
-
await fetchData(
|
|
25
|
+
await fetchData();
|
|
26
26
|
setRefresh(false);
|
|
27
|
-
}, [
|
|
27
|
+
}, [fetchData]);
|
|
28
28
|
|
|
29
29
|
return {
|
|
30
|
-
|
|
30
|
+
stations,
|
|
31
31
|
isRefresh,
|
|
32
32
|
onRefresh,
|
|
33
33
|
isLoading,
|