@eohjsc/react-native-smart-city 0.2.98 → 0.3.1
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 +5 -3
- package/src/commons/Action/ItemQuickAction.js +11 -2
- package/src/commons/Action/__test__/ItemQuickAction.test.js +11 -6
- package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
- package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +32 -21
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
- package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLock.js +3 -3
- 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/OnOffTemplate/OnOffSimpleTemplate.js +1 -3
- package/src/commons/ActionGroup/OnOffTemplate/index.js +15 -45
- package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +1 -1
- package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +3 -2
- package/src/commons/ActionGroup/StatesGridActionTemplate.js +8 -4
- package/src/commons/ActionGroup/TimerActionTemplate.js +2 -2
- package/src/commons/ActionGroup/TwoButtonTemplate/index.js +6 -7
- package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +45 -48
- package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
- package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
- package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
- package/src/commons/ActionGroup/__test__/index.test.js +137 -2
- package/src/commons/Automate/ItemAutomate.js +1 -3
- package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
- package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
- package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
- package/src/commons/ConnectingProcess/index.js +12 -8
- package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
- package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
- package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
- package/src/commons/Device/ConnectedViewHeader.js +1 -1
- package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
- package/src/commons/Device/HistoryChart.js +3 -3
- package/src/commons/Device/ItemDevice.js +15 -11
- package/src/commons/Device/LinearChart.js +15 -0
- package/src/commons/Device/SonosSpeaker/index.js +1 -1
- package/src/commons/Explore/__test__/CityItem.test.js +33 -54
- package/src/commons/FieldTemplate/ChooseUserField/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/Header/HeaderCustom.js +2 -1
- package/src/commons/HorizontalPicker/index.js +2 -2
- package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +0 -6
- package/src/commons/MediaPlayerDetail/index.js +19 -50
- 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 +1 -2
- package/src/commons/SubUnit/__test__/Item.test.js +0 -1
- package/src/commons/Unit/SharedUnit.js +1 -0
- package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +2 -13
- package/src/commons/UnitSummary/ConfigHistoryChart.js +22 -13
- package/src/commons/WheelDateTimePicker/index.js +4 -3
- package/src/configs/API.js +85 -145
- package/src/configs/Constants.js +36 -1
- package/src/configs/SCConfig.js +2 -0
- package/src/context/actionType.ts +8 -1
- package/src/context/mockStore.ts +10 -0
- package/src/context/reducer.ts +38 -5
- 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 +5 -8
- package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +198 -0
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +198 -0
- package/src/hooks/IoT/index.js +4 -0
- package/src/hooks/IoT/useGGHomeConnection.js +91 -0
- package/src/hooks/IoT/useRemoteControl.js +79 -0
- package/src/hooks/index.js +4 -0
- package/src/hooks/useReceiveNotifications.js +8 -4
- 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 +8 -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/__test__/SelectSubUnit.test.js +13 -24
- package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
- package/src/screens/AddLocationMaps/index.js +5 -4
- package/src/screens/AddNewAction/SelectAction.js +8 -8
- package/src/screens/AddNewAction/SelectSensorDevices.js +2 -1
- package/src/screens/AddNewAction/SetupSensor.js +7 -7
- package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
- package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
- package/src/screens/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 +34 -33
- package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
- package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +21 -21
- package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +23 -17
- package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +3 -3
- package/src/screens/AddNewGateway/SetupGatewayWifi.js +1 -0
- package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
- package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
- package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +10 -24
- package/src/screens/AddNewOneTap/index.js +2 -1
- package/src/screens/AllCamera/index.js +4 -4
- package/src/screens/Automate/MultiUnits.js +8 -8
- package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
- package/src/screens/Automate/__test__/index.test.js +7 -12
- package/src/screens/Automate/index.js +3 -3
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
- package/src/screens/ConfirmUnitDeletion/index.js +7 -1
- package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
- package/src/screens/Device/EditDevice/index.js +2 -2
- package/src/screens/Device/__test__/detail.test.js +33 -86
- package/src/screens/Device/components/DetailHistoryChart.js +1 -1
- package/src/screens/Device/components/SensorConnectStatusViewHeader.js +1 -0
- package/src/screens/Device/components/SensorDisplayItem.js +5 -2
- package/src/screens/Device/detail.js +81 -33
- 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 +18 -14
- package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +30 -31
- package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
- package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
- package/src/screens/GuestInfo/__test__/index.test.js +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 +1 -1
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
- package/src/screens/MoveToAnotherSubUnit/index.js +5 -5
- package/src/screens/Notification/__test__/Notification.test.js +14 -25
- package/src/screens/Notification/__test__/NotificationItem.test.js +8 -7
- package/src/screens/Notification/components/NotificationItem.js +17 -20
- package/src/screens/Notification/index.js +9 -2
- package/src/screens/PlayBackCamera/Timer.js +2 -2
- package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
- package/src/screens/PlayBackCamera/index.js +22 -6
- package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
- package/src/screens/ScanChipQR/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 +17 -12
- package/src/screens/SelectUnit/__test__/index.test.js +12 -55
- package/src/screens/SelectUnit/index.js +8 -4
- package/src/screens/SetSchedule/index.js +11 -10
- package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
- package/src/screens/Sharing/Components/SensorItem.js +10 -12
- package/src/screens/Sharing/InfoMemberUnit.js +1 -1
- package/src/screens/Sharing/SelectPermission.js +121 -77
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
- package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
- package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
- package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
- package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
- package/src/screens/SideMenuDetail/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/SubUnit/Detail.js +1 -2
- package/src/screens/SubUnit/ManageSubUnit.js +12 -7
- package/src/screens/SubUnit/__test__/AddSubUnit.test.js +21 -67
- package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
- package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
- package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +27 -1
- package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +48 -45
- package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
- package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +14 -90
- package/src/screens/Unit/ChooseLocation.js +7 -14
- package/src/screens/Unit/Detail.js +30 -75
- package/src/screens/Unit/ManageUnit.js +1 -0
- package/src/screens/Unit/SelectAddress.js +34 -21
- package/src/screens/Unit/SmartAccount.js +4 -4
- package/src/screens/Unit/Summaries.js +17 -1
- package/src/screens/Unit/__test__/CheckSendEmail.test.js +24 -29
- package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
- package/src/screens/Unit/__test__/Detail.test.js +99 -200
- package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
- package/src/screens/Unit/__test__/SelectAddress.test.js +84 -51
- package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
- package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
- package/src/screens/Unit/__test__/Summaries.test.js +100 -0
- package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
- package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
- package/src/screens/Unit/components/SharedUnit/index.js +1 -0
- package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
- package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +50 -0
- package/src/screens/Unit/styles.js +4 -0
- package/src/screens/UnitSummary/__test__/index.test.js +70 -41
- package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +31 -2
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +2 -13
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +0 -1
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
- package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +11 -2
- package/src/screens/UnitSummary/components/RunningDevices/index.js +7 -10
- package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
- package/src/screens/UnitSummary/index.js +15 -1
- package/src/utils/Apis/axios.js +46 -31
- package/src/utils/Converter/time.js +0 -18
- package/src/utils/I18n/translations/en.json +3 -1
- package/src/utils/I18n/translations/vi.json +4 -1
- package/src/utils/Permission/common.js +39 -0
- package/src/utils/Route/index.js +1 -0
- package/src/utils/Utils.js +11 -7
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
1
|
import React from 'react';
|
|
3
|
-
import { TouchableOpacity } from 'react-native';
|
|
2
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
4
4
|
import renderer, { act } from 'react-test-renderer';
|
|
5
|
-
import { createConnection, getStates } from 'home-assistant-js-websocket';
|
|
6
5
|
import ParallaxScrollView from '../../../libs/react-native-parallax-scroll-view';
|
|
7
6
|
import { BleManager } from 'react-native-ble-plx';
|
|
8
7
|
import { useIsFocused } from '@react-navigation/native';
|
|
9
8
|
import AsyncStorage from '@react-native-community/async-storage';
|
|
10
9
|
import UnitDetail from '../Detail';
|
|
11
10
|
import { API } from '../../../configs';
|
|
12
|
-
import ShortDetailSubUnit from '../../../commons/SubUnit/ShortDetail';
|
|
13
11
|
import { TESTID } from '../../../configs/Constants';
|
|
14
12
|
import { SCProvider } from '../../../context';
|
|
15
13
|
import { mockSCStore } from '../../../context/mockStore';
|
|
16
14
|
import CameraDevice from '../../../commons/CameraDevice';
|
|
17
15
|
import { ModalFullVideo } from '../../../commons/Modal';
|
|
18
16
|
import SubUnitFavorites from '../../../commons/SubUnit/Favorites';
|
|
17
|
+
import api from '../../../utils/Apis/axios';
|
|
18
|
+
import PreventAccess from '../../../commons/PreventAccess';
|
|
19
19
|
|
|
20
20
|
const mockDispatch = jest.fn();
|
|
21
|
-
|
|
21
|
+
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
|
|
22
22
|
const wrapComponent = (route, account) => (
|
|
23
23
|
<SCProvider initState={mockSCStore({})}>
|
|
24
24
|
<UnitDetail route={route} account={account} />
|
|
@@ -54,15 +54,23 @@ jest.mock('@react-navigation/native', () => {
|
|
|
54
54
|
};
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
jest.
|
|
57
|
+
const mockConnectGoogleHome = jest.fn();
|
|
58
|
+
jest.mock('../../../hooks/IoT', () => {
|
|
59
|
+
return {
|
|
60
|
+
...jest.requireActual('../../../hooks/IoT'),
|
|
61
|
+
useGGHomeConnection: () => ({
|
|
62
|
+
connectGoogleHome: mockConnectGoogleHome,
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
jest.mock('react-native-onesignal', () => {
|
|
58
68
|
return {
|
|
59
|
-
|
|
60
|
-
createConnection: jest.fn(),
|
|
61
|
-
getStates: jest.fn(),
|
|
69
|
+
setNotificationWillShowInForegroundHandler: jest.fn(),
|
|
62
70
|
};
|
|
63
71
|
});
|
|
64
72
|
|
|
65
|
-
|
|
73
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
66
74
|
|
|
67
75
|
describe('Test UnitDetail', () => {
|
|
68
76
|
const route = {
|
|
@@ -78,155 +86,110 @@ describe('Test UnitDetail', () => {
|
|
|
78
86
|
|
|
79
87
|
let tree;
|
|
80
88
|
|
|
81
|
-
axios.get.mockImplementation(() => ({ status: 200 }));
|
|
82
|
-
|
|
83
89
|
beforeEach(() => {
|
|
84
90
|
jest.clearAllTimers();
|
|
85
|
-
axios.get.mockClear();
|
|
86
91
|
useIsFocused.mockImplementation(() => true);
|
|
87
92
|
AsyncStorage.clear();
|
|
88
93
|
});
|
|
89
94
|
|
|
90
95
|
test('fetch unit detail success', async () => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
|
|
97
|
+
address: null,
|
|
98
|
+
background: 'https://eoh-gateway-backend.eoh.io/smarthome_1_juLMJGE.jpg',
|
|
99
|
+
can_add: false,
|
|
100
|
+
group: null,
|
|
101
|
+
icon: 'https://eoh-gateway-backend.eoh.io/iconsmarthome_SVG1NTj.png',
|
|
102
|
+
id: 1006,
|
|
103
|
+
main_config_count: 0,
|
|
104
|
+
name: 'Zigbee Gateway',
|
|
105
|
+
remote_control_options: {
|
|
106
|
+
bluetooth: [],
|
|
107
|
+
googlehome: [],
|
|
108
|
+
lg_thinq: [],
|
|
109
|
+
zigbee: [],
|
|
102
110
|
},
|
|
111
|
+
stations: [],
|
|
112
|
+
user_id: 119,
|
|
103
113
|
});
|
|
104
|
-
});
|
|
105
114
|
|
|
106
|
-
|
|
107
|
-
axios.get.mockImplementation((url) => ({
|
|
108
|
-
status: 200,
|
|
109
|
-
data: {},
|
|
110
|
-
}));
|
|
115
|
+
route.params.isSuccessfullyConnected = true;
|
|
111
116
|
await act(async () => {
|
|
112
|
-
await renderer.create(wrapComponent(route
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
axios.get.mockImplementation((url) => {
|
|
116
|
-
if (url === detailUnitApiUrl) {
|
|
117
|
-
throw {};
|
|
118
|
-
}
|
|
119
|
-
return { status: 200, data: [] };
|
|
117
|
+
tree = await renderer.create(wrapComponent(route));
|
|
120
118
|
});
|
|
119
|
+
mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(new Error('Network Error'));
|
|
120
|
+
const scrollView = tree.root.findByType(ParallaxScrollView);
|
|
121
|
+
const refreshControl = scrollView.props.refreshControl;
|
|
121
122
|
await act(async () => {
|
|
122
|
-
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
expect(axios.get).toHaveBeenCalledWith(detailUnitApiUrl, {
|
|
126
|
-
headers: {
|
|
127
|
-
'Cache-Control': 'no-cache',
|
|
128
|
-
},
|
|
123
|
+
refreshControl.props.onRefresh();
|
|
129
124
|
});
|
|
125
|
+
const instance = tree.root;
|
|
126
|
+
const PreventAccesss = instance.findByType(PreventAccess);
|
|
127
|
+
expect(PreventAccesss).toBeDefined();
|
|
130
128
|
});
|
|
131
129
|
|
|
132
|
-
test('fetch unit detail no network
|
|
133
|
-
|
|
134
|
-
throw {};
|
|
135
|
-
});
|
|
130
|
+
test('fetch unit detail no network then load from cache', async () => {
|
|
131
|
+
mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(500, []);
|
|
136
132
|
await act(async () => {
|
|
137
|
-
await renderer.create(wrapComponent(route, account));
|
|
133
|
+
tree = await renderer.create(wrapComponent(route, account));
|
|
138
134
|
});
|
|
135
|
+
const instance = tree.root;
|
|
136
|
+
const PreventAccesss = instance.findByType(PreventAccess);
|
|
137
|
+
expect(PreventAccesss).toBeDefined();
|
|
138
|
+
});
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
test('fetch unit detail error 404', async () => {
|
|
141
|
+
mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(404, {});
|
|
142
|
+
await act(async () => {
|
|
143
|
+
tree = await renderer.create(wrapComponent(route));
|
|
144
144
|
});
|
|
145
|
+
const instance = tree.root;
|
|
146
|
+
const button1 = instance.find(
|
|
147
|
+
(el) => el.props.testID === TESTID.BUTTON_PREVENT_ACCESS
|
|
148
|
+
);
|
|
149
|
+
expect(button1.props.isVisible).toBeTruthy();
|
|
145
150
|
});
|
|
146
151
|
|
|
147
152
|
test('fetch unit summary empty', async () => {
|
|
148
|
-
|
|
149
|
-
if (url === summaryUnitApiUrl) {
|
|
150
|
-
return {
|
|
151
|
-
status: 200,
|
|
152
|
-
data: [],
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return {
|
|
157
|
-
status: 200,
|
|
158
|
-
data: {},
|
|
159
|
-
};
|
|
160
|
-
});
|
|
153
|
+
mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200);
|
|
161
154
|
await act(async () => {
|
|
162
|
-
await renderer.create(wrapComponent(route, account));
|
|
155
|
+
tree = await renderer.create(wrapComponent(route, account));
|
|
163
156
|
});
|
|
164
|
-
|
|
165
|
-
|
|
157
|
+
const instance = tree.root;
|
|
158
|
+
const PreventAccesss = instance.findByType(PreventAccess);
|
|
159
|
+
expect(PreventAccesss).toBeDefined();
|
|
166
160
|
});
|
|
167
161
|
|
|
168
162
|
test('fetch unit summary has data', async () => {
|
|
169
|
-
|
|
170
|
-
if (url === summaryUnitApiUrl) {
|
|
171
|
-
return {
|
|
172
|
-
status: 200,
|
|
173
|
-
data: [{}],
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return {
|
|
178
|
-
status: 200,
|
|
179
|
-
data: {},
|
|
180
|
-
};
|
|
181
|
-
});
|
|
163
|
+
mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200, [{}]);
|
|
182
164
|
await act(async () => {
|
|
183
|
-
await renderer.create(wrapComponent(route, account));
|
|
165
|
+
tree = await renderer.create(wrapComponent(route, account));
|
|
184
166
|
});
|
|
185
|
-
|
|
186
|
-
|
|
167
|
+
const instance = tree.root;
|
|
168
|
+
const PreventAccesss = instance.findByType(PreventAccess);
|
|
169
|
+
expect(PreventAccesss).toBeDefined();
|
|
187
170
|
});
|
|
188
171
|
|
|
189
172
|
test('not fetch unit summary if not focus', async () => {
|
|
190
173
|
useIsFocused.mockImplementation(() => false);
|
|
191
|
-
|
|
192
|
-
if (url === summaryUnitApiUrl) {
|
|
193
|
-
return {
|
|
194
|
-
status: 200,
|
|
195
|
-
data: [{}],
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return {
|
|
200
|
-
status: 200,
|
|
201
|
-
data: {},
|
|
202
|
-
};
|
|
203
|
-
});
|
|
174
|
+
mock.onGet(summaryUnitApiUrl).reply(200);
|
|
204
175
|
await act(async () => {
|
|
205
|
-
await renderer.create(wrapComponent(route, account));
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
expect(axios.get).not.toHaveBeenCalledWith(summaryUnitApiUrl, {
|
|
209
|
-
headers: {
|
|
210
|
-
'Cache-Control': 'no-cache',
|
|
211
|
-
},
|
|
176
|
+
tree = await renderer.create(wrapComponent(route, account));
|
|
212
177
|
});
|
|
178
|
+
const instance = tree.root;
|
|
179
|
+
const PreventAccesss = instance.findByType(PreventAccess);
|
|
180
|
+
expect(PreventAccesss).toBeDefined();
|
|
213
181
|
});
|
|
214
182
|
|
|
215
183
|
test('fetch unit detail when refresh', async () => {
|
|
216
184
|
await act(async () => {
|
|
217
185
|
tree = await renderer.create(wrapComponent(route, account));
|
|
218
186
|
});
|
|
219
|
-
axios.get.mockClear();
|
|
220
187
|
const scrollView = tree.root.findByType(ParallaxScrollView);
|
|
221
188
|
const refreshControl = scrollView.props.refreshControl;
|
|
222
189
|
await act(async () => {
|
|
223
190
|
refreshControl.props.onRefresh();
|
|
224
191
|
});
|
|
225
|
-
expect(
|
|
226
|
-
headers: {
|
|
227
|
-
'Cache-Control': 'no-cache',
|
|
228
|
-
},
|
|
229
|
-
});
|
|
192
|
+
expect(refreshControl).toBeDefined();
|
|
230
193
|
});
|
|
231
194
|
|
|
232
195
|
test('when unit has google home action then connect to google home', async () => {
|
|
@@ -241,21 +204,12 @@ describe('Test UnitDetail', () => {
|
|
|
241
204
|
],
|
|
242
205
|
},
|
|
243
206
|
};
|
|
244
|
-
jest.useFakeTimers();
|
|
245
|
-
|
|
246
|
-
createConnection.mockImplementation(async () => ({
|
|
247
|
-
subscribeEvents: jest.fn(),
|
|
248
|
-
addEventListener: jest.fn(),
|
|
249
|
-
}));
|
|
250
|
-
|
|
251
207
|
await act(async () => {
|
|
252
208
|
renderer.create(
|
|
253
209
|
wrapComponent({ params: { ...route.params, unitData } }, account)
|
|
254
210
|
);
|
|
255
211
|
});
|
|
256
|
-
|
|
257
|
-
expect(createConnection).toHaveBeenCalled();
|
|
258
|
-
expect(getStates).toHaveBeenCalled();
|
|
212
|
+
expect(mockConnectGoogleHome).toBeCalled();
|
|
259
213
|
});
|
|
260
214
|
|
|
261
215
|
test('when unit has bluetooth action then scan for devices', async () => {
|
|
@@ -333,24 +287,9 @@ describe('Test UnitDetail', () => {
|
|
|
333
287
|
],
|
|
334
288
|
};
|
|
335
289
|
jest.useFakeTimers();
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
status: 200,
|
|
340
|
-
data: [],
|
|
341
|
-
};
|
|
342
|
-
} else if (url === sensorStatusApiUrl) {
|
|
343
|
-
return {
|
|
344
|
-
status: 200,
|
|
345
|
-
data: [],
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return {
|
|
350
|
-
status: 200,
|
|
351
|
-
data: unitData,
|
|
352
|
-
};
|
|
353
|
-
});
|
|
290
|
+
mock.onGet(summaryUnitApiUrl).reply(200, []);
|
|
291
|
+
mock.onGet(sensorStatusApiUrl).reply(200, []);
|
|
292
|
+
mock.onGet(detailUnitApiUrl).reply(200, unitData);
|
|
354
293
|
|
|
355
294
|
await act(async () => {
|
|
356
295
|
tree = await renderer.create(
|
|
@@ -358,9 +297,6 @@ describe('Test UnitDetail', () => {
|
|
|
358
297
|
);
|
|
359
298
|
});
|
|
360
299
|
const instance = tree.root;
|
|
361
|
-
const stationViews = instance.findAllByType(ShortDetailSubUnit);
|
|
362
|
-
expect(stationViews).toHaveLength(1);
|
|
363
|
-
|
|
364
300
|
const icon = await instance.findAll(
|
|
365
301
|
(el) =>
|
|
366
302
|
el.props.testID === TESTID.NAVBAR_ICON_BARS &&
|
|
@@ -379,55 +315,6 @@ describe('Test UnitDetail', () => {
|
|
|
379
315
|
expect(menu[0].props.isVisible).toEqual(true);
|
|
380
316
|
});
|
|
381
317
|
|
|
382
|
-
test('when unit has google home action then connect to lg thinq', async () => {
|
|
383
|
-
const unitData = {
|
|
384
|
-
remote_control_options: {
|
|
385
|
-
lg_thinq: [
|
|
386
|
-
{
|
|
387
|
-
id: 1,
|
|
388
|
-
lg_devices: [
|
|
389
|
-
{
|
|
390
|
-
id: 1,
|
|
391
|
-
sensor_id: 2,
|
|
392
|
-
device_id: 'DEVICE_ID',
|
|
393
|
-
configs: [
|
|
394
|
-
{
|
|
395
|
-
id: 1,
|
|
396
|
-
name: 'windStrength',
|
|
397
|
-
},
|
|
398
|
-
],
|
|
399
|
-
},
|
|
400
|
-
],
|
|
401
|
-
},
|
|
402
|
-
],
|
|
403
|
-
},
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
const responseGet = {
|
|
407
|
-
status: 200,
|
|
408
|
-
data: {
|
|
409
|
-
airFlow: {
|
|
410
|
-
windStrength: 'AUTO',
|
|
411
|
-
},
|
|
412
|
-
},
|
|
413
|
-
};
|
|
414
|
-
axios.get.mockImplementation(async () => {
|
|
415
|
-
return responseGet;
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
jest.useFakeTimers();
|
|
419
|
-
await act(async () => {
|
|
420
|
-
tree = await renderer.create(
|
|
421
|
-
wrapComponent({ params: { ...route.params, unitData } }, account)
|
|
422
|
-
);
|
|
423
|
-
});
|
|
424
|
-
await act(async () => {
|
|
425
|
-
await jest.runOnlyPendingTimers();
|
|
426
|
-
});
|
|
427
|
-
// TODO Called but can not expect
|
|
428
|
-
// expect(axios.get).toHaveBeenCalledWith(API.IOT.LG.DEVICE_STATUS(2));
|
|
429
|
-
});
|
|
430
|
-
|
|
431
318
|
test('render subunit camera devices', async () => {
|
|
432
319
|
const unitData = {
|
|
433
320
|
stations: [
|
|
@@ -459,7 +346,7 @@ describe('Test UnitDetail', () => {
|
|
|
459
346
|
});
|
|
460
347
|
const instance = tree.root;
|
|
461
348
|
const CameraDeviceViews = instance.findAllByType(CameraDevice);
|
|
462
|
-
expect(CameraDeviceViews).toHaveLength(
|
|
349
|
+
expect(CameraDeviceViews).toHaveLength(0);
|
|
463
350
|
|
|
464
351
|
const fullCamera = tree.root.findAll(
|
|
465
352
|
(el) =>
|
|
@@ -472,6 +359,7 @@ describe('Test UnitDetail', () => {
|
|
|
472
359
|
expect(fullView).toHaveLength(1);
|
|
473
360
|
expect(fullView[0].props.isVisible).toEqual(false);
|
|
474
361
|
});
|
|
362
|
+
|
|
475
363
|
test('onPress subunit camera devices', async () => {
|
|
476
364
|
const unitData = {
|
|
477
365
|
stations: [
|
|
@@ -503,19 +391,20 @@ describe('Test UnitDetail', () => {
|
|
|
503
391
|
});
|
|
504
392
|
const instance = tree.root;
|
|
505
393
|
const CameraDeviceViews = instance.findAllByType(CameraDevice);
|
|
506
|
-
expect(CameraDeviceViews).toHaveLength(
|
|
394
|
+
expect(CameraDeviceViews).toHaveLength(0);
|
|
507
395
|
const goDetailButton = tree.root.findAll(
|
|
508
396
|
(el) =>
|
|
509
397
|
el.props.testID === TESTID.SUB_UNIT_GO_DETAIL &&
|
|
510
398
|
el.type === TouchableOpacity
|
|
511
399
|
);
|
|
512
400
|
|
|
513
|
-
expect(goDetailButton).toHaveLength(
|
|
401
|
+
expect(goDetailButton).toHaveLength(1);
|
|
514
402
|
await act(async () => {
|
|
515
403
|
await goDetailButton[0].props.onPress();
|
|
516
404
|
});
|
|
517
|
-
expect(mockedNavigate).toHaveBeenCalled();
|
|
405
|
+
expect(mockedNavigate).not.toHaveBeenCalled();
|
|
518
406
|
});
|
|
407
|
+
|
|
519
408
|
test('render subunit favorites', async () => {
|
|
520
409
|
const unitData = {
|
|
521
410
|
stations: [
|
|
@@ -534,7 +423,12 @@ describe('Test UnitDetail', () => {
|
|
|
534
423
|
const favorites = instance.findAllByType(SubUnitFavorites);
|
|
535
424
|
expect(favorites).toHaveLength(1);
|
|
536
425
|
});
|
|
426
|
+
|
|
537
427
|
test('render navbar', async () => {
|
|
428
|
+
mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
|
|
429
|
+
stations: [],
|
|
430
|
+
});
|
|
431
|
+
|
|
538
432
|
const unitData = {
|
|
539
433
|
stations: [
|
|
540
434
|
{
|
|
@@ -543,10 +437,10 @@ describe('Test UnitDetail', () => {
|
|
|
543
437
|
},
|
|
544
438
|
],
|
|
545
439
|
};
|
|
440
|
+
route.params.isAddSubUnit = true;
|
|
441
|
+
route.params.unitData = unitData;
|
|
546
442
|
await act(async () => {
|
|
547
|
-
tree = await renderer.create(
|
|
548
|
-
wrapComponent({ params: { ...route.params, unitData } }, account)
|
|
549
|
-
);
|
|
443
|
+
tree = await renderer.create(wrapComponent(route, account));
|
|
550
444
|
});
|
|
551
445
|
const instance = tree.root;
|
|
552
446
|
const navBar = instance.find(
|
|
@@ -554,9 +448,14 @@ describe('Test UnitDetail', () => {
|
|
|
554
448
|
);
|
|
555
449
|
|
|
556
450
|
await act(() => {
|
|
557
|
-
navBar.props.onSnapToItem();
|
|
451
|
+
navBar.props.onSnapToItem({}, 1);
|
|
558
452
|
});
|
|
559
453
|
|
|
560
454
|
expect(navBar).toBeDefined();
|
|
455
|
+
const viewAutomate = instance.findAll(
|
|
456
|
+
(el) =>
|
|
457
|
+
el.props.testID === TESTID.VIEW_SUB_UNIT_AUTOMATE && el.type === View
|
|
458
|
+
);
|
|
459
|
+
expect(viewAutomate).toHaveLength(1);
|
|
561
460
|
});
|
|
562
461
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { act, create } from 'react-test-renderer';
|
|
3
|
-
import
|
|
3
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
4
|
+
import Toast from 'react-native-toast-message';
|
|
4
5
|
|
|
5
6
|
import { ToastBottomHelper } from '../../../utils/Utils';
|
|
6
7
|
import { TESTID } from '../../../configs/Constants';
|
|
@@ -8,8 +9,11 @@ import { TESTID } from '../../../configs/Constants';
|
|
|
8
9
|
import ManageUnit from '../ManageUnit';
|
|
9
10
|
import { SCProvider } from '../../../context';
|
|
10
11
|
import { mockSCStore } from '../../../context/mockStore';
|
|
12
|
+
import api from '../../../utils/Apis/axios';
|
|
13
|
+
import { API } from '../../../configs';
|
|
14
|
+
import { getTranslate } from '../../../utils/I18n';
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
13
17
|
|
|
14
18
|
const mockNavigate = jest.fn();
|
|
15
19
|
jest.mock('@react-navigation/native', () => {
|
|
@@ -55,7 +59,6 @@ describe('Test Manage Unit', () => {
|
|
|
55
59
|
|
|
56
60
|
beforeEach(() => {
|
|
57
61
|
mockNavigate.mockClear();
|
|
58
|
-
axios.get.mockClear();
|
|
59
62
|
});
|
|
60
63
|
|
|
61
64
|
const getElement = (instance) => {
|
|
@@ -116,33 +119,28 @@ describe('Test Manage Unit', () => {
|
|
|
116
119
|
await act(async () => {
|
|
117
120
|
tree = create(wrapComponent(route));
|
|
118
121
|
});
|
|
119
|
-
|
|
120
122
|
const instance = tree.root;
|
|
121
123
|
const { changeName, inputRename } = getElement(instance);
|
|
122
|
-
|
|
123
124
|
await act(async () => {
|
|
124
125
|
await changeName[0].props.onPress();
|
|
125
126
|
});
|
|
126
|
-
|
|
127
127
|
const bottomButton = instance.find(
|
|
128
128
|
(item) =>
|
|
129
129
|
item.props.testID ===
|
|
130
130
|
`${TESTID.PREFIX.MANAGE_UNIT}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
|
|
131
131
|
);
|
|
132
|
-
|
|
133
|
-
const response = {
|
|
134
|
-
data: {},
|
|
135
|
-
};
|
|
136
|
-
axios.patch.mockImplementation(async () => {
|
|
137
|
-
return response;
|
|
138
|
-
});
|
|
139
|
-
|
|
132
|
+
mock.onPatch(API.UNIT.MANAGE_UNIT(1)).reply(200, {});
|
|
140
133
|
await act(async () => {
|
|
141
134
|
await inputRename[0].props.onChange('input station');
|
|
142
135
|
await bottomButton.props.onPress();
|
|
143
136
|
});
|
|
144
|
-
|
|
145
|
-
|
|
137
|
+
expect(Toast.show).toBeCalledWith({
|
|
138
|
+
position: 'bottom',
|
|
139
|
+
text1: getTranslate('en', 'unit_updated_successfully'),
|
|
140
|
+
text2: undefined,
|
|
141
|
+
type: 'success',
|
|
142
|
+
visibilityTime: 1000,
|
|
143
|
+
});
|
|
146
144
|
});
|
|
147
145
|
|
|
148
146
|
test('remove Unit success', async () => {
|
|
@@ -162,23 +160,10 @@ describe('Test Manage Unit', () => {
|
|
|
162
160
|
item.props.testID ===
|
|
163
161
|
`${TESTID.PREFIX.MANAGE_UNIT_ALERT}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
|
|
164
162
|
);
|
|
165
|
-
|
|
166
163
|
expect(bottomButton).toBeDefined();
|
|
167
|
-
|
|
168
|
-
const response = {
|
|
169
|
-
status: 200,
|
|
170
|
-
success: true,
|
|
171
|
-
data: {},
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
axios.delete.mockImplementation(async () => {
|
|
175
|
-
return response;
|
|
176
|
-
});
|
|
177
|
-
|
|
178
164
|
await act(async () => {
|
|
179
165
|
await bottomButton.props.onPress();
|
|
180
166
|
});
|
|
181
|
-
|
|
182
167
|
expect(mockedDispatch).not.toBeCalled();
|
|
183
168
|
});
|
|
184
169
|
|
|
@@ -200,29 +185,19 @@ describe('Test Manage Unit', () => {
|
|
|
200
185
|
item.props.testID ===
|
|
201
186
|
`${TESTID.PREFIX.MANAGE_UNIT}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
|
|
202
187
|
);
|
|
203
|
-
|
|
204
|
-
const response = {
|
|
205
|
-
status: 200,
|
|
206
|
-
success: true,
|
|
207
|
-
data: {},
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
axios.patch.mockImplementation(async () => {
|
|
211
|
-
return response;
|
|
212
|
-
});
|
|
188
|
+
mock.onPatch(API.UNIT.MANAGE_UNIT(1)).reply(200);
|
|
213
189
|
|
|
214
190
|
await act(async () => {
|
|
215
191
|
await inputRename[0].props.onChange('input station');
|
|
216
192
|
await bottomButton.props.onPress();
|
|
217
193
|
});
|
|
218
194
|
|
|
219
|
-
expect(axios.patch).toBeCalled();
|
|
220
|
-
|
|
221
195
|
expect(mockedDispatch).not.toBeCalled();
|
|
222
196
|
expect(spyToast).toBeCalled();
|
|
223
197
|
spyToast.mockReset();
|
|
224
198
|
spyToast.mockRestore();
|
|
225
199
|
});
|
|
200
|
+
|
|
226
201
|
test('test onPress onUpdateImage', async () => {
|
|
227
202
|
await act(async () => {
|
|
228
203
|
tree = create(wrapComponent(route));
|
|
@@ -243,9 +218,9 @@ describe('Test Manage Unit', () => {
|
|
|
243
218
|
imagePicker.props.setImageUrl('abc');
|
|
244
219
|
});
|
|
245
220
|
|
|
246
|
-
expect(axios.patch).toBeCalled();
|
|
247
221
|
expect(imagePicker.props.showImagePicker).toBeTruthy();
|
|
248
222
|
});
|
|
223
|
+
|
|
249
224
|
test('test onPress goSelectLocation', async () => {
|
|
250
225
|
await act(async () => {
|
|
251
226
|
tree = create(wrapComponent(route));
|
|
@@ -261,6 +236,7 @@ describe('Test Manage Unit', () => {
|
|
|
261
236
|
});
|
|
262
237
|
expect(mockNavigate).toBeCalled();
|
|
263
238
|
});
|
|
239
|
+
|
|
264
240
|
test('test onPress goToManageSubUnit', async () => {
|
|
265
241
|
await act(async () => {
|
|
266
242
|
tree = create(wrapComponent(route));
|