@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,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
|
});
|
|
@@ -16,13 +16,13 @@ const useHanetCheckinData = (hanetCamera) => {
|
|
|
16
16
|
const [loadingMore, setLoadingMore] = useState(false);
|
|
17
17
|
const [canLoadMore, setCanLoadMore] = useState(true);
|
|
18
18
|
|
|
19
|
-
const fetchData = async (
|
|
19
|
+
const fetchData = async (selectedPage, selectedDate) => {
|
|
20
20
|
if (!hanetCamera) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
setPage(
|
|
24
|
-
setDate(
|
|
25
|
-
if (
|
|
23
|
+
setPage(selectedPage);
|
|
24
|
+
setDate(selectedDate);
|
|
25
|
+
if (selectedPage === 1) {
|
|
26
26
|
setRefreshing(true);
|
|
27
27
|
} else {
|
|
28
28
|
if (!canLoadMore) {
|
|
@@ -32,8 +32,8 @@ const useHanetCheckinData = (hanetCamera) => {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const params = new URLSearchParams();
|
|
35
|
-
params.append('page',
|
|
36
|
-
params.append('date',
|
|
35
|
+
params.append('page', selectedPage);
|
|
36
|
+
params.append('date', selectedDate.format('YYYY-MM-DD'));
|
|
37
37
|
const { success, data } = await axiosGet(
|
|
38
38
|
API.CAMERA.HANET.CHECKIN(hanetCamera.device_id),
|
|
39
39
|
{
|
|
@@ -43,17 +43,17 @@ const useHanetCheckinData = (hanetCamera) => {
|
|
|
43
43
|
if (success && data) {
|
|
44
44
|
setCountMember(data.count_member);
|
|
45
45
|
setCountStranger(data.count_stranger);
|
|
46
|
-
if (
|
|
46
|
+
if (selectedPage === 1) {
|
|
47
47
|
setCheckinData(data.results || []);
|
|
48
48
|
} else {
|
|
49
|
-
setCanLoadMore(
|
|
49
|
+
setCanLoadMore(selectedPage < Math.ceil(data.count / 20));
|
|
50
50
|
setCheckinData((prevData) =>
|
|
51
51
|
_.uniqBy(prevData.concat(data.results || []), 'id')
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
if (
|
|
56
|
+
if (selectedPage === 1) {
|
|
57
57
|
setRefreshing(false);
|
|
58
58
|
} else {
|
|
59
59
|
setLoadingMore(false);
|
|
@@ -75,8 +75,8 @@ const useHanetCheckinData = (hanetCamera) => {
|
|
|
75
75
|
const onMomentumScrollBegin = () =>
|
|
76
76
|
(onEndReachedCalledDuringMomentum = false);
|
|
77
77
|
|
|
78
|
-
const onChangeDate = (
|
|
79
|
-
fetchData(page,
|
|
78
|
+
const onChangeDate = (selectedDate) => {
|
|
79
|
+
fetchData(page, selectedDate);
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
const onReceiveNewCheckinData = (data) => {
|
|
@@ -13,12 +13,12 @@ const useHanetPlaceMembers = (place) => {
|
|
|
13
13
|
const [loadingMore, setLoadingMore] = useState(false);
|
|
14
14
|
const [canLoadMore, setCanLoadMore] = useState(true);
|
|
15
15
|
|
|
16
|
-
const fetchData = async (
|
|
16
|
+
const fetchData = async (selectedPage) => {
|
|
17
17
|
if (!place) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
setPage(
|
|
21
|
-
if (
|
|
20
|
+
setPage(selectedPage);
|
|
21
|
+
if (selectedPage === 1) {
|
|
22
22
|
setRefreshing(true);
|
|
23
23
|
} else {
|
|
24
24
|
if (!canLoadMore) {
|
|
@@ -28,23 +28,23 @@ const useHanetPlaceMembers = (place) => {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const params = new URLSearchParams();
|
|
31
|
-
params.append('page',
|
|
32
|
-
const { success, data } = await axiosGet(
|
|
31
|
+
params.append('page', selectedPage);
|
|
32
|
+
const { success, data: membersData } = await axiosGet(
|
|
33
33
|
API.CAMERA.HANET.PLACE_MEMBERS(place.place_id),
|
|
34
34
|
{
|
|
35
35
|
params,
|
|
36
36
|
}
|
|
37
37
|
);
|
|
38
|
-
if (success &&
|
|
39
|
-
if (
|
|
40
|
-
setData(
|
|
38
|
+
if (success && membersData) {
|
|
39
|
+
if (selectedPage === 1) {
|
|
40
|
+
setData(membersData.results || []);
|
|
41
41
|
} else {
|
|
42
|
-
setCanLoadMore(
|
|
43
|
-
setData((prevData) => prevData.concat(
|
|
42
|
+
setCanLoadMore(selectedPage < Math.ceil(membersData.count / 20));
|
|
43
|
+
setData((prevData) => prevData.concat(membersData.results || []));
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
if (
|
|
47
|
+
if (selectedPage === 1) {
|
|
48
48
|
setRefreshing(false);
|
|
49
49
|
} else {
|
|
50
50
|
setLoadingMore(false);
|
|
@@ -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
|
});
|
|
@@ -8,11 +8,14 @@ export default (unit, sensor) => {
|
|
|
8
8
|
const [isLoading, setIsLoading] = useState(false);
|
|
9
9
|
const fetchData = useCallback(async () => {
|
|
10
10
|
setIsLoading(true);
|
|
11
|
-
const { success, data } = await axiosGet(
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const { success, data: accessData } = await axiosGet(
|
|
12
|
+
API.UNIT.MANAGE_ACCESS(unit.id),
|
|
13
|
+
{
|
|
14
|
+
params: { sensor_id: sensor.id },
|
|
15
|
+
}
|
|
16
|
+
);
|
|
14
17
|
if (success) {
|
|
15
|
-
setData(
|
|
18
|
+
setData(accessData);
|
|
16
19
|
}
|
|
17
20
|
setIsLoading(false);
|
|
18
21
|
}, [unit.id, sensor.id]);
|
|
@@ -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.DEVICE.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.DEVICE.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);
|
|
@@ -49,7 +49,7 @@ const MoveToAnotherSubUnit = memo(({ route }) => {
|
|
|
49
49
|
|
|
50
50
|
const onSubmit = useCallback(async () => {
|
|
51
51
|
const { success } = await axiosPatch(
|
|
52
|
-
API.
|
|
52
|
+
API.DEVICE.CHANGE_SUB_UNIT(unit.id, station.id, sensor.id),
|
|
53
53
|
{
|
|
54
54
|
station_id: selectedSubUnit.id,
|
|
55
55
|
}
|
|
@@ -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}>
|