@eohjsc/react-native-smart-city 0.5.0 → 0.5.2-rc
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 +2 -2
- package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplateStyle.js +0 -1
- package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplateStyle.js +1 -0
- package/src/commons/ActionGroup/OnOffTemplate/SwitchButtonTemplate.js +60 -48
- package/src/commons/ActionGroup/OnOffTemplate/index.js +1 -2
- package/src/commons/ActionGroup/SliderRangeTemplate.js +60 -64
- package/src/commons/ActionGroup/SliderRangeTemplateStyles.js +2 -4
- package/src/commons/ActionGroup/TerminalBoxTemplate.js +6 -6
- package/src/commons/ActionGroup/TextBoxTemplate.js +2 -2
- package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +72 -16
- package/src/commons/ActionGroup/__test__/SwitchButtonTemplate.test.js +33 -25
- package/src/commons/ActionGroup/__test__/TextBoxTemplate.test.js +19 -0
- package/src/commons/Device/RainningSensor/CurrentRainSensor.js +50 -45
- package/src/commons/Form/TextInput.js +2 -0
- package/src/commons/Header/Styles/HeaderCustomStyles.js +1 -1
- package/src/commons/HeaderAni/index.js +1 -1
- package/src/commons/ProcessingBar/index.js +32 -0
- package/src/commons/ProcessingBar/styles.js +57 -0
- package/src/commons/Sharing/WrapHeaderScrollable.js +1 -2
- package/src/configs/AccessibilityLabel.js +8 -0
- package/src/navigations/AddMemberStack.js +8 -3
- package/src/screens/AddCommon/SelectUnit.js +1 -1
- package/src/screens/AddCommon/__test__/SelectUnit.test.js +1 -1
- package/src/screens/Automate/AddNewAction/SetupScriptDelay.js +1 -1
- package/src/screens/Automate/Components/InputName.js +8 -2
- package/src/screens/Automate/EditActionsList/index.js +5 -5
- package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +17 -3
- package/src/screens/Device/components/SensorDisplayItem.js +7 -3
- package/src/screens/Device/detail.js +1 -1
- package/src/screens/EnterPassword/index.js +3 -2
- package/src/screens/Sharing/Components/CheckBoxConfig.js +44 -0
- package/src/screens/Sharing/Components/CheckBoxCustom.js +2 -13
- package/src/screens/Sharing/Components/CheckBoxSubUnit.js +35 -0
- package/src/screens/Sharing/Components/EndDevice.js +93 -0
- package/src/screens/Sharing/Components/Styles/CheckBoxConfigStyles.js +18 -0
- package/src/screens/Sharing/Components/Styles/DeviceItemStyles.js +28 -35
- package/src/screens/Sharing/Components/index.js +1 -2
- package/src/screens/Sharing/InfoMemberUnit.js +5 -3
- package/src/screens/Sharing/SelectShareDevice.js +273 -0
- package/src/screens/Sharing/SelectUser.js +6 -0
- package/src/screens/Sharing/Styles/SelectPermissionStyles.js +2 -11
- package/src/screens/Sharing/UnitMemberList.js +2 -1
- package/src/screens/Sharing/UpdateShareDevice.js +322 -0
- package/src/screens/Sharing/__test__/SelectShareDevice.test.js +215 -0
- package/src/screens/Sharing/__test__/UnitMemberList.test.js +1 -1
- package/src/screens/Sharing/__test__/UpdateShareDevice.test.js +307 -0
- package/src/screens/Sharing/hooks/index.js +5 -0
- package/src/screens/SubUnit/AddSubUnit.js +2 -6
- package/src/screens/SubUnit/EditSubUnitStyles.js +2 -1
- package/src/screens/Unit/AddMenu.js +1 -1
- package/src/screens/Unit/ManageUnitStyles.js +1 -1
- package/src/utils/I18n/translations/en.js +2 -0
- package/src/utils/I18n/translations/vi.js +2 -0
- package/src/utils/Route/index.js +2 -1
- package/src/commons/ActionGroup/OnOffTemplate/styles.js +0 -7
- package/src/screens/Sharing/Components/DeviceItem.js +0 -146
- package/src/screens/Sharing/Components/__test__/DeviceItem.test.js +0 -48
- package/src/screens/Sharing/SharingSelectPermission.js +0 -409
- package/src/screens/Sharing/__test__/SharingSelectPermission.test.js +0 -292
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import React, { memo, useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { View, FlatList, Alert, ActivityIndicator } from 'react-native';
|
|
3
|
+
import { useNavigation } from '@react-navigation/native';
|
|
4
|
+
|
|
5
|
+
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
6
|
+
import ViewButtonBottom from '../../commons/ViewButtonBottom';
|
|
7
|
+
import Text from '../../commons/Text';
|
|
8
|
+
import styles from './Styles/SelectPermissionStyles';
|
|
9
|
+
import { axiosGet, axiosPost } from '../../utils/Apis/axios';
|
|
10
|
+
import { objectIds } from '../../utils/Utils';
|
|
11
|
+
import { API, Colors } from '../../configs';
|
|
12
|
+
import { AccessibilityLabel } from '../../configs/Constants';
|
|
13
|
+
import CheckBoxSubUnit from './Components/CheckBoxSubUnit';
|
|
14
|
+
import EndDevice from './Components/EndDevice';
|
|
15
|
+
|
|
16
|
+
const UpdateShareDevice = ({ route }) => {
|
|
17
|
+
const t = useTranslations();
|
|
18
|
+
const { unit, member } = route.params;
|
|
19
|
+
const navigation = useNavigation();
|
|
20
|
+
const [dataStations, setDataStations] = useState([]);
|
|
21
|
+
const [isTickAllDevices, setIsTickAllDevices] = useState(false);
|
|
22
|
+
const [expandedItemIds, setExpandedItemIds] = useState([]);
|
|
23
|
+
const [loading, setLoading] = useState(true);
|
|
24
|
+
const [needRefresh, setNeedRefresh] = useState(false);
|
|
25
|
+
|
|
26
|
+
const onTickAllDevices = (indexSubUnit, isChecked) => {
|
|
27
|
+
setIsTickAllDevices(isChecked);
|
|
28
|
+
const updatedDataStations = dataStations.map((station) => ({
|
|
29
|
+
...station,
|
|
30
|
+
isChecked,
|
|
31
|
+
devices: station.devices.map((device) => ({
|
|
32
|
+
...device,
|
|
33
|
+
isChecked,
|
|
34
|
+
actions: device.actions.map((action) => ({
|
|
35
|
+
...action,
|
|
36
|
+
isChecked,
|
|
37
|
+
})),
|
|
38
|
+
read_configs: device.read_configs.map((config) => ({
|
|
39
|
+
...config,
|
|
40
|
+
isChecked,
|
|
41
|
+
})),
|
|
42
|
+
})),
|
|
43
|
+
}));
|
|
44
|
+
setDataStations(updatedDataStations);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const onTickSubUnit = (indexSubUnit, isChecked) => {
|
|
48
|
+
dataStations[indexSubUnit] = {
|
|
49
|
+
...dataStations[indexSubUnit],
|
|
50
|
+
isChecked,
|
|
51
|
+
devices: dataStations[indexSubUnit].devices.map((i) => ({
|
|
52
|
+
...i,
|
|
53
|
+
isChecked,
|
|
54
|
+
actions: i.actions.map((j) => ({ ...j, isChecked })),
|
|
55
|
+
read_configs: i.read_configs.map((j) => ({ ...j, isChecked })),
|
|
56
|
+
})),
|
|
57
|
+
};
|
|
58
|
+
setDataStations(dataStations);
|
|
59
|
+
setIsTickAllDevices(!dataStations.some((object) => !object.isChecked));
|
|
60
|
+
setNeedRefresh(true);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const onTickEndDevice = (indexSubUnit, indexEndDevice, item, isChecked) => {
|
|
64
|
+
item.isChecked = isChecked;
|
|
65
|
+
item.actions = item.actions.map((j) => ({ ...j, isChecked }));
|
|
66
|
+
item.read_configs = item.read_configs.map((j) => ({ ...j, isChecked }));
|
|
67
|
+
|
|
68
|
+
dataStations[indexSubUnit].devices[indexEndDevice] = item;
|
|
69
|
+
|
|
70
|
+
dataStations[indexSubUnit] = {
|
|
71
|
+
...dataStations[indexSubUnit],
|
|
72
|
+
isChecked:
|
|
73
|
+
dataStations[indexSubUnit].devices.length ===
|
|
74
|
+
dataStations[indexSubUnit].devices.filter((i) => i.isChecked).length,
|
|
75
|
+
};
|
|
76
|
+
setIsTickAllDevices(!dataStations.some((i) => !i.isChecked));
|
|
77
|
+
setDataStations(dataStations);
|
|
78
|
+
setNeedRefresh(true);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const onTickedChild = (
|
|
82
|
+
indexSubUnit,
|
|
83
|
+
indexEndDevice,
|
|
84
|
+
configId,
|
|
85
|
+
item,
|
|
86
|
+
isConfig,
|
|
87
|
+
isChecked
|
|
88
|
+
) => {
|
|
89
|
+
const subUnit = dataStations[indexSubUnit];
|
|
90
|
+
const device = subUnit.devices[indexEndDevice];
|
|
91
|
+
const configs = item[`${isConfig ? 'read_configs' : 'actions'}`];
|
|
92
|
+
const child = configs.find((i) => i.id === configId);
|
|
93
|
+
|
|
94
|
+
child.isChecked = isChecked;
|
|
95
|
+
device.isChecked =
|
|
96
|
+
configs.length === configs.filter((i) => i.isChecked).length;
|
|
97
|
+
|
|
98
|
+
subUnit.isChecked =
|
|
99
|
+
subUnit.devices.length ===
|
|
100
|
+
subUnit.devices.filter((i) => i.isChecked).length;
|
|
101
|
+
|
|
102
|
+
setIsTickAllDevices(!dataStations.some((i) => !i.isChecked));
|
|
103
|
+
setDataStations(dataStations);
|
|
104
|
+
setNeedRefresh(true);
|
|
105
|
+
};
|
|
106
|
+
const toggleExpandEndDevice = (deviceItem) => () => {
|
|
107
|
+
setExpandedItemIds((ids) => {
|
|
108
|
+
const index = ids.indexOf(deviceItem.id);
|
|
109
|
+
if (index !== -1) {
|
|
110
|
+
return [...ids.slice(0, index), ...ids.slice(index + 1)];
|
|
111
|
+
} else {
|
|
112
|
+
return [...ids, deviceItem.id];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const expandEndDevice = (deviceItem) => () => {
|
|
118
|
+
if (!expandedItemIds.includes(deviceItem.id)) {
|
|
119
|
+
setExpandedItemIds((prev) => [...prev, deviceItem.id]);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const autoCheckedGroup = (stations, dataDeviceShared) => {
|
|
124
|
+
const { deviceIds, actionIds, configIds } = objectIds(dataDeviceShared);
|
|
125
|
+
const updatedStations = stations.map((station) => ({
|
|
126
|
+
...station,
|
|
127
|
+
isChecked: station.devices.every((device) =>
|
|
128
|
+
deviceIds.includes(device.id)
|
|
129
|
+
),
|
|
130
|
+
devices: station.devices.map((device) => ({
|
|
131
|
+
...device,
|
|
132
|
+
isChecked: deviceIds.includes(device.id),
|
|
133
|
+
actions: device.actions.map((action) => ({
|
|
134
|
+
...action,
|
|
135
|
+
isChecked: actionIds.includes(action.id),
|
|
136
|
+
})),
|
|
137
|
+
read_configs: device.read_configs.map((config) => ({
|
|
138
|
+
...config,
|
|
139
|
+
isChecked: configIds.includes(config.id),
|
|
140
|
+
})),
|
|
141
|
+
})),
|
|
142
|
+
}));
|
|
143
|
+
setDataStations(updatedStations);
|
|
144
|
+
setIsTickAllDevices(
|
|
145
|
+
updatedStations.length ===
|
|
146
|
+
updatedStations.filter((i) => i.isChecked).length
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const GroupEndDevice = ({ item, indexSubUnit }) => {
|
|
151
|
+
const { name, devices, isChecked } = item;
|
|
152
|
+
return (
|
|
153
|
+
<View style={styles.viewGroup}>
|
|
154
|
+
<CheckBoxSubUnit
|
|
155
|
+
title={name}
|
|
156
|
+
onPress={onTickSubUnit}
|
|
157
|
+
isChecked={isChecked}
|
|
158
|
+
indexSubUnit={indexSubUnit}
|
|
159
|
+
/>
|
|
160
|
+
<View style={styles.wrapDevice}>
|
|
161
|
+
{devices.map((i, index) => (
|
|
162
|
+
<EndDevice
|
|
163
|
+
item={i}
|
|
164
|
+
key={i.id}
|
|
165
|
+
onTickedChild={onTickedChild}
|
|
166
|
+
onTickEndDevice={onTickEndDevice}
|
|
167
|
+
isItemExpanded={expandedItemIds.includes(i.id)}
|
|
168
|
+
toggleExpandEndDevice={toggleExpandEndDevice(i)}
|
|
169
|
+
expandEndDevice={expandEndDevice(i)}
|
|
170
|
+
indexSubUnit={indexSubUnit}
|
|
171
|
+
indexEndDevice={index}
|
|
172
|
+
/>
|
|
173
|
+
))}
|
|
174
|
+
</View>
|
|
175
|
+
</View>
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const onPressBottom = async () => {
|
|
180
|
+
setLoading(true);
|
|
181
|
+
let read_permissions = [];
|
|
182
|
+
let control_permissions = [];
|
|
183
|
+
|
|
184
|
+
for (const station of dataStations) {
|
|
185
|
+
for (const end_device of station.devices) {
|
|
186
|
+
const action_ids = end_device.actions
|
|
187
|
+
.filter((action) => action.isChecked)
|
|
188
|
+
.map((action) => action.id);
|
|
189
|
+
|
|
190
|
+
const config_ids = end_device.read_configs
|
|
191
|
+
.filter((config) => config.isChecked)
|
|
192
|
+
.map((config) => config.id);
|
|
193
|
+
|
|
194
|
+
if (action_ids.length > 0) {
|
|
195
|
+
control_permissions.push({ id: end_device.id, values: action_ids });
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (config_ids.length > 0) {
|
|
199
|
+
read_permissions.push({ id: end_device.id, values: config_ids });
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (
|
|
203
|
+
action_ids.length === 0 &&
|
|
204
|
+
config_ids.length === 0 &&
|
|
205
|
+
end_device.isChecked
|
|
206
|
+
) {
|
|
207
|
+
read_permissions.push({ id: end_device.id, values: [] });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (!read_permissions.length && !control_permissions.length) {
|
|
213
|
+
setLoading(false);
|
|
214
|
+
Alert.alert('', t('choose_at_least_one'));
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
let phone = '';
|
|
218
|
+
let email = '';
|
|
219
|
+
if (member.phone_number) {
|
|
220
|
+
phone = member.phone_number;
|
|
221
|
+
email = '';
|
|
222
|
+
} else if (member.email) {
|
|
223
|
+
phone = '';
|
|
224
|
+
email = member.email;
|
|
225
|
+
}
|
|
226
|
+
const { success } = await axiosPost(API.SHARE.SHARE(), {
|
|
227
|
+
phone,
|
|
228
|
+
email,
|
|
229
|
+
unit: unit.id,
|
|
230
|
+
permissions: { read_permissions, control_permissions },
|
|
231
|
+
is_remove_old_permission: true,
|
|
232
|
+
});
|
|
233
|
+
setLoading(false);
|
|
234
|
+
success && navigation.goBack();
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const renderSubUnit = ({ item, index }) => (
|
|
238
|
+
<GroupEndDevice key={item.id} item={item} indexSubUnit={index} />
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
const renderFlatList = useMemo(() => {
|
|
242
|
+
setNeedRefresh(false);
|
|
243
|
+
return (
|
|
244
|
+
<FlatList
|
|
245
|
+
keyExtractor={(item) => item.id}
|
|
246
|
+
extraData={dataStations}
|
|
247
|
+
data={dataStations}
|
|
248
|
+
renderItem={renderSubUnit}
|
|
249
|
+
scrollIndicatorInsets={{ right: 1 }}
|
|
250
|
+
ListHeaderComponent={
|
|
251
|
+
<CheckBoxSubUnit
|
|
252
|
+
title={t('text_all_devices')}
|
|
253
|
+
onPress={onTickAllDevices}
|
|
254
|
+
isChecked={isTickAllDevices}
|
|
255
|
+
/>
|
|
256
|
+
}
|
|
257
|
+
/>
|
|
258
|
+
);
|
|
259
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
260
|
+
}, [dataStations, isTickAllDevices, expandedItemIds, needRefresh]);
|
|
261
|
+
|
|
262
|
+
const getShareUnitPermission = useCallback(
|
|
263
|
+
async (stations) => {
|
|
264
|
+
const { success, data } = await axiosGet(
|
|
265
|
+
API.SHARE.UNIT_MEMBER_SHARE_DEVICE(unit.id, member.id)
|
|
266
|
+
);
|
|
267
|
+
if (success) {
|
|
268
|
+
autoCheckedGroup(stations, data);
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
[member.id, unit.id]
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
const getUnitPermission = useCallback(async () => {
|
|
275
|
+
const { success, data } = await axiosGet(
|
|
276
|
+
API.SHARE.UNIT_PERMISSIONS(unit.id)
|
|
277
|
+
);
|
|
278
|
+
if (success) {
|
|
279
|
+
setDataStations(data);
|
|
280
|
+
await getShareUnitPermission(data);
|
|
281
|
+
}
|
|
282
|
+
setLoading(false);
|
|
283
|
+
}, [getShareUnitPermission, unit.id]);
|
|
284
|
+
|
|
285
|
+
useEffect(() => {
|
|
286
|
+
getUnitPermission();
|
|
287
|
+
}, [getUnitPermission]);
|
|
288
|
+
|
|
289
|
+
return (
|
|
290
|
+
<View style={styles.wrap}>
|
|
291
|
+
<Text semibold style={styles.title}>
|
|
292
|
+
{t('select_device')}
|
|
293
|
+
</Text>
|
|
294
|
+
<Text style={styles.subtitle}>{t('sharing_select_devices_hint')}</Text>
|
|
295
|
+
<View style={styles.contentContainer}>
|
|
296
|
+
{loading ? (
|
|
297
|
+
<ActivityIndicator color={Colors.Primary} />
|
|
298
|
+
) : dataStations.length > 0 ? (
|
|
299
|
+
renderFlatList
|
|
300
|
+
) : (
|
|
301
|
+
<Text
|
|
302
|
+
style={styles.textNodata}
|
|
303
|
+
accessibilityLabel={AccessibilityLabel.TEXT_NO_DATA_STATIONS}
|
|
304
|
+
>
|
|
305
|
+
{t('no_data')}
|
|
306
|
+
</Text>
|
|
307
|
+
)}
|
|
308
|
+
</View>
|
|
309
|
+
<View style={styles.wrapViewButtonStyle}>
|
|
310
|
+
<ViewButtonBottom
|
|
311
|
+
leftTitle={t('cancel')}
|
|
312
|
+
onLeftClick={() => navigation.goBack()}
|
|
313
|
+
rightTitle={t('done')}
|
|
314
|
+
rightDisabled={false}
|
|
315
|
+
onRightClick={onPressBottom}
|
|
316
|
+
/>
|
|
317
|
+
</View>
|
|
318
|
+
</View>
|
|
319
|
+
);
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
export default memo(UpdateShareDevice);
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { act } from '@testing-library/react-hooks';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Alert } from 'react-native';
|
|
4
|
+
import { create } from 'react-test-renderer';
|
|
5
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
6
|
+
import { ViewButtonBottom } from '../../../commons';
|
|
7
|
+
import { SCProvider } from '../../../context';
|
|
8
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
9
|
+
import API from '../../../configs/API';
|
|
10
|
+
import api from '../../../utils/Apis/axios';
|
|
11
|
+
import AccessibilityLabel from '../../../configs/AccessibilityLabel';
|
|
12
|
+
import SelectShareDevice from '../SelectShareDevice';
|
|
13
|
+
import Routes from '../../../utils/Route';
|
|
14
|
+
|
|
15
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
16
|
+
jest.spyOn(Alert, 'alert').mockImplementation(() => {});
|
|
17
|
+
const mockNavigate = jest.fn();
|
|
18
|
+
const mockGoBack = jest.fn();
|
|
19
|
+
jest.mock('@react-navigation/native', () => {
|
|
20
|
+
return {
|
|
21
|
+
...jest.requireActual('@react-navigation/native'),
|
|
22
|
+
useNavigation: () => ({
|
|
23
|
+
navigate: mockNavigate,
|
|
24
|
+
goBack: mockGoBack,
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const wrapComponent = (route) => (
|
|
30
|
+
<SCProvider initState={mockSCStore({})}>
|
|
31
|
+
<SelectShareDevice route={route} />
|
|
32
|
+
</SCProvider>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
describe('Test SelectShareDevice', () => {
|
|
36
|
+
let tree;
|
|
37
|
+
let route = {
|
|
38
|
+
params: {
|
|
39
|
+
unit: { id: 1, name: 'unit 1' },
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
let listDevices = [
|
|
43
|
+
{
|
|
44
|
+
id: 1,
|
|
45
|
+
name: 'Sub unit',
|
|
46
|
+
devices: [
|
|
47
|
+
{
|
|
48
|
+
id: 2,
|
|
49
|
+
actions: [{ id: 3, name: 'action 1' }],
|
|
50
|
+
read_configs: [{ id: 4, name: 'config 1' }],
|
|
51
|
+
name: 'child1',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: 5,
|
|
55
|
+
actions: [{ id: 6, name: 'action 2' }],
|
|
56
|
+
read_configs: [{ id: 7, name: 'config 2' }],
|
|
57
|
+
name: 'child2',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 8,
|
|
61
|
+
actions: [],
|
|
62
|
+
read_configs: [],
|
|
63
|
+
name: 'child3',
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
afterEach(() => {
|
|
70
|
+
Alert.alert.mockReset();
|
|
71
|
+
mock.resetHistory();
|
|
72
|
+
mockNavigate.mockClear();
|
|
73
|
+
mockGoBack.mockClear();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const clickCheckBoxAllDevice = async (instance, statusCheckbox) => {
|
|
77
|
+
const checkBoxAllDevice = instance.find(
|
|
78
|
+
(el) =>
|
|
79
|
+
el.props.accessibilityLabel ===
|
|
80
|
+
`${AccessibilityLabel.CHECK_BOX_CUSTOM}-undefined`
|
|
81
|
+
);
|
|
82
|
+
expect(checkBoxAllDevice.props.isChecked).toEqual(statusCheckbox);
|
|
83
|
+
await act(async () => {
|
|
84
|
+
await checkBoxAllDevice.props.onPress();
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const clickCheckBoxSubUnit = async (instance, statusCheckbox) => {
|
|
89
|
+
const checkBoxSubunit = instance.find(
|
|
90
|
+
(el) =>
|
|
91
|
+
el.props.accessibilityLabel ===
|
|
92
|
+
`${AccessibilityLabel.CHECK_BOX_CUSTOM}-0`
|
|
93
|
+
);
|
|
94
|
+
expect(checkBoxSubunit.props.isChecked).toEqual(statusCheckbox);
|
|
95
|
+
await act(async () => {
|
|
96
|
+
await checkBoxSubunit.props.onPress();
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const clickCheckBoxConfig = async (instance, configId, statusCheckbox) => {
|
|
101
|
+
let checkBoxConfig = instance.find(
|
|
102
|
+
(el) =>
|
|
103
|
+
el.props.accessibilityLabel ===
|
|
104
|
+
`${AccessibilityLabel.SHARE_DEVICE.CHECK_BOX_CONFIG}-${configId}`
|
|
105
|
+
);
|
|
106
|
+
expect(checkBoxConfig.props.isChecked).toEqual(statusCheckbox);
|
|
107
|
+
await act(async () => {
|
|
108
|
+
await checkBoxConfig.props.onPress();
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const clickExpandEndDevice = async (instance, indexEndDevice, statusIcon) => {
|
|
113
|
+
const expandEndDevice = instance.find(
|
|
114
|
+
(el) =>
|
|
115
|
+
el.props.accessibilityLabel ===
|
|
116
|
+
`${AccessibilityLabel.SHARE_DEVICE.EXPAND_END_DEVICE}-${indexEndDevice}`
|
|
117
|
+
);
|
|
118
|
+
expect(expandEndDevice.props.name).toEqual(statusIcon);
|
|
119
|
+
await act(async () => {
|
|
120
|
+
await expandEndDevice.props.onPress();
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const clickNameEndDevice = async (instance, indexEndDevice) => {
|
|
125
|
+
const nameEndDevice = instance.find(
|
|
126
|
+
(el) =>
|
|
127
|
+
el.props.accessibilityLabel ===
|
|
128
|
+
`${AccessibilityLabel.SHARE_DEVICE.CLICK_NAME_END_DEVICE}-${indexEndDevice}`
|
|
129
|
+
);
|
|
130
|
+
await act(async () => {
|
|
131
|
+
await nameEndDevice.props.onPress();
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
it('test user select share device', async () => {
|
|
136
|
+
mock.onGet(API.SHARE.UNIT_PERMISSIONS(1)).reply(200, listDevices);
|
|
137
|
+
|
|
138
|
+
await act(async () => {
|
|
139
|
+
tree = await create(wrapComponent(route));
|
|
140
|
+
});
|
|
141
|
+
let instance = tree.root;
|
|
142
|
+
await clickNameEndDevice(instance, 0); // click to select all configs in end device index 0
|
|
143
|
+
await clickNameEndDevice(instance, 0); // click again to remove all configs, and coverage expand end device
|
|
144
|
+
await clickCheckBoxConfig(instance, 3, false); // click to select action
|
|
145
|
+
await clickCheckBoxConfig(instance, 3, true); // click again to coverage case status reversal
|
|
146
|
+
await clickCheckBoxConfig(instance, 4, false); // click to select config
|
|
147
|
+
await clickCheckBoxConfig(instance, 4, true); // click again to coverage case status reversal
|
|
148
|
+
await clickExpandEndDevice(instance, 0, 'up');
|
|
149
|
+
await clickExpandEndDevice(instance, 0, 'down'); // click again to coverage case status reversal
|
|
150
|
+
|
|
151
|
+
await clickCheckBoxAllDevice(instance, false); // click to select all device
|
|
152
|
+
await clickCheckBoxSubUnit(instance, true); // click to remove all device in sub unit id 1
|
|
153
|
+
await clickNameEndDevice(instance, 1); // click to select all configs in end device index 1
|
|
154
|
+
await clickNameEndDevice(instance, 2); // click to select all configs in end device index 2
|
|
155
|
+
|
|
156
|
+
const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);
|
|
157
|
+
await act(async () => {
|
|
158
|
+
ViewButtonBottomElement[0].props.onRightClick();
|
|
159
|
+
});
|
|
160
|
+
expect(mockNavigate).toBeCalledWith(Routes.SharingInviteMembers, {
|
|
161
|
+
unit: { id: 1, name: 'unit 1' },
|
|
162
|
+
permissions: {
|
|
163
|
+
read_permissions: [
|
|
164
|
+
{ id: 5, values: [7] },
|
|
165
|
+
{ id: 8, values: [] },
|
|
166
|
+
],
|
|
167
|
+
control_permissions: [{ id: 5, values: [6] }],
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('test no data, api get UNIT_PERMISSIONS false', async () => {
|
|
173
|
+
mock.onGet(API.SHARE.UNIT_PERMISSIONS(1)).reply(400);
|
|
174
|
+
|
|
175
|
+
await act(async () => {
|
|
176
|
+
tree = await create(wrapComponent(route));
|
|
177
|
+
});
|
|
178
|
+
const instance = tree.root;
|
|
179
|
+
|
|
180
|
+
let text = instance.find(
|
|
181
|
+
(el) =>
|
|
182
|
+
el.props.accessibilityLabel === AccessibilityLabel.TEXT_NO_DATA_STATIONS
|
|
183
|
+
);
|
|
184
|
+
expect(text.props.children).toEqual('No data');
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('user not choose device click button back', async () => {
|
|
188
|
+
await act(async () => {
|
|
189
|
+
tree = await create(wrapComponent(route));
|
|
190
|
+
});
|
|
191
|
+
const instance = tree.root;
|
|
192
|
+
const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);
|
|
193
|
+
expect(ViewButtonBottomElement).toHaveLength(1);
|
|
194
|
+
|
|
195
|
+
await act(async () => {
|
|
196
|
+
ViewButtonBottomElement[0].props.onLeftClick();
|
|
197
|
+
});
|
|
198
|
+
expect(mockGoBack).toBeCalled();
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('user not choose device click button next', async () => {
|
|
202
|
+
await act(async () => {
|
|
203
|
+
tree = await create(wrapComponent(route));
|
|
204
|
+
});
|
|
205
|
+
const instance = tree.root;
|
|
206
|
+
const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);
|
|
207
|
+
expect(ViewButtonBottomElement).toHaveLength(1);
|
|
208
|
+
await act(async () => {
|
|
209
|
+
ViewButtonBottomElement[0].props.onRightClick();
|
|
210
|
+
});
|
|
211
|
+
expect(Alert.alert.mock.calls[0][1]).toEqual(
|
|
212
|
+
'Please choose at least one sensor.'
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
@@ -71,7 +71,7 @@ describe('test MemberList', () => {
|
|
|
71
71
|
await memberListButtons[1].props.onPress();
|
|
72
72
|
});
|
|
73
73
|
expect(mockedNavigate).toBeCalledWith(Routes.AddMemberStack, {
|
|
74
|
-
screen: Routes.
|
|
74
|
+
screen: Routes.SelectShareDevice,
|
|
75
75
|
params: { unit: { id: 1 } },
|
|
76
76
|
});
|
|
77
77
|
});
|