@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,91 +0,0 @@
|
|
|
1
|
-
import { useContext, useCallback } from 'react';
|
|
2
|
-
import { SCContext, useSCContextSelector } from '../../context';
|
|
3
|
-
import { Action } from '../../context/actionType';
|
|
4
|
-
import {
|
|
5
|
-
googleHomeConnect,
|
|
6
|
-
googleHomeDisconnect,
|
|
7
|
-
} from '../../iot/RemoteControl/GoogleHome';
|
|
8
|
-
import { axiosPost } from '../../utils/Apis/axios';
|
|
9
|
-
import { API } from '../../configs';
|
|
10
|
-
|
|
11
|
-
const useGGHomeConnection = () => {
|
|
12
|
-
const { setAction } = useContext(SCContext);
|
|
13
|
-
const { connections } = useSCContextSelector((state) => state.iot.googlehome);
|
|
14
|
-
const { listDevice } = useSCContextSelector((state) => state);
|
|
15
|
-
|
|
16
|
-
const onEstablished = useCallback(
|
|
17
|
-
async (newConnections, options) => {
|
|
18
|
-
setAction(Action.SET_GOOGLE_HOME_CONNECTIONS, newConnections);
|
|
19
|
-
|
|
20
|
-
const isConnected = options.some(
|
|
21
|
-
(option) => !!newConnections[option.chip_id]
|
|
22
|
-
);
|
|
23
|
-
let chipId = options[0].chip_id;
|
|
24
|
-
if (!isConnected) {
|
|
25
|
-
setAction(Action.LIST_DEVICE_TYPES, {
|
|
26
|
-
chipId: chipId,
|
|
27
|
-
sentEmail: true,
|
|
28
|
-
});
|
|
29
|
-
await axiosPost(API.GOOGLE_HOME.CHECK_SEND_EMAIL(), {
|
|
30
|
-
chip_id: chipId,
|
|
31
|
-
is_connected: false,
|
|
32
|
-
});
|
|
33
|
-
} else if (isConnected && listDevice[chipId]?.sentEmail) {
|
|
34
|
-
setAction(Action.LIST_DEVICE_TYPES, {
|
|
35
|
-
chipId: chipId,
|
|
36
|
-
sentEmail: false,
|
|
37
|
-
});
|
|
38
|
-
await axiosPost(API.GOOGLE_HOME.CHECK_SEND_EMAIL(), {
|
|
39
|
-
chip_id: chipId,
|
|
40
|
-
is_connected: true,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
[setAction, listDevice]
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const onDisconnected = useCallback(
|
|
48
|
-
async (option) => {
|
|
49
|
-
setAction(Action.CHANGE_GOOGLE_HOME_CONN_STATE, { option, data: 0 });
|
|
50
|
-
},
|
|
51
|
-
[setAction]
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const onReconnected = useCallback(
|
|
55
|
-
async (option, connection) => {
|
|
56
|
-
setAction(Action.CHANGE_GOOGLE_HOME_CONN_STATE, {
|
|
57
|
-
option,
|
|
58
|
-
data: connection,
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
[setAction]
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
const connectGoogleHome = useCallback(
|
|
65
|
-
async (options) => {
|
|
66
|
-
await googleHomeConnect(
|
|
67
|
-
connections,
|
|
68
|
-
options,
|
|
69
|
-
onEstablished,
|
|
70
|
-
onDisconnected,
|
|
71
|
-
onReconnected
|
|
72
|
-
);
|
|
73
|
-
},
|
|
74
|
-
[connections, onEstablished, onDisconnected, onReconnected]
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
const disconnectGoogleHome = useCallback(
|
|
78
|
-
async (options) => {
|
|
79
|
-
await googleHomeDisconnect(connections, options);
|
|
80
|
-
setAction(Action.SET_GOOGLE_HOME_CONNECTIONS, {});
|
|
81
|
-
},
|
|
82
|
-
[setAction, connections]
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
connectGoogleHome,
|
|
87
|
-
disconnectGoogleHome,
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export default useGGHomeConnection;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import { useSCContextSelector } from '../../context';
|
|
3
|
-
import { sendCommandOverGoogleHome } from '../../iot/RemoteControl/GoogleHome';
|
|
4
|
-
import { sendCommandOverInternet } from '../../iot/RemoteControl/Internet';
|
|
5
|
-
import { sendCommandOverLGThinq } from '../../iot/RemoteControl/LG';
|
|
6
|
-
import {
|
|
7
|
-
sendCommandOverBluetooth,
|
|
8
|
-
SEND_COMMAND_OVER_BLUETOOTH_FAIL,
|
|
9
|
-
} from '../../iot/RemoteControl/Bluetooth';
|
|
10
|
-
import { ToastBottomHelper } from '../../utils/Utils';
|
|
11
|
-
import { t } from 'i18n-js';
|
|
12
|
-
|
|
13
|
-
const useRemoteControl = () => {
|
|
14
|
-
const ggHomeConnections = useSCContextSelector(
|
|
15
|
-
(state) => state.iot.googlehome.connections
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
const sendRemoteCommand = useCallback(
|
|
19
|
-
async (sensor, action, data, userId, actionName) => {
|
|
20
|
-
// No action, raise not authorized
|
|
21
|
-
let result = false;
|
|
22
|
-
if (!action) {
|
|
23
|
-
ToastBottomHelper.error(
|
|
24
|
-
t('your_account_has_not_been_authorized_to_control')
|
|
25
|
-
);
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (action.command_prefer_over_bluetooth) {
|
|
30
|
-
try {
|
|
31
|
-
result = await sendCommandOverBluetooth(sensor, action, data, userId);
|
|
32
|
-
} catch (err) {
|
|
33
|
-
if (err === SEND_COMMAND_OVER_BLUETOOTH_FAIL) {
|
|
34
|
-
result = await sendCommandOverInternet(
|
|
35
|
-
sensor,
|
|
36
|
-
action,
|
|
37
|
-
data,
|
|
38
|
-
'bluetooth',
|
|
39
|
-
actionName
|
|
40
|
-
);
|
|
41
|
-
} else {
|
|
42
|
-
throw err;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
action.command_prefer_over_internet ||
|
|
49
|
-
action.command_prefer_over_bluetooth
|
|
50
|
-
) {
|
|
51
|
-
result = await sendCommandOverInternet(
|
|
52
|
-
sensor,
|
|
53
|
-
action,
|
|
54
|
-
data,
|
|
55
|
-
'internet'
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (action.command_prefer_over_googlehome) {
|
|
60
|
-
result = await sendCommandOverGoogleHome(
|
|
61
|
-
ggHomeConnections,
|
|
62
|
-
sensor,
|
|
63
|
-
action,
|
|
64
|
-
data
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (action.command_prefer_over_lg) {
|
|
69
|
-
result = await sendCommandOverLGThinq(sensor, action, data);
|
|
70
|
-
}
|
|
71
|
-
return result;
|
|
72
|
-
},
|
|
73
|
-
[ggHomeConnections]
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
return sendRemoteCommand;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export default useRemoteControl;
|
package/src/hooks/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { StyleSheet } from 'react-native';
|
|
2
|
-
import { Device } from '../configs';
|
|
3
|
-
|
|
4
|
-
export const styles = StyleSheet.create({
|
|
5
|
-
icLeft: {
|
|
6
|
-
marginLeft: Device.isIOS ? 8 : 0,
|
|
7
|
-
},
|
|
8
|
-
headerLocation: {
|
|
9
|
-
alignItems: 'center',
|
|
10
|
-
justifyContent: 'center',
|
|
11
|
-
width: 290,
|
|
12
|
-
},
|
|
13
|
-
headerTitle: {
|
|
14
|
-
fontSize: 20,
|
|
15
|
-
lineHeight: 28,
|
|
16
|
-
},
|
|
17
|
-
headerContent: {
|
|
18
|
-
textAlign: 'center',
|
|
19
|
-
paddingBottom: 4,
|
|
20
|
-
},
|
|
21
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { create, act } from 'react-test-renderer';
|
|
3
|
-
|
|
4
|
-
import MemberList from '../MemberList';
|
|
5
|
-
import { AlertAction } from '../../../commons';
|
|
6
|
-
import { SCProvider } from '../../../context';
|
|
7
|
-
import { mockSCStore } from '../../../context/mockStore';
|
|
8
|
-
import { TouchableOpacity } from 'react-native';
|
|
9
|
-
import Routes from '../../../utils/Route';
|
|
10
|
-
|
|
11
|
-
jest.mock('../../../hooks/Common', () => {
|
|
12
|
-
return {
|
|
13
|
-
useIsOwnerOfUnit: () => ({ isOwner: false }),
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const mockedNavigate = jest.fn();
|
|
18
|
-
const mockUseIsFocused = jest.fn();
|
|
19
|
-
|
|
20
|
-
jest.mock('@react-navigation/native', () => {
|
|
21
|
-
return {
|
|
22
|
-
...jest.requireActual('@react-navigation/native'),
|
|
23
|
-
useNavigation: () => ({
|
|
24
|
-
navigate: mockedNavigate,
|
|
25
|
-
}),
|
|
26
|
-
useIsFocused: () => ({
|
|
27
|
-
isFocused: mockUseIsFocused,
|
|
28
|
-
}),
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const wrapComponent = (route, state) => (
|
|
33
|
-
<SCProvider initState={mockSCStore({})}>
|
|
34
|
-
<MemberList route={route} />
|
|
35
|
-
</SCProvider>
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
describe('test MemberList', () => {
|
|
39
|
-
let route;
|
|
40
|
-
let localState = {
|
|
41
|
-
auth: {
|
|
42
|
-
account: {
|
|
43
|
-
user: {
|
|
44
|
-
id: 2,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
beforeEach(() => {
|
|
51
|
-
route = {
|
|
52
|
-
params: {
|
|
53
|
-
unitId: 1,
|
|
54
|
-
unit: {
|
|
55
|
-
id: 1,
|
|
56
|
-
user_id: 2,
|
|
57
|
-
name: '',
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('AlertAction rightButtonClick', async () => {
|
|
64
|
-
let tree;
|
|
65
|
-
await act(async () => {
|
|
66
|
-
tree = await create(wrapComponent(route, localState));
|
|
67
|
-
});
|
|
68
|
-
const instance = tree.root;
|
|
69
|
-
const alertAction = instance.findByType(AlertAction);
|
|
70
|
-
await act(async () => {
|
|
71
|
-
alertAction.props.rightButtonClick();
|
|
72
|
-
});
|
|
73
|
-
const MemberListButtons = instance.findAllByType(TouchableOpacity);
|
|
74
|
-
await MemberListButtons[1].props.onPress();
|
|
75
|
-
expect(mockedNavigate).not.toBeCalledWith(Routes.AddMemberStack, {
|
|
76
|
-
screen: Routes.SharingSelectPermission,
|
|
77
|
-
params: { unit: { id: 1 } },
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Colors } from '../../configs';
|
|
2
|
-
import { StyleSheet } from 'react-native';
|
|
3
|
-
import { getBottomSpace } from 'react-native-iphone-x-helper';
|
|
4
|
-
|
|
5
|
-
export default StyleSheet.create({
|
|
6
|
-
container: {
|
|
7
|
-
flex: 1,
|
|
8
|
-
backgroundColor: Colors.White,
|
|
9
|
-
},
|
|
10
|
-
scrollview: {
|
|
11
|
-
flex: 1,
|
|
12
|
-
marginHorizontal: 16,
|
|
13
|
-
},
|
|
14
|
-
wrap: {
|
|
15
|
-
paddingBottom: 100,
|
|
16
|
-
},
|
|
17
|
-
viewBottomFixed: {
|
|
18
|
-
position: 'absolute',
|
|
19
|
-
bottom: 0,
|
|
20
|
-
left: 0,
|
|
21
|
-
right: 0,
|
|
22
|
-
paddingBottom: getBottomSpace() > 0 ? getBottomSpace() : 32,
|
|
23
|
-
paddingTop: 24,
|
|
24
|
-
backgroundColor: Colors.White,
|
|
25
|
-
borderColor: Colors.ShadownTransparent,
|
|
26
|
-
borderTopWidth: 1,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import MockAdapter from 'axios-mock-adapter';
|
|
3
|
-
import { act, create } from 'react-test-renderer';
|
|
4
|
-
|
|
5
|
-
import { TESTID } from '../../../configs/Constants';
|
|
6
|
-
|
|
7
|
-
import { SCProvider } from '../../../context';
|
|
8
|
-
import { mockSCStore } from '../../../context/mockStore';
|
|
9
|
-
import SideMenuDetail from '../index';
|
|
10
|
-
import { API } from '../../../configs';
|
|
11
|
-
import { TouchableOpacity } from 'react-native';
|
|
12
|
-
import { ModalCustom } from '../../../commons/Modal';
|
|
13
|
-
import { ToastBottomHelper } from '../../../utils/Utils';
|
|
14
|
-
import api from '../../../utils/Apis/axios';
|
|
15
|
-
|
|
16
|
-
const mock = new MockAdapter(api.axiosInstance);
|
|
17
|
-
|
|
18
|
-
const wrapComponent = (route) => (
|
|
19
|
-
<SCProvider initState={mockSCStore({})}>
|
|
20
|
-
<SideMenuDetail route={route} />
|
|
21
|
-
</SCProvider>
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
describe('Test SideMenuDetail', () => {
|
|
25
|
-
let tree;
|
|
26
|
-
const spyToastSuccess = jest.spyOn(ToastBottomHelper, 'success');
|
|
27
|
-
const spyToastError = jest.spyOn(ToastBottomHelper, 'error');
|
|
28
|
-
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
spyToastSuccess.mockReset();
|
|
31
|
-
spyToastSuccess.mockRestore();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const chooseUser = async (instance) => {
|
|
35
|
-
const ChooseField = instance.find(
|
|
36
|
-
(item) =>
|
|
37
|
-
item.props.testID === TESTID.CHOOSE_FIELD &&
|
|
38
|
-
item.type === TouchableOpacity
|
|
39
|
-
);
|
|
40
|
-
await act(async () => {
|
|
41
|
-
await ChooseField.props.onPress();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const popup = instance.find(
|
|
45
|
-
(item) =>
|
|
46
|
-
item.props.testID === TESTID.CHOOSE_POPUP && item.type === ModalCustom
|
|
47
|
-
);
|
|
48
|
-
expect(popup.props.isVisible).toBeTruthy();
|
|
49
|
-
|
|
50
|
-
const button_choose_done = instance.find(
|
|
51
|
-
(el) =>
|
|
52
|
-
el.props.testID === TESTID.CHOOSE_POPUP + TESTID.BOTTOM_VIEW_MAIN &&
|
|
53
|
-
el.type === TouchableOpacity
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
await act(async () => {
|
|
57
|
-
await button_choose_done.props.onPress();
|
|
58
|
-
});
|
|
59
|
-
expect(popup.props.isVisible).toBeFalsy();
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const enterPasscode = async (instance) => {
|
|
63
|
-
const inputPasscode = instance.find(
|
|
64
|
-
(item) => item.props.testID === TESTID.PASSCODE_FIELD
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
await act(async () => {
|
|
68
|
-
await inputPasscode.props.onChangeText('123456');
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const onPressSubmitData = async (instance) => {
|
|
73
|
-
const buttonSubmit = instance.find(
|
|
74
|
-
(el) =>
|
|
75
|
-
el.props.testID === TESTID.SUBMIT + TESTID.BOTTOM_VIEW_MAIN &&
|
|
76
|
-
el.type === TouchableOpacity
|
|
77
|
-
);
|
|
78
|
-
await act(async () => {
|
|
79
|
-
await buttonSubmit.props.onPress();
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
test('render SideMenuDetail template choose field', async () => {
|
|
84
|
-
const response_side_menu = {
|
|
85
|
-
status: 200,
|
|
86
|
-
data: {
|
|
87
|
-
id: 1,
|
|
88
|
-
action: '3df74a11-1a95-4a65-8e08-936b88c8b5ca',
|
|
89
|
-
fields: [
|
|
90
|
-
{
|
|
91
|
-
type: 'choose_user',
|
|
92
|
-
key: 'user_id',
|
|
93
|
-
action: {
|
|
94
|
-
type: 'action_zigbee',
|
|
95
|
-
id: 1,
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
type: 'passcode',
|
|
100
|
-
key: 'passcode',
|
|
101
|
-
action: {
|
|
102
|
-
type: 'action_zigbee',
|
|
103
|
-
id: 1,
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
type: 'schedule',
|
|
108
|
-
key: 'schedule',
|
|
109
|
-
action: {
|
|
110
|
-
type: 'action_zigbee',
|
|
111
|
-
id: {
|
|
112
|
-
always: 2,
|
|
113
|
-
recurring: 4,
|
|
114
|
-
temporary: 5,
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
],
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
const response_unit_members = {
|
|
122
|
-
status: 200,
|
|
123
|
-
data: [{ id: 1, name: 'Ken' }],
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
mock
|
|
127
|
-
.onGet(API.DEVICE.SIDE_MENU_DETAIL(1, 1))
|
|
128
|
-
.reply(200, response_side_menu.data);
|
|
129
|
-
mock
|
|
130
|
-
.onGet(API.SHARE.UNITS_MEMBERS(1))
|
|
131
|
-
.reply(200, response_unit_members.data);
|
|
132
|
-
mock.onPost(API.DEVICE.TRIGGER_ACTION(1)).reply(200, []);
|
|
133
|
-
|
|
134
|
-
const route = {
|
|
135
|
-
params: {
|
|
136
|
-
unit: { id: 1 },
|
|
137
|
-
sensor: { id: 1 },
|
|
138
|
-
side_menu: { id: 1, name: 'Setup generate pass code' },
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
await act(async () => {
|
|
142
|
-
tree = await create(wrapComponent(route));
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const instance = tree.root;
|
|
146
|
-
await chooseUser(instance);
|
|
147
|
-
await onPressSubmitData(instance);
|
|
148
|
-
expect(spyToastError).toBeCalled();
|
|
149
|
-
|
|
150
|
-
await enterPasscode(instance);
|
|
151
|
-
await onPressSubmitData(instance);
|
|
152
|
-
expect(spyToastSuccess).toBeCalled();
|
|
153
|
-
});
|
|
154
|
-
});
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import React, { memo, useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import { View, ScrollView } from 'react-native';
|
|
3
|
-
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
4
|
-
|
|
5
|
-
import styles from './SideMenuDetailStyles';
|
|
6
|
-
import { HeaderCustom } from '../../commons/Header';
|
|
7
|
-
import BottomButtonView from '../../commons/BottomButtonView';
|
|
8
|
-
import { axiosGet, axiosPost } from '../../utils/Apis/axios';
|
|
9
|
-
import { API } from '../../configs';
|
|
10
|
-
import PasscodeField from '../../commons/FieldTemplate/PasscodeField';
|
|
11
|
-
import ChooseUserField from '../../commons/FieldTemplate/ChooseUserField';
|
|
12
|
-
import ScheduleField from '../../commons/FieldTemplate/ScheduleField';
|
|
13
|
-
import { TESTID } from '../../configs/Constants';
|
|
14
|
-
import { ToastBottomHelper } from '../../utils/Utils';
|
|
15
|
-
import { useNavigation } from '@react-navigation/native';
|
|
16
|
-
|
|
17
|
-
const SideMenuDetail = memo(({ route }) => {
|
|
18
|
-
const t = useTranslations();
|
|
19
|
-
const { goBack } = useNavigation();
|
|
20
|
-
const { unit, sensor, side_menu } = route?.params || {};
|
|
21
|
-
const [sideMenu, setSideMenu] = useState({});
|
|
22
|
-
const [dataForm, setDataForm] = useState([]);
|
|
23
|
-
|
|
24
|
-
const renderTemplateField = useCallback(
|
|
25
|
-
(item, index) => {
|
|
26
|
-
const keyItem = item.key;
|
|
27
|
-
const dataItem = item;
|
|
28
|
-
switch (item.type) {
|
|
29
|
-
case 'choose_user':
|
|
30
|
-
return (
|
|
31
|
-
<ChooseUserField
|
|
32
|
-
key={index} // Todo avoid waring unique "key" prop
|
|
33
|
-
unit={unit}
|
|
34
|
-
dataItem={dataItem}
|
|
35
|
-
index={index}
|
|
36
|
-
setDataForm={setDataForm}
|
|
37
|
-
dataForm={dataForm}
|
|
38
|
-
/>
|
|
39
|
-
);
|
|
40
|
-
case 'passcode':
|
|
41
|
-
return (
|
|
42
|
-
<PasscodeField
|
|
43
|
-
key={index}
|
|
44
|
-
dataItem={dataItem}
|
|
45
|
-
index={index}
|
|
46
|
-
setDataForm={setDataForm}
|
|
47
|
-
dataForm={dataForm}
|
|
48
|
-
/>
|
|
49
|
-
);
|
|
50
|
-
case 'schedule':
|
|
51
|
-
return (
|
|
52
|
-
<ScheduleField
|
|
53
|
-
key={index}
|
|
54
|
-
dataItem={dataItem}
|
|
55
|
-
keyItem={keyItem}
|
|
56
|
-
setDataForm={setDataForm}
|
|
57
|
-
dataForm={dataForm}
|
|
58
|
-
/>
|
|
59
|
-
);
|
|
60
|
-
default:
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
[unit, dataForm]
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
const onPressSubmit = useCallback(async () => {
|
|
68
|
-
const data = {};
|
|
69
|
-
const actionZigbee = [];
|
|
70
|
-
for (let i = 0; i < dataForm.length; i++) {
|
|
71
|
-
if (!dataForm[i].valid) {
|
|
72
|
-
ToastBottomHelper.error(t('invaild_data'));
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (dataForm[i].data) {
|
|
76
|
-
data[dataForm[i].key] = dataForm[i].data;
|
|
77
|
-
if (
|
|
78
|
-
dataForm[i].action_zigbee &&
|
|
79
|
-
!actionZigbee.includes(dataForm[i].action_zigbee)
|
|
80
|
-
) {
|
|
81
|
-
actionZigbee.push(dataForm[i].action_zigbee);
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
data[dataForm[i].key] = null;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
data.action_zigbee = actionZigbee;
|
|
89
|
-
|
|
90
|
-
const { success } = await axiosPost(API.DEVICE.TRIGGER_ACTION(sensor.id), {
|
|
91
|
-
key: sideMenu.action,
|
|
92
|
-
data,
|
|
93
|
-
source: 'smart_lock',
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
if (success) {
|
|
97
|
-
ToastBottomHelper.success(t('activated_successfully'));
|
|
98
|
-
goBack();
|
|
99
|
-
} else {
|
|
100
|
-
ToastBottomHelper.error(t('activation_failed'));
|
|
101
|
-
}
|
|
102
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
103
|
-
}, [dataForm]);
|
|
104
|
-
|
|
105
|
-
const fetchSideMenuDetail = useCallback(async () => {
|
|
106
|
-
const { success, data } = await axiosGet(
|
|
107
|
-
API.DEVICE.SIDE_MENU_DETAIL(sensor.id, side_menu.id)
|
|
108
|
-
);
|
|
109
|
-
if (success) {
|
|
110
|
-
setSideMenu(data);
|
|
111
|
-
setDataForm(data.fields);
|
|
112
|
-
}
|
|
113
|
-
}, [sensor.id, side_menu.id]);
|
|
114
|
-
|
|
115
|
-
useEffect(() => {
|
|
116
|
-
fetchSideMenuDetail();
|
|
117
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
118
|
-
}, []);
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
<View style={styles.container}>
|
|
122
|
-
<HeaderCustom
|
|
123
|
-
title={side_menu.name}
|
|
124
|
-
titleStyle={styles.title}
|
|
125
|
-
isShowSeparator
|
|
126
|
-
/>
|
|
127
|
-
<ScrollView
|
|
128
|
-
showsVerticalScrollIndicator={false}
|
|
129
|
-
showsHorizontalScrollIndicator={false}
|
|
130
|
-
style={styles.scrollview}
|
|
131
|
-
>
|
|
132
|
-
<View style={styles.wrap}>
|
|
133
|
-
{dataForm.map((item, index) => {
|
|
134
|
-
return renderTemplateField(item, index);
|
|
135
|
-
})}
|
|
136
|
-
</View>
|
|
137
|
-
</ScrollView>
|
|
138
|
-
<BottomButtonView
|
|
139
|
-
style={styles.viewBottomFixed}
|
|
140
|
-
testIDPrefix={TESTID.SUBMIT}
|
|
141
|
-
mainTitle={t('done')}
|
|
142
|
-
onPressMain={onPressSubmit}
|
|
143
|
-
/>
|
|
144
|
-
</View>
|
|
145
|
-
);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
export default SideMenuDetail;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ScrollView } from 'react-native';
|
|
3
|
-
import MockAdapter from 'axios-mock-adapter';
|
|
4
|
-
import renderer, { act } from 'react-test-renderer';
|
|
5
|
-
import { API } from '../../../configs';
|
|
6
|
-
import { SCProvider } from '../../../context';
|
|
7
|
-
import { mockSCStore } from '../../../context/mockStore';
|
|
8
|
-
import Summaries from '../Summaries';
|
|
9
|
-
import SummaryItem from '../../../commons/SummaryItem';
|
|
10
|
-
import api from '../../../utils/Apis/axios';
|
|
11
|
-
import { useReceiveNotifications } from '../../../hooks';
|
|
12
|
-
|
|
13
|
-
const mock = new MockAdapter(api.axiosInstance);
|
|
14
|
-
|
|
15
|
-
const wrapComponent = (props) => (
|
|
16
|
-
<SCProvider initState={mockSCStore({})}>
|
|
17
|
-
<Summaries {...props} />
|
|
18
|
-
</SCProvider>
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
jest.mock('react', () => {
|
|
22
|
-
return {
|
|
23
|
-
...jest.requireActual('react'),
|
|
24
|
-
memo: (x) => x,
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const mockedNavigate = jest.fn();
|
|
29
|
-
jest.mock('@react-navigation/native', () => {
|
|
30
|
-
return {
|
|
31
|
-
...jest.requireActual('@react-navigation/native'),
|
|
32
|
-
useIsFocused: jest.fn(),
|
|
33
|
-
useNavigation: () => ({
|
|
34
|
-
navigate: mockedNavigate,
|
|
35
|
-
}),
|
|
36
|
-
};
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
jest.mock('react-native-onesignal', () => {
|
|
40
|
-
return {
|
|
41
|
-
setNotificationWillShowInForegroundHandler: jest.fn(),
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
jest.mock('../../../hooks', () => {
|
|
46
|
-
return {
|
|
47
|
-
...jest.requireActual('../../../hooks'),
|
|
48
|
-
useReceiveNotifications: jest.fn(() => ({ dataNotification: null })),
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('Test Summaries', () => {
|
|
53
|
-
let tree, props;
|
|
54
|
-
|
|
55
|
-
beforeEach(() => {
|
|
56
|
-
props = {
|
|
57
|
-
unit: {
|
|
58
|
-
id: 1,
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('render Summaries receive noti with summary_id then reload', async () => {
|
|
64
|
-
mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200, [{ id: 1 }]);
|
|
65
|
-
const dataNotification = {
|
|
66
|
-
params: {
|
|
67
|
-
summary_id: 1,
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
useReceiveNotifications.mockImplementationOnce(() => ({
|
|
71
|
-
dataNotification,
|
|
72
|
-
}));
|
|
73
|
-
await act(async () => {
|
|
74
|
-
tree = await renderer.create(wrapComponent(props));
|
|
75
|
-
});
|
|
76
|
-
const instance = tree.root;
|
|
77
|
-
const scrollview = instance.findByType(ScrollView);
|
|
78
|
-
expect(scrollview).toBeDefined();
|
|
79
|
-
const items = instance.findAllByType(SummaryItem);
|
|
80
|
-
await act(async () => {
|
|
81
|
-
items[0].props.goToSummary({ id: 1 });
|
|
82
|
-
});
|
|
83
|
-
expect(mockedNavigate).toBeCalled();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('render Summaries receive noti with summary_id then not reload', async () => {
|
|
87
|
-
mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200, [{ id: 1 }]);
|
|
88
|
-
const dataNotification = {
|
|
89
|
-
params: {
|
|
90
|
-
unit_id: 1,
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
useReceiveNotifications.mockImplementationOnce(() => ({
|
|
94
|
-
dataNotification,
|
|
95
|
-
}));
|
|
96
|
-
await act(async () => {
|
|
97
|
-
tree = await renderer.create(wrapComponent(props));
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|