@eohjsc/react-native-smart-city 0.3.7 → 0.3.10
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 +36 -15
- package/package.json +10 -6
- package/react-native-smart-city.podspec +1 -0
- package/src/commons/Action/ItemQuickAction.js +16 -4
- package/src/commons/Action/__test__/ItemQuickAction.test.js +11 -6
- package/src/commons/ActionGroup/ColorPickerTemplate.js +37 -24
- package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +24 -0
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +14 -0
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/index.js +1 -0
- package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +8 -2
- package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplate.js +10 -10
- package/src/commons/ActionGroup/OnOffTemplate/index.js +3 -2
- package/src/commons/ActionGroup/SliderRangeTemplate.js +6 -2
- package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +7 -3
- package/src/commons/ActionGroup/StatesGridActionTemplate.js +22 -8
- package/src/commons/ActionGroup/TimerActionTemplate.js +11 -3
- package/src/commons/ActionGroup/TwoButtonTemplate/index.js +1 -5
- package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
- package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +14 -14
- package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +53 -78
- package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +36 -20
- package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
- package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
- package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
- package/src/commons/ActionGroup/__test__/index.test.js +135 -0
- package/src/commons/Auth/AccountList.js +1 -1
- 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 +76 -26
- 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 +7 -3
- package/src/commons/Device/ItemDevice.js +34 -13
- package/src/commons/Device/LinearChart.js +15 -0
- package/src/commons/Device/PMSensor/PMSensorIndicatior.js +16 -12
- package/src/commons/Device/PMSensor/PMSensorIndicatorStyles.js +3 -0
- package/src/commons/Device/SonosSpeaker/index.js +1 -1
- package/src/commons/Device/WaterQualitySensor/ListQualityIndicator.js +1 -0
- package/src/commons/Device/WaterQualitySensor/QualityIndicatorsItem.js +7 -2
- package/src/commons/Explore/__test__/CityItem.test.js +33 -54
- package/src/commons/FieldTemplate/ChooseUserField/ChooseFieldStyles.js +25 -0
- package/src/commons/FieldTemplate/ChooseUserField/ChoosePopup.js +96 -0
- package/src/commons/FieldTemplate/ChooseUserField/ChoosePopupStyles.js +39 -0
- package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +118 -0
- package/src/commons/FieldTemplate/ChooseUserField/index.js +62 -0
- package/src/commons/FieldTemplate/PasscodeField/PasscodeFieldStyles.js +30 -0
- package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +90 -0
- package/src/commons/FieldTemplate/PasscodeField/index.js +43 -0
- package/src/commons/FieldTemplate/ScheduleField/ScheduleFieldStyles.js +13 -0
- package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +179 -0
- package/src/commons/FieldTemplate/ScheduleField/index.js +176 -0
- package/src/commons/Form/CurrencyInput.js +15 -1
- package/src/commons/Form/TextInputPassword.js +1 -1
- package/src/commons/FullLoading/index.js +2 -1
- package/src/commons/Header/HeaderCustom.js +2 -1
- package/src/commons/HeaderAni/index.js +6 -1
- package/src/commons/HorizontalPicker/index.js +2 -2
- package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +0 -6
- package/src/commons/MediaPlayerDetail/index.js +29 -47
- package/src/commons/MenuActionAddnew/index.js +1 -0
- package/src/commons/MenuActionList/index.js +1 -0
- package/src/commons/MenuActionMore/index.js +1 -1
- package/src/commons/PreventAccess/__test__/PreventAccess.test.js +62 -0
- package/src/commons/PreventAccess/index.js +9 -1
- package/src/commons/Sharing/MemberList.js +10 -2
- package/src/commons/Sharing/WrapHeaderScrollable.js +2 -0
- 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 +9 -2
- package/src/commons/Unit/SharedUnit.js +1 -0
- package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
- package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +28 -1
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +2 -13
- package/src/commons/UnitSummary/ConfigHistoryChart.js +55 -13
- package/src/commons/WheelDateTimePicker/index.js +4 -3
- package/src/configs/API.js +87 -143
- package/src/configs/Constants.js +80 -1
- package/src/configs/SCConfig.js +4 -0
- package/src/context/actionType.ts +11 -0
- package/src/context/mockStore.ts +12 -0
- package/src/context/reducer.ts +57 -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 +199 -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 +93 -0
- package/src/hooks/IoT/useRemoteControl.js +79 -0
- package/src/hooks/index.js +4 -0
- package/src/hooks/useReceiveNotifications.js +12 -7
- 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/navigations/UnitStack.js +11 -20
- package/src/navigations/UnitStackStyles.js +21 -0
- package/src/screens/AQIGuide/index.js +1 -1
- package/src/screens/ActivityLog/FilterPopup.js +2 -0
- 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/SelectSubUnit.js +1 -0
- package/src/screens/AddCommon/SelectUnit.js +1 -0
- package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
- package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
- package/src/screens/AddLocationMaps/__test__/index.test.js +265 -0
- package/src/screens/AddLocationMaps/index.js +48 -21
- package/src/screens/AddNewAction/SelectAction.js +32 -13
- package/src/screens/AddNewAction/SelectSensorDevices.js +8 -2
- package/src/screens/AddNewAction/SetupSensor.js +67 -32
- package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
- package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
- package/src/screens/AddNewAction/__test__/SetupSensor.test.js +2 -0
- package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +3 -1
- package/src/screens/AddNewAutoSmart/index.js +5 -2
- package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
- package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +42 -34
- package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
- 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 +1 -0
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +23 -17
- package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +46 -40
- package/src/screens/AddNewGateway/PlugAndPlay/__test__/GatewayWifiList.test.js +64 -10
- package/src/screens/AddNewGateway/SelectGateway.js +1 -0
- package/src/screens/AddNewGateway/SetupGatewayWifi.js +2 -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/AddNewGateway/index.js +1 -0
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +10 -24
- package/src/screens/AddNewOneTap/index.js +3 -2
- 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 +5 -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 +17 -15
- package/src/screens/Device/__test__/detail.test.js +33 -86
- package/src/screens/Device/components/DetailHistoryChart.js +1 -1
- package/src/screens/Device/components/SensorConnectStatusViewHeader.js +44 -24
- package/src/screens/Device/components/SensorDisplayItem.js +5 -2
- package/src/screens/Device/detail.js +85 -26
- 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 +6 -3
- package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
- package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +20 -2
- package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +40 -23
- package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
- package/src/screens/EmergencySetting/index.js +4 -1
- package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
- package/src/screens/Explore/index.js +2 -0
- package/src/screens/GuestInfo/__test__/index.test.js +14 -41
- package/src/screens/GuestInfo/components/RecurringDetail.js +1 -0
- 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 +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 +2 -1
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
- package/src/screens/MoveToAnotherSubUnit/index.js +6 -6
- package/src/screens/Notification/__test__/Notification.test.js +31 -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 +13 -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 +54 -35
- package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
- package/src/screens/ScanChipQR/components/QRScan/index.js +1 -0
- 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 +19 -14
- package/src/screens/SelectUnit/__test__/index.test.js +12 -55
- package/src/screens/SelectUnit/index.js +9 -4
- package/src/screens/SetSchedule/index.js +15 -11
- package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
- package/src/screens/SharedUnit/index.js +2 -0
- package/src/screens/Sharing/Components/SensorItem.js +10 -12
- package/src/screens/Sharing/InfoMemberUnit.js +1 -1
- package/src/screens/Sharing/MemberList.js +12 -11
- package/src/screens/Sharing/SelectPermission.js +136 -83
- 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/Sharing/hooks/index.js +3 -0
- package/src/screens/SideMenuDetail/SideMenuDetailStyles.js +28 -0
- package/src/screens/SideMenuDetail/__test__/index.test.js +154 -0
- package/src/screens/SideMenuDetail/index.js +148 -0
- package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +3 -2
- package/src/screens/SmartIr/components/SelectBrand.js +1 -1
- package/src/screens/SubUnit/AddSubUnit.js +23 -17
- package/src/screens/SubUnit/Detail.js +1 -2
- package/src/screens/SubUnit/EditSubUnit.js +15 -13
- package/src/screens/SubUnit/ManageSubUnit.js +13 -7
- package/src/screens/SubUnit/__test__/AddSubUnit.test.js +29 -89
- 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/AddLGDevice.js +1 -0
- package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +22 -91
- package/src/screens/TDSGuide/index.js +4 -1
- package/src/screens/UVIndexGuide/index.js +1 -1
- package/src/screens/Unit/ChooseLocation.js +7 -14
- package/src/screens/Unit/Detail.js +32 -75
- package/src/screens/Unit/ManageUnit.js +1 -0
- package/src/screens/Unit/SelectAddress.js +45 -23
- package/src/screens/Unit/SmartAccount.js +4 -4
- package/src/screens/Unit/Station/index.js +4 -0
- package/src/screens/Unit/Summaries.js +18 -2
- 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 +98 -199
- package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
- package/src/screens/Unit/__test__/SelectAddress.test.js +159 -49
- 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/MyUnitDevice/index.js +4 -4
- package/src/screens/Unit/components/SharedUnit/index.js +1 -0
- package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +2 -2
- 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 +8 -0
- package/src/screens/UnitSummary/__test__/index.test.js +91 -30
- 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/screens/WaterQualityGuide/index.js +1 -1
- package/src/utils/Apis/axios.js +54 -31
- package/src/utils/Converter/time.js +0 -18
- package/src/utils/I18n/translations/en.json +11 -1
- package/src/utils/I18n/translations/vi.json +12 -1
- package/src/utils/Permission/common.js +67 -0
- package/src/utils/Route/index.js +1 -0
- package/src/utils/Setting/Location.js +30 -0
- package/src/utils/Utils.js +12 -7
- package/src/utils/__test__/Utils.test.js +12 -0
|
@@ -2,15 +2,16 @@ import React from 'react';
|
|
|
2
2
|
import { create, act } from 'react-test-renderer';
|
|
3
3
|
import moment from 'moment';
|
|
4
4
|
import { useNavigation } from '@react-navigation/native';
|
|
5
|
-
import
|
|
5
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
6
6
|
import SharedUnit from '../SharedUnit';
|
|
7
7
|
import { TESTID } from '../../../../configs/Constants';
|
|
8
8
|
import { API } from '../../../../configs';
|
|
9
9
|
import Routes from '../../../../utils/Route';
|
|
10
10
|
import { SCProvider } from '../../../../context';
|
|
11
11
|
import { mockSCStore } from '../../../../context/mockStore';
|
|
12
|
+
import api from '../../../../utils/Apis/axios';
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
14
15
|
|
|
15
16
|
const mockRenewItem = jest.fn();
|
|
16
17
|
const wrapComponent = (item, navigation) => (
|
|
@@ -37,10 +38,6 @@ jest.mock('@react-navigation/native', () => {
|
|
|
37
38
|
describe('Test SharedUnit', () => {
|
|
38
39
|
let tree;
|
|
39
40
|
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
axios.post.mockClear();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
41
|
let unit = {
|
|
45
42
|
background: '',
|
|
46
43
|
icon: '',
|
|
@@ -60,14 +57,8 @@ describe('Test SharedUnit', () => {
|
|
|
60
57
|
|
|
61
58
|
test('test create SharedUnit unit is not pin, not star', async () => {
|
|
62
59
|
const navigation = useNavigation();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
success: true,
|
|
66
|
-
};
|
|
67
|
-
axios.post.mockImplementation(async () => {
|
|
68
|
-
return response;
|
|
69
|
-
});
|
|
70
|
-
|
|
60
|
+
mock.onPost(API.UNIT.PIN_UNIT(3)).reply(200);
|
|
61
|
+
mock.onPost(API.UNIT.STAR_UNIT(3)).reply(200);
|
|
71
62
|
await act(async () => {
|
|
72
63
|
tree = await create(wrapComponent(item, navigation));
|
|
73
64
|
});
|
|
@@ -85,41 +76,50 @@ describe('Test SharedUnit', () => {
|
|
|
85
76
|
unitData: unit,
|
|
86
77
|
},
|
|
87
78
|
});
|
|
88
|
-
|
|
89
79
|
const iconRemovePinSharedUnit = instance.findAll(
|
|
90
80
|
(el) => el.props.testID === TESTID.ICON_REMOVE_PIN_SHARED_UNIT
|
|
91
81
|
);
|
|
92
|
-
expect(iconRemovePinSharedUnit).toHaveLength(0);
|
|
93
|
-
|
|
94
82
|
const iconAddPinSharedUnit = instance.find(
|
|
95
83
|
(el) => el.props.testID === TESTID.ICON_ADD_PIN_SHARED_UNIT
|
|
96
84
|
);
|
|
97
85
|
act(() => {
|
|
98
86
|
iconAddPinSharedUnit.props.onPress();
|
|
99
87
|
});
|
|
100
|
-
expect(axios.post).toHaveBeenCalledWith(API.UNIT.PIN_UNIT(3));
|
|
101
|
-
|
|
102
88
|
const iconAddStarSharedUnit = instance.find(
|
|
103
89
|
(el) => el.props.testID === TESTID.ICON_ADD_STAR_SHARED_UNIT
|
|
104
90
|
);
|
|
105
91
|
act(() => {
|
|
106
92
|
iconAddStarSharedUnit.props.onPress();
|
|
107
93
|
});
|
|
108
|
-
expect(
|
|
94
|
+
expect(iconRemovePinSharedUnit).toHaveLength(0);
|
|
109
95
|
});
|
|
110
96
|
|
|
111
97
|
test('test create SharedUnit unit is pin, is star', async () => {
|
|
112
98
|
const navigation = useNavigation();
|
|
113
99
|
item.is_pin = true;
|
|
114
100
|
item.is_star = true;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
success: true,
|
|
118
|
-
};
|
|
119
|
-
axios.post.mockImplementation(async () => {
|
|
120
|
-
return response;
|
|
101
|
+
await act(async () => {
|
|
102
|
+
tree = await create(wrapComponent(item, navigation));
|
|
121
103
|
});
|
|
104
|
+
const instance = tree.root;
|
|
105
|
+
const iconRemovePinSharedUnit = instance.find(
|
|
106
|
+
(el) => el.props.testID === TESTID.ICON_REMOVE_PIN_SHARED_UNIT
|
|
107
|
+
);
|
|
108
|
+
mock.onPost(API.UNIT.UNPIN_UNIT(3)).reply(200);
|
|
109
|
+
await iconRemovePinSharedUnit.props.onPress();
|
|
122
110
|
|
|
111
|
+
const iconRemoveStarSharedUnit = instance.find(
|
|
112
|
+
(el) => el.props.testID === TESTID.ICON_REMOVE_STAR_SHARED_UNIT
|
|
113
|
+
);
|
|
114
|
+
mock.onPost(API.UNIT.UNSTAR_UNIT(3)).reply(200);
|
|
115
|
+
await iconRemoveStarSharedUnit.props.onPress();
|
|
116
|
+
expect(mockRenewItem).toBeCalled();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('test create SharedUnit unit is pin, is star with call api failure', async () => {
|
|
120
|
+
const navigation = useNavigation();
|
|
121
|
+
item.is_pin = true;
|
|
122
|
+
item.is_star = true;
|
|
123
123
|
await act(async () => {
|
|
124
124
|
tree = await create(wrapComponent(item, navigation));
|
|
125
125
|
});
|
|
@@ -127,17 +127,14 @@ describe('Test SharedUnit', () => {
|
|
|
127
127
|
const iconRemovePinSharedUnit = instance.find(
|
|
128
128
|
(el) => el.props.testID === TESTID.ICON_REMOVE_PIN_SHARED_UNIT
|
|
129
129
|
);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
});
|
|
133
|
-
expect(axios.post).toHaveBeenCalledWith(API.UNIT.UNPIN_UNIT(3));
|
|
130
|
+
mock.onPost(API.UNIT.UNPIN_UNIT(3)).reply(400);
|
|
131
|
+
await iconRemovePinSharedUnit.props.onPress();
|
|
134
132
|
|
|
135
133
|
const iconRemoveStarSharedUnit = instance.find(
|
|
136
134
|
(el) => el.props.testID === TESTID.ICON_REMOVE_STAR_SHARED_UNIT
|
|
137
135
|
);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
expect(axios.post).toHaveBeenCalledWith(API.UNIT.UNSTAR_UNIT(3));
|
|
136
|
+
mock.onPost(API.UNIT.UNSTAR_UNIT(3)).reply(200);
|
|
137
|
+
await iconRemoveStarSharedUnit.props.onPress();
|
|
138
|
+
expect(mockRenewItem).toBeCalled();
|
|
142
139
|
});
|
|
143
140
|
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useEffect, useCallback } from 'react';
|
|
2
|
+
import { scanBluetoothDevices } from '../../../iot/RemoteControl/Bluetooth';
|
|
3
|
+
import { lgThinqConnect } from '../../../iot/RemoteControl/LG';
|
|
4
|
+
import { useGGHomeConnection } from '../../../hooks/IoT';
|
|
5
|
+
import { useSCContextSelector } from '../../../context';
|
|
6
|
+
|
|
7
|
+
export const useUnitConnectRemoteDevices = (unit) => {
|
|
8
|
+
const { isNetworkConnected } = useSCContextSelector((state) => state.app);
|
|
9
|
+
|
|
10
|
+
const { connectGoogleHome } = useGGHomeConnection();
|
|
11
|
+
|
|
12
|
+
let lgThinqConnected = false;
|
|
13
|
+
|
|
14
|
+
const handleLgThinqConnect = useCallback(async (options) => {
|
|
15
|
+
if (lgThinqConnected) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
19
|
+
lgThinqConnected = true;
|
|
20
|
+
await lgThinqConnect(options);
|
|
21
|
+
}, []);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (unit.remote_control_options && unit.remote_control_options.bluetooth) {
|
|
25
|
+
scanBluetoothDevices(unit.remote_control_options.bluetooth);
|
|
26
|
+
}
|
|
27
|
+
}, [unit]);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (
|
|
31
|
+
unit.remote_control_options &&
|
|
32
|
+
unit.remote_control_options.googlehome?.length &&
|
|
33
|
+
isNetworkConnected
|
|
34
|
+
) {
|
|
35
|
+
(async () => {
|
|
36
|
+
await connectGoogleHome(unit.remote_control_options.googlehome);
|
|
37
|
+
})();
|
|
38
|
+
}
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
}, [unit, isNetworkConnected]);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (unit.remote_control_options && unit.remote_control_options.lg_thinq) {
|
|
44
|
+
(async () => {
|
|
45
|
+
await handleLgThinqConnect(unit.remote_control_options.lg_thinq);
|
|
46
|
+
})();
|
|
47
|
+
}
|
|
48
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
49
|
+
}, [unit]);
|
|
50
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { act, create } from 'react-test-renderer';
|
|
3
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
4
|
+
import { RefreshControl } from 'react-native';
|
|
5
|
+
|
|
3
6
|
import Routes from '../../../utils/Route';
|
|
4
7
|
import UnitSummary from '..';
|
|
5
|
-
import axios from 'axios';
|
|
6
8
|
import { API } from '../../../configs';
|
|
7
|
-
import { RefreshControl } from 'react-native';
|
|
8
9
|
import { TESTID } from '../../../configs/Constants';
|
|
9
10
|
import { TouchableOpacity } from 'react-native';
|
|
10
11
|
import AirQuality from '../../../commons/UnitSummary/AirQuality';
|
|
@@ -14,10 +15,12 @@ import RunningDevices from '../components/RunningDevices';
|
|
|
14
15
|
import Temperature from '../components/Temperature';
|
|
15
16
|
import UvIndex from '../components/UvIndex';
|
|
16
17
|
import WaterQuality from '../components/WaterQuality';
|
|
18
|
+
import { useReceiveNotifications } from '../../../hooks';
|
|
17
19
|
import { SCProvider } from '../../../context';
|
|
18
20
|
import { mockSCStore } from '../../../context/mockStore';
|
|
21
|
+
import api from '../../../utils/Apis/axios';
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
21
24
|
|
|
22
25
|
const mockedNavigate = jest.fn();
|
|
23
26
|
|
|
@@ -30,6 +33,19 @@ jest.mock('@react-navigation/native', () => {
|
|
|
30
33
|
};
|
|
31
34
|
});
|
|
32
35
|
|
|
36
|
+
jest.mock('react-native-onesignal', () => {
|
|
37
|
+
return {
|
|
38
|
+
setNotificationWillShowInForegroundHandler: jest.fn(),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
jest.mock('../../../hooks', () => {
|
|
43
|
+
return {
|
|
44
|
+
...jest.requireActual('../../../hooks'),
|
|
45
|
+
useReceiveNotifications: jest.fn(() => ({ dataNotification: null })),
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
33
49
|
const wrapComponent = (route) => (
|
|
34
50
|
<SCProvider initState={mockSCStore({})}>
|
|
35
51
|
<UnitSummary route={route} />
|
|
@@ -40,12 +56,15 @@ describe('Test UnitSummary', () => {
|
|
|
40
56
|
let route;
|
|
41
57
|
|
|
42
58
|
beforeEach(() => {
|
|
59
|
+
mock.resetHistory();
|
|
43
60
|
Date.now = jest.fn(() => new Date('2021-01-24T12:00:00.000Z'));
|
|
44
61
|
route = {
|
|
45
62
|
params: {
|
|
63
|
+
unitId: 1,
|
|
46
64
|
unitData: {
|
|
47
65
|
id: 1,
|
|
48
66
|
},
|
|
67
|
+
summaryId: 1,
|
|
49
68
|
summaryData: {
|
|
50
69
|
id: 1,
|
|
51
70
|
name: '',
|
|
@@ -57,6 +76,7 @@ describe('Test UnitSummary', () => {
|
|
|
57
76
|
let tree;
|
|
58
77
|
|
|
59
78
|
test('onRefresh', async () => {
|
|
79
|
+
mock.onGet(API.UNIT.UNIT_SUMMARY_DETAIL(1, 1)).reply(200);
|
|
60
80
|
act(() => {
|
|
61
81
|
tree = create(wrapComponent(route));
|
|
62
82
|
});
|
|
@@ -65,53 +85,94 @@ describe('Test UnitSummary', () => {
|
|
|
65
85
|
act(() => {
|
|
66
86
|
refreshControl.props.onRefresh();
|
|
67
87
|
});
|
|
68
|
-
expect(
|
|
69
|
-
expect(axios.get).toHaveBeenCalledWith(
|
|
70
|
-
API.UNIT.UNIT_SUMMARY_DETAIL(1, 1),
|
|
71
|
-
{}
|
|
72
|
-
);
|
|
88
|
+
expect(refreshControl).toBeDefined();
|
|
73
89
|
});
|
|
74
90
|
|
|
75
91
|
test('render fetchSummaryDetail failed', async () => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
92
|
+
mock.onGet(API.UNIT.UNIT_SUMMARY_DETAIL(1, 1)).reply(200, {});
|
|
93
|
+
act(() => {
|
|
94
|
+
tree = create(wrapComponent(route));
|
|
95
|
+
});
|
|
96
|
+
const instance = tree.root;
|
|
97
|
+
const refreshControl = instance.findByType(RefreshControl);
|
|
98
|
+
expect(refreshControl).toBeDefined();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('render fetchSummaryDetail success', async () => {
|
|
102
|
+
jest.useFakeTimers();
|
|
103
|
+
mock.onGet(API.UNIT.UNIT_SUMMARY_DETAIL(1, 1)).reply(200);
|
|
104
|
+
act(() => {
|
|
105
|
+
tree = create(wrapComponent(route));
|
|
106
|
+
});
|
|
107
|
+
act(() => {
|
|
108
|
+
jest.runOnlyPendingTimers();
|
|
109
|
+
});
|
|
110
|
+
const instance = tree.root;
|
|
111
|
+
const refreshControl = instance.findByType(RefreshControl);
|
|
112
|
+
expect(refreshControl).toBeDefined();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('render fetchUnitDetail success', async () => {
|
|
116
|
+
route = {
|
|
117
|
+
params: {
|
|
118
|
+
unitId: 1,
|
|
119
|
+
unitData: null,
|
|
120
|
+
summaryData: {
|
|
121
|
+
id: 1,
|
|
122
|
+
name: '',
|
|
123
|
+
screen: Routes.AirQuality,
|
|
124
|
+
},
|
|
80
125
|
},
|
|
81
126
|
};
|
|
82
|
-
|
|
83
|
-
|
|
127
|
+
jest.useFakeTimers();
|
|
128
|
+
mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {});
|
|
84
129
|
act(() => {
|
|
85
130
|
tree = create(wrapComponent(route));
|
|
86
131
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
);
|
|
132
|
+
act(() => {
|
|
133
|
+
jest.runOnlyPendingTimers();
|
|
134
|
+
});
|
|
135
|
+
const instance = tree.root;
|
|
136
|
+
const refreshControl = instance.findByType(RefreshControl);
|
|
137
|
+
expect(refreshControl).toBeDefined();
|
|
92
138
|
});
|
|
93
139
|
|
|
94
|
-
test('
|
|
140
|
+
test('test receive notification with summary_id then reload data', async () => {
|
|
95
141
|
jest.useFakeTimers();
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
142
|
+
mock.onGet(API.UNIT.UNIT_SUMMARY_DETAIL(1, 1)).reply(200);
|
|
143
|
+
const dataNotification = {
|
|
144
|
+
params: {
|
|
145
|
+
summary_id: 1,
|
|
100
146
|
},
|
|
101
147
|
};
|
|
102
|
-
|
|
148
|
+
useReceiveNotifications.mockImplementationOnce(() => ({
|
|
149
|
+
dataNotification,
|
|
150
|
+
}));
|
|
151
|
+
act(() => {
|
|
152
|
+
tree = create(wrapComponent(route));
|
|
153
|
+
});
|
|
154
|
+
act(() => {
|
|
155
|
+
jest.runOnlyPendingTimers();
|
|
156
|
+
});
|
|
157
|
+
});
|
|
103
158
|
|
|
159
|
+
test('test receive notification with other summary_id then not reload data', async () => {
|
|
160
|
+
jest.useFakeTimers();
|
|
161
|
+
mock.onGet(API.UNIT.UNIT_SUMMARY_DETAIL(1, 1)).reply(200);
|
|
162
|
+
const dataNotification = {
|
|
163
|
+
params: {
|
|
164
|
+
summary_id: 2,
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
useReceiveNotifications.mockImplementationOnce(() => ({
|
|
168
|
+
dataNotification,
|
|
169
|
+
}));
|
|
104
170
|
act(() => {
|
|
105
171
|
tree = create(wrapComponent(route));
|
|
106
172
|
});
|
|
107
173
|
act(() => {
|
|
108
174
|
jest.runOnlyPendingTimers();
|
|
109
175
|
});
|
|
110
|
-
expect(axios.get).toHaveBeenCalled();
|
|
111
|
-
expect(axios.get).toHaveBeenCalledWith(
|
|
112
|
-
API.UNIT.UNIT_SUMMARY_DETAIL(1, 1),
|
|
113
|
-
{}
|
|
114
|
-
);
|
|
115
176
|
});
|
|
116
177
|
|
|
117
178
|
let list_value = [
|
package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
2
|
import renderer, { act } from 'react-test-renderer';
|
|
3
3
|
import { TESTID } from '../../../../../configs/Constants';
|
|
4
|
-
import { Colors } from '../../../../../configs';
|
|
4
|
+
import { API, Colors } from '../../../../../configs';
|
|
5
5
|
import PowerConsumption from '../index';
|
|
6
6
|
import { SCProvider } from '../../../../../context';
|
|
7
7
|
import { mockSCStore } from '../../../../../context/mockStore';
|
|
8
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
9
|
+
import api from '../../../../../utils/Apis/axios';
|
|
10
|
+
|
|
11
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
12
|
+
const mockSetState = jest.fn();
|
|
13
|
+
|
|
14
|
+
jest.mock('react', () => {
|
|
15
|
+
return {
|
|
16
|
+
...jest.requireActual('react'),
|
|
17
|
+
useState: jest.fn(),
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
useState.mockImplementation((init) => [init, mockSetState]);
|
|
8
21
|
|
|
9
22
|
const wrapComponent = (summaryDetail) => (
|
|
10
23
|
<SCProvider initState={mockSCStore({})}>
|
|
@@ -64,4 +77,20 @@ describe('Test 3PPowerConsumption', () => {
|
|
|
64
77
|
];
|
|
65
78
|
expect(listIndicator.props.data).toEqual(resultList);
|
|
66
79
|
});
|
|
80
|
+
|
|
81
|
+
test('render 3PPowerConsumption with total_power', async () => {
|
|
82
|
+
mock.onGet(API.VALUE_CONSUME.DISPLAY_HISTORY()).reply(200, [{}]);
|
|
83
|
+
const summaryDetail = {
|
|
84
|
+
volt1Value: 200,
|
|
85
|
+
current1Value: 20,
|
|
86
|
+
activePowerValue: 10,
|
|
87
|
+
powerFactor1Value: 30,
|
|
88
|
+
totalPowerValue: 20,
|
|
89
|
+
listConfigs: { total_power: 1 },
|
|
90
|
+
};
|
|
91
|
+
await act(async () => {
|
|
92
|
+
tree = await renderer.create(wrapComponent(summaryDetail));
|
|
93
|
+
});
|
|
94
|
+
expect(mockSetState).toHaveBeenCalledWith([{}]);
|
|
95
|
+
});
|
|
67
96
|
});
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { act, create } from 'react-test-renderer';
|
|
3
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
4
|
+
import moment from 'moment';
|
|
5
|
+
|
|
3
6
|
import ConfigHistoryChart from '../';
|
|
4
7
|
import { SCProvider } from '../../../../../context';
|
|
5
8
|
import { mockSCStore } from '../../../../../context/mockStore';
|
|
6
9
|
import HistoryChart from '../../../../../commons/Device/HistoryChart';
|
|
7
|
-
import
|
|
8
|
-
import
|
|
10
|
+
import api from '../../../../../utils/Apis/axios';
|
|
11
|
+
import { API } from '../../../../../configs';
|
|
9
12
|
|
|
10
13
|
jest.mock('react', () => {
|
|
11
14
|
return {
|
|
@@ -14,7 +17,7 @@ jest.mock('react', () => {
|
|
|
14
17
|
};
|
|
15
18
|
});
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
18
21
|
|
|
19
22
|
const wrapComponent = (configs = []) => (
|
|
20
23
|
<SCProvider initState={mockSCStore({})}>
|
|
@@ -48,7 +51,7 @@ describe('Test HistoryChart', () => {
|
|
|
48
51
|
},
|
|
49
52
|
],
|
|
50
53
|
};
|
|
51
|
-
|
|
54
|
+
mock.onGet(API.CONFIG.DISPLAY_HISTORY).reply(200, response.data);
|
|
52
55
|
const configs = [{ id: 1 }];
|
|
53
56
|
await act(async () => {
|
|
54
57
|
tree = await create(wrapComponent(configs));
|
|
@@ -4,6 +4,7 @@ import moment from 'moment';
|
|
|
4
4
|
import { API } from '../../../../configs';
|
|
5
5
|
import HistoryChart from '../../../../commons/Device/HistoryChart';
|
|
6
6
|
import { axiosGet } from '../../../../utils/Apis/axios';
|
|
7
|
+
import { updateConfigChart } from '../../../../commons/UnitSummary/ConfigHistoryChart';
|
|
7
8
|
|
|
8
9
|
export const dateTimeType = {
|
|
9
10
|
date: 'date',
|
|
@@ -30,19 +31,7 @@ const ConfigHistoryChart = memo(({ configs }) => {
|
|
|
30
31
|
const { success, data } = await axiosGet(API.CONFIG.DISPLAY_HISTORY, {
|
|
31
32
|
params,
|
|
32
33
|
});
|
|
33
|
-
|
|
34
|
-
for (let i = 0; i < data.length; i++) {
|
|
35
|
-
for (let j = 0; j < data[i].data.length; j++) {
|
|
36
|
-
data[i].data[j].x = moment(data[i].data[j].x).toDate();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
setChartData(
|
|
40
|
-
configuration.map((config) => {
|
|
41
|
-
config.data = data.find((k) => k.config === config.id).data;
|
|
42
|
-
return config;
|
|
43
|
-
})
|
|
44
|
-
);
|
|
45
|
-
}
|
|
34
|
+
updateConfigChart(success, data, configuration, setChartData);
|
|
46
35
|
};
|
|
47
36
|
fetchData();
|
|
48
37
|
}, [startDate, endDate, configs]);
|
package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import renderer, { act } from 'react-test-renderer';
|
|
3
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
4
|
+
|
|
3
5
|
import { TESTID } from '../../../../../configs/Constants';
|
|
4
|
-
import { Colors } from '../../../../../configs';
|
|
6
|
+
import { API, Colors } from '../../../../../configs';
|
|
5
7
|
import ListQualityIndicator from '../../../../../commons/Device/WaterQualitySensor/ListQualityIndicator';
|
|
6
|
-
import axios from 'axios';
|
|
7
8
|
import PowerConsumption from '../index';
|
|
8
9
|
import { SCProvider } from '../../../../../context';
|
|
9
10
|
import { mockSCStore } from '../../../../../context/mockStore';
|
|
11
|
+
import api from '../../../../../utils/Apis/axios';
|
|
12
|
+
import { Today } from '../../../../../commons';
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
12
15
|
|
|
13
16
|
const wrapComponent = (summaryDetail) => (
|
|
14
17
|
<SCProvider initState={mockSCStore({})}>
|
|
@@ -86,15 +89,13 @@ describe('Test PowerConsumption', () => {
|
|
|
86
89
|
},
|
|
87
90
|
};
|
|
88
91
|
|
|
89
|
-
|
|
90
|
-
status: 200,
|
|
91
|
-
};
|
|
92
|
-
axios.get.mockImplementation(async (url) => response);
|
|
93
|
-
|
|
92
|
+
mock.onGet(API.VALUE_CONSUME.DISPLAY_HISTORY()).reply(200);
|
|
94
93
|
await act(async () => {
|
|
95
94
|
tree = await renderer.create(wrapComponent(summaryDetail));
|
|
96
95
|
});
|
|
97
|
-
|
|
96
|
+
const instance = tree.root;
|
|
97
|
+
const Todays = instance.findByType(Today);
|
|
98
|
+
expect(Todays).toBeDefined();
|
|
98
99
|
});
|
|
99
100
|
|
|
100
101
|
test('render with unsuccess fetch', async () => {
|
|
@@ -113,16 +114,13 @@ describe('Test PowerConsumption', () => {
|
|
|
113
114
|
volt: 209,
|
|
114
115
|
},
|
|
115
116
|
};
|
|
116
|
-
|
|
117
|
-
const response = {
|
|
118
|
-
data: {},
|
|
119
|
-
};
|
|
120
|
-
axios.get.mockImplementation(async (url) => response);
|
|
121
|
-
|
|
117
|
+
mock.onGet(API.VALUE_CONSUME.DISPLAY_HISTORY()).reply(200, {});
|
|
122
118
|
await act(async () => {
|
|
123
119
|
tree = await renderer.create(wrapComponent(summaryDetail));
|
|
124
120
|
});
|
|
125
|
-
|
|
121
|
+
const instance = tree.root;
|
|
122
|
+
const Todays = instance.findByType(Today);
|
|
123
|
+
expect(Todays).toBeDefined();
|
|
126
124
|
});
|
|
127
125
|
|
|
128
126
|
test('render without value', async () => {
|
|
@@ -13,7 +13,6 @@ const wrapComponent = (unit, summaryDetail) => (
|
|
|
13
13
|
);
|
|
14
14
|
|
|
15
15
|
const mockedNavigate = jest.fn();
|
|
16
|
-
|
|
17
16
|
jest.mock('@react-navigation/native', () => {
|
|
18
17
|
return {
|
|
19
18
|
...jest.requireActual('@react-navigation/native'),
|
|
@@ -23,6 +22,16 @@ jest.mock('@react-navigation/native', () => {
|
|
|
23
22
|
};
|
|
24
23
|
});
|
|
25
24
|
|
|
25
|
+
const mockConnectGoogleHome = jest.fn();
|
|
26
|
+
jest.mock('../../../../../hooks/IoT', () => {
|
|
27
|
+
return {
|
|
28
|
+
...jest.requireActual('../../../../../hooks/IoT'),
|
|
29
|
+
useGGHomeConnection: () => ({
|
|
30
|
+
connectGoogleHome: mockConnectGoogleHome,
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
|
|
26
35
|
describe('test RunningDevices', () => {
|
|
27
36
|
afterEach(() => {
|
|
28
37
|
mockedNavigate.mockClear();
|
|
@@ -73,6 +82,7 @@ describe('test RunningDevices', () => {
|
|
|
73
82
|
act(() => {
|
|
74
83
|
button[0].props.onPress();
|
|
75
84
|
});
|
|
85
|
+
expect(mockConnectGoogleHome).toBeCalled();
|
|
76
86
|
});
|
|
77
87
|
});
|
|
78
88
|
|
|
@@ -112,7 +122,6 @@ describe('test RunningDevices', () => {
|
|
|
112
122
|
button[0].props.onPress();
|
|
113
123
|
});
|
|
114
124
|
expect(mockedNavigate).toBeCalledWith('DeviceDetail', {
|
|
115
|
-
isGGHomeConnected: false,
|
|
116
125
|
sensorData: summaryDetail.devices[0],
|
|
117
126
|
station: 'station',
|
|
118
127
|
title: undefined,
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import React, { memo,
|
|
1
|
+
import React, { memo, useEffect } from 'react';
|
|
2
2
|
import { StyleSheet, View } from 'react-native';
|
|
3
3
|
import ItemDevice from '../../../../commons/Device/ItemDevice';
|
|
4
4
|
import { scanBluetoothDevices } from '../../../../iot/RemoteControl/Bluetooth';
|
|
5
|
-
import {
|
|
5
|
+
import { useGGHomeConnection } from '../../../../hooks/IoT';
|
|
6
6
|
|
|
7
7
|
const RunningDevices = memo(({ unit, summaryDetail }) => {
|
|
8
|
-
const [isGGHomeConnected, setIsGGHomeConnected] = useState(false);
|
|
9
8
|
const { devices } = summaryDetail;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
setIsGGHomeConnected(isConnected);
|
|
13
|
-
}, []);
|
|
9
|
+
|
|
10
|
+
const { connectGoogleHome } = useGGHomeConnection();
|
|
14
11
|
|
|
15
12
|
useEffect(() => {
|
|
16
13
|
if (unit.remote_control_options) {
|
|
@@ -18,10 +15,11 @@ const RunningDevices = memo(({ unit, summaryDetail }) => {
|
|
|
18
15
|
scanBluetoothDevices(unit.remote_control_options.bluetooth);
|
|
19
16
|
}
|
|
20
17
|
if (unit.remote_control_options.googlehome) {
|
|
21
|
-
|
|
18
|
+
(async () =>
|
|
19
|
+
await connectGoogleHome(unit.remote_control_options.googlehome))();
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
|
-
}, [
|
|
22
|
+
}, [connectGoogleHome, unit]);
|
|
25
23
|
return (
|
|
26
24
|
<View style={styles.container}>
|
|
27
25
|
{!!devices &&
|
|
@@ -39,7 +37,6 @@ const RunningDevices = memo(({ unit, summaryDetail }) => {
|
|
|
39
37
|
sensor={item}
|
|
40
38
|
unit={unit}
|
|
41
39
|
station={item.station}
|
|
42
|
-
isGGHomeConnected={isGGHomeConnected}
|
|
43
40
|
/>
|
|
44
41
|
);
|
|
45
42
|
})}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { memo, useMemo } from 'react';
|
|
2
2
|
import { StyleSheet, View } from 'react-native';
|
|
3
|
-
import
|
|
3
|
+
import { useTranslations } from '../../../../hooks/Common/useTranslations';
|
|
4
4
|
|
|
5
5
|
import { Colors } from '../../../../configs';
|
|
6
6
|
import { Section, Today } from '../../../../commons';
|
|
@@ -11,7 +11,7 @@ import SvgRain from '../../../../../assets/images/Device/rain-outline.svg';
|
|
|
11
11
|
import SvgTemperature from '../../../../../assets/images/Device/temperature.svg';
|
|
12
12
|
import SvgWind from '../../../../../assets/images/Device/wind.svg';
|
|
13
13
|
|
|
14
|
-
const getDataTemperature = (summaryDetail) => {
|
|
14
|
+
const getDataTemperature = (summaryDetail, t) => {
|
|
15
15
|
return [
|
|
16
16
|
{
|
|
17
17
|
id: '0',
|
|
@@ -52,8 +52,8 @@ const Temperature = memo(({ summaryDetail }) => {
|
|
|
52
52
|
}, [listConfigs]);
|
|
53
53
|
|
|
54
54
|
const dataTemperature = useMemo(
|
|
55
|
-
() => getDataTemperature(summaryDetail),
|
|
56
|
-
[summaryDetail]
|
|
55
|
+
() => getDataTemperature(summaryDetail, t),
|
|
56
|
+
[summaryDetail, t]
|
|
57
57
|
);
|
|
58
58
|
|
|
59
59
|
const configs = useMemo(() => {
|