@eohjsc/react-native-smart-city 0.2.99 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -1
- package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
- 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/StatesGridActionTemplate.js +8 -4
- package/src/commons/ActionGroup/TimerActionTemplate.js +2 -2
- package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
- 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 +135 -0
- 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/__test__/Connecting.test.js +136 -3
- package/src/commons/ConnectingProcess/index.js +1 -1
- 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/Hanet/ItemHanetDevice.test.js +58 -0
- package/src/commons/Device/LinearChart.js +15 -0
- 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/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
- package/src/commons/SubUnit/OneTap/index.js +1 -2
- package/src/commons/Unit/SharedUnit.js +1 -0
- package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
- package/src/configs/API.js +85 -139
- package/src/configs/Constants.js +11 -0
- package/src/configs/SCConfig.js +2 -0
- package/src/iot/RemoteControl/__test__/GoogleHome.test.js +8 -30
- package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
- package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
- 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/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/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/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/Automate/__test__/MultiUnits.test.js +6 -9
- package/src/screens/Automate/__test__/index.test.js +7 -12
- 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/__test__/detail.test.js +22 -83
- package/src/screens/Device/detail.js +4 -6
- package/src/screens/Device/hooks/useFavoriteDevice.js +5 -9
- package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
- 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/EnterPassword/__test__/EnterPassword.test.js +41 -25
- package/src/screens/GuestInfo/__test__/index.test.js +13 -40
- 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/hooks/__test__/useHanetCheckinData.test.js +43 -35
- package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
- 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/index.js +1 -1
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
- package/src/screens/MoveToAnotherSubUnit/index.js +4 -4
- package/src/screens/Notification/__test__/Notification.test.js +14 -25
- package/src/screens/Notification/__test__/NotificationItem.test.js +4 -3
- package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
- package/src/screens/PlayBackCamera/index.js +19 -3
- package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
- 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 +2 -1
- package/src/screens/SelectUnit/__test__/index.test.js +11 -54
- package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
- package/src/screens/Sharing/InfoMemberUnit.js +1 -1
- package/src/screens/Sharing/SelectPermission.js +107 -70
- 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 +10 -21
- 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/hooks/__test__/useManageSubUnit.test.js +47 -44
- package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +14 -90
- package/src/screens/Unit/ChooseLocation.js +1 -1
- package/src/screens/Unit/ManageUnit.js +1 -0
- package/src/screens/Unit/__test__/CheckSendEmail.test.js +15 -28
- package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
- package/src/screens/Unit/__test__/Detail.test.js +83 -185
- package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
- package/src/screens/Unit/__test__/SelectAddress.test.js +13 -39
- package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
- package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
- 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/UnitSummary/__test__/index.test.js +18 -43
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
- package/src/utils/Apis/axios.js +37 -13
- package/src/utils/Utils.js +6 -6
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TouchableOpacity } from 'react-native';
|
|
3
3
|
import { create, act } from 'react-test-renderer';
|
|
4
|
-
import
|
|
4
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
5
|
+
|
|
5
6
|
import { SCProvider } from '../../../context';
|
|
6
7
|
import { mockSCStore } from '../../../context/mockStore';
|
|
7
8
|
import HanetMemberInfo from '../MemberInfo';
|
|
@@ -10,6 +11,8 @@ import TextInput from '../../../commons/Form/TextInput';
|
|
|
10
11
|
import BottomButtonView from '../../../commons/BottomButtonView';
|
|
11
12
|
import BottomSheet from '../../../commons/BottomSheet';
|
|
12
13
|
import { TESTID } from '../../../configs/Constants';
|
|
14
|
+
import api from '../../../utils/Apis/axios';
|
|
15
|
+
import { API } from '../../../configs';
|
|
13
16
|
|
|
14
17
|
const wrapComponent = (route) => (
|
|
15
18
|
<SCProvider initState={mockSCStore({})}>
|
|
@@ -37,7 +40,7 @@ jest.mock('@react-navigation/native', () => {
|
|
|
37
40
|
};
|
|
38
41
|
});
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
41
44
|
|
|
42
45
|
describe('Test HanetMemberInfo', () => {
|
|
43
46
|
let tree, route;
|
|
@@ -45,9 +48,6 @@ describe('Test HanetMemberInfo', () => {
|
|
|
45
48
|
beforeEach(() => {
|
|
46
49
|
mockedNavigate.mockClear();
|
|
47
50
|
mockedGoBack.mockClear();
|
|
48
|
-
axios.post.mockClear();
|
|
49
|
-
axios.patch.mockClear();
|
|
50
|
-
axios.delete.mockClear();
|
|
51
51
|
route = {
|
|
52
52
|
params: {
|
|
53
53
|
hanetPlace: {
|
|
@@ -72,23 +72,18 @@ describe('Test HanetMemberInfo', () => {
|
|
|
72
72
|
const touches = instance.findAllByType(TouchableOpacity);
|
|
73
73
|
expect(touches).toHaveLength(7);
|
|
74
74
|
const alertAction = instance.findByType(AlertAction);
|
|
75
|
-
|
|
76
75
|
// open alert action
|
|
77
76
|
await act(async () => {
|
|
78
77
|
await touches[2].props.onPress();
|
|
79
78
|
});
|
|
80
|
-
expect(alertAction.props.visible).toBe(true);
|
|
81
|
-
|
|
82
79
|
const textInput = instance.findByType(TextInput);
|
|
83
|
-
|
|
84
|
-
axios.patch.mockImplementationOnce(async () => ({ status: 200 }));
|
|
85
|
-
|
|
80
|
+
mock.onPatch(API.CAMERA.HANET.RENAME_MEMBER(1, 1)).reply(200);
|
|
86
81
|
// change name and press rename
|
|
87
82
|
await act(async () => {
|
|
88
83
|
await textInput.props.onChange('new name');
|
|
89
84
|
await alertAction.props.rightButtonClick();
|
|
90
85
|
});
|
|
91
|
-
expect(
|
|
86
|
+
expect(alertAction.props.visible).toBe(false);
|
|
92
87
|
});
|
|
93
88
|
|
|
94
89
|
test('Test remove member', async () => {
|
|
@@ -105,15 +100,11 @@ describe('Test HanetMemberInfo', () => {
|
|
|
105
100
|
await touches[3].props.onPress();
|
|
106
101
|
});
|
|
107
102
|
expect(alertAction.props.visible).toBe(true);
|
|
108
|
-
|
|
109
|
-
axios.delete.mockImplementationOnce(async () => ({ status: 200 }));
|
|
110
|
-
|
|
103
|
+
mock.onDelete(API.CAMERA.HANET.REMOVE_MEMBER(1, 1)).reply(200);
|
|
111
104
|
// press remove
|
|
112
105
|
await act(async () => {
|
|
113
106
|
await alertAction.props.rightButtonClick();
|
|
114
107
|
});
|
|
115
|
-
|
|
116
|
-
expect(axios.delete).toHaveBeenCalled();
|
|
117
108
|
expect(mockedGoBack).toHaveBeenCalled();
|
|
118
109
|
});
|
|
119
110
|
|
|
@@ -153,24 +144,14 @@ describe('Test HanetMemberInfo', () => {
|
|
|
153
144
|
const instance = tree.root;
|
|
154
145
|
const touches = instance.findAllByType(TouchableOpacity);
|
|
155
146
|
expect(touches).toHaveLength(7);
|
|
156
|
-
|
|
157
147
|
await act(async () => {
|
|
158
148
|
await touches[1].props.onPress();
|
|
159
149
|
});
|
|
160
|
-
|
|
161
150
|
const bottomSheet = instance.findByType(BottomSheet);
|
|
162
151
|
expect(bottomSheet.props.isVisible).toBe(true);
|
|
163
|
-
|
|
164
|
-
axios.patch.mockImplementationOnce(async () => ({
|
|
165
|
-
status: 200,
|
|
166
|
-
data: {
|
|
167
|
-
avatar_uri: 'uri',
|
|
168
|
-
},
|
|
169
|
-
}));
|
|
152
|
+
mock.onPatch(API.CAMERA.HANET.UPDATE_FACE_ID(1, 1)).reply(200);
|
|
170
153
|
await chooseSetFaceIDOption(instance, 1);
|
|
171
|
-
|
|
172
154
|
expect(bottomSheet.props.isVisible).toBe(false);
|
|
173
|
-
expect(axios.patch).toBeCalled(); // call api update face id
|
|
174
155
|
});
|
|
175
156
|
|
|
176
157
|
test('Test register new member', async () => {
|
|
@@ -196,7 +177,6 @@ describe('Test HanetMemberInfo', () => {
|
|
|
196
177
|
expect(bottomSheet.props.isVisible).toBe(true);
|
|
197
178
|
|
|
198
179
|
await chooseSetFaceIDOption(instance, 1);
|
|
199
|
-
expect(axios.patch).not.toBeCalled(); // not call api
|
|
200
180
|
|
|
201
181
|
// open alert action
|
|
202
182
|
const alertAction = instance.findByType(AlertAction);
|
|
@@ -211,15 +191,13 @@ describe('Test HanetMemberInfo', () => {
|
|
|
211
191
|
await textInput.props.onChange('new name');
|
|
212
192
|
await alertAction.props.rightButtonClick();
|
|
213
193
|
});
|
|
214
|
-
expect(axios.post).not.toBeCalled();
|
|
215
194
|
|
|
216
195
|
// finish
|
|
217
196
|
const bottomButton = instance.findByType(BottomButtonView);
|
|
218
|
-
|
|
197
|
+
mock.onPost(API.CAMERA.HANET.REGISTER(1)).reply(200);
|
|
219
198
|
await act(async () => {
|
|
220
199
|
await bottomButton.props.onPressMain();
|
|
221
200
|
});
|
|
222
|
-
expect(axios.post).toBeCalled();
|
|
223
201
|
expect(mockedNavigate).toBeCalled();
|
|
224
202
|
});
|
|
225
203
|
});
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { act, renderHook } from '@testing-library/react-hooks';
|
|
2
2
|
import { useHanetCheckinData } from '../index';
|
|
3
|
-
import
|
|
3
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
4
4
|
import moment from 'moment';
|
|
5
|
+
import api from '../../../../utils/Apis/axios';
|
|
6
|
+
import { API } from '../../../../configs';
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
7
9
|
|
|
8
10
|
describe('Test useHanetCheckinData', () => {
|
|
9
11
|
let props, data;
|
|
10
12
|
|
|
11
13
|
beforeEach(() => {
|
|
12
14
|
Date.now = jest.fn(() => new Date('2021-09-09T10:00:00.000Z'));
|
|
13
|
-
axios.get.mockClear();
|
|
14
15
|
props = {
|
|
15
16
|
device_id: 1,
|
|
16
17
|
place: {
|
|
@@ -51,40 +52,20 @@ describe('Test useHanetCheckinData', () => {
|
|
|
51
52
|
|
|
52
53
|
test('Test onRefresh', async () => {
|
|
53
54
|
const { result } = renderHook(() => useHanetCheckinData(props));
|
|
54
|
-
|
|
55
|
-
status: 200,
|
|
56
|
-
data: data,
|
|
57
|
-
}));
|
|
55
|
+
mock.onGet(API.CAMERA.HANET.CHECKIN(1)).reply(200, data);
|
|
58
56
|
await act(async () => {
|
|
59
57
|
await result.current.onRefresh();
|
|
60
58
|
});
|
|
61
|
-
expect(
|
|
59
|
+
expect(result.current.countMember).toBe(data.count_member);
|
|
62
60
|
});
|
|
63
61
|
|
|
64
|
-
test('Test
|
|
65
|
-
const { result } = renderHook(() => useHanetCheckinData(
|
|
66
|
-
|
|
67
|
-
status: 200,
|
|
68
|
-
data: data,
|
|
69
|
-
}));
|
|
70
|
-
await act(async () => {
|
|
71
|
-
await result.current.onLoadMore();
|
|
72
|
-
});
|
|
73
|
-
expect(axios.get).toHaveBeenCalled();
|
|
74
|
-
|
|
75
|
-
axios.get.mockClear();
|
|
76
|
-
|
|
77
|
-
await act(async () => {
|
|
78
|
-
await result.current.onLoadMore();
|
|
79
|
-
});
|
|
80
|
-
expect(axios.get).toHaveBeenCalledTimes(0);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('Test onMomentumScrollBegin', async () => {
|
|
84
|
-
const { result } = renderHook(() => useHanetCheckinData(props));
|
|
62
|
+
test('Test render without props', async () => {
|
|
63
|
+
const { result } = renderHook(() => useHanetCheckinData());
|
|
64
|
+
mock.onGet(API.CAMERA.HANET.CHECKIN(1)).reply(200, data);
|
|
85
65
|
await act(async () => {
|
|
86
|
-
await result.current.
|
|
66
|
+
await result.current.onRefresh();
|
|
87
67
|
});
|
|
68
|
+
expect(result.current.refreshing).toBeFalsy();
|
|
88
69
|
});
|
|
89
70
|
|
|
90
71
|
test('Test onReceiveNewCheckinData', async () => {
|
|
@@ -101,9 +82,9 @@ describe('Test useHanetCheckinData', () => {
|
|
|
101
82
|
await act(async () => {
|
|
102
83
|
await result.current.onReceiveNewCheckinData(newData);
|
|
103
84
|
});
|
|
104
|
-
expect(result.current.checkinData).toHaveLength(
|
|
85
|
+
expect(result.current.checkinData).toHaveLength(3);
|
|
105
86
|
expect(result.current.countMember).toBe(1);
|
|
106
|
-
expect(result.current.countStranger).
|
|
87
|
+
expect(result.current.countStranger).toBe(1);
|
|
107
88
|
|
|
108
89
|
const newData2 = {
|
|
109
90
|
id: 2,
|
|
@@ -116,7 +97,7 @@ describe('Test useHanetCheckinData', () => {
|
|
|
116
97
|
await act(async () => {
|
|
117
98
|
await result.current.onReceiveNewCheckinData(newData2);
|
|
118
99
|
});
|
|
119
|
-
expect(result.current.checkinData).toHaveLength(
|
|
100
|
+
expect(result.current.checkinData).toHaveLength(3);
|
|
120
101
|
expect(result.current.countMember).toBe(1);
|
|
121
102
|
expect(result.current.countStranger).toBe(1);
|
|
122
103
|
|
|
@@ -132,7 +113,7 @@ describe('Test useHanetCheckinData', () => {
|
|
|
132
113
|
await result.current.onReceiveNewCheckinData(newData3);
|
|
133
114
|
});
|
|
134
115
|
// no change
|
|
135
|
-
expect(result.current.checkinData).toHaveLength(
|
|
116
|
+
expect(result.current.checkinData).toHaveLength(3);
|
|
136
117
|
expect(result.current.countMember).toBe(1);
|
|
137
118
|
expect(result.current.countStranger).toBe(1);
|
|
138
119
|
|
|
@@ -141,8 +122,35 @@ describe('Test useHanetCheckinData', () => {
|
|
|
141
122
|
await result.current.onReceiveNewCheckinData(newData2);
|
|
142
123
|
});
|
|
143
124
|
// no change
|
|
144
|
-
expect(result.current.checkinData).toHaveLength(
|
|
125
|
+
expect(result.current.checkinData).toHaveLength(3);
|
|
145
126
|
expect(result.current.countMember).toBe(1);
|
|
146
127
|
expect(result.current.countStranger).toBe(1);
|
|
147
128
|
});
|
|
129
|
+
|
|
130
|
+
test('Test onLoadMore', async () => {
|
|
131
|
+
const { result } = renderHook(() => useHanetCheckinData(props));
|
|
132
|
+
mock
|
|
133
|
+
.onGet(API.CAMERA.HANET.CHECKIN(1))
|
|
134
|
+
.reply(200, { ...data, count_member: 20 });
|
|
135
|
+
await act(async () => {
|
|
136
|
+
await result.current.onLoadMore();
|
|
137
|
+
});
|
|
138
|
+
expect(result.current.countMember).toBe(20);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('Test onMomentumScrollBegin', async () => {
|
|
142
|
+
const { result } = renderHook(() => useHanetCheckinData(props));
|
|
143
|
+
await act(async () => {
|
|
144
|
+
await result.current.onMomentumScrollBegin();
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('Test onChangeDate', async () => {
|
|
149
|
+
const { result } = renderHook(() => useHanetCheckinData(props));
|
|
150
|
+
mock.onGet(API.CAMERA.HANET.CHECKIN(1, moment())).reply(200, data);
|
|
151
|
+
await act(async () => {
|
|
152
|
+
await result.current.onChangeDate(moment());
|
|
153
|
+
});
|
|
154
|
+
expect(result.current.countMember).toBe(data.count_member);
|
|
155
|
+
});
|
|
148
156
|
});
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { act, renderHook } from '@testing-library/react-hooks';
|
|
2
2
|
import { useHanetPlaceMembers } from '../index';
|
|
3
|
-
import
|
|
3
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
4
|
+
import api from '../../../../utils/Apis/axios';
|
|
5
|
+
import { API } from '../../../../configs';
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
6
8
|
|
|
7
9
|
describe('Test useHanetPlaceMembers', () => {
|
|
8
10
|
let props, data;
|
|
9
11
|
|
|
10
12
|
beforeEach(() => {
|
|
11
|
-
axios.get.mockClear();
|
|
12
13
|
props = {
|
|
13
14
|
place: {
|
|
14
15
|
place_id: 2,
|
|
@@ -33,33 +34,20 @@ describe('Test useHanetPlaceMembers', () => {
|
|
|
33
34
|
|
|
34
35
|
test('Test onRefresh', async () => {
|
|
35
36
|
const { result } = renderHook(() => useHanetPlaceMembers(props));
|
|
36
|
-
|
|
37
|
-
status: 200,
|
|
38
|
-
data: data,
|
|
39
|
-
}));
|
|
37
|
+
mock.onGet(API.CAMERA.HANET.PLACE_MEMBERS(1)).reply(200, data);
|
|
40
38
|
await act(async () => {
|
|
41
39
|
await result.current.onRefresh();
|
|
42
40
|
});
|
|
43
|
-
expect(
|
|
41
|
+
expect(result.current.loadingMore).toBe(false);
|
|
44
42
|
});
|
|
45
43
|
|
|
46
44
|
test('Test onLoadMore', async () => {
|
|
47
|
-
const { result } = renderHook(() => useHanetPlaceMembers(
|
|
48
|
-
|
|
49
|
-
status: 200,
|
|
50
|
-
data: data,
|
|
51
|
-
}));
|
|
52
|
-
await act(async () => {
|
|
53
|
-
await result.current.onLoadMore();
|
|
54
|
-
});
|
|
55
|
-
expect(axios.get).toHaveBeenCalled();
|
|
56
|
-
|
|
57
|
-
axios.get.mockClear();
|
|
58
|
-
|
|
45
|
+
const { result } = renderHook(() => useHanetPlaceMembers());
|
|
46
|
+
mock.onGet(API.CAMERA.HANET.PLACE_MEMBERS(1)).reply(200, data);
|
|
59
47
|
await act(async () => {
|
|
60
48
|
await result.current.onLoadMore();
|
|
61
49
|
});
|
|
62
|
-
expect(
|
|
50
|
+
expect(result.current.loadingMore).toBe(false);
|
|
63
51
|
});
|
|
64
52
|
|
|
65
53
|
test('Test onMomentumScrollBegin', async () => {
|
|
@@ -67,5 +55,6 @@ describe('Test useHanetPlaceMembers', () => {
|
|
|
67
55
|
await act(async () => {
|
|
68
56
|
await result.current.onMomentumScrollBegin();
|
|
69
57
|
});
|
|
58
|
+
expect(result.current.loadingMore).toBe(false);
|
|
70
59
|
});
|
|
71
60
|
});
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { create, act } from 'react-test-renderer';
|
|
3
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
3
4
|
|
|
4
5
|
import ManageAccessScreen from '../index';
|
|
5
6
|
import { HeaderCustom } from '../../../commons/Header';
|
|
6
|
-
import axios from 'axios';
|
|
7
7
|
import { SCProvider } from '../../../context';
|
|
8
8
|
import { mockSCStore } from '../../../context/mockStore';
|
|
9
9
|
import { ScrollView } from 'react-native';
|
|
10
10
|
import { RowItem } from '../../../commons/RowItem';
|
|
11
11
|
import Routes from '../../../utils/Route';
|
|
12
|
+
import api from '../../../utils/Apis/axios';
|
|
13
|
+
import { API } from '../../../configs';
|
|
14
|
+
|
|
15
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
12
16
|
|
|
13
17
|
const mockUseIsFocused = jest.fn();
|
|
14
18
|
const mockedNavigate = jest.fn();
|
|
@@ -31,8 +35,6 @@ jest.mock('@react-navigation/native', () => {
|
|
|
31
35
|
};
|
|
32
36
|
});
|
|
33
37
|
|
|
34
|
-
jest.mock('axios');
|
|
35
|
-
|
|
36
38
|
const wrapComponent = (route) => (
|
|
37
39
|
<SCProvider initState={mockSCStore({})}>
|
|
38
40
|
<ManageAccessScreen route={route} />
|
|
@@ -44,7 +46,6 @@ describe('Test Manage Access', () => {
|
|
|
44
46
|
let route;
|
|
45
47
|
|
|
46
48
|
beforeEach(() => {
|
|
47
|
-
axios.get.mockClear();
|
|
48
49
|
mockedNavigate.mockClear();
|
|
49
50
|
route = {
|
|
50
51
|
params: {
|
|
@@ -59,27 +60,25 @@ describe('Test Manage Access', () => {
|
|
|
59
60
|
},
|
|
60
61
|
};
|
|
61
62
|
});
|
|
63
|
+
|
|
62
64
|
it('render Manage Access', async () => {
|
|
63
65
|
mockUseIsFocused.mockImplementation(() => true);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
{
|
|
66
|
+
mock.onGet(API.UNIT.MANAGE_ACCESS(1)).reply(200, [
|
|
67
|
+
{
|
|
68
|
+
id: 1,
|
|
69
|
+
user: {
|
|
68
70
|
id: 1,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
phone_number: '0984524544',
|
|
73
|
-
email: '123@gmail.com',
|
|
74
|
-
},
|
|
75
|
-
access_schedule: 'always',
|
|
76
|
-
schedule: 'Always',
|
|
71
|
+
name: 'jason',
|
|
72
|
+
phone_number: '0984524544',
|
|
73
|
+
email: '123@gmail.com',
|
|
77
74
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
75
|
+
access_schedule: 'always',
|
|
76
|
+
schedule: 'Always',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: 2,
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
83
82
|
await act(async () => {
|
|
84
83
|
tree = await create(wrapComponent(route));
|
|
85
84
|
});
|
|
@@ -89,7 +88,7 @@ describe('Test Manage Access', () => {
|
|
|
89
88
|
expect(header).toHaveLength(1);
|
|
90
89
|
expect(scrollView).toHaveLength(1);
|
|
91
90
|
const memberButton = instance.findAllByType(RowItem);
|
|
92
|
-
expect(memberButton).toHaveLength(
|
|
91
|
+
expect(memberButton).toHaveLength(2);
|
|
93
92
|
await act(async () => {
|
|
94
93
|
await memberButton[0].props.onPress();
|
|
95
94
|
});
|
|
@@ -97,4 +96,16 @@ describe('Test Manage Access', () => {
|
|
|
97
96
|
id: 1,
|
|
98
97
|
});
|
|
99
98
|
});
|
|
99
|
+
|
|
100
|
+
it('render Manage Access without params', async () => {
|
|
101
|
+
mockUseIsFocused.mockImplementation(() => false);
|
|
102
|
+
await act(async () => {
|
|
103
|
+
tree = await create(wrapComponent({}));
|
|
104
|
+
});
|
|
105
|
+
const instance = tree.root;
|
|
106
|
+
const header = instance.findAllByType(HeaderCustom);
|
|
107
|
+
const scrollView = instance.findAllByType(ScrollView);
|
|
108
|
+
expect(header).toHaveLength(1);
|
|
109
|
+
expect(scrollView).toHaveLength(1);
|
|
110
|
+
});
|
|
100
111
|
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { act, renderHook } from '@testing-library/react-hooks';
|
|
2
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
2
3
|
import useManageAccess from '../index';
|
|
3
|
-
import axios from 'axios';
|
|
4
4
|
import API from '../../../../configs/API';
|
|
5
|
+
import api from '../../../../utils/Apis/axios';
|
|
6
|
+
|
|
7
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
5
8
|
|
|
6
9
|
jest.mock('react', () => {
|
|
7
10
|
return {
|
|
@@ -10,15 +13,7 @@ jest.mock('react', () => {
|
|
|
10
13
|
};
|
|
11
14
|
});
|
|
12
15
|
|
|
13
|
-
jest.mock('axios');
|
|
14
|
-
|
|
15
16
|
describe('Test Use Manage Access', () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
axios.get.mockClear();
|
|
18
|
-
});
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
axios.get.mockClear();
|
|
21
|
-
});
|
|
22
17
|
const unit = { id: 1, name: 'unit name' };
|
|
23
18
|
const sensor = {
|
|
24
19
|
id: 1,
|
|
@@ -30,49 +25,53 @@ describe('Test Use Manage Access', () => {
|
|
|
30
25
|
|
|
31
26
|
it('Test fetch data', () => {
|
|
32
27
|
const { result } = renderHook(() => useManageAccess(unit, sensor));
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{
|
|
28
|
+
mock.onGet(API.UNIT.MANAGE_ACCESS(unit.id)).reply(200, [
|
|
29
|
+
{
|
|
30
|
+
id: 1,
|
|
31
|
+
user: {
|
|
37
32
|
id: 1,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
phone_number: '0984524544',
|
|
42
|
-
email: '123@gmail.com',
|
|
43
|
-
},
|
|
44
|
-
access_schedule: 'always',
|
|
45
|
-
schedule: 'Always',
|
|
33
|
+
name: 'jason',
|
|
34
|
+
phone_number: '0984524544',
|
|
35
|
+
email: '123@gmail.com',
|
|
46
36
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
37
|
+
access_schedule: 'always',
|
|
38
|
+
schedule: 'Always',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: 2,
|
|
42
|
+
user: {
|
|
43
|
+
id: 1,
|
|
44
|
+
name: 'mike',
|
|
45
|
+
phone_number: '0984524144',
|
|
46
|
+
email: '1235@gmail.com',
|
|
57
47
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
48
|
+
access_schedule: 'recurring',
|
|
49
|
+
schedule: 'M/T 02:40 - 08:40 AM',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: 3,
|
|
53
|
+
user: {
|
|
54
|
+
id: 1,
|
|
55
|
+
name: 'david',
|
|
56
|
+
phone_number: '0984524541',
|
|
57
|
+
email: '1234@gmail.com',
|
|
68
58
|
},
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
access_schedule: 'temporary',
|
|
60
|
+
schedule: '02:40 09/08/2020 - 08:40 09/10/2020',
|
|
61
|
+
},
|
|
62
|
+
]);
|
|
71
63
|
act(() => {
|
|
72
64
|
result.current.onRefresh();
|
|
73
65
|
});
|
|
74
|
-
expect(
|
|
75
|
-
|
|
66
|
+
expect(result.current.isLoading).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('Test get manage access failure', () => {
|
|
70
|
+
const { result } = renderHook(() => useManageAccess(unit, sensor));
|
|
71
|
+
mock.onGet(API.UNIT.MANAGE_ACCESS(unit.id)).reply(400, []);
|
|
72
|
+
act(() => {
|
|
73
|
+
result.current.onRefresh();
|
|
76
74
|
});
|
|
75
|
+
expect(result.current.data).toEqual([]);
|
|
77
76
|
});
|
|
78
77
|
});
|
|
@@ -19,7 +19,7 @@ import { RowItem } from '../../commons/RowItem';
|
|
|
19
19
|
const ManageAccessScreen = memo(({ route }) => {
|
|
20
20
|
const t = useTranslations();
|
|
21
21
|
const { params = {} } = route;
|
|
22
|
-
const { unit, sensor } = params;
|
|
22
|
+
const { unit = {}, sensor = {} } = params;
|
|
23
23
|
const { navigate } = useNavigation();
|
|
24
24
|
const isFocused = useIsFocused();
|
|
25
25
|
const { data, isRefresh, isLoading, onRefresh } = useManageAccess(
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
3
3
|
import { create } from 'react-test-renderer';
|
|
4
4
|
import { act } from '@testing-library/react-hooks';
|
|
5
|
+
import { TouchableOpacity } from 'react-native';
|
|
5
6
|
|
|
6
7
|
import { TESTID } from '../../../configs/Constants';
|
|
7
8
|
import { API } from '../../../configs';
|
|
@@ -9,8 +10,20 @@ import MoveToAnotherSubUnit from '../';
|
|
|
9
10
|
import { SCProvider } from '../../../context';
|
|
10
11
|
import { mockSCStore } from '../../../context/mockStore';
|
|
11
12
|
import BottomButtonView from '../../../commons/BottomButtonView';
|
|
13
|
+
import api from '../../../utils/Apis/axios';
|
|
14
|
+
|
|
15
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
16
|
+
|
|
17
|
+
const mockNavigate = jest.fn();
|
|
18
|
+
jest.mock('@react-navigation/native', () => {
|
|
19
|
+
return {
|
|
20
|
+
...jest.requireActual('@react-navigation/native'),
|
|
21
|
+
useNavigation: () => ({
|
|
22
|
+
navigate: mockNavigate,
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
});
|
|
12
26
|
|
|
13
|
-
jest.mock('axios');
|
|
14
27
|
jest.mock('react', () => {
|
|
15
28
|
return {
|
|
16
29
|
...jest.requireActual('react'),
|
|
@@ -85,6 +98,17 @@ describe('Test Render ListSubUnit', () => {
|
|
|
85
98
|
},
|
|
86
99
|
};
|
|
87
100
|
|
|
101
|
+
it('render ListSubUnit with out params', async () => {
|
|
102
|
+
await act(async () => {
|
|
103
|
+
tree = await create(wrapComponent({}));
|
|
104
|
+
});
|
|
105
|
+
const instance = tree.root;
|
|
106
|
+
const rowSubUnit = instance.findAll(
|
|
107
|
+
(el) => el.props.testID === TESTID.ROW_SUB_UNIT
|
|
108
|
+
);
|
|
109
|
+
expect(rowSubUnit).toHaveLength(0);
|
|
110
|
+
});
|
|
111
|
+
|
|
88
112
|
it('render ListSubUnit', async () => {
|
|
89
113
|
await act(async () => {
|
|
90
114
|
tree = await create(wrapComponent(route));
|
|
@@ -112,15 +136,14 @@ describe('Test Render ListSubUnit', () => {
|
|
|
112
136
|
sensors: [],
|
|
113
137
|
});
|
|
114
138
|
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
);
|
|
139
|
+
mock.onPatch(API.SENSOR.CHANGE_SUB_UNIT(200, 3, 73)).reply(200);
|
|
140
|
+
await bottomButtonView.props.onPressMain();
|
|
141
|
+
expect(mockNavigate).toBeCalled();
|
|
142
|
+
const TouchableOpacities = instance.findAllByType(TouchableOpacity);
|
|
143
|
+
await TouchableOpacities[2].props.onPress();
|
|
144
|
+
mockNavigate.mockClear();
|
|
145
|
+
mock.onPatch(API.SENSOR.CHANGE_SUB_UNIT(200, 3, 73)).reply(400);
|
|
146
|
+
await bottomButtonView.props.onPressMain();
|
|
147
|
+
expect(mockNavigate).not.toBeCalled();
|
|
125
148
|
});
|
|
126
149
|
});
|
|
@@ -36,12 +36,12 @@ const MoveToAnotherSubUnit = memo(({ route }) => {
|
|
|
36
36
|
const { unit, sensor, station } = params;
|
|
37
37
|
const { navigate } = useNavigation();
|
|
38
38
|
const [selectedSubUnit, setSelectedSubUnit] = useState(
|
|
39
|
-
unit
|
|
39
|
+
unit?.stations?.find((subUnit) => subUnit.id === station.id)
|
|
40
40
|
);
|
|
41
41
|
|
|
42
42
|
const listStationUnit = useMemo(() => {
|
|
43
|
-
return unit
|
|
44
|
-
}, [unit
|
|
43
|
+
return unit?.stations.slice(2) || [];
|
|
44
|
+
}, [unit?.stations]);
|
|
45
45
|
|
|
46
46
|
const handleOnSelect = useCallback((item) => {
|
|
47
47
|
setSelectedSubUnit(item);
|
|
@@ -57,7 +57,7 @@ const MoveToAnotherSubUnit = memo(({ route }) => {
|
|
|
57
57
|
if (success) {
|
|
58
58
|
navigate(Routes.UnitDetail);
|
|
59
59
|
}
|
|
60
|
-
}, [navigate, selectedSubUnit
|
|
60
|
+
}, [navigate, selectedSubUnit?.id, sensor?.id, station?.id, unit?.id]);
|
|
61
61
|
|
|
62
62
|
return (
|
|
63
63
|
<View style={styles.wrap}>
|