@eohjsc/react-native-smart-city 0.3.48 → 0.3.49
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/package.json +4 -4
- package/src/Images/DevMode/file_copy.svg +3 -0
- package/src/Images/DevMode/inforCode.png +0 -0
- package/src/Images/DevMode/inforCode@2x.png +0 -0
- package/src/Images/DevMode/inforCode@3x.png +0 -0
- package/src/commons/Action/__test__/ItemQuickAction.test.js +0 -7
- package/src/commons/ActionGroup/__test__/ColorPickerTemplate.test.js +1 -8
- package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +1 -1
- package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +1 -8
- package/src/commons/ActionTemplate/__test__/index.test.js +0 -7
- package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +3 -3
- package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +1 -1
- package/src/commons/Dashboard/MyUnit/index.js +30 -4
- package/src/commons/DevMode/Styles/ItemStyles.js +1 -1
- package/src/commons/Device/PMSensor/PMSensorIndicatior.js +2 -1
- package/src/commons/FourButtonFilterHistory/__test__/FourButtonFilterHistory.test.js +0 -7
- package/src/commons/Header/HeaderCustom.js +13 -6
- package/src/commons/MediaPlayer/__test__/index.test.js +0 -7
- package/src/commons/MediaPlayerDetail/__test__/MediaPlayerFull.test.js +0 -1
- package/src/commons/MenuActionMore/index.js +4 -1
- package/src/commons/NavBar/index.js +1 -1
- package/src/commons/OneTapTemplate/OptionsDropdownActionTemplate.js +1 -1
- package/src/commons/OneTapTemplate/__test__/NumberUpDownActionTemplate.test.js +0 -7
- package/src/commons/OneTapTemplate/__test__/OptionsDropdownActionTemplate.test.js +0 -7
- package/src/commons/OneTapTemplate/__test__/StatesGridActionTemplate.test.js +0 -7
- package/src/commons/RowItem/index.js +6 -1
- package/src/commons/SelectUnit/index.js +4 -1
- package/src/commons/StatusBox/styles.js +8 -3
- package/src/commons/SubUnit/__test__/Favorites.test.js +0 -7
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +0 -7
- package/src/commons/Tabbar/__test__/index.test.js +0 -7
- package/src/commons/Unit/__test__/HeaderUnit.test.js +0 -5
- package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +0 -7
- package/src/configs/API.js +28 -0
- package/src/configs/AccessibilityLabel.js +13 -0
- package/src/configs/Colors.js +4 -0
- package/src/configs/Constants.js +6 -0
- package/src/configs/Images.js +1 -0
- package/src/context/actionType.ts +8 -1
- package/src/context/mockStore.ts +8 -2
- package/src/context/reducer.ts +27 -4
- package/src/hooks/IoT/__test__/useWatchConfigs.test.js +46 -0
- package/src/hooks/IoT/useBluetoothConnection.js +78 -4
- package/src/hooks/IoT/useBluetoothDeviceConnected.js +1 -1
- package/src/iot/RemoteControl/Bluetooth.js +0 -16
- package/src/iot/RemoteControl/__test__/Bluetooth.test.js +0 -25
- package/src/navigations/Main.js +39 -0
- package/src/navigations/UnitStack.js +18 -5
- package/src/screens/ActivityLog/__test__/FilterPopup.test.js +0 -7
- package/src/screens/ActivityLog/__test__/ItemLog.test.js +0 -7
- package/src/screens/ActivityLog/__test__/index.test.js +0 -7
- package/src/screens/AddLocationMaps/__test__/index.test.js +0 -7
- package/src/screens/AddNewAction/SelectAction.js +22 -18
- package/src/screens/AddNewAction/__test__/SelectAction.test.js +35 -16
- package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +0 -7
- package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +0 -4
- package/src/screens/AddNewGateway/ConnectingZigbeeDevice.js +17 -4
- package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/ConnectingModbusDevice.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/ConnectingWifiDevice.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/ConnectingZigbeeDevice.test.js +4 -7
- package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +0 -7
- package/src/screens/AddNewGateway/__test__/SelectDeviceType.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +0 -4
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +0 -7
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +0 -1
- package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +0 -7
- package/src/screens/Device/__test__/detail.test.js +1 -1
- package/src/screens/Device/detail.js +11 -3
- package/src/screens/Device/hooks/useDisconnectedDevice.js +26 -7
- package/src/screens/EmergencyContacts/__test__/hooks.test.js +79 -0
- package/src/screens/Gateway/DetailConfigActionModbus/__test__/index.test.js +138 -0
- package/src/screens/Gateway/DetailConfigActionModbus/index.js +180 -0
- package/src/screens/Gateway/DetailConfigActionModbus/styles.js +9 -0
- package/src/screens/Gateway/DetailConfigActionZigbee/__test__/index.test.js +73 -0
- package/src/screens/Gateway/DetailConfigActionZigbee/index.js +62 -0
- package/src/screens/Gateway/DetailConfigActionZigbee/styles.js +9 -0
- package/src/screens/Gateway/DeviceGatewayInfo/__test__/index.test.js +73 -0
- package/src/screens/Gateway/DeviceGatewayInfo/index.js +96 -0
- package/src/screens/Gateway/DeviceGatewayInfo/styles.js +9 -0
- package/src/screens/Gateway/DeviceModbusDetail/__test__/index.test.js +393 -0
- package/src/screens/Gateway/DeviceModbusDetail/index.js +176 -0
- package/src/screens/Gateway/DeviceModbusDetail/styles.js +12 -0
- package/src/screens/Gateway/DeviceZigbeeDetail/__test__/index.test.js +265 -0
- package/src/screens/Gateway/DeviceZigbeeDetail/index.js +148 -0
- package/src/screens/Gateway/DeviceZigbeeDetail/styles.js +12 -0
- package/src/screens/Gateway/GatewayConnectionMethods/__test__/index.test.js +37 -0
- package/src/screens/Gateway/GatewayConnectionMethods/index.js +73 -0
- package/src/screens/Gateway/GatewayConnectionMethods/styles.js +45 -0
- package/src/screens/Gateway/GatewayDetail/__test__/index.test.js +298 -0
- package/src/screens/Gateway/GatewayDetail/index.js +148 -0
- package/src/screens/Gateway/GatewayDetail/styles.js +12 -0
- package/src/screens/Gateway/GatewayInfo/__test__/index.test.js +137 -0
- package/src/screens/Gateway/GatewayInfo/index.js +115 -0
- package/src/screens/Gateway/GatewayInfo/styles.js +9 -0
- package/src/screens/Gateway/__test__/index.test.js +58 -0
- package/src/screens/Gateway/components/Detail/__test__/index.test.js +46 -0
- package/src/screens/Gateway/components/Detail/index.js +62 -0
- package/src/screens/Gateway/components/Detail/styles.js +27 -0
- package/src/screens/Gateway/components/DetailActionModbus/__test__/index.test.js +49 -0
- package/src/screens/Gateway/components/DetailActionModbus/index.js +52 -0
- package/src/screens/Gateway/components/DetailActionModbus/styles.js +32 -0
- package/src/screens/Gateway/components/DetailConfigAction/__test__/index.test.js +59 -0
- package/src/screens/Gateway/components/DetailConfigAction/index.js +69 -0
- package/src/screens/Gateway/components/DetailConfigAction/styles.js +21 -0
- package/src/screens/Gateway/components/GatewayItem/__test__/index.test.js +1 -1
- package/src/screens/Gateway/components/GatewayItem/styles.js +4 -33
- package/src/screens/Gateway/components/Information/__test__/index.test.js +70 -0
- package/src/screens/Gateway/components/Information/index.js +116 -0
- package/src/screens/Gateway/components/Information/styles.js +59 -0
- package/src/screens/Gateway/components/RowItem/__test__/index.test.js +67 -0
- package/src/screens/Gateway/components/RowItem/index.js +65 -0
- package/src/screens/Gateway/components/RowItem/styles.js +25 -0
- package/src/screens/Gateway/components/TabPaneCT/__test__/index.test.js +98 -0
- package/src/screens/Gateway/components/TabPaneCT/index.js +134 -0
- package/src/screens/Gateway/components/TabPaneCT/styles.js +58 -0
- package/src/screens/Gateway/hooks/__test__/index.test.js +93 -0
- package/src/screens/Gateway/hooks/useGateway.js +110 -16
- package/src/screens/Gateway/index.js +19 -3
- package/src/screens/Gateway/styles.js +6 -8
- package/src/screens/Gateway/utils/index.js +16 -0
- package/src/screens/GuestInfo/__test__/index.test.js +0 -7
- package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +0 -7
- package/src/screens/HanetCamera/__test__/Detail.test.js +0 -7
- package/src/screens/HanetCamera/__test__/ManageAccess.test.js +0 -7
- package/src/screens/HanetCamera/__test__/MemberInfo.test.js +0 -7
- package/src/screens/ManageAccess/__test__/ManageAccess.test.js +0 -6
- package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +0 -7
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +0 -7
- package/src/screens/Notification/__test__/Notification.test.js +0 -7
- package/src/screens/PlayBackCamera/__test__/index.test.js +0 -1
- package/src/screens/ScriptDetail/__test__/index.test.js +0 -7
- package/src/screens/SelectUnit/__test__/index.test.js +0 -1
- package/src/screens/SetSchedule/__test__/index.test.js +0 -7
- package/src/screens/Sharing/Components/__test__/DeviceItem.test.js +0 -7
- package/src/screens/Sharing/Components/__test__/ItemChangeRole.test.js +0 -7
- package/src/screens/Sharing/Components/__test__/TitleCheckBox.test.js +0 -7
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +0 -6
- package/src/screens/Sharing/hooks/__test__/index.test.js +80 -0
- package/src/screens/SmartAccount/ListDevice/__test__/DeviceItem.test.js +0 -7
- package/src/screens/SmartIr/__test__/ButtonsBottom.test.js +0 -6
- package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +1 -6
- package/src/screens/SmartIr/__test__/SelectBrand.test.js +1 -6
- package/src/screens/SmartIr/__test__/SelectDeviceType.test.js +1 -6
- package/src/screens/SubUnit/AddSubUnit.js +1 -0
- package/src/screens/SubUnit/ManageSubUnit.js +4 -1
- package/src/screens/SubUnit/hooks/__test__/useEmergencyContacts.test.js +34 -0
- package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +0 -7
- package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +0 -7
- package/src/screens/Unit/__test__/AddMenu.test.js +0 -7
- package/src/screens/Unit/__test__/CheckSendEmail.test.js +1 -1
- package/src/screens/Unit/__test__/ChooseLocation.test.js +0 -7
- package/src/screens/Unit/__test__/Detail.test.js +1 -8
- package/src/screens/Unit/__test__/SelectAddToFavorites.test.js +0 -7
- package/src/screens/Unit/__test__/SelectAddress.test.js +0 -7
- package/src/screens/Unit/__test__/SmartAccount.test.js +0 -7
- package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -7
- package/src/screens/Unit/__test__/Summaries.test.js +0 -7
- package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +4 -3
- package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +2 -2
- package/src/utils/I18n/translations/en.json +28 -0
- package/src/utils/I18n/translations/vi.json +28 -0
- package/src/utils/Route/index.js +8 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { create, act } from 'react-test-renderer';
|
|
3
|
+
import { SCProvider } from '../../../../context';
|
|
4
|
+
import { mockSCStore } from '../../../../context/mockStore';
|
|
5
|
+
import DeviceModbusDetail from '..';
|
|
6
|
+
import { useRoute } from '@react-navigation/native';
|
|
7
|
+
import { HeaderCustom } from '../../../../commons';
|
|
8
|
+
import { AccessibilityLabel } from '../../../../configs/Constants';
|
|
9
|
+
import Routes from '../../../../utils/Route';
|
|
10
|
+
import TabPaneCT from '../../components/TabPaneCT';
|
|
11
|
+
import MenuActionMore from '../../../../commons/MenuActionMore';
|
|
12
|
+
import { Alert } from 'react-native';
|
|
13
|
+
import Toast from 'react-native-toast-message';
|
|
14
|
+
import SegmentedControl from '@react-native-community/segmented-control';
|
|
15
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
16
|
+
import api from '../../../../utils/Apis/axios';
|
|
17
|
+
import { API } from '../../../../configs';
|
|
18
|
+
import { PERMISSION_TYPE } from '../../../../configs/Constants';
|
|
19
|
+
import Detail from '../../components/Detail';
|
|
20
|
+
|
|
21
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
22
|
+
|
|
23
|
+
const wrapComponent = () => (
|
|
24
|
+
<SCProvider initState={mockSCStore({})}>
|
|
25
|
+
<DeviceModbusDetail />
|
|
26
|
+
</SCProvider>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
jest.mock('react-native', () => {
|
|
30
|
+
const RN = jest.requireActual('react-native');
|
|
31
|
+
return Object.setPrototypeOf(
|
|
32
|
+
{
|
|
33
|
+
Alert: {
|
|
34
|
+
...RN.Alert,
|
|
35
|
+
alert: jest.fn(),
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
RN
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const mockPop = jest.fn();
|
|
43
|
+
const mockNavigate = jest.fn();
|
|
44
|
+
jest.mock('@react-navigation/native', () => {
|
|
45
|
+
return {
|
|
46
|
+
...jest.requireActual('@react-navigation/native'),
|
|
47
|
+
useNavigation: () => ({
|
|
48
|
+
navigate: mockNavigate,
|
|
49
|
+
pop: mockPop,
|
|
50
|
+
}),
|
|
51
|
+
useRoute: jest.fn(),
|
|
52
|
+
useIsFocused: () => true,
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const headerCustomOnPressMore = async (instance) => {
|
|
57
|
+
const headerCustom = instance?.findAllByType(HeaderCustom);
|
|
58
|
+
const buttonMore = headerCustom[0].findByProps({
|
|
59
|
+
accessibilityLabel: AccessibilityLabel.MENU_POPPER_MORE,
|
|
60
|
+
});
|
|
61
|
+
await act(async () => {
|
|
62
|
+
buttonMore.props.onPress();
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
describe('Test DeviceModbusDetail', () => {
|
|
67
|
+
let tree;
|
|
68
|
+
beforeEach(() => {
|
|
69
|
+
useRoute.mockReturnValue({
|
|
70
|
+
params: {
|
|
71
|
+
device: { id: 1, name: 'abc' },
|
|
72
|
+
gatewayId: 1,
|
|
73
|
+
isModbus: true,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
afterEach(() => {
|
|
78
|
+
mock.reset();
|
|
79
|
+
mock.resetHistory();
|
|
80
|
+
mockNavigate.mockClear();
|
|
81
|
+
Toast.show.mockClear();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('test render DeviceModbusDetail', async () => {
|
|
85
|
+
await act(async () => {
|
|
86
|
+
tree = await create(wrapComponent());
|
|
87
|
+
});
|
|
88
|
+
const instance = tree.root;
|
|
89
|
+
const detail = instance?.findByType(Detail);
|
|
90
|
+
const headerCustom = detail.findAllByType(HeaderCustom);
|
|
91
|
+
const tabPaneCT = detail.findAllByType(TabPaneCT);
|
|
92
|
+
const menuActionMore = detail.findAllByType(MenuActionMore);
|
|
93
|
+
|
|
94
|
+
expect(headerCustom).toHaveLength(1);
|
|
95
|
+
expect(tabPaneCT).toHaveLength(1);
|
|
96
|
+
expect(menuActionMore).toHaveLength(1);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('test render DeviceModbusDetail onPress more and onPress DeviceGatewayInfo', async () => {
|
|
100
|
+
await act(async () => {
|
|
101
|
+
tree = await create(wrapComponent());
|
|
102
|
+
});
|
|
103
|
+
const instance = tree.root;
|
|
104
|
+
const detail = instance?.findByType(Detail);
|
|
105
|
+
headerCustomOnPressMore(detail);
|
|
106
|
+
const menuActionMore = detail?.findAllByType(MenuActionMore);
|
|
107
|
+
expect(menuActionMore[0].props.isVisible).toEqual(true);
|
|
108
|
+
await act(async () => {
|
|
109
|
+
menuActionMore[0].props.listMenuItem[0].doAction();
|
|
110
|
+
});
|
|
111
|
+
expect(mockNavigate).toHaveBeenCalledWith(Routes.DeviceGatewayInfo, {
|
|
112
|
+
device: { id: 1, name: 'abc' },
|
|
113
|
+
isDevice: true,
|
|
114
|
+
isModbus: true,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('test render DeviceZigbeeDetail onPress more and onPress Delete zigbee', async () => {
|
|
119
|
+
await act(async () => {
|
|
120
|
+
tree = await create(wrapComponent());
|
|
121
|
+
});
|
|
122
|
+
const instance = tree.root;
|
|
123
|
+
const detail = instance?.findByType(Detail);
|
|
124
|
+
headerCustomOnPressMore(detail);
|
|
125
|
+
const menuActionMore = detail?.findByType(MenuActionMore);
|
|
126
|
+
expect(menuActionMore.props.isVisible).toEqual(true);
|
|
127
|
+
await act(async () => {
|
|
128
|
+
menuActionMore.props.listMenuItem[1].doAction();
|
|
129
|
+
});
|
|
130
|
+
expect(Alert.alert.mock.calls[0][0]).toEqual(
|
|
131
|
+
'Are you sure you want to delete device "undefined" ?'
|
|
132
|
+
);
|
|
133
|
+
mock.onDelete(API.DEV_MODE.ZIGBEE.DEVICE_DETAIL(1, 1)).reply(200);
|
|
134
|
+
await act(async () => {
|
|
135
|
+
await Alert.alert.mock.calls[0][2][1].onPress();
|
|
136
|
+
});
|
|
137
|
+
expect(mockPop).toBeCalledWith(1);
|
|
138
|
+
expect(Toast.show).toBeCalledWith({
|
|
139
|
+
position: 'bottom',
|
|
140
|
+
text1: 'Delete successfully!',
|
|
141
|
+
text2: undefined,
|
|
142
|
+
type: 'success',
|
|
143
|
+
visibilityTime: 1000,
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('test render DeviceZigbeeDetail onPress TabPanel config write', async () => {
|
|
148
|
+
mock.onGet(API.DEV_MODE.MODBUS.REGISTER(1, 1)).reply(200, [
|
|
149
|
+
{ id: 1, func: 1 },
|
|
150
|
+
{ id: 2, func: 6 },
|
|
151
|
+
]);
|
|
152
|
+
await act(async () => {
|
|
153
|
+
tree = await create(wrapComponent());
|
|
154
|
+
});
|
|
155
|
+
const instance = tree.root;
|
|
156
|
+
const detail = instance?.findByType(Detail);
|
|
157
|
+
const tabPaneCT = detail.findByType(TabPaneCT);
|
|
158
|
+
const segmentedControl = tabPaneCT.findByType(SegmentedControl);
|
|
159
|
+
await act(async () => {
|
|
160
|
+
await segmentedControl.props.onChange({
|
|
161
|
+
nativeEvent: { selectedSegmentIndex: 0 },
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
expect(tabPaneCT.props.listTabs[0].data).toEqual([{ func: 6, id: 2 }]);
|
|
165
|
+
expect(tabPaneCT.props.listTabs[0].title).toEqual(
|
|
166
|
+
PERMISSION_TYPE.CONFIG_WRITE
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('test render DeviceZigbeeDetail onPress TabPanel config read', async () => {
|
|
171
|
+
mock.onGet(API.DEV_MODE.MODBUS.REGISTER(1, 1)).reply(200, [
|
|
172
|
+
{ id: 1, func: 1 },
|
|
173
|
+
{ id: 2, func: 6 },
|
|
174
|
+
]);
|
|
175
|
+
await act(async () => {
|
|
176
|
+
tree = await create(wrapComponent());
|
|
177
|
+
});
|
|
178
|
+
const instance = tree.root;
|
|
179
|
+
const detail = instance?.findByType(Detail);
|
|
180
|
+
const tabPaneCT = detail.findByType(TabPaneCT);
|
|
181
|
+
const segmentedControl = tabPaneCT.findByType(SegmentedControl);
|
|
182
|
+
await act(async () => {
|
|
183
|
+
await segmentedControl.props.onChange({
|
|
184
|
+
nativeEvent: { selectedSegmentIndex: 1 },
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
expect(tabPaneCT.props.listTabs[1].data).toEqual([{ func: 1, id: 1 }]);
|
|
188
|
+
expect(tabPaneCT.props.listTabs[1].title).toEqual(
|
|
189
|
+
PERMISSION_TYPE.CONFIG_READ
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('test render DeviceZigbeeDetail onPress TabPanel action', async () => {
|
|
194
|
+
mock.onGet(API.DEV_MODE.MODBUS.ACTION(1, 1)).reply(200, [
|
|
195
|
+
{
|
|
196
|
+
id: 1,
|
|
197
|
+
name: 'action 1',
|
|
198
|
+
items: [{ id: 1, len1: 1, len2: 2, ex: '' }],
|
|
199
|
+
},
|
|
200
|
+
]);
|
|
201
|
+
await act(async () => {
|
|
202
|
+
tree = await create(wrapComponent());
|
|
203
|
+
});
|
|
204
|
+
const instance = tree.root;
|
|
205
|
+
const detail = instance?.findByType(Detail);
|
|
206
|
+
const tabPaneCT = detail.findByType(TabPaneCT);
|
|
207
|
+
const segmentedControl = tabPaneCT.findByType(SegmentedControl);
|
|
208
|
+
await act(async () => {
|
|
209
|
+
await segmentedControl.props.onChange({
|
|
210
|
+
nativeEvent: { selectedSegmentIndex: 2 },
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
expect(tabPaneCT.props.listTabs[2].data).toEqual([
|
|
214
|
+
{
|
|
215
|
+
id: 1,
|
|
216
|
+
name: 'action 1',
|
|
217
|
+
items: [
|
|
218
|
+
{
|
|
219
|
+
ex: '',
|
|
220
|
+
id: 1,
|
|
221
|
+
len1: 1,
|
|
222
|
+
len2: 2,
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
]);
|
|
227
|
+
expect(tabPaneCT.props.listTabs[2].title).toEqual(PERMISSION_TYPE.ACTION);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('test render DeviceZigbeeDetail onPress TabPanel config write onPressRow', async () => {
|
|
231
|
+
mock.onGet(API.DEV_MODE.MODBUS.REGISTER(1, 1)).reply(200, [
|
|
232
|
+
{ id: 1, func: 1 },
|
|
233
|
+
{ id: 2, func: 6 },
|
|
234
|
+
]);
|
|
235
|
+
await act(async () => {
|
|
236
|
+
tree = await create(wrapComponent());
|
|
237
|
+
});
|
|
238
|
+
const instance = tree.root;
|
|
239
|
+
const detail = instance?.findByType(Detail);
|
|
240
|
+
const tabPaneCT = detail.findByType(TabPaneCT);
|
|
241
|
+
const segmentedControl = tabPaneCT.findByType(SegmentedControl);
|
|
242
|
+
await act(async () => {
|
|
243
|
+
await segmentedControl.props.onChange({
|
|
244
|
+
nativeEvent: { selectedSegmentIndex: 0 },
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
await act(async () => {
|
|
248
|
+
await detail.props.onPressRow(1);
|
|
249
|
+
});
|
|
250
|
+
expect(mockNavigate).toBeCalledWith(Routes.DetailConfigActionModbus, {
|
|
251
|
+
gatewayId: 1,
|
|
252
|
+
device: {
|
|
253
|
+
id: 1,
|
|
254
|
+
name: 'abc',
|
|
255
|
+
},
|
|
256
|
+
isAction: false,
|
|
257
|
+
isConfigRead: false,
|
|
258
|
+
isConfigWrite: true,
|
|
259
|
+
itemActionConfig: 1,
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('test render DeviceZigbeeDetail onPress TabPanel config read onPressRow', async () => {
|
|
264
|
+
mock.onGet(API.DEV_MODE.MODBUS.REGISTER(1, 1)).reply(200, [
|
|
265
|
+
{ id: 1, func: 1 },
|
|
266
|
+
{ id: 2, func: 6 },
|
|
267
|
+
]);
|
|
268
|
+
await act(async () => {
|
|
269
|
+
tree = await create(wrapComponent());
|
|
270
|
+
});
|
|
271
|
+
const instance = tree.root;
|
|
272
|
+
const detail = instance?.findByType(Detail);
|
|
273
|
+
const tabPaneCT = detail.findByType(TabPaneCT);
|
|
274
|
+
const segmentedControl = tabPaneCT.findByType(SegmentedControl);
|
|
275
|
+
await act(async () => {
|
|
276
|
+
await segmentedControl.props.onChange({
|
|
277
|
+
nativeEvent: { selectedSegmentIndex: 1 },
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
await act(async () => {
|
|
281
|
+
await detail.props.onPressRow(1);
|
|
282
|
+
});
|
|
283
|
+
expect(mockNavigate).toBeCalledWith(Routes.DetailConfigActionModbus, {
|
|
284
|
+
gatewayId: 1,
|
|
285
|
+
device: {
|
|
286
|
+
id: 1,
|
|
287
|
+
name: 'abc',
|
|
288
|
+
},
|
|
289
|
+
isAction: false,
|
|
290
|
+
isConfigRead: true,
|
|
291
|
+
isConfigWrite: false,
|
|
292
|
+
itemActionConfig: 1,
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('test render DeviceZigbeeDetail onPress TabPanel action onPressRow', async () => {
|
|
297
|
+
mock.onGet(API.DEV_MODE.MODBUS.ACTION(1, 1)).reply(200, [
|
|
298
|
+
{
|
|
299
|
+
id: 1,
|
|
300
|
+
name: 'action 1',
|
|
301
|
+
items: [{ id: 1, len1: 1, len2: 2, ex: '' }],
|
|
302
|
+
},
|
|
303
|
+
]);
|
|
304
|
+
await act(async () => {
|
|
305
|
+
tree = await create(wrapComponent());
|
|
306
|
+
});
|
|
307
|
+
const instance = tree.root;
|
|
308
|
+
const detail = instance?.findByType(Detail);
|
|
309
|
+
const tabPaneCT = detail.findByType(TabPaneCT);
|
|
310
|
+
const segmentedControl = tabPaneCT.findByType(SegmentedControl);
|
|
311
|
+
await act(async () => {
|
|
312
|
+
await segmentedControl.props.onChange({
|
|
313
|
+
nativeEvent: { selectedSegmentIndex: 2 },
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
await act(async () => {
|
|
317
|
+
await detail.props.onPressRow(1);
|
|
318
|
+
});
|
|
319
|
+
expect(mockNavigate).toBeCalledWith(Routes.DetailConfigActionModbus, {
|
|
320
|
+
gatewayId: 1,
|
|
321
|
+
device: {
|
|
322
|
+
id: 1,
|
|
323
|
+
name: 'abc',
|
|
324
|
+
},
|
|
325
|
+
isAction: true,
|
|
326
|
+
isConfigRead: false,
|
|
327
|
+
isConfigWrite: false,
|
|
328
|
+
itemActionConfig: 1,
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('test render DeviceZigbeeDetail onPress TabPanel config write onRefresh', async () => {
|
|
333
|
+
mock.onGet(API.DEV_MODE.MODBUS.REGISTER(1, 1)).reply(200, [
|
|
334
|
+
{ id: 1, func: 1 },
|
|
335
|
+
{ id: 2, func: 6 },
|
|
336
|
+
]);
|
|
337
|
+
|
|
338
|
+
await act(async () => {
|
|
339
|
+
tree = await create(wrapComponent());
|
|
340
|
+
});
|
|
341
|
+
const instance = tree.root;
|
|
342
|
+
const detail = instance?.findByType(Detail);
|
|
343
|
+
const tabPaneCT = detail.findByType(TabPaneCT);
|
|
344
|
+
await act(async () => {
|
|
345
|
+
await detail.props.onRefresh();
|
|
346
|
+
});
|
|
347
|
+
expect(tabPaneCT.props.listTabs[0].data).toEqual([{ func: 6, id: 2 }]);
|
|
348
|
+
expect(tabPaneCT.props.listTabs[0].title).toEqual(
|
|
349
|
+
PERMISSION_TYPE.CONFIG_WRITE
|
|
350
|
+
);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('test render DeviceZigbeeDetail onPress TabPanel action onRefresh', async () => {
|
|
354
|
+
mock.onGet(API.DEV_MODE.MODBUS.ACTION(1, 1)).reply(200, [
|
|
355
|
+
{
|
|
356
|
+
id: 1,
|
|
357
|
+
name: 'action 1',
|
|
358
|
+
items: [{ id: 1, len1: 1, len2: 2, ex: '' }],
|
|
359
|
+
},
|
|
360
|
+
]);
|
|
361
|
+
|
|
362
|
+
await act(async () => {
|
|
363
|
+
tree = await create(wrapComponent());
|
|
364
|
+
});
|
|
365
|
+
const instance = tree.root;
|
|
366
|
+
const detail = instance?.findByType(Detail);
|
|
367
|
+
const tabPaneCT = detail.findByType(TabPaneCT);
|
|
368
|
+
const segmentedControl = tabPaneCT.findByType(SegmentedControl);
|
|
369
|
+
await act(async () => {
|
|
370
|
+
await segmentedControl.props.onChange({
|
|
371
|
+
nativeEvent: { selectedSegmentIndex: 2 },
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
await act(async () => {
|
|
375
|
+
await detail.props.onRefresh();
|
|
376
|
+
});
|
|
377
|
+
expect(tabPaneCT.props.listTabs[2].data).toEqual([
|
|
378
|
+
{
|
|
379
|
+
id: 1,
|
|
380
|
+
items: [
|
|
381
|
+
{
|
|
382
|
+
ex: '',
|
|
383
|
+
id: 1,
|
|
384
|
+
len1: 1,
|
|
385
|
+
len2: 2,
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
name: 'action 1',
|
|
389
|
+
},
|
|
390
|
+
]);
|
|
391
|
+
expect(tabPaneCT.props.listTabs[2].title).toEqual(PERMISSION_TYPE.ACTION);
|
|
392
|
+
});
|
|
393
|
+
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import React, { memo, useMemo, useEffect, useCallback } from 'react';
|
|
2
|
+
import { View, Alert } from 'react-native';
|
|
3
|
+
import t from '../../../hooks/Common/useTranslations';
|
|
4
|
+
import {
|
|
5
|
+
useRoute,
|
|
6
|
+
useNavigation,
|
|
7
|
+
useIsFocused,
|
|
8
|
+
} from '@react-navigation/native';
|
|
9
|
+
import { useGateway } from '../hooks/useGateway';
|
|
10
|
+
import Routes from '../../../utils/Route';
|
|
11
|
+
import { PERMISSION_TYPE } from '../../../configs/Constants';
|
|
12
|
+
import Detail from '../components/Detail';
|
|
13
|
+
import styles from './styles';
|
|
14
|
+
|
|
15
|
+
const DeviceModbusDetail = () => {
|
|
16
|
+
const { params = {} } = useRoute();
|
|
17
|
+
const { device = {}, gatewayId = '', isModbus } = params;
|
|
18
|
+
const { navigate } = useNavigation();
|
|
19
|
+
const isFocused = useIsFocused();
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
selectedIndex,
|
|
23
|
+
detailDeviceModbus,
|
|
24
|
+
setSelectedIndex,
|
|
25
|
+
deleteDeviceDetail,
|
|
26
|
+
fetchRegistersModbus,
|
|
27
|
+
fetchActionsModbus,
|
|
28
|
+
setRefresh,
|
|
29
|
+
refresh,
|
|
30
|
+
} = useGateway();
|
|
31
|
+
const listTabs = useMemo(
|
|
32
|
+
() => [
|
|
33
|
+
{
|
|
34
|
+
id: 1,
|
|
35
|
+
title: PERMISSION_TYPE.CONFIG_WRITE,
|
|
36
|
+
data: detailDeviceModbus?.config_write,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 2,
|
|
40
|
+
title: PERMISSION_TYPE.CONFIG_READ,
|
|
41
|
+
data: detailDeviceModbus?.config_read,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: 3,
|
|
45
|
+
title: PERMISSION_TYPE.ACTION,
|
|
46
|
+
data: detailDeviceModbus?.actions,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
detailDeviceModbus?.actions,
|
|
51
|
+
detailDeviceModbus?.config_read,
|
|
52
|
+
detailDeviceModbus?.config_write,
|
|
53
|
+
]
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const listMenuItem = useMemo(() => {
|
|
57
|
+
const RouteGatewayInformation = {
|
|
58
|
+
id: 1,
|
|
59
|
+
text: t('device_information'),
|
|
60
|
+
doAction: () =>
|
|
61
|
+
navigate(Routes.DeviceGatewayInfo, {
|
|
62
|
+
device,
|
|
63
|
+
isDevice: true,
|
|
64
|
+
isModbus,
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
const ListDeleteGateway = {
|
|
68
|
+
id: 2,
|
|
69
|
+
text: t('delete_device'),
|
|
70
|
+
textStyle: styles.textColorRed,
|
|
71
|
+
doAction: () =>
|
|
72
|
+
Alert.alert(
|
|
73
|
+
t('message_delete_device', { name: device?.sensor?.name }),
|
|
74
|
+
'',
|
|
75
|
+
[
|
|
76
|
+
{
|
|
77
|
+
text: t('cancel'),
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
text: t('ok'),
|
|
81
|
+
onPress: () =>
|
|
82
|
+
deleteDeviceDetail(gatewayId, device?.id, false, isModbus),
|
|
83
|
+
style: 'destructive',
|
|
84
|
+
},
|
|
85
|
+
]
|
|
86
|
+
),
|
|
87
|
+
};
|
|
88
|
+
return [RouteGatewayInformation, ListDeleteGateway];
|
|
89
|
+
}, [deleteDeviceDetail, gatewayId, isModbus, device, navigate]);
|
|
90
|
+
|
|
91
|
+
const isConfigRead = useMemo(() => {
|
|
92
|
+
return listTabs[selectedIndex]?.title === PERMISSION_TYPE.CONFIG_READ;
|
|
93
|
+
}, [listTabs, selectedIndex]);
|
|
94
|
+
|
|
95
|
+
const isConfigWrite = useMemo(() => {
|
|
96
|
+
return listTabs[selectedIndex]?.title === PERMISSION_TYPE.CONFIG_WRITE;
|
|
97
|
+
}, [listTabs, selectedIndex]);
|
|
98
|
+
|
|
99
|
+
const isAction = useMemo(() => {
|
|
100
|
+
return listTabs[selectedIndex]?.title === PERMISSION_TYPE.ACTION;
|
|
101
|
+
}, [listTabs, selectedIndex]);
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (isFocused) {
|
|
105
|
+
if (isConfigRead || isConfigWrite) {
|
|
106
|
+
fetchRegistersModbus(gatewayId, device?.id);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (isAction) {
|
|
110
|
+
fetchActionsModbus(gatewayId, device?.id);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}, [
|
|
115
|
+
fetchRegistersModbus,
|
|
116
|
+
gatewayId,
|
|
117
|
+
isFocused,
|
|
118
|
+
device?.id,
|
|
119
|
+
isConfigRead,
|
|
120
|
+
isConfigWrite,
|
|
121
|
+
isAction,
|
|
122
|
+
fetchActionsModbus,
|
|
123
|
+
]);
|
|
124
|
+
|
|
125
|
+
const onPressRow = useCallback(
|
|
126
|
+
(item) => {
|
|
127
|
+
navigate(Routes.DetailConfigActionModbus, {
|
|
128
|
+
itemActionConfig: item,
|
|
129
|
+
gatewayId: gatewayId,
|
|
130
|
+
device: device,
|
|
131
|
+
isConfigRead,
|
|
132
|
+
isConfigWrite,
|
|
133
|
+
isAction,
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
[device, gatewayId, isAction, isConfigRead, isConfigWrite, navigate]
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const onRefresh = useCallback(() => {
|
|
140
|
+
setRefresh(true);
|
|
141
|
+
if (isConfigRead || isConfigWrite) {
|
|
142
|
+
fetchRegistersModbus(gatewayId, device?.id);
|
|
143
|
+
}
|
|
144
|
+
if (isAction) {
|
|
145
|
+
fetchActionsModbus(gatewayId, device?.id);
|
|
146
|
+
}
|
|
147
|
+
setRefresh(false);
|
|
148
|
+
}, [
|
|
149
|
+
device?.id,
|
|
150
|
+
fetchActionsModbus,
|
|
151
|
+
fetchRegistersModbus,
|
|
152
|
+
gatewayId,
|
|
153
|
+
isAction,
|
|
154
|
+
isConfigRead,
|
|
155
|
+
isConfigWrite,
|
|
156
|
+
setRefresh,
|
|
157
|
+
]);
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<View style={styles.wrap}>
|
|
161
|
+
<Detail
|
|
162
|
+
title={device?.sensor?.name || ''}
|
|
163
|
+
listMenuItem={listMenuItem}
|
|
164
|
+
listTabs={listTabs}
|
|
165
|
+
selectedIndex={selectedIndex}
|
|
166
|
+
setSelectedIndex={setSelectedIndex}
|
|
167
|
+
isDevice
|
|
168
|
+
onPressRow={onPressRow}
|
|
169
|
+
onRefresh={onRefresh}
|
|
170
|
+
refresh={refresh}
|
|
171
|
+
/>
|
|
172
|
+
</View>
|
|
173
|
+
);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export default memo(DeviceModbusDetail);
|