@eohjsc/react-native-smart-city 0.7.21 → 0.7.23
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 +1 -1
- package/src/Images/Common/default_end_device.png +0 -0
- package/src/commons/ActionGroup/TerminalBoxTemplate.js +3 -0
- package/src/commons/ActionTemplate/OnOffButtonAction.js +38 -4
- package/src/commons/ActionTemplate/OnOffSimpleAction.js +55 -15
- package/src/commons/ActionTemplate/OnOffSmartLockAction.js +46 -8
- package/src/commons/ActionTemplate/SwitchButtonAction.js +35 -4
- package/src/commons/ActionTemplate/ThreeButtonAction.js +13 -3
- package/src/commons/ActionTemplate/__test__/OnOffButtonAction.test.js +46 -7
- package/src/commons/ActionTemplate/__test__/OnOffSimpleAction.test.js +66 -6
- package/src/commons/ActionTemplate/__test__/OnOffSmartLockAction.test.js +53 -13
- package/src/commons/ActionTemplate/__test__/SwitchButtonAction.test.js +46 -7
- package/src/commons/ActionTemplate/__test__/index.test.js +6 -2
- package/src/commons/ActionTemplate/index.js +65 -10
- package/src/commons/Dashboard/MyUnit/index.js +19 -20
- package/src/commons/DevMode/Search.js +1 -1
- package/src/commons/Device/RainningSensor/CurrentRainSensor.js +5 -5
- package/src/commons/MediaPlayerDetail/MediaPlayerFull.js +26 -32
- package/src/commons/OneTapTemplate/StatesGridActionTemplate.js +8 -6
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +6 -0
- package/src/commons/SubUnit/OneTap/index.js +5 -0
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +9 -11
- package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +2 -2
- package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +1 -1
- package/src/configs/API.js +10 -0
- package/src/configs/AccessibilityLabel.js +5 -1
- package/src/configs/Images.js +1 -0
- package/src/navigations/AddMemberStack.js +3 -3
- package/src/screens/ActivityLog/__test__/index.test.js +10 -0
- package/src/screens/ActivityLog/hooks/index.js +1 -1
- package/src/screens/AddCommon/SelectUnit.js +3 -2
- package/src/screens/AddLocationMaps/__test__/index.test.js +13 -13
- package/src/screens/Automate/AddNewAction/ChooseAction.js +15 -51
- package/src/screens/Automate/AddNewAction/SelectControlDevices.js +13 -3
- package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +74 -54
- package/src/screens/Automate/AddNewAction/__test__/ChooseAction.test.js +114 -4
- package/src/screens/Automate/AddNewAction/__test__/ChooseConfig.test.js +9 -11
- package/src/screens/Automate/AddNewAction/__test__/SetupConfigCondition.test.js +37 -8
- package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +5 -0
- package/src/screens/Automate/AddNewAutoSmart/__test__/AddAutomationTypeSmart.test.js +31 -0
- package/src/screens/Automate/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +18 -2
- package/src/screens/Automate/Components/InputName.js +7 -6
- package/src/screens/Automate/Constants.js +12 -0
- package/src/screens/Automate/EditActionsList/UpdateActionScript.js +24 -55
- package/src/screens/Automate/EditActionsList/__tests__/UpdateActionScript.test.js +298 -41
- package/src/screens/Automate/EditActionsList/__tests__/index.test.js +2 -2
- package/src/screens/Automate/EditActionsList/index.js +26 -14
- package/src/screens/Automate/MultiUnits.js +9 -1
- package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +3 -3
- package/src/screens/Automate/ScriptDetail/Components/AddActionScript.js +4 -10
- package/src/screens/Automate/ScriptDetail/Components/DeleteScript.js +2 -4
- package/src/screens/Automate/ScriptDetail/__test__/index.test.js +78 -0
- package/src/screens/Automate/ScriptDetail/index.js +16 -10
- package/src/screens/Automate/ScriptDetail/utils.js +39 -35
- package/src/screens/Automate/SetSchedule/AddEditConditionSchedule.js +27 -160
- package/src/screens/Automate/SetSchedule/EditSchedule.js +269 -0
- package/src/screens/Automate/SetSchedule/__test__/AddEditConditionSchedule.test.js +327 -22
- package/src/screens/Automate/SetSchedule/__test__/index.test.js +35 -22
- package/src/screens/Automate/SetSchedule/components/RepeatOptionsPopup.js +2 -8
- package/src/screens/Automate/SetSchedule/index.js +15 -129
- package/src/screens/Automate/SetSchedule/styles/indexStyles.js +9 -0
- package/src/screens/Automate/__test__/MultiUnits.test.js +6 -1
- package/src/screens/Automate/hooks/useAction.js +222 -0
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +69 -13
- package/src/screens/ConfirmUnitDeletion/index.js +14 -14
- package/src/screens/Device/__test__/detail.test.js +48 -1
- package/src/screens/Device/detail.js +46 -3
- package/src/screens/PlayBackCamera/__test__/index.test.js +48 -13
- package/src/screens/PlayBackCamera/index.js +1 -1
- package/src/screens/Sharing/Components/ConfigItem.js +34 -0
- package/src/screens/Sharing/Components/DeviceItem.js +77 -0
- package/src/screens/Sharing/Components/ItemChangeRole.js +3 -4
- package/src/screens/Sharing/Components/ShareDeviceSelector.js +255 -0
- package/src/screens/Sharing/Components/Styles/CheckBoxCustomStyles.js +1 -1
- package/src/screens/Sharing/Components/Styles/DeviceItemStyles.js +11 -27
- package/src/screens/Sharing/{Styles/SelectPermissionStyles.js → Components/Styles/ShareDeviceSelectorStyles.js} +3 -11
- package/src/screens/Sharing/Components/SubUnitItem.js +28 -0
- package/src/screens/Sharing/Components/SubUnitTreeView.js +68 -0
- package/src/screens/Sharing/Components/TitleCheckBox.js +23 -41
- package/src/screens/Sharing/Components/__test__/ItemChangeRole.test.js +7 -7
- package/src/screens/Sharing/Components/__test__/ShareDeviceSelector.test.js +298 -0
- package/src/screens/Sharing/Components/index.js +14 -1
- package/src/screens/Sharing/InfoMemberUnit.js +20 -20
- package/src/screens/Sharing/SelectShareDevice.js +11 -255
- package/src/screens/Sharing/SelectUser.js +12 -12
- package/src/screens/Sharing/UpdateShareDevice.js +45 -301
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +58 -11
- package/src/screens/Sharing/__test__/SelectShareDevice.test.js +51 -160
- package/src/screens/Sharing/__test__/SelectUser.test.js +72 -10
- package/src/screens/Sharing/__test__/UpdateShareDevice.test.js +49 -209
- package/src/utils/Apis/axios.js +6 -0
- package/src/utils/I18n/translations/en.js +9 -1
- package/src/utils/I18n/translations/vi.js +10 -2
- package/src/commons/Sharing/StationDevicePermissions.js +0 -204
- package/src/screens/Automate/constants.js +0 -0
- package/src/screens/Sharing/Components/CheckBoxConfig.js +0 -44
- package/src/screens/Sharing/Components/CheckBoxSubUnit.js +0 -35
- package/src/screens/Sharing/Components/EndDevice.js +0 -93
- package/src/screens/Sharing/Components/Styles/CheckBoxConfigStyles.js +0 -18
- package/src/screens/Sharing/Components/Styles/TitleCheckBoxStyles.js +0 -21
- package/src/screens/Sharing/Components/__test__/TitleCheckBox.test.js +0 -31
|
@@ -38,16 +38,45 @@ describe('Test ChooseAction', () => {
|
|
|
38
38
|
stationName: 'stationName',
|
|
39
39
|
automateId: 1,
|
|
40
40
|
scriptName: 'scriptName test',
|
|
41
|
+
scriptItems: [],
|
|
41
42
|
},
|
|
42
43
|
};
|
|
43
44
|
});
|
|
44
45
|
|
|
45
46
|
test('test onSave have automateId', async () => {
|
|
47
|
+
const response = [
|
|
48
|
+
{
|
|
49
|
+
id: 1,
|
|
50
|
+
title: '',
|
|
51
|
+
template: 'on_off_button_action_template',
|
|
52
|
+
configuration: {
|
|
53
|
+
allow_config_store_value: true,
|
|
54
|
+
config: 1,
|
|
55
|
+
action_on: '94ae262d-46e3-42ff-9d10-516831ecc830',
|
|
56
|
+
action_off: '6b5e49ce-22b3-49c3-bf61-0202970ce587',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
|
|
46
61
|
mock.onPost(API.AUTOMATE.ADD_SCRIPT_ACTION(1)).reply(200);
|
|
47
62
|
await act(async () => {
|
|
48
63
|
tree = await renderer.create(wrapComponent(route));
|
|
49
64
|
});
|
|
50
65
|
const instance = tree.root;
|
|
66
|
+
|
|
67
|
+
const cards = instance.findAllByType(SelectActionCard);
|
|
68
|
+
await act(async () => {
|
|
69
|
+
cards.map((card) => card.props.onPress());
|
|
70
|
+
});
|
|
71
|
+
const onButton = instance.find(
|
|
72
|
+
(el) =>
|
|
73
|
+
el.props.accessibilityLabel === AccessibilityLabel.ON_BUTTON &&
|
|
74
|
+
el.type === TouchableOpacity
|
|
75
|
+
);
|
|
76
|
+
await act(async () => {
|
|
77
|
+
await onButton.props.onPress();
|
|
78
|
+
});
|
|
79
|
+
|
|
51
80
|
const bottomButton = instance.findByType(BottomButtonView);
|
|
52
81
|
await act(async () => {
|
|
53
82
|
bottomButton.props.onPressMain();
|
|
@@ -56,12 +85,39 @@ describe('Test ChooseAction', () => {
|
|
|
56
85
|
});
|
|
57
86
|
|
|
58
87
|
it('test onSave fail not permission', async () => {
|
|
88
|
+
const response = [
|
|
89
|
+
{
|
|
90
|
+
id: 1,
|
|
91
|
+
title: '',
|
|
92
|
+
template: 'on_off_button_action_template',
|
|
93
|
+
configuration: {
|
|
94
|
+
allow_config_store_value: true,
|
|
95
|
+
config: 1,
|
|
96
|
+
action_on: '94ae262d-46e3-42ff-9d10-516831ecc830',
|
|
97
|
+
action_off: '6b5e49ce-22b3-49c3-bf61-0202970ce587',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
|
|
59
102
|
mock.onPost(API.AUTOMATE.ADD_SCRIPT_ACTION(1)).reply(404);
|
|
60
103
|
await act(async () => {
|
|
61
104
|
tree = await renderer.create(wrapComponent(route));
|
|
62
105
|
});
|
|
63
106
|
const instance = tree.root;
|
|
64
107
|
|
|
108
|
+
const cards = instance.findAllByType(SelectActionCard);
|
|
109
|
+
await act(async () => {
|
|
110
|
+
cards.map((card) => card.props.onPress());
|
|
111
|
+
});
|
|
112
|
+
const onButton = instance.find(
|
|
113
|
+
(el) =>
|
|
114
|
+
el.props.accessibilityLabel === AccessibilityLabel.ON_BUTTON &&
|
|
115
|
+
el.type === TouchableOpacity
|
|
116
|
+
);
|
|
117
|
+
await act(async () => {
|
|
118
|
+
await onButton.props.onPress();
|
|
119
|
+
});
|
|
120
|
+
|
|
65
121
|
const bottomButton = instance.findByType(BottomButtonView);
|
|
66
122
|
await act(async () => {
|
|
67
123
|
bottomButton.props.onPressMain();
|
|
@@ -87,7 +143,8 @@ describe('Test ChooseAction', () => {
|
|
|
87
143
|
config2 = 2,
|
|
88
144
|
config3 = 3,
|
|
89
145
|
config4 = 4,
|
|
90
|
-
config5 = 5
|
|
146
|
+
config5 = 5,
|
|
147
|
+
config6 = 6;
|
|
91
148
|
const response = [
|
|
92
149
|
{
|
|
93
150
|
id: 1,
|
|
@@ -97,7 +154,7 @@ describe('Test ChooseAction', () => {
|
|
|
97
154
|
allow_config_store_value: true,
|
|
98
155
|
config: config1,
|
|
99
156
|
action_on: '94ae262d-46e3-42ff-9d10-516831ecc830',
|
|
100
|
-
action_off: '
|
|
157
|
+
action_off: 'd988f6f6-1347-480b-8912-e986d0b7fb76',
|
|
101
158
|
},
|
|
102
159
|
},
|
|
103
160
|
{
|
|
@@ -169,6 +226,17 @@ describe('Test ChooseAction', () => {
|
|
|
169
226
|
],
|
|
170
227
|
},
|
|
171
228
|
},
|
|
229
|
+
{
|
|
230
|
+
id: 6,
|
|
231
|
+
title: 'Power',
|
|
232
|
+
template: 'OnOffSimpleActionTemplate',
|
|
233
|
+
configuration: {
|
|
234
|
+
allow_config_store_value: true,
|
|
235
|
+
config: config6,
|
|
236
|
+
action_on: 'a9b9fcc5-a939-4163-95c9-03b0011d46c5',
|
|
237
|
+
action_off: '2863b435-788f-4a86-bca8-7005763709e5',
|
|
238
|
+
},
|
|
239
|
+
},
|
|
172
240
|
];
|
|
173
241
|
mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
|
|
174
242
|
await act(async () => {
|
|
@@ -182,14 +250,14 @@ describe('Test ChooseAction', () => {
|
|
|
182
250
|
cards.map((card) => card.props.onPress());
|
|
183
251
|
});
|
|
184
252
|
|
|
185
|
-
const simpleActionOn = instance.
|
|
253
|
+
const simpleActionOn = instance.findAll(
|
|
186
254
|
(el) =>
|
|
187
255
|
el.props.accessibilityLabel ===
|
|
188
256
|
AccessibilityLabel.ON_OFF_SIMPLE_ACTION_ON &&
|
|
189
257
|
el.type === TouchableOpacity
|
|
190
258
|
);
|
|
191
259
|
await act(async () => {
|
|
192
|
-
await simpleActionOn.props.onPress();
|
|
260
|
+
await simpleActionOn[0].props.onPress();
|
|
193
261
|
});
|
|
194
262
|
|
|
195
263
|
const selectOptions = instance.findAll(
|
|
@@ -243,7 +311,18 @@ describe('Test ChooseAction', () => {
|
|
|
243
311
|
await chooseMode.props.onPress(response[4].configuration.options[0]);
|
|
244
312
|
});
|
|
245
313
|
|
|
314
|
+
const simpleActionToggle = instance.findAll(
|
|
315
|
+
(el) =>
|
|
316
|
+
el.props.accessibilityLabel ===
|
|
317
|
+
AccessibilityLabel.ON_OFF_SIMPLE_ACTION_TOGGLE &&
|
|
318
|
+
el.type === TouchableOpacity
|
|
319
|
+
);
|
|
320
|
+
await act(async () => {
|
|
321
|
+
await simpleActionToggle[1].props.onPress();
|
|
322
|
+
});
|
|
323
|
+
|
|
246
324
|
mock.onPost(API.AUTOMATE.ADD_SCRIPT_ACTION(1)).reply(200);
|
|
325
|
+
mock.onPost(API.AUTOMATE.ADD_SCRIPT_TOGGLE(1)).reply(200);
|
|
247
326
|
const buttonSave = instance.find(
|
|
248
327
|
(el) =>
|
|
249
328
|
el.props.accessibilityLabel === AccessibilityLabel.BOTTOM_VIEW_MAIN &&
|
|
@@ -253,6 +332,8 @@ describe('Test ChooseAction', () => {
|
|
|
253
332
|
await buttonSave.props.onPress();
|
|
254
333
|
});
|
|
255
334
|
|
|
335
|
+
expect(mock.history.post).toHaveLength(2);
|
|
336
|
+
expect(mock.history.post[0].url).toEqual(API.AUTOMATE.ADD_SCRIPT_ACTION(1));
|
|
256
337
|
expect(mock.history.post[0].data).toEqual(
|
|
257
338
|
JSON.stringify({
|
|
258
339
|
list_action: [
|
|
@@ -263,6 +344,7 @@ describe('Test ChooseAction', () => {
|
|
|
263
344
|
config_id: config1,
|
|
264
345
|
config_value: 1,
|
|
265
346
|
},
|
|
347
|
+
order: 1,
|
|
266
348
|
},
|
|
267
349
|
{
|
|
268
350
|
action: '05195362-75de-4db5-9e5e-98fef9d4910c',
|
|
@@ -272,6 +354,7 @@ describe('Test ChooseAction', () => {
|
|
|
272
354
|
config_id: config2,
|
|
273
355
|
config_value: 1,
|
|
274
356
|
},
|
|
357
|
+
order: 2,
|
|
275
358
|
},
|
|
276
359
|
{
|
|
277
360
|
action: 'b498234c-6c1a-452d-a1d1-87a314c20528',
|
|
@@ -280,6 +363,7 @@ describe('Test ChooseAction', () => {
|
|
|
280
363
|
config_id: config3,
|
|
281
364
|
config_value: 29,
|
|
282
365
|
},
|
|
366
|
+
order: 3,
|
|
283
367
|
},
|
|
284
368
|
{
|
|
285
369
|
action: '11111111-6c1a-452d-a1d1-87a314c20528',
|
|
@@ -288,10 +372,35 @@ describe('Test ChooseAction', () => {
|
|
|
288
372
|
config_id: config4,
|
|
289
373
|
config_value: 28,
|
|
290
374
|
},
|
|
375
|
+
order: 4,
|
|
291
376
|
},
|
|
292
377
|
{
|
|
293
378
|
action: '800ff454-4e2a-4a38-bad6-1bded728193e',
|
|
294
379
|
data: { config_id: config5, config_value: 1 },
|
|
380
|
+
order: 5,
|
|
381
|
+
},
|
|
382
|
+
],
|
|
383
|
+
})
|
|
384
|
+
);
|
|
385
|
+
expect(mock.history.post[1].url).toEqual(API.AUTOMATE.ADD_SCRIPT_TOGGLE(1));
|
|
386
|
+
expect(mock.history.post[1].data).toEqual(
|
|
387
|
+
JSON.stringify({
|
|
388
|
+
list_action: [
|
|
389
|
+
{
|
|
390
|
+
action_on: 'a9b9fcc5-a939-4163-95c9-03b0011d46c5',
|
|
391
|
+
action_off: '2863b435-788f-4a86-bca8-7005763709e5',
|
|
392
|
+
config: config6,
|
|
393
|
+
action_on_data: {
|
|
394
|
+
state: 1,
|
|
395
|
+
config_id: config6,
|
|
396
|
+
config_value: 1,
|
|
397
|
+
},
|
|
398
|
+
action_off_data: {
|
|
399
|
+
state: 0,
|
|
400
|
+
config_id: config6,
|
|
401
|
+
config_value: 0,
|
|
402
|
+
},
|
|
403
|
+
order: 6,
|
|
295
404
|
},
|
|
296
405
|
],
|
|
297
406
|
})
|
|
@@ -365,6 +474,7 @@ describe('Test ChooseAction', () => {
|
|
|
365
474
|
config_id: config1,
|
|
366
475
|
config_value: 0,
|
|
367
476
|
},
|
|
477
|
+
order: 1,
|
|
368
478
|
},
|
|
369
479
|
],
|
|
370
480
|
})
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import renderer, { act } from 'react-test-renderer';
|
|
3
|
-
import MockAdapter from 'axios-mock-adapter';
|
|
4
2
|
|
|
3
|
+
import { API } from '../../../../configs';
|
|
5
4
|
import ChooseConfig from '../ChooseConfig';
|
|
6
|
-
import { SCProvider } from '../../../../context';
|
|
7
|
-
import { mockSCStore } from '../../../../context/mockStore';
|
|
8
5
|
import { DEVICE_TYPE } from '../../../../configs/Constants';
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
6
|
+
import GridItem from '../../../../commons/Grid/GridItem';
|
|
7
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import Routes from '../../../../utils/Route';
|
|
10
|
+
import { SCProvider } from '../../../../context';
|
|
12
11
|
import Text from '../../../../commons/Text';
|
|
12
|
+
import { TouchableWithoutFeedback } from 'react-native';
|
|
13
|
+
import api from '../../../../utils/Apis/axios';
|
|
14
|
+
import { mockSCStore } from '../../../../context/mockStore';
|
|
13
15
|
import t from '../../../../hooks/Common/useTranslations';
|
|
14
|
-
import Routes from '../../../../utils/Route';
|
|
15
16
|
import { useNavigation } from '@react-navigation/native';
|
|
16
|
-
import { TouchableWithoutFeedback } from 'react-native';
|
|
17
|
-
import GridItem from '../../../../commons/Grid/GridItem';
|
|
18
17
|
|
|
19
18
|
const mock = new MockAdapter(api.axiosInstance);
|
|
20
19
|
|
|
@@ -44,7 +43,6 @@ describe('Test ChooseConfig', () => {
|
|
|
44
43
|
await act(async () => {
|
|
45
44
|
tree = await renderer.create(wrapComponent(route));
|
|
46
45
|
});
|
|
47
|
-
expect(tree.root.findAllByType(TitleCheckBox)).toHaveLength(0);
|
|
48
46
|
expect(mock.history.get).toHaveLength(1);
|
|
49
47
|
});
|
|
50
48
|
|
|
@@ -14,6 +14,7 @@ import { ToastBottomHelper } from '../../../../utils/Utils';
|
|
|
14
14
|
import SetupConfigCondition from '../SetupConfigCondition';
|
|
15
15
|
import AccessibilityLabel from '../../../../configs/AccessibilityLabel';
|
|
16
16
|
import { API } from '../../../../configs';
|
|
17
|
+
import { AUTOMATE_TYPE } from '../../../../configs/Constants';
|
|
17
18
|
import api from '../../../../utils/Apis/axios';
|
|
18
19
|
import MockAdapter from 'axios-mock-adapter';
|
|
19
20
|
|
|
@@ -172,7 +173,9 @@ describe('Test SetupConfigCondition', () => {
|
|
|
172
173
|
);
|
|
173
174
|
useRoute.mockReturnValue({
|
|
174
175
|
params: {
|
|
175
|
-
automate: {
|
|
176
|
+
automate: {
|
|
177
|
+
config: 1,
|
|
178
|
+
},
|
|
176
179
|
config: {
|
|
177
180
|
id: 1,
|
|
178
181
|
name: 'config name',
|
|
@@ -193,12 +196,20 @@ describe('Test SetupConfigCondition', () => {
|
|
|
193
196
|
gridItems[0].findByType(TouchableWithoutFeedback).props.onPress();
|
|
194
197
|
});
|
|
195
198
|
|
|
196
|
-
expect(global.mockedNavigate).
|
|
199
|
+
expect(global.mockedNavigate).toHaveBeenCalledWith(Routes.ValueChangeName, {
|
|
197
200
|
automate: {
|
|
198
|
-
|
|
199
|
-
|
|
201
|
+
conditions: [
|
|
202
|
+
{
|
|
203
|
+
condition: 'value_evaluation',
|
|
204
|
+
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
205
|
+
config: 1,
|
|
206
|
+
value: [1, 0],
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
config: 1,
|
|
200
210
|
},
|
|
201
211
|
closeScreen: undefined,
|
|
212
|
+
unitId: undefined,
|
|
202
213
|
});
|
|
203
214
|
});
|
|
204
215
|
|
|
@@ -213,7 +224,9 @@ describe('Test SetupConfigCondition', () => {
|
|
|
213
224
|
);
|
|
214
225
|
useRoute.mockReturnValue({
|
|
215
226
|
params: {
|
|
216
|
-
automate: {
|
|
227
|
+
automate: {
|
|
228
|
+
config: 1,
|
|
229
|
+
},
|
|
217
230
|
config: {
|
|
218
231
|
id: 1,
|
|
219
232
|
name: 'config name',
|
|
@@ -262,10 +275,18 @@ describe('Test SetupConfigCondition', () => {
|
|
|
262
275
|
|
|
263
276
|
expect(global.mockedNavigate).toBeCalledWith(Routes.ValueChangeName, {
|
|
264
277
|
automate: {
|
|
265
|
-
|
|
266
|
-
|
|
278
|
+
conditions: [
|
|
279
|
+
{
|
|
280
|
+
condition: '<',
|
|
281
|
+
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
282
|
+
config: 1,
|
|
283
|
+
value: value,
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
config: 1,
|
|
267
287
|
},
|
|
268
288
|
closeScreen: undefined,
|
|
289
|
+
unitId: undefined,
|
|
269
290
|
});
|
|
270
291
|
};
|
|
271
292
|
|
|
@@ -395,10 +416,18 @@ describe('Test SetupConfigCondition', () => {
|
|
|
395
416
|
gridItems[0].props.onPress();
|
|
396
417
|
});
|
|
397
418
|
|
|
419
|
+
expect(mock.history.post).toHaveLength(1);
|
|
420
|
+
expect(mock.history.post[0].data).toEqual(
|
|
421
|
+
JSON.stringify({
|
|
422
|
+
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
423
|
+
condition: 'value_evaluation',
|
|
424
|
+
value: [1, 0],
|
|
425
|
+
})
|
|
426
|
+
);
|
|
398
427
|
expect(global.mockedNavigate).toBeCalledWith({
|
|
399
428
|
name: 'ScriptDetail',
|
|
400
429
|
params: {
|
|
401
|
-
preAutomate: {
|
|
430
|
+
preAutomate: { id: 1 },
|
|
402
431
|
},
|
|
403
432
|
});
|
|
404
433
|
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { act, create } from 'react-test-renderer';
|
|
2
|
+
|
|
3
|
+
import AddAutomationTypeSmart from '../AddAutomationTypeSmart';
|
|
4
|
+
import AddTypeSmart from '../AddTypeSmart';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { SCProvider } from '../../../../context';
|
|
7
|
+
import { mockSCStore } from '../../../../context/mockStore';
|
|
8
|
+
|
|
9
|
+
const wrapComponent = (route) => (
|
|
10
|
+
<SCProvider initState={mockSCStore({})}>
|
|
11
|
+
<AddAutomationTypeSmart route={route} />
|
|
12
|
+
</SCProvider>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
describe('test AddNewAutoSmart', () => {
|
|
16
|
+
let tree;
|
|
17
|
+
let route = {
|
|
18
|
+
params: {
|
|
19
|
+
automate: { unit: 1 },
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
it('test render AddNewAutoSmart', async () => {
|
|
24
|
+
await act(async () => {
|
|
25
|
+
tree = await create(wrapComponent(route));
|
|
26
|
+
});
|
|
27
|
+
const instance = tree.root;
|
|
28
|
+
const items = instance.findAllByType(AddTypeSmart);
|
|
29
|
+
expect(items).toHaveLength(1);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -44,7 +44,15 @@ describe('test AddNewAutoSmart', () => {
|
|
|
44
44
|
expect(global.mockedNavigate).toHaveBeenCalledWith(
|
|
45
45
|
Routes.SelectMonitorDevices,
|
|
46
46
|
{
|
|
47
|
-
automate: {
|
|
47
|
+
automate: {
|
|
48
|
+
type: 'value_change',
|
|
49
|
+
conditions: [
|
|
50
|
+
{
|
|
51
|
+
type: 'value_change',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
unit: 1,
|
|
55
|
+
},
|
|
48
56
|
closeScreen: undefined,
|
|
49
57
|
unitId: 1,
|
|
50
58
|
}
|
|
@@ -64,7 +72,15 @@ describe('test AddNewAutoSmart', () => {
|
|
|
64
72
|
expect(items[2].props.isSelected).toBeTruthy();
|
|
65
73
|
|
|
66
74
|
expect(global.mockedNavigate).toHaveBeenCalledWith(Routes.SetSchedule, {
|
|
67
|
-
automate: {
|
|
75
|
+
automate: {
|
|
76
|
+
type: 'schedule',
|
|
77
|
+
conditions: [
|
|
78
|
+
{
|
|
79
|
+
type: 'schedule',
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
unit: 1,
|
|
83
|
+
},
|
|
68
84
|
closeScreen: undefined,
|
|
69
85
|
unitId: 1,
|
|
70
86
|
});
|
|
@@ -7,13 +7,13 @@ import { AccessibilityLabel } from '../../../configs/Constants';
|
|
|
7
7
|
import _TextInput from '../../../commons/Form/TextInput';
|
|
8
8
|
import styles from './InputNameStyles';
|
|
9
9
|
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
10
|
-
import { axiosPost
|
|
10
|
+
import { axiosPost } from '../../../utils/Apis/axios';
|
|
11
11
|
import NewActionWrapper from '../../Automate/AddNewAction/NewActionWrapper';
|
|
12
12
|
import Routes from '../../../utils/Route';
|
|
13
13
|
|
|
14
14
|
const InputName = ({ title, placeholder }) => {
|
|
15
15
|
const { automate = {}, closeScreen } = useRoute().params;
|
|
16
|
-
const {
|
|
16
|
+
const { name: automateName } = automate;
|
|
17
17
|
const t = useTranslations();
|
|
18
18
|
const { navigate } = useNavigation();
|
|
19
19
|
const [name, setName] = useState(automateName);
|
|
@@ -31,9 +31,10 @@ const InputName = ({ title, placeholder }) => {
|
|
|
31
31
|
name: name,
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
const { success, data } =
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const { success, data } = await axiosPost(
|
|
35
|
+
API.AUTOMATE.CREATE_AUTOMATE_V2(),
|
|
36
|
+
params
|
|
37
|
+
);
|
|
37
38
|
|
|
38
39
|
if (success) {
|
|
39
40
|
navigate({
|
|
@@ -46,7 +47,7 @@ const InputName = ({ title, placeholder }) => {
|
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
49
|
setProcessing(false);
|
|
49
|
-
}, [processing, automate, name,
|
|
50
|
+
}, [processing, automate, name, navigate, closeScreen]);
|
|
50
51
|
|
|
51
52
|
return (
|
|
52
53
|
<NewActionWrapper
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const REPEAT_OPTIONS = {
|
|
2
|
+
ONCE: 'once',
|
|
3
|
+
EVERYDAY: 'every_day',
|
|
4
|
+
EVERYWEEK: 'every_week',
|
|
5
|
+
TIMERANGE: 'time_range',
|
|
6
|
+
INTERVAL: 'interval',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const TIME_RANGE_REPEAT_OPTIONS = {
|
|
10
|
+
EVERYDAY: 'every_day',
|
|
11
|
+
EVERYWEEK: 'every_week',
|
|
12
|
+
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import React, { useCallback,
|
|
1
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
2
2
|
import { View } from 'react-native';
|
|
3
3
|
import { useNavigation } from '@react-navigation/native';
|
|
4
4
|
|
|
5
5
|
import NewActionWrapper from '../AddNewAction/NewActionWrapper';
|
|
6
6
|
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
7
|
-
import { axiosGet
|
|
7
|
+
import { axiosGet } from '../../../utils/Apis/axios';
|
|
8
8
|
import { API } from '../../../configs';
|
|
9
9
|
import { ToastBottomHelper } from '../../../utils/Utils';
|
|
10
10
|
import Routes from '../../../utils/Route';
|
|
11
|
+
import useAction from '../hooks/useAction';
|
|
11
12
|
import RenderActionItem from '../AddNewAction/RenderActionItem';
|
|
12
13
|
import { useBackendPermission } from '../../../utils/Permission/backend';
|
|
13
14
|
import AccessibilityLabel from '../../../configs/AccessibilityLabel';
|
|
@@ -19,30 +20,23 @@ const UpdateActionScript = ({ route }) => {
|
|
|
19
20
|
unitId,
|
|
20
21
|
device,
|
|
21
22
|
automateId,
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
activatedScript,
|
|
24
|
+
scriptItems,
|
|
24
25
|
closeScreen,
|
|
25
26
|
} = route.params;
|
|
26
27
|
const permissions = useBackendPermission();
|
|
27
28
|
const { max_actions_per_automation } = permissions || {};
|
|
28
|
-
const [data, setData] = useState([]);
|
|
29
|
-
const [actions, setActions] = useState([]);
|
|
30
29
|
const [processing, setProcessing] = useState(false);
|
|
31
30
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
}, [max_actions_per_automation, numberActionAdded]);
|
|
35
|
-
|
|
36
|
-
const fetchData = useCallback(async () => {
|
|
37
|
-
const { success, data: automateData } = await axiosGet(
|
|
38
|
-
API.DEVICE.DISPLAY_ACTIONS(device.id)
|
|
39
|
-
);
|
|
31
|
+
const { displayActions, saveActions, onSelectAction, onUpdateSubmit } =
|
|
32
|
+
useAction(device, scriptItems, activatedScript);
|
|
40
33
|
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
const numberActionCanAdd = useMemo(() => {
|
|
35
|
+
return max_actions_per_automation - scriptItems.length;
|
|
36
|
+
}, [max_actions_per_automation, scriptItems.length]);
|
|
43
37
|
|
|
44
38
|
const onSave = useCallback(async () => {
|
|
45
|
-
if (
|
|
39
|
+
if (saveActions.length > numberActionCanAdd + 1) {
|
|
46
40
|
ToastBottomHelper.error(
|
|
47
41
|
`${t('you_can_only_add_more', { number: numberActionCanAdd })} ${t(
|
|
48
42
|
numberActionCanAdd > 1 ? 'actions' : 'action'
|
|
@@ -53,18 +47,11 @@ const UpdateActionScript = ({ route }) => {
|
|
|
53
47
|
return;
|
|
54
48
|
}
|
|
55
49
|
setProcessing(true);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const { success } = await axiosPut(
|
|
62
|
-
API.AUTOMATE.UPDATE_SCRIPT_ACTION(automateId),
|
|
63
|
-
{
|
|
64
|
-
id: scriptItemId,
|
|
65
|
-
list_action,
|
|
66
|
-
unit: unitId,
|
|
67
|
-
}
|
|
50
|
+
|
|
51
|
+
const success = await onUpdateSubmit(
|
|
52
|
+
automateId,
|
|
53
|
+
activatedScript.id,
|
|
54
|
+
unitId
|
|
68
55
|
);
|
|
69
56
|
|
|
70
57
|
if (success) {
|
|
@@ -84,38 +71,20 @@ const UpdateActionScript = ({ route }) => {
|
|
|
84
71
|
setProcessing(false);
|
|
85
72
|
}
|
|
86
73
|
}, [
|
|
87
|
-
actions,
|
|
88
74
|
numberActionCanAdd,
|
|
89
75
|
automateId,
|
|
90
|
-
|
|
76
|
+
activatedScript.id,
|
|
77
|
+
saveActions.length,
|
|
91
78
|
unitId,
|
|
92
|
-
|
|
79
|
+
onUpdateSubmit,
|
|
93
80
|
navigate,
|
|
81
|
+
t,
|
|
94
82
|
]);
|
|
95
83
|
|
|
96
|
-
const handleOnSelectAction = (action) => {
|
|
97
|
-
setActions((prevActions) => {
|
|
98
|
-
const index = prevActions.findIndex(
|
|
99
|
-
(item) => item.index === action.index
|
|
100
|
-
);
|
|
101
|
-
if (index !== -1) {
|
|
102
|
-
const newActions = [...prevActions];
|
|
103
|
-
newActions[index] = action;
|
|
104
|
-
return newActions;
|
|
105
|
-
} else {
|
|
106
|
-
return [...prevActions, action];
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
useEffect(() => {
|
|
112
|
-
fetchData();
|
|
113
|
-
}, [fetchData]);
|
|
114
|
-
|
|
115
84
|
return (
|
|
116
85
|
<NewActionWrapper
|
|
117
86
|
closeScreen={closeScreen}
|
|
118
|
-
canNext={
|
|
87
|
+
canNext={saveActions.length}
|
|
119
88
|
onNext={onSave}
|
|
120
89
|
nextTitle={t('update_now')}
|
|
121
90
|
name={t('choose_action')}
|
|
@@ -123,14 +92,14 @@ const UpdateActionScript = ({ route }) => {
|
|
|
123
92
|
showLoading={processing}
|
|
124
93
|
>
|
|
125
94
|
<View>
|
|
126
|
-
{!!
|
|
127
|
-
|
|
95
|
+
{!!displayActions.length &&
|
|
96
|
+
displayActions.map((item, index) => (
|
|
128
97
|
<RenderActionItem
|
|
129
98
|
key={`action_item_${index}`}
|
|
130
99
|
device={device}
|
|
131
100
|
item={item}
|
|
132
101
|
index={index}
|
|
133
|
-
handleOnSelectAction={
|
|
102
|
+
handleOnSelectAction={onSelectAction}
|
|
134
103
|
t={t}
|
|
135
104
|
/>
|
|
136
105
|
))}
|