@eohjsc/react-native-smart-city 0.3.4 → 0.3.7
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 +15 -36
- package/package.json +5 -9
- package/react-native-smart-city.podspec +0 -1
- package/src/commons/Action/ItemQuickAction.js +4 -16
- package/src/commons/Action/__test__/ItemQuickAction.test.js +6 -11
- package/src/commons/ActionGroup/ColorPickerTemplate.js +24 -37
- package/src/commons/ActionGroup/CurtainButtonTemplate.js +5 -10
- package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +31 -12
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +0 -4
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +0 -14
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/index.js +0 -1
- package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +2 -8
- package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplate.js +10 -10
- package/src/commons/ActionGroup/OnOffTemplate/index.js +2 -3
- package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +9 -7
- package/src/commons/ActionGroup/SliderRangeTemplate.js +2 -6
- package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +3 -7
- package/src/commons/ActionGroup/StatesGridActionTemplate.js +8 -22
- package/src/commons/ActionGroup/TimerActionTemplate.js +3 -11
- package/src/commons/ActionGroup/TwoButtonTemplate/index.js +5 -1
- package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +4 -53
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +83 -3
- package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +14 -14
- package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +78 -53
- package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +20 -36
- package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +57 -1
- package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +6 -58
- package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +1 -49
- package/src/commons/ActionGroup/__test__/index.test.js +4 -142
- package/src/commons/Auth/AccountList.js +1 -1
- package/src/commons/Automate/ItemAutomate.js +3 -1
- package/src/commons/Connecting/__test__/Connecting.test.js +2 -19
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +3 -7
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +11 -8
- package/src/commons/ConnectingProcess/__test__/Connecting.test.js +3 -136
- package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +2 -3
- package/src/commons/ConnectingProcess/index.js +25 -75
- package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +13 -16
- package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
- package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +5 -0
- package/src/commons/Device/ConnectedViewHeader.js +1 -1
- package/src/commons/Device/HistoryChart.js +3 -7
- package/src/commons/Device/ItemDevice.js +12 -19
- package/src/commons/Device/LinearChart.js +0 -15
- package/src/commons/Device/PMSensor/PMSensorIndicatior.js +12 -16
- package/src/commons/Device/PMSensor/PMSensorIndicatorStyles.js +0 -3
- package/src/commons/Device/SonosSpeaker/index.js +1 -1
- package/src/commons/Device/WaterQualitySensor/ListQualityIndicator.js +0 -1
- package/src/commons/Device/WaterQualitySensor/QualityIndicatorsItem.js +2 -7
- package/src/commons/Explore/__test__/CityItem.test.js +54 -33
- package/src/commons/Form/CurrencyInput.js +1 -15
- package/src/commons/Form/TextInputPassword.js +1 -1
- package/src/commons/FullLoading/index.js +1 -2
- package/src/commons/Header/HeaderCustom.js +1 -2
- package/src/commons/HeaderAni/index.js +1 -6
- package/src/commons/HorizontalPicker/index.js +2 -2
- package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +6 -0
- package/src/commons/MediaPlayerDetail/index.js +47 -25
- package/src/commons/MenuActionAddnew/index.js +0 -1
- package/src/commons/MenuActionList/index.js +0 -1
- package/src/commons/MenuActionMore/index.js +1 -1
- package/src/commons/PreventAccess/index.js +1 -9
- package/src/commons/Sharing/MemberList.js +2 -10
- package/src/commons/Sharing/WrapHeaderScrollable.js +0 -2
- package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +1 -0
- package/src/commons/SubUnit/Favorites/index.js +3 -2
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +35 -8
- package/src/commons/SubUnit/OneTap/index.js +2 -1
- package/src/commons/SubUnit/ShortDetail.js +9 -25
- package/src/commons/SubUnit/__test__/Item.test.js +1 -0
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +2 -9
- package/src/commons/Unit/SharedUnit.js +0 -1
- package/src/commons/Unit/__test__/SharedUnit.test.js +183 -38
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +13 -2
- package/src/commons/UnitSummary/ConfigHistoryChart.js +13 -22
- package/src/commons/WheelDateTimePicker/index.js +3 -4
- package/src/configs/API.js +143 -87
- package/src/configs/Constants.js +2 -57
- package/src/configs/SCConfig.js +0 -4
- package/src/context/actionType.ts +0 -8
- package/src/context/mockStore.ts +0 -10
- package/src/context/reducer.ts +2 -38
- package/src/hooks/Common/index.js +0 -2
- package/src/hooks/Common/useGetIdUser.js +5 -1
- package/src/hooks/Common/useSensorsStatus.js +4 -4
- package/src/hooks/useReceiveNotifications.js +5 -9
- package/src/iot/Monitor.js +2 -3
- package/src/iot/RemoteControl/Bluetooth.js +1 -1
- package/src/iot/RemoteControl/GoogleHome.js +49 -75
- package/src/iot/RemoteControl/Internet.js +1 -1
- package/src/iot/RemoteControl/__test__/GoogleHome.test.js +48 -95
- package/src/iot/RemoteControl/__test__/Internet.test.js +7 -18
- package/src/iot/RemoteControl/__test__/LgThinq.test.js +177 -36
- package/src/iot/RemoteControl/index.js +52 -52
- package/src/navigations/UnitStack.js +20 -11
- package/src/screens/AQIGuide/index.js +1 -1
- package/src/screens/ActivityLog/FilterPopup.js +0 -2
- package/src/screens/ActivityLog/__test__/index.test.js +23 -38
- package/src/screens/ActivityLog/hooks/__test__/index.test.js +90 -51
- package/src/screens/ActivityLog/hooks/index.js +1 -1
- package/src/screens/ActivityLog/index.js +2 -2
- package/src/screens/AddCommon/SelectSubUnit.js +0 -1
- package/src/screens/AddCommon/SelectUnit.js +0 -1
- package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +24 -13
- package/src/screens/AddCommon/__test__/SelectUnit.test.js +33 -9
- package/src/screens/AddLocationMaps/index.js +5 -9
- package/src/screens/AddNewAction/SelectAction.js +8 -8
- package/src/screens/AddNewAction/SelectSensorDevices.js +2 -8
- package/src/screens/AddNewAction/SetupSensor.js +7 -7
- package/src/screens/AddNewAction/__test__/SelectAction.test.js +91 -10
- package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +26 -40
- package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +1 -3
- package/src/screens/AddNewAutoSmart/index.js +2 -5
- package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
- package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -42
- package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +4 -0
- package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +22 -22
- package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
- package/src/screens/AddNewDevice/index.js +0 -1
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +17 -23
- package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +4 -7
- package/src/screens/AddNewGateway/SelectGateway.js +0 -1
- package/src/screens/AddNewGateway/SetupGatewayWifi.js +0 -2
- package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +6 -4
- package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +4 -0
- package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +29 -5
- package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +4 -0
- package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +4 -0
- package/src/screens/AddNewGateway/index.js +0 -1
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +24 -10
- package/src/screens/AddNewOneTap/index.js +2 -3
- package/src/screens/AllCamera/index.js +4 -4
- package/src/screens/Automate/MultiUnits.js +8 -8
- package/src/screens/Automate/__test__/MultiUnits.test.js +9 -6
- package/src/screens/Automate/__test__/index.test.js +12 -7
- package/src/screens/Automate/index.js +3 -5
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +8 -36
- package/src/screens/ConfirmUnitDeletion/index.js +1 -7
- package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +22 -71
- package/src/screens/Device/EditDevice/index.js +15 -17
- package/src/screens/Device/__test__/detail.test.js +86 -33
- package/src/screens/Device/components/DetailHistoryChart.js +1 -1
- package/src/screens/Device/components/SensorConnectStatusViewHeader.js +0 -1
- package/src/screens/Device/components/SensorDisplayItem.js +2 -5
- package/src/screens/Device/detail.js +24 -80
- package/src/screens/Device/hooks/useDisconnectedDevice.js +4 -4
- package/src/screens/Device/hooks/useFavoriteDevice.js +9 -5
- package/src/screens/DeviceInfo/__test__/index.test.js +2 -0
- package/src/screens/EditActionsList/index.js +1 -1
- package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +3 -6
- package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +19 -7
- package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +2 -20
- package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +23 -40
- package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
- package/src/screens/EmergencySetting/index.js +1 -4
- package/src/screens/EnterPassword/__test__/EnterPassword.test.js +25 -41
- package/src/screens/Explore/index.js +0 -2
- package/src/screens/GuestInfo/__test__/index.test.js +41 -14
- package/src/screens/GuestInfo/components/RecurringDetail.js +0 -1
- package/src/screens/GuestInfo/components/TemporaryDetail.js +2 -2
- package/src/screens/HanetCamera/Detail.js +1 -1
- package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +12 -8
- package/src/screens/HanetCamera/__test__/Detail.test.js +42 -27
- package/src/screens/HanetCamera/__test__/ManageAccess.test.js +5 -8
- package/src/screens/HanetCamera/__test__/MemberInfo.test.js +32 -10
- package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +2 -3
- package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +35 -43
- package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +21 -10
- 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 +22 -33
- package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +45 -44
- package/src/screens/ManageAccess/hooks/index.js +4 -7
- package/src/screens/ManageAccess/index.js +1 -2
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +12 -35
- package/src/screens/MoveToAnotherSubUnit/index.js +6 -6
- package/src/screens/Notification/__test__/Notification.test.js +25 -14
- package/src/screens/Notification/__test__/NotificationItem.test.js +7 -8
- package/src/screens/Notification/components/NotificationItem.js +20 -17
- package/src/screens/Notification/index.js +2 -9
- package/src/screens/PlayBackCamera/Timer.js +2 -2
- package/src/screens/PlayBackCamera/__test__/index.test.js +2 -87
- package/src/screens/PlayBackCamera/index.js +6 -22
- package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +20 -7
- package/src/screens/ScanChipQR/components/QRScan/index.js +0 -1
- package/src/screens/ScanChipQR/hooks/index.js +16 -15
- package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +24 -8
- package/src/screens/ScriptDetail/__test__/index.test.js +86 -17
- package/src/screens/ScriptDetail/index.js +14 -19
- package/src/screens/SelectUnit/__test__/index.test.js +55 -12
- package/src/screens/SelectUnit/index.js +4 -9
- package/src/screens/SetSchedule/index.js +11 -15
- package/src/screens/SharedUnit/__test__/TabHeader.test.js +2 -0
- package/src/screens/SharedUnit/index.js +0 -2
- package/src/screens/Sharing/Components/SensorItem.js +12 -10
- package/src/screens/Sharing/InfoMemberUnit.js +1 -1
- package/src/screens/Sharing/MemberList.js +11 -12
- package/src/screens/Sharing/SelectPermission.js +76 -121
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +29 -47
- package/src/screens/Sharing/__test__/MemberList.test.js +127 -13
- package/src/screens/Sharing/__test__/SelectPermission.test.js +38 -28
- package/src/screens/Sharing/__test__/SelectUser.test.js +38 -17
- package/src/screens/Sharing/hooks/index.js +0 -3
- package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +2 -3
- package/src/screens/SmartIr/components/SelectBrand.js +1 -1
- package/src/screens/SubUnit/AddSubUnit.js +17 -23
- package/src/screens/SubUnit/Detail.js +2 -1
- package/src/screens/SubUnit/EditSubUnit.js +13 -15
- package/src/screens/SubUnit/ManageSubUnit.js +7 -13
- package/src/screens/SubUnit/__test__/AddSubUnit.test.js +89 -29
- package/src/screens/SubUnit/__test__/Detail.test.js +8 -31
- package/src/screens/SubUnit/__test__/EditSubUnit.test.js +89 -21
- package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +1 -27
- package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +45 -48
- package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
- package/src/screens/SyncLGDevice/AddLGDevice.js +0 -1
- package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +91 -22
- package/src/screens/TDSGuide/index.js +1 -4
- package/src/screens/UVIndexGuide/index.js +1 -1
- package/src/screens/Unit/ChooseLocation.js +14 -7
- package/src/screens/Unit/Detail.js +75 -30
- package/src/screens/Unit/ManageUnit.js +0 -1
- package/src/screens/Unit/SelectAddress.js +23 -45
- package/src/screens/Unit/SmartAccount.js +4 -4
- package/src/screens/Unit/Station/index.js +0 -4
- package/src/screens/Unit/Summaries.js +2 -18
- package/src/screens/Unit/__test__/CheckSendEmail.test.js +29 -24
- package/src/screens/Unit/__test__/ChooseLocation.test.js +14 -27
- package/src/screens/Unit/__test__/Detail.test.js +200 -99
- package/src/screens/Unit/__test__/ManageUnit.test.js +42 -18
- package/src/screens/Unit/__test__/SelectAddress.test.js +49 -159
- package/src/screens/Unit/__test__/SmartAccount.test.js +9 -17
- package/src/screens/Unit/__test__/SmartAccountItem.test.js +1 -0
- package/src/screens/Unit/components/MyUnitDevice/index.js +4 -4
- package/src/screens/Unit/components/SharedUnit/index.js +0 -1
- package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +2 -2
- package/src/screens/Unit/components/__test__/SharedUnit.test.js +34 -31
- package/src/screens/Unit/styles.js +0 -4
- package/src/screens/UnitSummary/__test__/index.test.js +30 -91
- package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +2 -31
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +4 -7
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +13 -2
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +1 -0
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +16 -14
- package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +2 -11
- package/src/screens/UnitSummary/components/RunningDevices/index.js +10 -7
- package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
- package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +2 -10
- package/src/screens/UnitSummary/index.js +1 -15
- package/src/screens/WaterQualityGuide/index.js +1 -1
- package/src/utils/Apis/axios.js +31 -54
- package/src/utils/Converter/time.js +18 -0
- package/src/utils/I18n/translations/en.json +1 -7
- package/src/utils/I18n/translations/vi.json +1 -8
- package/src/utils/Route/index.js +0 -1
- package/src/utils/Utils.js +7 -11
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +0 -24
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplateWithNullConfigValue.test.js +0 -60
- package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +0 -77
- package/src/commons/Calendar/__test__/Calendar.test.js +0 -33
- package/src/commons/Device/Hanet/ItemHanetDevice.test.js +0 -58
- package/src/commons/FieldTemplate/ChooseUserField/ChooseFieldStyles.js +0 -25
- package/src/commons/FieldTemplate/ChooseUserField/ChoosePopup.js +0 -96
- package/src/commons/FieldTemplate/ChooseUserField/ChoosePopupStyles.js +0 -39
- package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +0 -118
- package/src/commons/FieldTemplate/ChooseUserField/index.js +0 -62
- package/src/commons/FieldTemplate/PasscodeField/PasscodeFieldStyles.js +0 -30
- package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +0 -90
- package/src/commons/FieldTemplate/PasscodeField/index.js +0 -43
- package/src/commons/FieldTemplate/ScheduleField/ScheduleFieldStyles.js +0 -13
- package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +0 -179
- package/src/commons/FieldTemplate/ScheduleField/index.js +0 -176
- package/src/commons/PreventAccess/__test__/PreventAccess.test.js +0 -62
- package/src/hooks/Common/useGGHomeDeviceConnected.js +0 -16
- package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +0 -198
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +0 -198
- package/src/hooks/IoT/index.js +0 -4
- package/src/hooks/IoT/useGGHomeConnection.js +0 -91
- package/src/hooks/IoT/useRemoteControl.js +0 -79
- package/src/hooks/index.js +0 -4
- package/src/navigations/UnitStackStyles.js +0 -21
- package/src/screens/Sharing/__test__/MemberList2.test.js +0 -80
- package/src/screens/SideMenuDetail/SideMenuDetailStyles.js +0 -28
- package/src/screens/SideMenuDetail/__test__/index.test.js +0 -154
- package/src/screens/SideMenuDetail/index.js +0 -148
- package/src/screens/Unit/__test__/Summaries.test.js +0 -100
- package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +0 -36
- package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +0 -54
- package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +0 -50
- package/src/utils/Permission/common.js +0 -67
- package/src/utils/Setting/Location.js +0 -30
- package/src/utils/__test__/Utils.test.js +0 -12
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TouchableOpacity } from 'react-native';
|
|
3
3
|
import { create, act } from 'react-test-renderer';
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import axios from 'axios';
|
|
6
5
|
import { SCProvider } from '../../../context';
|
|
7
6
|
import { mockSCStore } from '../../../context/mockStore';
|
|
8
7
|
import HanetMemberInfo from '../MemberInfo';
|
|
@@ -11,8 +10,6 @@ import TextInput from '../../../commons/Form/TextInput';
|
|
|
11
10
|
import BottomButtonView from '../../../commons/BottomButtonView';
|
|
12
11
|
import BottomSheet from '../../../commons/BottomSheet';
|
|
13
12
|
import { TESTID } from '../../../configs/Constants';
|
|
14
|
-
import api from '../../../utils/Apis/axios';
|
|
15
|
-
import { API } from '../../../configs';
|
|
16
13
|
|
|
17
14
|
const wrapComponent = (route) => (
|
|
18
15
|
<SCProvider initState={mockSCStore({})}>
|
|
@@ -40,7 +37,7 @@ jest.mock('@react-navigation/native', () => {
|
|
|
40
37
|
};
|
|
41
38
|
});
|
|
42
39
|
|
|
43
|
-
|
|
40
|
+
jest.mock('axios');
|
|
44
41
|
|
|
45
42
|
describe('Test HanetMemberInfo', () => {
|
|
46
43
|
let tree, route;
|
|
@@ -48,6 +45,9 @@ describe('Test HanetMemberInfo', () => {
|
|
|
48
45
|
beforeEach(() => {
|
|
49
46
|
mockedNavigate.mockClear();
|
|
50
47
|
mockedGoBack.mockClear();
|
|
48
|
+
axios.post.mockClear();
|
|
49
|
+
axios.patch.mockClear();
|
|
50
|
+
axios.delete.mockClear();
|
|
51
51
|
route = {
|
|
52
52
|
params: {
|
|
53
53
|
hanetPlace: {
|
|
@@ -72,18 +72,23 @@ describe('Test HanetMemberInfo', () => {
|
|
|
72
72
|
const touches = instance.findAllByType(TouchableOpacity);
|
|
73
73
|
expect(touches).toHaveLength(7);
|
|
74
74
|
const alertAction = instance.findByType(AlertAction);
|
|
75
|
+
|
|
75
76
|
// open alert action
|
|
76
77
|
await act(async () => {
|
|
77
78
|
await touches[2].props.onPress();
|
|
78
79
|
});
|
|
80
|
+
expect(alertAction.props.visible).toBe(true);
|
|
81
|
+
|
|
79
82
|
const textInput = instance.findByType(TextInput);
|
|
80
|
-
|
|
83
|
+
|
|
84
|
+
axios.patch.mockImplementationOnce(async () => ({ status: 200 }));
|
|
85
|
+
|
|
81
86
|
// change name and press rename
|
|
82
87
|
await act(async () => {
|
|
83
88
|
await textInput.props.onChange('new name');
|
|
84
89
|
await alertAction.props.rightButtonClick();
|
|
85
90
|
});
|
|
86
|
-
expect(
|
|
91
|
+
expect(axios.patch).toHaveBeenCalled();
|
|
87
92
|
});
|
|
88
93
|
|
|
89
94
|
test('Test remove member', async () => {
|
|
@@ -100,11 +105,15 @@ describe('Test HanetMemberInfo', () => {
|
|
|
100
105
|
await touches[3].props.onPress();
|
|
101
106
|
});
|
|
102
107
|
expect(alertAction.props.visible).toBe(true);
|
|
103
|
-
|
|
108
|
+
|
|
109
|
+
axios.delete.mockImplementationOnce(async () => ({ status: 200 }));
|
|
110
|
+
|
|
104
111
|
// press remove
|
|
105
112
|
await act(async () => {
|
|
106
113
|
await alertAction.props.rightButtonClick();
|
|
107
114
|
});
|
|
115
|
+
|
|
116
|
+
expect(axios.delete).toHaveBeenCalled();
|
|
108
117
|
expect(mockedGoBack).toHaveBeenCalled();
|
|
109
118
|
});
|
|
110
119
|
|
|
@@ -144,14 +153,24 @@ describe('Test HanetMemberInfo', () => {
|
|
|
144
153
|
const instance = tree.root;
|
|
145
154
|
const touches = instance.findAllByType(TouchableOpacity);
|
|
146
155
|
expect(touches).toHaveLength(7);
|
|
156
|
+
|
|
147
157
|
await act(async () => {
|
|
148
158
|
await touches[1].props.onPress();
|
|
149
159
|
});
|
|
160
|
+
|
|
150
161
|
const bottomSheet = instance.findByType(BottomSheet);
|
|
151
162
|
expect(bottomSheet.props.isVisible).toBe(true);
|
|
152
|
-
|
|
163
|
+
|
|
164
|
+
axios.patch.mockImplementationOnce(async () => ({
|
|
165
|
+
status: 200,
|
|
166
|
+
data: {
|
|
167
|
+
avatar_uri: 'uri',
|
|
168
|
+
},
|
|
169
|
+
}));
|
|
153
170
|
await chooseSetFaceIDOption(instance, 1);
|
|
171
|
+
|
|
154
172
|
expect(bottomSheet.props.isVisible).toBe(false);
|
|
173
|
+
expect(axios.patch).toBeCalled(); // call api update face id
|
|
155
174
|
});
|
|
156
175
|
|
|
157
176
|
test('Test register new member', async () => {
|
|
@@ -177,6 +196,7 @@ describe('Test HanetMemberInfo', () => {
|
|
|
177
196
|
expect(bottomSheet.props.isVisible).toBe(true);
|
|
178
197
|
|
|
179
198
|
await chooseSetFaceIDOption(instance, 1);
|
|
199
|
+
expect(axios.patch).not.toBeCalled(); // not call api
|
|
180
200
|
|
|
181
201
|
// open alert action
|
|
182
202
|
const alertAction = instance.findByType(AlertAction);
|
|
@@ -191,13 +211,15 @@ describe('Test HanetMemberInfo', () => {
|
|
|
191
211
|
await textInput.props.onChange('new name');
|
|
192
212
|
await alertAction.props.rightButtonClick();
|
|
193
213
|
});
|
|
214
|
+
expect(axios.post).not.toBeCalled();
|
|
194
215
|
|
|
195
216
|
// finish
|
|
196
217
|
const bottomButton = instance.findByType(BottomButtonView);
|
|
197
|
-
|
|
218
|
+
axios.post.mockImplementationOnce(async () => ({ status: 200 }));
|
|
198
219
|
await act(async () => {
|
|
199
220
|
await bottomButton.props.onPressMain();
|
|
200
221
|
});
|
|
222
|
+
expect(axios.post).toBeCalled();
|
|
201
223
|
expect(mockedNavigate).toBeCalled();
|
|
202
224
|
});
|
|
203
225
|
});
|
|
@@ -31,7 +31,7 @@ const RequestFaceIDPopup = ({
|
|
|
31
31
|
text: t('pick_available_image_from_your_phone'),
|
|
32
32
|
onChoose: async () => {
|
|
33
33
|
setHide();
|
|
34
|
-
const
|
|
34
|
+
const options = {
|
|
35
35
|
mediaType: 'photo',
|
|
36
36
|
compressImageMaxHeight: 1280,
|
|
37
37
|
compressImageMaxWidth: 738,
|
|
@@ -39,9 +39,8 @@ const RequestFaceIDPopup = ({
|
|
|
39
39
|
forceJpg: true,
|
|
40
40
|
};
|
|
41
41
|
try {
|
|
42
|
-
const result = await ImagePicker.openPicker(
|
|
42
|
+
const result = await ImagePicker.openPicker(options);
|
|
43
43
|
onChooseFile && onChooseFile(result);
|
|
44
|
-
// eslint-disable-next-line no-empty
|
|
45
44
|
} catch (e) {}
|
|
46
45
|
},
|
|
47
46
|
},
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { act, renderHook } from '@testing-library/react-hooks';
|
|
2
2
|
import { useHanetCheckinData } from '../index';
|
|
3
|
-
import
|
|
3
|
+
import axios from 'axios';
|
|
4
4
|
import moment from 'moment';
|
|
5
|
-
import api from '../../../../utils/Apis/axios';
|
|
6
|
-
import { API } from '../../../../configs';
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
jest.mock('axios');
|
|
9
7
|
|
|
10
8
|
describe('Test useHanetCheckinData', () => {
|
|
11
9
|
let props, data;
|
|
12
10
|
|
|
13
11
|
beforeEach(() => {
|
|
14
12
|
Date.now = jest.fn(() => new Date('2021-09-09T10:00:00.000Z'));
|
|
13
|
+
axios.get.mockClear();
|
|
15
14
|
props = {
|
|
16
15
|
device_id: 1,
|
|
17
16
|
place: {
|
|
@@ -52,20 +51,40 @@ describe('Test useHanetCheckinData', () => {
|
|
|
52
51
|
|
|
53
52
|
test('Test onRefresh', async () => {
|
|
54
53
|
const { result } = renderHook(() => useHanetCheckinData(props));
|
|
55
|
-
|
|
54
|
+
axios.get.mockImplementationOnce(() => ({
|
|
55
|
+
status: 200,
|
|
56
|
+
data: data,
|
|
57
|
+
}));
|
|
56
58
|
await act(async () => {
|
|
57
59
|
await result.current.onRefresh();
|
|
58
60
|
});
|
|
59
|
-
expect(
|
|
61
|
+
expect(axios.get).toHaveBeenCalled();
|
|
60
62
|
});
|
|
61
63
|
|
|
62
|
-
test('Test
|
|
63
|
-
const { result } = renderHook(() => useHanetCheckinData());
|
|
64
|
-
|
|
64
|
+
test('Test onLoadMore', async () => {
|
|
65
|
+
const { result } = renderHook(() => useHanetCheckinData(props));
|
|
66
|
+
axios.get.mockImplementationOnce(() => ({
|
|
67
|
+
status: 200,
|
|
68
|
+
data: data,
|
|
69
|
+
}));
|
|
65
70
|
await act(async () => {
|
|
66
|
-
await result.current.
|
|
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));
|
|
85
|
+
await act(async () => {
|
|
86
|
+
await result.current.onMomentumScrollBegin();
|
|
67
87
|
});
|
|
68
|
-
expect(result.current.refreshing).toBeFalsy();
|
|
69
88
|
});
|
|
70
89
|
|
|
71
90
|
test('Test onReceiveNewCheckinData', async () => {
|
|
@@ -82,9 +101,9 @@ describe('Test useHanetCheckinData', () => {
|
|
|
82
101
|
await act(async () => {
|
|
83
102
|
await result.current.onReceiveNewCheckinData(newData);
|
|
84
103
|
});
|
|
85
|
-
expect(result.current.checkinData).toHaveLength(
|
|
104
|
+
expect(result.current.checkinData).toHaveLength(1);
|
|
86
105
|
expect(result.current.countMember).toBe(1);
|
|
87
|
-
expect(result.current.countStranger).toBe(1);
|
|
106
|
+
expect(result.current.countStranger).not.toBe(1);
|
|
88
107
|
|
|
89
108
|
const newData2 = {
|
|
90
109
|
id: 2,
|
|
@@ -97,7 +116,7 @@ describe('Test useHanetCheckinData', () => {
|
|
|
97
116
|
await act(async () => {
|
|
98
117
|
await result.current.onReceiveNewCheckinData(newData2);
|
|
99
118
|
});
|
|
100
|
-
expect(result.current.checkinData).toHaveLength(
|
|
119
|
+
expect(result.current.checkinData).toHaveLength(2);
|
|
101
120
|
expect(result.current.countMember).toBe(1);
|
|
102
121
|
expect(result.current.countStranger).toBe(1);
|
|
103
122
|
|
|
@@ -113,7 +132,7 @@ describe('Test useHanetCheckinData', () => {
|
|
|
113
132
|
await result.current.onReceiveNewCheckinData(newData3);
|
|
114
133
|
});
|
|
115
134
|
// no change
|
|
116
|
-
expect(result.current.checkinData).toHaveLength(
|
|
135
|
+
expect(result.current.checkinData).toHaveLength(2);
|
|
117
136
|
expect(result.current.countMember).toBe(1);
|
|
118
137
|
expect(result.current.countStranger).toBe(1);
|
|
119
138
|
|
|
@@ -122,35 +141,8 @@ describe('Test useHanetCheckinData', () => {
|
|
|
122
141
|
await result.current.onReceiveNewCheckinData(newData2);
|
|
123
142
|
});
|
|
124
143
|
// no change
|
|
125
|
-
expect(result.current.checkinData).toHaveLength(
|
|
144
|
+
expect(result.current.checkinData).toHaveLength(2);
|
|
126
145
|
expect(result.current.countMember).toBe(1);
|
|
127
146
|
expect(result.current.countStranger).toBe(1);
|
|
128
147
|
});
|
|
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
|
-
});
|
|
156
148
|
});
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { act, renderHook } from '@testing-library/react-hooks';
|
|
2
2
|
import { useHanetPlaceMembers } from '../index';
|
|
3
|
-
import
|
|
4
|
-
import api from '../../../../utils/Apis/axios';
|
|
5
|
-
import { API } from '../../../../configs';
|
|
3
|
+
import axios from 'axios';
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
jest.mock('axios');
|
|
8
6
|
|
|
9
7
|
describe('Test useHanetPlaceMembers', () => {
|
|
10
8
|
let props, data;
|
|
11
9
|
|
|
12
10
|
beforeEach(() => {
|
|
11
|
+
axios.get.mockClear();
|
|
13
12
|
props = {
|
|
14
13
|
place: {
|
|
15
14
|
place_id: 2,
|
|
@@ -34,20 +33,33 @@ describe('Test useHanetPlaceMembers', () => {
|
|
|
34
33
|
|
|
35
34
|
test('Test onRefresh', async () => {
|
|
36
35
|
const { result } = renderHook(() => useHanetPlaceMembers(props));
|
|
37
|
-
|
|
36
|
+
axios.get.mockImplementationOnce(() => ({
|
|
37
|
+
status: 200,
|
|
38
|
+
data: data,
|
|
39
|
+
}));
|
|
38
40
|
await act(async () => {
|
|
39
41
|
await result.current.onRefresh();
|
|
40
42
|
});
|
|
41
|
-
expect(
|
|
43
|
+
expect(axios.get).toHaveBeenCalled();
|
|
42
44
|
});
|
|
43
45
|
|
|
44
46
|
test('Test onLoadMore', async () => {
|
|
45
|
-
const { result } = renderHook(() => useHanetPlaceMembers());
|
|
46
|
-
|
|
47
|
+
const { result } = renderHook(() => useHanetPlaceMembers(props));
|
|
48
|
+
axios.get.mockImplementationOnce(() => ({
|
|
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
|
+
|
|
47
59
|
await act(async () => {
|
|
48
60
|
await result.current.onLoadMore();
|
|
49
61
|
});
|
|
50
|
-
expect(
|
|
62
|
+
expect(axios.get).toHaveBeenCalledTimes(0);
|
|
51
63
|
});
|
|
52
64
|
|
|
53
65
|
test('Test onMomentumScrollBegin', async () => {
|
|
@@ -55,6 +67,5 @@ describe('Test useHanetPlaceMembers', () => {
|
|
|
55
67
|
await act(async () => {
|
|
56
68
|
await result.current.onMomentumScrollBegin();
|
|
57
69
|
});
|
|
58
|
-
expect(result.current.loadingMore).toBe(false);
|
|
59
70
|
});
|
|
60
71
|
});
|
|
@@ -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 (page, date) => {
|
|
20
20
|
if (!hanetCamera) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
setPage(
|
|
24
|
-
setDate(
|
|
25
|
-
if (
|
|
23
|
+
setPage(page);
|
|
24
|
+
setDate(date);
|
|
25
|
+
if (page === 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', page);
|
|
36
|
+
params.append('date', date.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 (page === 1) {
|
|
47
47
|
setCheckinData(data.results || []);
|
|
48
48
|
} else {
|
|
49
|
-
setCanLoadMore(
|
|
49
|
+
setCanLoadMore(page < 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 (page === 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 = (date) => {
|
|
79
|
+
fetchData(page, date);
|
|
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 (page) => {
|
|
17
17
|
if (!place) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
setPage(
|
|
21
|
-
if (
|
|
20
|
+
setPage(page);
|
|
21
|
+
if (page === 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
|
|
31
|
+
params.append('page', page);
|
|
32
|
+
const { success, data } = 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 && data) {
|
|
39
|
+
if (page === 1) {
|
|
40
|
+
setData(data.results || []);
|
|
41
41
|
} else {
|
|
42
|
-
setCanLoadMore(
|
|
43
|
-
setData((prevData) => prevData.concat(
|
|
42
|
+
setCanLoadMore(page < Math.ceil(data.count / 20));
|
|
43
|
+
setData((prevData) => prevData.concat(data.results || []));
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
if (
|
|
47
|
+
if (page === 1) {
|
|
48
48
|
setRefreshing(false);
|
|
49
49
|
} else {
|
|
50
50
|
setLoadingMore(false);
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { create, act } from 'react-test-renderer';
|
|
3
|
-
import MockAdapter from 'axios-mock-adapter';
|
|
4
3
|
|
|
5
4
|
import ManageAccessScreen from '../index';
|
|
6
5
|
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);
|
|
16
12
|
|
|
17
13
|
const mockUseIsFocused = jest.fn();
|
|
18
14
|
const mockedNavigate = jest.fn();
|
|
@@ -35,6 +31,8 @@ jest.mock('@react-navigation/native', () => {
|
|
|
35
31
|
};
|
|
36
32
|
});
|
|
37
33
|
|
|
34
|
+
jest.mock('axios');
|
|
35
|
+
|
|
38
36
|
const wrapComponent = (route) => (
|
|
39
37
|
<SCProvider initState={mockSCStore({})}>
|
|
40
38
|
<ManageAccessScreen route={route} />
|
|
@@ -46,6 +44,7 @@ describe('Test Manage Access', () => {
|
|
|
46
44
|
let route;
|
|
47
45
|
|
|
48
46
|
beforeEach(() => {
|
|
47
|
+
axios.get.mockClear();
|
|
49
48
|
mockedNavigate.mockClear();
|
|
50
49
|
route = {
|
|
51
50
|
params: {
|
|
@@ -60,25 +59,27 @@ describe('Test Manage Access', () => {
|
|
|
60
59
|
},
|
|
61
60
|
};
|
|
62
61
|
});
|
|
63
|
-
|
|
64
62
|
it('render Manage Access', async () => {
|
|
65
63
|
mockUseIsFocused.mockImplementation(() => true);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
const response = {
|
|
65
|
+
status: 200,
|
|
66
|
+
data: [
|
|
67
|
+
{
|
|
70
68
|
id: 1,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
user: {
|
|
70
|
+
id: 1,
|
|
71
|
+
name: 'jason',
|
|
72
|
+
phone_number: '0984524544',
|
|
73
|
+
email: '123@gmail.com',
|
|
74
|
+
},
|
|
75
|
+
access_schedule: 'always',
|
|
76
|
+
schedule: 'Always',
|
|
74
77
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
},
|
|
81
|
-
]);
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
axios.get.mockImplementation(async () => {
|
|
81
|
+
return response;
|
|
82
|
+
});
|
|
82
83
|
await act(async () => {
|
|
83
84
|
tree = await create(wrapComponent(route));
|
|
84
85
|
});
|
|
@@ -88,7 +89,7 @@ describe('Test Manage Access', () => {
|
|
|
88
89
|
expect(header).toHaveLength(1);
|
|
89
90
|
expect(scrollView).toHaveLength(1);
|
|
90
91
|
const memberButton = instance.findAllByType(RowItem);
|
|
91
|
-
expect(memberButton).toHaveLength(
|
|
92
|
+
expect(memberButton).toHaveLength(1);
|
|
92
93
|
await act(async () => {
|
|
93
94
|
await memberButton[0].props.onPress();
|
|
94
95
|
});
|
|
@@ -96,16 +97,4 @@ describe('Test Manage Access', () => {
|
|
|
96
97
|
id: 1,
|
|
97
98
|
});
|
|
98
99
|
});
|
|
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
|
-
});
|
|
111
100
|
});
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { act, renderHook } from '@testing-library/react-hooks';
|
|
2
|
-
import MockAdapter from 'axios-mock-adapter';
|
|
3
2
|
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);
|
|
8
5
|
|
|
9
6
|
jest.mock('react', () => {
|
|
10
7
|
return {
|
|
@@ -13,7 +10,15 @@ jest.mock('react', () => {
|
|
|
13
10
|
};
|
|
14
11
|
});
|
|
15
12
|
|
|
13
|
+
jest.mock('axios');
|
|
14
|
+
|
|
16
15
|
describe('Test Use Manage Access', () => {
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
axios.get.mockClear();
|
|
18
|
+
});
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
axios.get.mockClear();
|
|
21
|
+
});
|
|
17
22
|
const unit = { id: 1, name: 'unit name' };
|
|
18
23
|
const sensor = {
|
|
19
24
|
id: 1,
|
|
@@ -25,53 +30,49 @@ describe('Test Use Manage Access', () => {
|
|
|
25
30
|
|
|
26
31
|
it('Test fetch data', () => {
|
|
27
32
|
const { result } = renderHook(() => useManageAccess(unit, sensor));
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
axios.get.mockImplementation(() => ({
|
|
34
|
+
status: 200,
|
|
35
|
+
data: [
|
|
36
|
+
{
|
|
32
37
|
id: 1,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
user: {
|
|
39
|
+
id: 1,
|
|
40
|
+
name: 'jason',
|
|
41
|
+
phone_number: '0984524544',
|
|
42
|
+
email: '123@gmail.com',
|
|
43
|
+
},
|
|
44
|
+
access_schedule: 'always',
|
|
45
|
+
schedule: 'Always',
|
|
36
46
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
{
|
|
48
|
+
id: 2,
|
|
49
|
+
user: {
|
|
50
|
+
id: 1,
|
|
51
|
+
name: 'mike',
|
|
52
|
+
phone_number: '0984524144',
|
|
53
|
+
email: '1235@gmail.com',
|
|
54
|
+
},
|
|
55
|
+
access_schedule: 'recurring',
|
|
56
|
+
schedule: 'M/T 02:40 - 08:40 AM',
|
|
47
57
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
{
|
|
59
|
+
id: 3,
|
|
60
|
+
user: {
|
|
61
|
+
id: 1,
|
|
62
|
+
name: 'david',
|
|
63
|
+
phone_number: '0984524541',
|
|
64
|
+
email: '1234@gmail.com',
|
|
65
|
+
},
|
|
66
|
+
access_schedule: 'temporary',
|
|
67
|
+
schedule: '02:40 09/08/2020 - 08:40 09/10/2020',
|
|
58
68
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
]);
|
|
69
|
+
],
|
|
70
|
+
}));
|
|
63
71
|
act(() => {
|
|
64
72
|
result.current.onRefresh();
|
|
65
73
|
});
|
|
66
|
-
expect(
|
|
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();
|
|
74
|
+
expect(axios.get).toHaveBeenCalledWith(API.UNIT.MANAGE_ACCESS(unit.id), {
|
|
75
|
+
params: { sensor_id: sensor.id },
|
|
74
76
|
});
|
|
75
|
-
expect(result.current.data).toEqual([]);
|
|
76
77
|
});
|
|
77
78
|
});
|