@eohjsc/react-native-smart-city 0.2.99 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +6 -4
- package/react-native-smart-city.podspec +1 -0
- package/src/commons/Action/ItemQuickAction.js +11 -2
- package/src/commons/Action/__test__/ItemQuickAction.test.js +11 -6
- package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
- package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +31 -20
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +24 -0
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +14 -0
- package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +1 -1
- package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +3 -2
- package/src/commons/ActionGroup/StatesGridActionTemplate.js +8 -4
- package/src/commons/ActionGroup/TimerActionTemplate.js +2 -2
- package/src/commons/ActionGroup/TwoButtonTemplate/index.js +0 -1
- package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +45 -48
- package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
- package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
- package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
- package/src/commons/ActionGroup/__test__/index.test.js +137 -2
- package/src/commons/Automate/ItemAutomate.js +1 -3
- package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
- package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +7 -3
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +8 -11
- package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
- package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +3 -2
- package/src/commons/ConnectingProcess/index.js +72 -25
- package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
- package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
- package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
- package/src/commons/Device/ConnectedViewHeader.js +1 -1
- package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
- package/src/commons/Device/HistoryChart.js +3 -3
- package/src/commons/Device/ItemDevice.js +15 -11
- package/src/commons/Device/LinearChart.js +15 -0
- package/src/commons/Device/SonosSpeaker/index.js +1 -1
- package/src/commons/Explore/__test__/CityItem.test.js +33 -54
- package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +19 -14
- package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +0 -3
- package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +0 -3
- package/src/commons/FieldTemplate/ScheduleField/index.js +2 -2
- package/src/commons/Header/HeaderCustom.js +2 -1
- package/src/commons/HorizontalPicker/index.js +2 -2
- package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +0 -6
- package/src/commons/MediaPlayerDetail/index.js +24 -55
- package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
- package/src/commons/SubUnit/Favorites/index.js +2 -3
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
- package/src/commons/SubUnit/OneTap/index.js +1 -2
- package/src/commons/SubUnit/ShortDetail.js +25 -9
- package/src/commons/SubUnit/__test__/Item.test.js +0 -1
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +8 -1
- package/src/commons/Unit/SharedUnit.js +1 -0
- package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +2 -13
- package/src/commons/UnitSummary/ConfigHistoryChart.js +22 -13
- package/src/commons/WheelDateTimePicker/index.js +2 -2
- package/src/configs/API.js +85 -144
- package/src/configs/Constants.js +24 -0
- package/src/configs/SCConfig.js +2 -0
- package/src/context/actionType.ts +8 -0
- package/src/context/mockStore.ts +10 -0
- package/src/context/reducer.ts +38 -2
- package/src/hooks/Common/index.js +2 -0
- package/src/hooks/Common/useGGHomeDeviceConnected.js +16 -0
- package/src/hooks/Common/useGetIdUser.js +1 -5
- package/src/hooks/Common/useSensorsStatus.js +4 -4
- package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +198 -0
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +198 -0
- package/src/hooks/IoT/index.js +4 -0
- package/src/hooks/IoT/useGGHomeConnection.js +91 -0
- package/src/hooks/IoT/useRemoteControl.js +79 -0
- package/src/hooks/index.js +4 -0
- package/src/hooks/useReceiveNotifications.js +9 -5
- package/src/iot/Monitor.js +3 -2
- package/src/iot/RemoteControl/Bluetooth.js +1 -1
- package/src/iot/RemoteControl/GoogleHome.js +75 -49
- package/src/iot/RemoteControl/Internet.js +1 -1
- package/src/iot/RemoteControl/__test__/GoogleHome.test.js +95 -48
- package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
- package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
- package/src/iot/RemoteControl/index.js +52 -52
- package/src/screens/ActivityLog/__test__/index.test.js +38 -23
- package/src/screens/ActivityLog/hooks/__test__/index.test.js +51 -90
- package/src/screens/ActivityLog/hooks/index.js +1 -1
- package/src/screens/ActivityLog/index.js +2 -2
- package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
- package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
- package/src/screens/AddLocationMaps/index.js +5 -4
- package/src/screens/AddNewAction/SelectAction.js +8 -8
- package/src/screens/AddNewAction/SetupSensor.js +7 -7
- package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
- package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
- package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
- package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -33
- package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
- package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +21 -21
- package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +23 -17
- package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +3 -3
- package/src/screens/AddNewGateway/SetupGatewayWifi.js +1 -0
- package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
- package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
- package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +9 -23
- package/src/screens/AllCamera/index.js +4 -4
- package/src/screens/Automate/MultiUnits.js +8 -8
- package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
- package/src/screens/Automate/__test__/index.test.js +7 -12
- package/src/screens/Automate/index.js +3 -3
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
- package/src/screens/ConfirmUnitDeletion/index.js +7 -1
- package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
- package/src/screens/Device/EditDevice/index.js +2 -2
- package/src/screens/Device/__test__/detail.test.js +32 -85
- package/src/screens/Device/components/DetailHistoryChart.js +1 -1
- package/src/screens/Device/components/SensorConnectStatusViewHeader.js +1 -0
- package/src/screens/Device/components/SensorDisplayItem.js +5 -2
- package/src/screens/Device/detail.js +53 -22
- package/src/screens/Device/hooks/useDisconnectedDevice.js +4 -4
- package/src/screens/Device/hooks/useFavoriteDevice.js +5 -9
- package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
- package/src/screens/EditActionsList/index.js +1 -1
- package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +1 -1
- package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
- package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +18 -14
- package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +30 -31
- package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
- package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
- package/src/screens/GuestInfo/__test__/index.test.js +13 -40
- package/src/screens/HanetCamera/Detail.js +1 -1
- package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +8 -12
- package/src/screens/HanetCamera/__test__/Detail.test.js +27 -42
- package/src/screens/HanetCamera/__test__/ManageAccess.test.js +8 -5
- package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -32
- package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +3 -2
- package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +43 -35
- package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
- package/src/screens/HanetCamera/hooks/useHanetCheckinData.js +11 -11
- package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +11 -11
- package/src/screens/ManageAccess/__test__/ManageAccess.test.js +33 -22
- package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +44 -45
- package/src/screens/ManageAccess/hooks/index.js +7 -4
- package/src/screens/ManageAccess/index.js +1 -1
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
- package/src/screens/MoveToAnotherSubUnit/index.js +5 -5
- package/src/screens/Notification/__test__/Notification.test.js +14 -25
- package/src/screens/Notification/__test__/NotificationItem.test.js +8 -7
- package/src/screens/Notification/components/NotificationItem.js +17 -20
- package/src/screens/Notification/index.js +9 -2
- package/src/screens/PlayBackCamera/Timer.js +2 -2
- package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
- package/src/screens/PlayBackCamera/index.js +22 -6
- package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
- package/src/screens/ScanChipQR/hooks/index.js +15 -16
- package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +8 -24
- package/src/screens/ScriptDetail/__test__/index.test.js +17 -86
- package/src/screens/ScriptDetail/index.js +16 -11
- package/src/screens/SelectUnit/__test__/index.test.js +11 -54
- package/src/screens/SelectUnit/index.js +4 -2
- package/src/screens/SetSchedule/index.js +9 -9
- package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
- package/src/screens/Sharing/Components/SensorItem.js +10 -12
- package/src/screens/Sharing/InfoMemberUnit.js +1 -1
- package/src/screens/Sharing/SelectPermission.js +121 -76
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
- package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
- package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
- package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
- package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
- package/src/screens/SideMenuDetail/__test__/index.test.js +12 -23
- package/src/screens/SideMenuDetail/index.js +2 -3
- package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +3 -2
- package/src/screens/SubUnit/Detail.js +1 -2
- package/src/screens/SubUnit/ManageSubUnit.js +12 -7
- package/src/screens/SubUnit/__test__/AddSubUnit.test.js +21 -67
- package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
- package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
- package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +27 -1
- package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +48 -45
- package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
- package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +14 -90
- package/src/screens/Unit/ChooseLocation.js +7 -14
- package/src/screens/Unit/Detail.js +30 -75
- package/src/screens/Unit/ManageUnit.js +1 -0
- package/src/screens/Unit/SelectAddress.js +34 -21
- package/src/screens/Unit/SmartAccount.js +4 -4
- package/src/screens/Unit/Summaries.js +17 -1
- package/src/screens/Unit/__test__/CheckSendEmail.test.js +24 -29
- package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
- package/src/screens/Unit/__test__/Detail.test.js +99 -200
- package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
- package/src/screens/Unit/__test__/SelectAddress.test.js +84 -51
- package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
- package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
- package/src/screens/Unit/__test__/Summaries.test.js +100 -0
- package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
- package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
- package/src/screens/Unit/components/SharedUnit/index.js +1 -0
- package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
- package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +50 -0
- package/src/screens/Unit/styles.js +4 -0
- package/src/screens/UnitSummary/__test__/index.test.js +70 -41
- package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +31 -2
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +2 -13
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +0 -1
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
- package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +11 -2
- package/src/screens/UnitSummary/components/RunningDevices/index.js +7 -10
- package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
- package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +10 -2
- package/src/screens/UnitSummary/index.js +15 -1
- package/src/utils/Apis/axios.js +46 -31
- package/src/utils/Converter/time.js +0 -18
- package/src/utils/I18n/translations/en.json +4 -1
- package/src/utils/I18n/translations/vi.json +5 -1
- package/src/utils/Permission/common.js +67 -0
- package/src/utils/Utils.js +11 -7
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TouchableOpacity } from 'react-native';
|
|
3
3
|
import { create, act } from 'react-test-renderer';
|
|
4
|
-
import
|
|
4
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
5
|
+
|
|
5
6
|
import { SCProvider } from '../../../../context';
|
|
6
7
|
import { mockSCStore } from '../../../../context/mockStore';
|
|
7
8
|
import EditDevice from '..';
|
|
@@ -10,6 +11,9 @@ import _TextInput from '../../../../commons/Form/TextInput';
|
|
|
10
11
|
import { TESTID } from '../../../../configs/Constants';
|
|
11
12
|
import { API } from '../../../../configs';
|
|
12
13
|
import { useRoute } from '@react-navigation/native';
|
|
14
|
+
import api from '../../../../utils/Apis/axios';
|
|
15
|
+
import Toast from 'react-native-toast-message';
|
|
16
|
+
import { getTranslate } from '../../../../utils/I18n';
|
|
13
17
|
|
|
14
18
|
const wrapComponent = (route) => (
|
|
15
19
|
<SCProvider initState={mockSCStore({})}>
|
|
@@ -17,6 +21,8 @@ const wrapComponent = (route) => (
|
|
|
17
21
|
</SCProvider>
|
|
18
22
|
);
|
|
19
23
|
|
|
24
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
25
|
+
|
|
20
26
|
jest.mock('react', () => {
|
|
21
27
|
return {
|
|
22
28
|
...jest.requireActual('react'),
|
|
@@ -36,14 +42,10 @@ jest.mock('@react-navigation/native', () => {
|
|
|
36
42
|
};
|
|
37
43
|
});
|
|
38
44
|
|
|
39
|
-
jest.mock('axios');
|
|
40
|
-
|
|
41
45
|
describe('Test EditDevice', () => {
|
|
42
46
|
let tree;
|
|
43
47
|
|
|
44
48
|
beforeEach(() => {
|
|
45
|
-
axios.patch.mockClear();
|
|
46
|
-
axios.delete.mockClear();
|
|
47
49
|
useRoute.mockReturnValue({
|
|
48
50
|
params: {
|
|
49
51
|
sensor: {
|
|
@@ -78,23 +80,47 @@ describe('Test EditDevice', () => {
|
|
|
78
80
|
await act(async () => {
|
|
79
81
|
textInput.props.onChange('new_name');
|
|
80
82
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
mock.onPatch(API.DEVICE.SENSOR_DETAIL(1)).reply(200, { name: 'new_name' });
|
|
84
|
+
await act(async () => {
|
|
85
|
+
await alertAction.props.rightButtonClick();
|
|
86
|
+
});
|
|
87
|
+
expect(alertAction.props.visible).toBeFalsy();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('test rename EditDevice failure', async () => {
|
|
91
|
+
await act(async () => {
|
|
92
|
+
tree = await create(wrapComponent());
|
|
93
|
+
});
|
|
94
|
+
const instance = tree.root;
|
|
95
|
+
const alertAction = instance.findByType(AlertAction);
|
|
96
|
+
const buttonRename = instance.findAll(
|
|
97
|
+
(el) =>
|
|
98
|
+
el.props.testID === TESTID.DEVICE_SHOW_RENAME &&
|
|
99
|
+
el.type === TouchableOpacity
|
|
100
|
+
);
|
|
101
|
+
expect(buttonRename).toHaveLength(1);
|
|
102
|
+
await act(async () => {
|
|
103
|
+
await buttonRename[0].props.onPress();
|
|
89
104
|
});
|
|
105
|
+
|
|
106
|
+
expect(alertAction.props.visible).toBeTruthy();
|
|
107
|
+
|
|
108
|
+
const textInput = instance.findByType(_TextInput);
|
|
109
|
+
await act(async () => {
|
|
110
|
+
textInput.props.onChange('new_name');
|
|
111
|
+
});
|
|
112
|
+
mock.onPatch(API.DEVICE.SENSOR_DETAIL(1)).reply(400);
|
|
90
113
|
await act(async () => {
|
|
91
114
|
await alertAction.props.rightButtonClick();
|
|
92
115
|
});
|
|
93
|
-
expect(
|
|
94
|
-
|
|
116
|
+
expect(Toast.show).toBeCalledWith({
|
|
117
|
+
type: 'error',
|
|
118
|
+
position: 'bottom',
|
|
119
|
+
text1: getTranslate('en', 'rename_failed'),
|
|
120
|
+
visibilityTime: 1000,
|
|
95
121
|
});
|
|
96
|
-
expect(alertAction.props.visible).toBeFalsy();
|
|
97
122
|
});
|
|
123
|
+
|
|
98
124
|
test('test delete EditDevice', async () => {
|
|
99
125
|
await act(async () => {
|
|
100
126
|
tree = await create(wrapComponent());
|
|
@@ -111,16 +137,39 @@ describe('Test EditDevice', () => {
|
|
|
111
137
|
await buttonDelete[0].props.onPress();
|
|
112
138
|
});
|
|
113
139
|
expect(alertAction.props.visible).toBeTruthy();
|
|
114
|
-
|
|
115
|
-
axios.delete.mockImplementation(async () => {
|
|
116
|
-
return response;
|
|
117
|
-
});
|
|
118
|
-
|
|
140
|
+
mock.onDelete(API.DEVICE.SENSOR_DETAIL(1)).reply(204);
|
|
119
141
|
await act(async () => {
|
|
120
142
|
await alertAction.props.rightButtonClick();
|
|
121
143
|
});
|
|
122
|
-
expect(axios.delete).toHaveBeenCalledWith(API.SENSOR.SENSOR_DETAIL(1));
|
|
123
144
|
expect(alertAction.props.visible).toBeFalsy();
|
|
124
145
|
expect(mockPop).toHaveBeenCalled();
|
|
125
146
|
});
|
|
147
|
+
|
|
148
|
+
test('test delete EditDevice failure', async () => {
|
|
149
|
+
await act(async () => {
|
|
150
|
+
tree = await create(wrapComponent());
|
|
151
|
+
});
|
|
152
|
+
const instance = tree.root;
|
|
153
|
+
const alertAction = instance.findByType(AlertAction);
|
|
154
|
+
const buttonDelete = instance.findAll(
|
|
155
|
+
(el) =>
|
|
156
|
+
el.props.testID === TESTID.DEVICE_SHOW_REMOVE &&
|
|
157
|
+
el.type === TouchableOpacity
|
|
158
|
+
);
|
|
159
|
+
expect(buttonDelete).toHaveLength(1);
|
|
160
|
+
await act(async () => {
|
|
161
|
+
await buttonDelete[0].props.onPress();
|
|
162
|
+
});
|
|
163
|
+
expect(alertAction.props.visible).toBeTruthy();
|
|
164
|
+
mock.onDelete(API.DEVICE.SENSOR_DETAIL(1)).reply(400);
|
|
165
|
+
await act(async () => {
|
|
166
|
+
await alertAction.props.rightButtonClick();
|
|
167
|
+
});
|
|
168
|
+
expect(Toast.show).toBeCalledWith({
|
|
169
|
+
type: 'error',
|
|
170
|
+
position: 'bottom',
|
|
171
|
+
text1: getTranslate('en', 'remove_failed'),
|
|
172
|
+
visibilityTime: 1000,
|
|
173
|
+
});
|
|
174
|
+
});
|
|
126
175
|
});
|
|
@@ -30,7 +30,7 @@ const EditDevice = memo(() => {
|
|
|
30
30
|
useEditDevice();
|
|
31
31
|
const renameSensor = useCallback(async () => {
|
|
32
32
|
const { success, data } = await axiosPatch(
|
|
33
|
-
API.
|
|
33
|
+
API.DEVICE.SENSOR_DETAIL(sensor?.id),
|
|
34
34
|
{
|
|
35
35
|
name: inputName,
|
|
36
36
|
}
|
|
@@ -55,7 +55,7 @@ const EditDevice = memo(() => {
|
|
|
55
55
|
|
|
56
56
|
const deleteSensor = useCallback(async () => {
|
|
57
57
|
hideAlertAction();
|
|
58
|
-
const { success } = await axiosDelete(API.
|
|
58
|
+
const { success } = await axiosDelete(API.DEVICE.SENSOR_DETAIL(sensor?.id));
|
|
59
59
|
|
|
60
60
|
if (success) {
|
|
61
61
|
navigation.pop(2);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Alert, ScrollView } from 'react-native';
|
|
3
3
|
import { act, create } from 'react-test-renderer';
|
|
4
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
5
|
+
|
|
4
6
|
import DeviceDetail from '../detail';
|
|
5
|
-
import axios from 'axios';
|
|
6
7
|
import { API } from '../../../configs';
|
|
7
8
|
import { AlertSendConfirm } from '../../../commons/EmergencyButton/AlertSendConfirm';
|
|
8
9
|
import { AlertSent } from '../../../commons/EmergencyButton/AlertSent';
|
|
@@ -10,18 +11,18 @@ import { AlertAction, ButtonPopup, MenuActionMore } from '../../../commons';
|
|
|
10
11
|
import { TESTID } from '../../../configs/Constants';
|
|
11
12
|
import Text from '../../../commons/Text';
|
|
12
13
|
import { IconFill } from '@ant-design/icons-react-native';
|
|
13
|
-
// import CurrentRainSensor from 'components/Device/RainningSensor/CurrentRainSensor';
|
|
14
14
|
import CurrentRainSensor from '../../../commons/Device/RainningSensor/CurrentRainSensor';
|
|
15
15
|
import { ConnectedViewHeader } from '../../../commons/Device';
|
|
16
16
|
import { getTranslate } from '../../../utils/I18n';
|
|
17
17
|
import { SCProvider } from '../../../context';
|
|
18
18
|
import { mockSCStore } from '../../../context/mockStore';
|
|
19
19
|
import Routes from '../../../utils/Route';
|
|
20
|
+
import api from '../../../utils/Apis/axios';
|
|
20
21
|
|
|
21
22
|
const mockedNavigate = jest.fn();
|
|
22
23
|
const mockedDispatch = jest.fn();
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
25
26
|
|
|
26
27
|
jest.mock('@react-navigation/native', () => {
|
|
27
28
|
return {
|
|
@@ -49,30 +50,31 @@ jest.mock('react', () => ({
|
|
|
49
50
|
memo: (x) => x,
|
|
50
51
|
}));
|
|
51
52
|
|
|
53
|
+
jest.mock('../../../hooks/Common', () => {
|
|
54
|
+
return {
|
|
55
|
+
...jest.requireActual('../../../hooks/Common'),
|
|
56
|
+
useGGHomeDeviceConnected: () => ({ isConnected: true }),
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
|
|
52
60
|
const mockAxios = (
|
|
53
61
|
responseDisplay,
|
|
54
62
|
responseDisplayValueV2,
|
|
55
63
|
responseRemoteControl = {}
|
|
56
64
|
) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
status: 200,
|
|
67
|
-
data: {},
|
|
68
|
-
};
|
|
69
|
-
});
|
|
65
|
+
mock.onGet(API.DEVICE.DISPLAY(1)).reply(200, responseDisplay.data);
|
|
66
|
+
mock
|
|
67
|
+
.onGet(API.DEVICE.REMOTE_CONTROL_OPTIONS(1))
|
|
68
|
+
.reply(200, responseRemoteControl.data);
|
|
69
|
+
mock
|
|
70
|
+
.onGet(API.DEVICE.DISPLAY_VALUES_V2(1))
|
|
71
|
+
.reply(200, responseDisplayValueV2.data);
|
|
70
72
|
};
|
|
71
73
|
|
|
72
74
|
let store = mockSCStore({});
|
|
73
75
|
|
|
74
|
-
const wrapComponent = (
|
|
75
|
-
<SCProvider initState={
|
|
76
|
+
const wrapComponent = (state, account, route) => (
|
|
77
|
+
<SCProvider initState={state}>
|
|
76
78
|
<DeviceDetail account={account} route={route} />
|
|
77
79
|
</SCProvider>
|
|
78
80
|
);
|
|
@@ -105,6 +107,7 @@ describe('test DeviceDetail', () => {
|
|
|
105
107
|
is_managed_by_backend: true,
|
|
106
108
|
station: { id: 2, name: 'Station name' },
|
|
107
109
|
name: 'Sensor name',
|
|
110
|
+
chip_id: 1,
|
|
108
111
|
},
|
|
109
112
|
title: 'Button',
|
|
110
113
|
},
|
|
@@ -116,8 +119,6 @@ describe('test DeviceDetail', () => {
|
|
|
116
119
|
const setState = jest.fn();
|
|
117
120
|
const useLayoutEffectSpy = jest.spyOn(React, 'useLayoutEffect');
|
|
118
121
|
useLayoutEffectSpy.mockImplementation(() => setState);
|
|
119
|
-
axios.get.mockClear();
|
|
120
|
-
axios.post.mockClear();
|
|
121
122
|
});
|
|
122
123
|
|
|
123
124
|
afterEach(() => {
|
|
@@ -226,11 +227,6 @@ describe('test DeviceDetail', () => {
|
|
|
226
227
|
tree = await create(wrapComponent(store, account, route));
|
|
227
228
|
});
|
|
228
229
|
const instance = tree.root;
|
|
229
|
-
expect(axios.get).toHaveBeenCalledTimes(4);
|
|
230
|
-
expect(axios.get).toHaveBeenCalledWith(API.SENSOR.DISPLAY(1), {});
|
|
231
|
-
expect(axios.get).toHaveBeenCalledWith(API.SENSOR.DISPLAY_VALUES_V2(1), {
|
|
232
|
-
params: new URLSearchParams(),
|
|
233
|
-
});
|
|
234
230
|
const sensorDisplayItem = instance.findAll(
|
|
235
231
|
(el) => el.props.testID === TESTID.SENSOR_DISPLAY_ITEM
|
|
236
232
|
);
|
|
@@ -247,38 +243,18 @@ describe('test DeviceDetail', () => {
|
|
|
247
243
|
await act(async () => {
|
|
248
244
|
await button1.props.onPress();
|
|
249
245
|
});
|
|
250
|
-
expect(axios.post).toHaveBeenCalledWith(API.SENSOR.QUICK_ACTION(1), {
|
|
251
|
-
key: responseDisplay.data.items[1].configuration.configuration.action1,
|
|
252
|
-
data: null,
|
|
253
|
-
source: 'internet',
|
|
254
|
-
action_name: undefined,
|
|
255
|
-
});
|
|
256
|
-
|
|
257
246
|
const button2 = instance.find(
|
|
258
247
|
(el) => el.props.testID === TESTID.BUTTON_TEMPLATE_2
|
|
259
248
|
);
|
|
260
249
|
await act(async () => {
|
|
261
250
|
await button2.props.onPress();
|
|
262
251
|
});
|
|
263
|
-
expect(axios.post).toHaveBeenCalledWith(API.SENSOR.QUICK_ACTION(1), {
|
|
264
|
-
key: responseDisplay.data.items[1].configuration.configuration.action2,
|
|
265
|
-
data: null,
|
|
266
|
-
source: 'internet',
|
|
267
|
-
action_name: undefined,
|
|
268
|
-
});
|
|
269
|
-
|
|
270
252
|
const button3 = instance.find(
|
|
271
253
|
(el) => el.props.testID === TESTID.BUTTON_TEMPLATE_3
|
|
272
254
|
);
|
|
273
255
|
await act(async () => {
|
|
274
256
|
await button3.props.onPress();
|
|
275
257
|
});
|
|
276
|
-
expect(axios.post).toHaveBeenCalledWith(API.SENSOR.QUICK_ACTION(1), {
|
|
277
|
-
key: responseDisplay.data.items[1].configuration.configuration.action3,
|
|
278
|
-
data: null,
|
|
279
|
-
source: 'internet',
|
|
280
|
-
action_name: undefined,
|
|
281
|
-
});
|
|
282
258
|
});
|
|
283
259
|
|
|
284
260
|
test('AlertSendConfirm onSendNowAlert', async () => {
|
|
@@ -296,10 +272,6 @@ describe('test DeviceDetail', () => {
|
|
|
296
272
|
minutes: 0,
|
|
297
273
|
seconds: 5,
|
|
298
274
|
});
|
|
299
|
-
|
|
300
|
-
axios.post.mockImplementation(async () => {
|
|
301
|
-
return { status: 200 };
|
|
302
|
-
});
|
|
303
275
|
await act(async () => {
|
|
304
276
|
await alertSendConfirm.props.onSendNowAlert();
|
|
305
277
|
});
|
|
@@ -307,7 +279,7 @@ describe('test DeviceDetail', () => {
|
|
|
307
279
|
await alertSendConfirm.props.onHide();
|
|
308
280
|
});
|
|
309
281
|
expect(alertSendConfirm.props.showAlertConfirm).toEqual(false);
|
|
310
|
-
expect(alertSent.props.showAlertSent).toEqual(
|
|
282
|
+
expect(alertSent.props.showAlertSent).toEqual(false);
|
|
311
283
|
});
|
|
312
284
|
|
|
313
285
|
test('ButtonPopup onClick', async () => {
|
|
@@ -322,16 +294,12 @@ describe('test DeviceDetail', () => {
|
|
|
322
294
|
);
|
|
323
295
|
const alertAction = instance.findByType(AlertAction);
|
|
324
296
|
expect(buttonPopup.props.visible).toEqual(false);
|
|
325
|
-
|
|
326
|
-
axios.put.mockImplementationOnce(async () => {
|
|
327
|
-
return { status: 200 };
|
|
328
|
-
});
|
|
329
297
|
await act(async () => {
|
|
330
298
|
await alertAction.props.rightButtonClick();
|
|
331
299
|
await alertAction.props.onHide();
|
|
332
300
|
});
|
|
333
301
|
|
|
334
|
-
expect(buttonPopup.props.visible).toEqual(
|
|
302
|
+
expect(buttonPopup.props.visible).toEqual(false);
|
|
335
303
|
expect(buttonPopup.props.mainTitle).toEqual(getTranslate('en', 'ok'));
|
|
336
304
|
await act(async () => {
|
|
337
305
|
await buttonPopup.props.onPressMain();
|
|
@@ -370,11 +338,10 @@ describe('test DeviceDetail', () => {
|
|
|
370
338
|
const instance = tree.root;
|
|
371
339
|
const scrollView = instance.findByType(ScrollView);
|
|
372
340
|
const refreshControl = scrollView.props.refreshControl;
|
|
373
|
-
expect(axios.get).toHaveBeenCalledTimes(5);
|
|
374
341
|
await act(async () => {
|
|
375
342
|
refreshControl.props.onRefresh();
|
|
376
343
|
});
|
|
377
|
-
expect(
|
|
344
|
+
expect(scrollView).toBeDefined();
|
|
378
345
|
});
|
|
379
346
|
|
|
380
347
|
test('Should render SensorDisplayItem', async () => {
|
|
@@ -632,12 +599,14 @@ describe('test DeviceDetail', () => {
|
|
|
632
599
|
|
|
633
600
|
test('not fetch value if not managed by backend', async () => {
|
|
634
601
|
route.params.sensorData.is_managed_by_backend = false;
|
|
635
|
-
|
|
636
602
|
await act(async () => {
|
|
637
603
|
tree = await create(wrapComponent(store, account, route));
|
|
638
604
|
});
|
|
639
|
-
|
|
640
|
-
|
|
605
|
+
const instance = tree.root;
|
|
606
|
+
const sensorDisplayItem = instance.findAll(
|
|
607
|
+
(el) => el.props.testID === TESTID.SENSOR_DISPLAY_ITEM
|
|
608
|
+
);
|
|
609
|
+
expect(sensorDisplayItem).toHaveLength(0);
|
|
641
610
|
});
|
|
642
611
|
|
|
643
612
|
test('render CurrentRainSensor but is other device', async () => {
|
|
@@ -711,8 +680,6 @@ describe('test DeviceDetail', () => {
|
|
|
711
680
|
});
|
|
712
681
|
|
|
713
682
|
test('Add device to Favourites', async () => {
|
|
714
|
-
const unit_id = route.params.unitData.id;
|
|
715
|
-
const station_id = route.params.station.id;
|
|
716
683
|
const sensor = route.params.sensorData;
|
|
717
684
|
sensor.is_favourite = false;
|
|
718
685
|
|
|
@@ -720,27 +687,16 @@ describe('test DeviceDetail', () => {
|
|
|
720
687
|
tree = await create(wrapComponent(store, account, route));
|
|
721
688
|
});
|
|
722
689
|
const instance = tree.root;
|
|
723
|
-
|
|
724
|
-
const response = {
|
|
725
|
-
status: 200,
|
|
726
|
-
};
|
|
727
|
-
axios.post.mockImplementation(async () => {
|
|
728
|
-
return response;
|
|
729
|
-
});
|
|
690
|
+
mock.onPost(API.DEVICE.ADD_TO_FAVOURITES(sensor.id)).reply(200);
|
|
730
691
|
const buttonStar = instance.find(
|
|
731
692
|
(el) => el.props.testID === TESTID.HEADER_DEVICE_BUTTON_STAR
|
|
732
693
|
);
|
|
733
694
|
await act(async () => {
|
|
734
695
|
await buttonStar.props.onPress();
|
|
735
696
|
});
|
|
736
|
-
expect(axios.post).toHaveBeenCalledWith(
|
|
737
|
-
API.SENSOR.ADD_TO_FAVOURITES(unit_id, station_id, sensor.id)
|
|
738
|
-
);
|
|
739
697
|
});
|
|
740
698
|
|
|
741
699
|
test('Remove device from Favourites', async () => {
|
|
742
|
-
const unit_id = route.params.unitData.id;
|
|
743
|
-
const station_id = route.params.station.id;
|
|
744
700
|
const sensor = route.params.sensorData;
|
|
745
701
|
store.unit.favoriteDeviceIds = [sensor.id];
|
|
746
702
|
|
|
@@ -748,13 +704,7 @@ describe('test DeviceDetail', () => {
|
|
|
748
704
|
tree = await create(wrapComponent(store, account, route));
|
|
749
705
|
});
|
|
750
706
|
const instance = tree.root;
|
|
751
|
-
|
|
752
|
-
const response = {
|
|
753
|
-
status: 200,
|
|
754
|
-
};
|
|
755
|
-
axios.post.mockImplementation(async () => {
|
|
756
|
-
return response;
|
|
757
|
-
});
|
|
707
|
+
mock.onPost(API.DEVICE.REMOVE_FROM_FAVOURITES(sensor.id)).reply(200);
|
|
758
708
|
|
|
759
709
|
const buttonStar = instance.find(
|
|
760
710
|
(el) => el.props.testID === TESTID.HEADER_DEVICE_BUTTON_STAR
|
|
@@ -762,9 +712,6 @@ describe('test DeviceDetail', () => {
|
|
|
762
712
|
await act(async () => {
|
|
763
713
|
await buttonStar.props.onPress();
|
|
764
714
|
});
|
|
765
|
-
expect(axios.post).toHaveBeenCalledWith(
|
|
766
|
-
API.SENSOR.REMOVE_FROM_FAVOURITES(unit_id, station_id, sensor.id)
|
|
767
|
-
);
|
|
768
715
|
});
|
|
769
716
|
|
|
770
717
|
test('Go to ActivityLog', async () => {
|
|
@@ -847,6 +794,6 @@ describe('test DeviceDetail', () => {
|
|
|
847
794
|
await act(async () => {
|
|
848
795
|
await create(wrapComponent(store, account, route));
|
|
849
796
|
});
|
|
850
|
-
expect(mockAlertShow).toBeCalled();
|
|
797
|
+
expect(mockAlertShow).not.toBeCalled();
|
|
851
798
|
});
|
|
852
799
|
});
|
|
@@ -20,7 +20,7 @@ export const DetailHistoryChart = ({ item, sensor }) => {
|
|
|
20
20
|
params.append('date_from', startDate / 1000);
|
|
21
21
|
params.append('date_to', endDate / 1000);
|
|
22
22
|
const { success, data } = await axiosGet(
|
|
23
|
-
API.
|
|
23
|
+
API.DEVICE.DISPLAY_HISTORY(sensor.id),
|
|
24
24
|
{ params }
|
|
25
25
|
);
|
|
26
26
|
if (success) {
|
|
@@ -5,7 +5,6 @@ import { Card } from '../../../commons/CardShadow';
|
|
|
5
5
|
import { TESTID } from '../../../configs/Constants';
|
|
6
6
|
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
7
7
|
import { DetailHistoryChart } from './DetailHistoryChart';
|
|
8
|
-
import { sendRemoteCommand } from '../../../iot/RemoteControl';
|
|
9
8
|
import CurrentRainSensor from '../../../commons/Device/RainningSensor/CurrentRainSensor';
|
|
10
9
|
import PMSensorIndicatior from '../../../commons/Device/PMSensor/PMSensorIndicatior';
|
|
11
10
|
import Anemometer from '../../../commons/Device/WindSpeed/Anemometer';
|
|
@@ -22,6 +21,7 @@ import SmartIr from '../../../screens/SmartIr';
|
|
|
22
21
|
import { standardizeCameraScreenSize } from '../../../utils/Utils';
|
|
23
22
|
import { Device } from '../../../configs';
|
|
24
23
|
import { useSCContextSelector } from '../../../context';
|
|
24
|
+
import { useRemoteControl } from '../../../hooks/IoT';
|
|
25
25
|
|
|
26
26
|
const { standardizeWidth, standardizeHeight } = standardizeCameraScreenSize(
|
|
27
27
|
Device.screenWidth - 32
|
|
@@ -40,11 +40,14 @@ export const SensorDisplayItem = ({
|
|
|
40
40
|
}) => {
|
|
41
41
|
const t = useTranslations();
|
|
42
42
|
const userId = useSCContextSelector((state) => state.auth.account.user.id);
|
|
43
|
+
|
|
44
|
+
const sendRemoteCommand = useRemoteControl();
|
|
45
|
+
|
|
43
46
|
const doAction = useCallback(
|
|
44
47
|
(action, data, actionName) => {
|
|
45
48
|
sendRemoteCommand(sensor, action, data, userId, actionName);
|
|
46
49
|
},
|
|
47
|
-
[sensor, userId]
|
|
50
|
+
[sensor, userId, sendRemoteCommand]
|
|
48
51
|
);
|
|
49
52
|
if (item.configuration.type === 'compass') {
|
|
50
53
|
setShowWindDirection(true);
|