@eohjsc/react-native-smart-city 0.7.20 → 0.7.22
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/assets/images/Schedule.svg +39 -0
- package/assets/images/ValueChange.svg +49 -0
- package/package.json +1 -1
- package/src/Images/Common/default_end_device.png +0 -0
- package/src/commons/Automate/ButtonAddCondition.js +51 -0
- package/src/commons/Automate/ItemConditionScriptDetail.js +28 -15
- package/src/commons/Automate/ItemConditionScriptDetailStyles.js +9 -0
- 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/Widgets/IFrameWithConfig/IFrameWithConfig.js +1 -3
- package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +1 -1
- package/src/configs/API.js +16 -1
- package/src/configs/AccessibilityLabel.js +9 -1
- package/src/configs/Images.js +1 -0
- package/src/context/actionType.ts +5 -0
- package/src/context/reducer.ts +30 -1
- package/src/navigations/AddMemberStack.js +3 -3
- package/src/navigations/UnitStack.js +8 -0
- package/src/screens/AddCommon/SelectUnit.js +3 -2
- package/src/screens/AddLocationMaps/__test__/index.test.js +13 -13
- package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +73 -30
- package/src/screens/Automate/AddNewAction/__test__/ChooseConfig.test.js +9 -11
- package/src/screens/Automate/AddNewAction/__test__/SetupConfigCondition.test.js +115 -10
- package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +7 -3
- package/src/screens/Automate/AddNewAutoSmart/__test__/AddAutomationTypeSmart.test.js +31 -0
- package/src/screens/Automate/ScriptDetail/Components/DeleteCondition.js +51 -0
- package/src/screens/Automate/ScriptDetail/Components/ModalAddCondition.js +196 -0
- package/src/screens/Automate/ScriptDetail/Styles/indexStyles.js +18 -0
- package/src/screens/Automate/ScriptDetail/__test__/index.test.js +441 -47
- package/src/screens/Automate/ScriptDetail/index.js +359 -72
- package/src/screens/Automate/ScriptDetail/utils.js +7 -31
- package/src/screens/Automate/SetSchedule/AddEditConditionSchedule.js +173 -0
- package/src/screens/Automate/SetSchedule/__test__/AddEditConditionSchedule.test.js +211 -0
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +69 -13
- package/src/screens/ConfirmUnitDeletion/index.js +14 -14
- 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/I18n/translations/en.js +22 -1
- package/src/utils/I18n/translations/vi.js +23 -3
- package/src/utils/Route/index.js +1 -0
- package/src/commons/Sharing/StationDevicePermissions.js +0 -204
- 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
|
@@ -57,9 +57,15 @@ export default StyleSheet.create({
|
|
|
57
57
|
},
|
|
58
58
|
editButton: {
|
|
59
59
|
height: 40,
|
|
60
|
+
paddingLeft: 40,
|
|
60
61
|
justifyContent: 'center',
|
|
61
62
|
alignItems: 'center',
|
|
62
63
|
},
|
|
64
|
+
rowActionList: {
|
|
65
|
+
flexDirection: 'row',
|
|
66
|
+
alignItems: 'center',
|
|
67
|
+
justifyContent: 'space-between',
|
|
68
|
+
},
|
|
63
69
|
moreButton: {
|
|
64
70
|
marginLeft: -5,
|
|
65
71
|
},
|
|
@@ -183,6 +189,12 @@ export default StyleSheet.create({
|
|
|
183
189
|
justifyContent: 'center',
|
|
184
190
|
alignItems: 'center',
|
|
185
191
|
},
|
|
192
|
+
width30: {
|
|
193
|
+
width: '30%',
|
|
194
|
+
},
|
|
195
|
+
width40: {
|
|
196
|
+
width: '40%',
|
|
197
|
+
},
|
|
186
198
|
width50: {
|
|
187
199
|
width: '50%',
|
|
188
200
|
},
|
|
@@ -198,6 +210,12 @@ export default StyleSheet.create({
|
|
|
198
210
|
maxWidth: 190,
|
|
199
211
|
marginRight: 5,
|
|
200
212
|
},
|
|
213
|
+
boxCondition: {
|
|
214
|
+
flexDirection: 'row',
|
|
215
|
+
alignItems: 'center',
|
|
216
|
+
maxWidth: 210,
|
|
217
|
+
marginRight: 5,
|
|
218
|
+
},
|
|
201
219
|
card: {
|
|
202
220
|
marginRight: 0,
|
|
203
221
|
padding: 10,
|
|
@@ -24,8 +24,22 @@ import { ToastBottomHelper } from '../../../../utils/Utils';
|
|
|
24
24
|
import { getTranslate } from '../../../../utils/I18n';
|
|
25
25
|
import AddActionScript from '../Components/AddActionScript';
|
|
26
26
|
import ItemConditionScriptDetail from '../../../../commons/Automate/ItemConditionScriptDetail';
|
|
27
|
+
import ModalAddCondition from '../Components/ModalAddCondition';
|
|
27
28
|
|
|
28
|
-
const wrapComponent = (
|
|
29
|
+
const wrapComponent = (
|
|
30
|
+
route,
|
|
31
|
+
storeData = {
|
|
32
|
+
auth: {
|
|
33
|
+
account: {
|
|
34
|
+
user: {
|
|
35
|
+
permissions: {
|
|
36
|
+
max_actions_per_automation: 1,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
) => (
|
|
29
43
|
<SCProvider initState={mockSCStore(storeData)}>
|
|
30
44
|
<ScriptDetail route={route} />
|
|
31
45
|
</SCProvider>
|
|
@@ -63,14 +77,18 @@ describe('Test ScriptDetail', () => {
|
|
|
63
77
|
id: 1,
|
|
64
78
|
can_edit: true,
|
|
65
79
|
type: 'value_change',
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
conditions: [
|
|
81
|
+
{
|
|
82
|
+
id: 1,
|
|
83
|
+
type: 'value_change',
|
|
84
|
+
condition: '<',
|
|
85
|
+
config: 'PM2.5 (Mr.Son Office)',
|
|
86
|
+
config_id: 201,
|
|
87
|
+
config_name: 'PM2.5 (Mr.Son Office)',
|
|
88
|
+
sensor_id: 73,
|
|
89
|
+
value: 35,
|
|
90
|
+
},
|
|
91
|
+
],
|
|
74
92
|
script: {
|
|
75
93
|
name: 'name',
|
|
76
94
|
enable: true,
|
|
@@ -112,6 +130,15 @@ describe('Test ScriptDetail', () => {
|
|
|
112
130
|
str_emails: 'email0@eoh.io',
|
|
113
131
|
},
|
|
114
132
|
},
|
|
133
|
+
{
|
|
134
|
+
action_script: null,
|
|
135
|
+
notify_script: null,
|
|
136
|
+
sms_script: {
|
|
137
|
+
message: 'message',
|
|
138
|
+
unit_id: 60,
|
|
139
|
+
str_emails: '0902xxx',
|
|
140
|
+
},
|
|
141
|
+
},
|
|
115
142
|
],
|
|
116
143
|
};
|
|
117
144
|
});
|
|
@@ -154,6 +181,9 @@ describe('Test ScriptDetail', () => {
|
|
|
154
181
|
};
|
|
155
182
|
|
|
156
183
|
it('test rename script', async () => {
|
|
184
|
+
mock
|
|
185
|
+
.onGet(API.AUTOMATE.FETCH_AUTOMATE(1))
|
|
186
|
+
.reply(200, route.params.preAutomate);
|
|
157
187
|
await act(async () => {
|
|
158
188
|
tree = await create(wrapComponent(route));
|
|
159
189
|
});
|
|
@@ -235,6 +265,278 @@ describe('Test ScriptDetail', () => {
|
|
|
235
265
|
);
|
|
236
266
|
});
|
|
237
267
|
|
|
268
|
+
it('test edit condition value change single unit', async () => {
|
|
269
|
+
await act(async () => {
|
|
270
|
+
tree = await create(wrapComponent(route));
|
|
271
|
+
});
|
|
272
|
+
const instance = tree.root;
|
|
273
|
+
const button = instance.find(
|
|
274
|
+
(el) =>
|
|
275
|
+
el.props.accessibilityLabel === AccessibilityLabel.ICON_MENU_POPUP &&
|
|
276
|
+
el.type === TouchableOpacity
|
|
277
|
+
);
|
|
278
|
+
await act(async () => {
|
|
279
|
+
await button.props.onPress();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const menuActionMore = instance.find(
|
|
283
|
+
(el) =>
|
|
284
|
+
el.props.accessibilityLabel === AccessibilityLabel.MENU_POPPER_MORE_2
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
await act(async () => {
|
|
288
|
+
menuActionMore.props.onItemClick({ doAction: jest.fn() });
|
|
289
|
+
menuActionMore.props.listMenuItem[0].doAction();
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
expect(global.mockedNavigate).toBeCalledWith(Routes.SelectMonitorDevices, {
|
|
293
|
+
automate: route.params.preAutomate,
|
|
294
|
+
closeScreen: Routes.ScriptDetail,
|
|
295
|
+
routeName: null,
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('test edit condition value change multi unit', async () => {
|
|
300
|
+
route.params.preAutomate.unit = null;
|
|
301
|
+
await act(async () => {
|
|
302
|
+
tree = await create(wrapComponent(route));
|
|
303
|
+
});
|
|
304
|
+
const instance = tree.root;
|
|
305
|
+
const button = instance.find(
|
|
306
|
+
(el) =>
|
|
307
|
+
el.props.accessibilityLabel === AccessibilityLabel.ICON_MENU_POPUP &&
|
|
308
|
+
el.type === TouchableOpacity
|
|
309
|
+
);
|
|
310
|
+
await act(async () => {
|
|
311
|
+
await button.props.onPress();
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
const menuActionMore = instance.find(
|
|
315
|
+
(el) =>
|
|
316
|
+
el.props.accessibilityLabel === AccessibilityLabel.MENU_POPPER_MORE_2
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
await act(async () => {
|
|
320
|
+
menuActionMore.props.onItemClick({ doAction: jest.fn() });
|
|
321
|
+
menuActionMore.props.listMenuItem[0].doAction();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
expect(global.mockedNavigate).toBeCalledWith(Routes.SelectUnit, {
|
|
325
|
+
automate: route.params.preAutomate,
|
|
326
|
+
routeName: Routes.SelectMonitorDevices,
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('test edit condition schedule', async () => {
|
|
331
|
+
route.params.preAutomate.type = AUTOMATE_TYPE.SCHEDULE;
|
|
332
|
+
route.params.preAutomate.conditions[0].type = AUTOMATE_TYPE.SCHEDULE;
|
|
333
|
+
await act(async () => {
|
|
334
|
+
tree = await create(wrapComponent(route));
|
|
335
|
+
});
|
|
336
|
+
const instance = tree.root;
|
|
337
|
+
const button = instance.find(
|
|
338
|
+
(el) =>
|
|
339
|
+
el.props.accessibilityLabel === AccessibilityLabel.ICON_MENU_POPUP &&
|
|
340
|
+
el.type === TouchableOpacity
|
|
341
|
+
);
|
|
342
|
+
await act(async () => {
|
|
343
|
+
await button.props.onPress();
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
const menuActionMore = instance.find(
|
|
347
|
+
(el) =>
|
|
348
|
+
el.props.accessibilityLabel === AccessibilityLabel.MENU_POPPER_MORE_2
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
await act(async () => {
|
|
352
|
+
menuActionMore.props.onItemClick({ doAction: jest.fn() });
|
|
353
|
+
menuActionMore.props.listMenuItem[0].doAction();
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
expect(global.mockedNavigate).toBeCalledWith(
|
|
357
|
+
Routes.AddEditConditionSchedule,
|
|
358
|
+
{
|
|
359
|
+
automate: route.params.preAutomate,
|
|
360
|
+
condition: route.params.preAutomate.conditions[0],
|
|
361
|
+
isUpdateCondition: true,
|
|
362
|
+
closeScreen: Routes.ScriptDetail,
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
const testDeleteCondition = async (statusCode, toastSpy, toastMessage) => {
|
|
368
|
+
const spyToast = jest.spyOn(ToastBottomHelper, toastSpy);
|
|
369
|
+
mock.onDelete(API.AUTOMATE.DELETE_CONDITION(1, 1)).reply(statusCode);
|
|
370
|
+
|
|
371
|
+
await act(async () => {
|
|
372
|
+
tree = await create(wrapComponent(route));
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
const instance = tree.root;
|
|
376
|
+
const button = instance.find(
|
|
377
|
+
(el) =>
|
|
378
|
+
el.props.accessibilityLabel === AccessibilityLabel.ICON_MENU_POPUP &&
|
|
379
|
+
el.type === TouchableOpacity
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
await act(async () => {
|
|
383
|
+
await button.props.onPress();
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
const menuActionMore = instance.find(
|
|
387
|
+
(el) =>
|
|
388
|
+
el.props.accessibilityLabel === AccessibilityLabel.MENU_POPPER_MORE_2
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
await act(async () => {
|
|
392
|
+
menuActionMore.props.onItemClick({ doAction: jest.fn() });
|
|
393
|
+
menuActionMore.props.listMenuItem[1].doAction();
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
const model = instance.find(
|
|
397
|
+
(el) =>
|
|
398
|
+
el.props.accessibilityLabel ===
|
|
399
|
+
AccessibilityLabel.AUTOMATE_DELETE_CONDITION
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
await act(async () => {
|
|
403
|
+
model.props.rightButtonClick();
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
expect(spyToast).toHaveBeenCalledWith(toastMessage);
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
it('test delete condition success', async () => {
|
|
410
|
+
await testDeleteCondition(204, 'success', 'Removed successfully!');
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it('test delete condition call api fail', async () => {
|
|
414
|
+
await testDeleteCondition(400, 'error', 'Remove failed');
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it('test can not delete condition because not owner', async () => {
|
|
418
|
+
route.params.preAutomate.can_edit = false;
|
|
419
|
+
await act(async () => {
|
|
420
|
+
tree = await create(wrapComponent(route));
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
const instance = tree.root;
|
|
424
|
+
const button = instance.find(
|
|
425
|
+
(el) =>
|
|
426
|
+
el.props.accessibilityLabel === AccessibilityLabel.ICON_MENU_POPUP &&
|
|
427
|
+
el.type === TouchableOpacity
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
await act(async () => {
|
|
431
|
+
await button.props.onPress();
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
const menuActionMore = instance.find(
|
|
435
|
+
(el) =>
|
|
436
|
+
el.props.accessibilityLabel === AccessibilityLabel.MENU_POPPER_MORE_2
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
await act(async () => {
|
|
440
|
+
menuActionMore.props.onItemClick({ doAction: jest.fn() });
|
|
441
|
+
menuActionMore.props.listMenuItem[1].doAction();
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
const model = instance.find(
|
|
445
|
+
(el) =>
|
|
446
|
+
el.props.accessibilityLabel ===
|
|
447
|
+
AccessibilityLabel.AUTOMATE_DELETE_CONDITION
|
|
448
|
+
);
|
|
449
|
+
expect(model).toBeDefined();
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it('test edit script list action', async () => {
|
|
453
|
+
mock.onGet(API.AUTOMATE.SCRIPT_ITEMS(1)).reply(200, data);
|
|
454
|
+
await act(async () => {
|
|
455
|
+
tree = await create(wrapComponent(route));
|
|
456
|
+
});
|
|
457
|
+
const instance = tree.root;
|
|
458
|
+
|
|
459
|
+
const buttonEditScript = instance.find(
|
|
460
|
+
(el) =>
|
|
461
|
+
el.props.accessibilityLabel ===
|
|
462
|
+
AccessibilityLabel.BUTTON_EDIT_SCRIPT_ACTION &&
|
|
463
|
+
el.type === TouchableOpacity
|
|
464
|
+
);
|
|
465
|
+
await act(async () => {
|
|
466
|
+
await buttonEditScript.props.onPress();
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
expect(global.mockedNavigate).toBeCalledWith(Routes.EditActionsList, {
|
|
470
|
+
data: data.script_items,
|
|
471
|
+
id: 1,
|
|
472
|
+
unitId: 2,
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
const testUpdateNeedAllCondition = async (
|
|
477
|
+
statusCode,
|
|
478
|
+
toastSpy,
|
|
479
|
+
toastMessage,
|
|
480
|
+
index
|
|
481
|
+
) => {
|
|
482
|
+
const spyToast = jest.spyOn(ToastBottomHelper, toastSpy);
|
|
483
|
+
mock.onPost(API.AUTOMATE.NEED_ALL_CONDITIONS(1)).reply(statusCode);
|
|
484
|
+
|
|
485
|
+
await act(async () => {
|
|
486
|
+
tree = await create(
|
|
487
|
+
wrapComponent(route, {
|
|
488
|
+
auth: {
|
|
489
|
+
account: {
|
|
490
|
+
user: {
|
|
491
|
+
permissions: {
|
|
492
|
+
max_conditions_per_automation: 1,
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
},
|
|
496
|
+
},
|
|
497
|
+
})
|
|
498
|
+
);
|
|
499
|
+
});
|
|
500
|
+
const instance = tree.root;
|
|
501
|
+
const showPopup = instance.find(
|
|
502
|
+
(el) =>
|
|
503
|
+
el.props.accessibilityLabel === AccessibilityLabel.AUTOMATE_CONDITION
|
|
504
|
+
);
|
|
505
|
+
await act(async () => {
|
|
506
|
+
await showPopup.props.onPress();
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
const selects = instance.findAll(
|
|
510
|
+
(el) =>
|
|
511
|
+
el.props.accessibilityLabel ===
|
|
512
|
+
AccessibilityLabel.AUTOMATE_SELECT_CONDITION &&
|
|
513
|
+
el.type === TouchableOpacity
|
|
514
|
+
);
|
|
515
|
+
expect(selects).toHaveLength(2);
|
|
516
|
+
await act(async () => {
|
|
517
|
+
await selects[index].props.onPress();
|
|
518
|
+
});
|
|
519
|
+
expect(spyToast).toHaveBeenCalledWith(toastMessage);
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
it('test update need all condition success', async () => {
|
|
523
|
+
await testUpdateNeedAllCondition(
|
|
524
|
+
200,
|
|
525
|
+
'success',
|
|
526
|
+
'Update condition success',
|
|
527
|
+
0
|
|
528
|
+
);
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it('test update need all condition fail', async () => {
|
|
532
|
+
await testUpdateNeedAllCondition(
|
|
533
|
+
400,
|
|
534
|
+
'error',
|
|
535
|
+
'Error! Please try later',
|
|
536
|
+
1
|
|
537
|
+
);
|
|
538
|
+
});
|
|
539
|
+
|
|
238
540
|
it('test cannot edit condition because not owner', async () => {
|
|
239
541
|
route.params.preAutomate.can_edit = false;
|
|
240
542
|
const spyToastError = jest.spyOn(ToastBottomHelper, 'error');
|
|
@@ -358,8 +660,10 @@ describe('Test ScriptDetail', () => {
|
|
|
358
660
|
expect(global.mockedGoBack).not.toHaveBeenCalled();
|
|
359
661
|
});
|
|
360
662
|
|
|
361
|
-
|
|
362
|
-
|
|
663
|
+
const testTriggerOneTap = async (statusCode, toastSpy, toastMessage) => {
|
|
664
|
+
const spyToast = jest.spyOn(ToastBottomHelper, toastSpy);
|
|
665
|
+
mock.onGet(API.AUTOMATE.SCRIPT_ITEMS(1)).reply(200, data);
|
|
666
|
+
mock.onPost(API.AUTOMATE.ACTION_ONE_TAP(1)).reply(statusCode);
|
|
363
667
|
route.params.preAutomate.type = AUTOMATE_TYPE.ONE_TAP;
|
|
364
668
|
|
|
365
669
|
await act(async () => {
|
|
@@ -372,11 +676,20 @@ describe('Test ScriptDetail', () => {
|
|
|
372
676
|
AccessibilityLabel.BUTTON_ACTIVATE_ONE_TAP &&
|
|
373
677
|
el.type === TouchableOpacity
|
|
374
678
|
);
|
|
375
|
-
|
|
679
|
+
|
|
376
680
|
await act(async () => {
|
|
377
681
|
await buttonActivate.props.onPress();
|
|
378
682
|
});
|
|
379
|
-
|
|
683
|
+
|
|
684
|
+
expect(spyToast).toHaveBeenCalledWith(toastMessage);
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
it('test activate call one tap success', async () => {
|
|
688
|
+
await testTriggerOneTap(200, 'success', 'Activated successfully.');
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
it('test activate call one tap fail', async () => {
|
|
692
|
+
await testTriggerOneTap(400, 'error', 'Activation failed.');
|
|
380
693
|
});
|
|
381
694
|
|
|
382
695
|
it('test press add action', async () => {
|
|
@@ -388,7 +701,7 @@ describe('Test ScriptDetail', () => {
|
|
|
388
701
|
script_items: null,
|
|
389
702
|
},
|
|
390
703
|
];
|
|
391
|
-
mock.onGet(API.AUTOMATE.
|
|
704
|
+
mock.onGet(API.AUTOMATE.SCRIPT_ITEMS(1)).reply(200, data);
|
|
392
705
|
const auth = {
|
|
393
706
|
account: {
|
|
394
707
|
user: {
|
|
@@ -599,7 +912,7 @@ describe('Test ScriptDetail', () => {
|
|
|
599
912
|
});
|
|
600
913
|
|
|
601
914
|
it('test press disable script', async () => {
|
|
602
|
-
mock.onGet(API.AUTOMATE.
|
|
915
|
+
mock.onGet(API.AUTOMATE.SCRIPT_ITEMS(1)).reply(200, data);
|
|
603
916
|
mock.onPost(API.AUTOMATE.ENABLE_SCRIPT(1)).reply(200, data);
|
|
604
917
|
await act(async () => {
|
|
605
918
|
tree = await create(wrapComponent(route));
|
|
@@ -627,7 +940,7 @@ describe('Test ScriptDetail', () => {
|
|
|
627
940
|
});
|
|
628
941
|
|
|
629
942
|
it('test press add action reach limit', async () => {
|
|
630
|
-
mock.onGet(API.AUTOMATE.
|
|
943
|
+
mock.onGet(API.AUTOMATE.SCRIPT_ITEMS(1)).reply(200, data);
|
|
631
944
|
await act(async () => {
|
|
632
945
|
tree = await create(
|
|
633
946
|
wrapComponent(route, {
|
|
@@ -664,7 +977,7 @@ describe('Test ScriptDetail', () => {
|
|
|
664
977
|
|
|
665
978
|
it('test not see add action', async () => {
|
|
666
979
|
route.params.preAutomate.can_edit = false;
|
|
667
|
-
mock.onGet(API.AUTOMATE.
|
|
980
|
+
mock.onGet(API.AUTOMATE.SCRIPT_ITEMS(1)).reply(200, data);
|
|
668
981
|
await act(async () => {
|
|
669
982
|
tree = await create(wrapComponent(route));
|
|
670
983
|
});
|
|
@@ -740,13 +1053,16 @@ describe('Test ScriptDetail', () => {
|
|
|
740
1053
|
const automate = {
|
|
741
1054
|
can_edit: true,
|
|
742
1055
|
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
1056
|
+
conditions: [
|
|
1057
|
+
{
|
|
1058
|
+
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
1059
|
+
config_name: 'Light Value',
|
|
1060
|
+
value: 3,
|
|
1061
|
+
condition: '>',
|
|
1062
|
+
end_device_id: 1,
|
|
1063
|
+
unit_id: 1,
|
|
1064
|
+
},
|
|
1065
|
+
],
|
|
750
1066
|
script: {
|
|
751
1067
|
name: 'name',
|
|
752
1068
|
enable: true,
|
|
@@ -777,11 +1093,6 @@ describe('Test ScriptDetail', () => {
|
|
|
777
1093
|
menuActionMore.props.listMenuItem[2].doAction();
|
|
778
1094
|
});
|
|
779
1095
|
|
|
780
|
-
expectMockedDispatch(Routes.AddUnknownTypeSmart, {
|
|
781
|
-
automate: automate,
|
|
782
|
-
closeScreen: undefined,
|
|
783
|
-
});
|
|
784
|
-
|
|
785
1096
|
expect(menuActionMore.props.listMenuItem[0].text).toEqual('Device display');
|
|
786
1097
|
await act(async () => {
|
|
787
1098
|
menuActionMore.props.listMenuItem[0].doAction();
|
|
@@ -791,7 +1102,7 @@ describe('Test ScriptDetail', () => {
|
|
|
791
1102
|
unitId: 1,
|
|
792
1103
|
});
|
|
793
1104
|
global.mockedNavigate.mockClear();
|
|
794
|
-
expect(menuActionMore.props.listMenuItem[1].text).toEqual('Unit');
|
|
1105
|
+
expect(menuActionMore.props.listMenuItem[1].text).toEqual('Go to Unit');
|
|
795
1106
|
await act(async () => {
|
|
796
1107
|
menuActionMore.props.listMenuItem[1].doAction();
|
|
797
1108
|
});
|
|
@@ -805,7 +1116,14 @@ describe('Test ScriptDetail', () => {
|
|
|
805
1116
|
...route.params,
|
|
806
1117
|
preAutomate: {
|
|
807
1118
|
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
808
|
-
|
|
1119
|
+
conditions: [
|
|
1120
|
+
{
|
|
1121
|
+
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
1122
|
+
config_name: 'Light Value',
|
|
1123
|
+
value: 3,
|
|
1124
|
+
condition: '=',
|
|
1125
|
+
},
|
|
1126
|
+
],
|
|
809
1127
|
},
|
|
810
1128
|
};
|
|
811
1129
|
await act(async () => {
|
|
@@ -823,11 +1141,14 @@ describe('Test ScriptDetail', () => {
|
|
|
823
1141
|
...route.params,
|
|
824
1142
|
preAutomate: {
|
|
825
1143
|
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
1144
|
+
conditions: [
|
|
1145
|
+
{
|
|
1146
|
+
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
1147
|
+
config_name: 'Light Value',
|
|
1148
|
+
value: 3,
|
|
1149
|
+
condition: '<',
|
|
1150
|
+
},
|
|
1151
|
+
],
|
|
831
1152
|
},
|
|
832
1153
|
};
|
|
833
1154
|
await act(async () => {
|
|
@@ -845,11 +1166,13 @@ describe('Test ScriptDetail', () => {
|
|
|
845
1166
|
...route.params,
|
|
846
1167
|
preAutomate: {
|
|
847
1168
|
type: AUTOMATE_TYPE.SCHEDULE,
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
1169
|
+
conditions: [
|
|
1170
|
+
{
|
|
1171
|
+
type: AUTOMATE_TYPE.SCHEDULE,
|
|
1172
|
+
repeat: 'every_day',
|
|
1173
|
+
time_repeat: '19:00:00',
|
|
1174
|
+
},
|
|
1175
|
+
],
|
|
853
1176
|
},
|
|
854
1177
|
};
|
|
855
1178
|
await act(async () => {
|
|
@@ -867,12 +1190,15 @@ describe('Test ScriptDetail', () => {
|
|
|
867
1190
|
...route.params,
|
|
868
1191
|
preAutomate: {
|
|
869
1192
|
type: AUTOMATE_TYPE.SCHEDULE,
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
1193
|
+
conditions: [
|
|
1194
|
+
{
|
|
1195
|
+
type: AUTOMATE_TYPE.SCHEDULE,
|
|
1196
|
+
repeat: 'every_week',
|
|
1197
|
+
date_repeat: '2022-01-02',
|
|
1198
|
+
time_repeat: '19:00:00',
|
|
1199
|
+
weekday_repeat: ['1', '2', '4', '6'],
|
|
1200
|
+
},
|
|
1201
|
+
],
|
|
876
1202
|
},
|
|
877
1203
|
};
|
|
878
1204
|
await act(async () => {
|
|
@@ -1029,4 +1355,72 @@ describe('Test ScriptDetail', () => {
|
|
|
1029
1355
|
});
|
|
1030
1356
|
expect(mock.history.post.length).toBe(0);
|
|
1031
1357
|
});
|
|
1358
|
+
|
|
1359
|
+
it('test user have max_conditions_per_automation', async () => {
|
|
1360
|
+
mock.onGet(API.AUTOMATE.SCRIPT_ITEMS(1)).reply(200, data);
|
|
1361
|
+
await act(async () => {
|
|
1362
|
+
tree = await create(
|
|
1363
|
+
wrapComponent(route, {
|
|
1364
|
+
auth: {
|
|
1365
|
+
account: {
|
|
1366
|
+
user: {
|
|
1367
|
+
permissions: {
|
|
1368
|
+
max_conditions_per_automation: 2,
|
|
1369
|
+
max_actions_per_automation: 0,
|
|
1370
|
+
},
|
|
1371
|
+
},
|
|
1372
|
+
},
|
|
1373
|
+
},
|
|
1374
|
+
})
|
|
1375
|
+
);
|
|
1376
|
+
});
|
|
1377
|
+
const instance = tree.root;
|
|
1378
|
+
const text_number = instance.find(
|
|
1379
|
+
(el) =>
|
|
1380
|
+
el.props.accessibilityLabel ===
|
|
1381
|
+
AccessibilityLabel.AUTOMATE_NUMBER_CONDITION && el.type === Text
|
|
1382
|
+
);
|
|
1383
|
+
expect(text_number.props.children).toEqual('Available [1] condition');
|
|
1384
|
+
const buttonAddCondition = instance.find(
|
|
1385
|
+
(el) =>
|
|
1386
|
+
el.props.accessibilityLabel ===
|
|
1387
|
+
AccessibilityLabel.BUTTON_ADD_CONDITION &&
|
|
1388
|
+
el.type === TouchableOpacity
|
|
1389
|
+
);
|
|
1390
|
+
await act(async () => {
|
|
1391
|
+
await buttonAddCondition.props.onPress();
|
|
1392
|
+
});
|
|
1393
|
+
|
|
1394
|
+
const model = instance.findByType(ModalAddCondition);
|
|
1395
|
+
expect(model.props.isVisible).toBe(true);
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1398
|
+
it('can not add condition because user reach_max_conditions_per_automation', async () => {
|
|
1399
|
+
mock.onGet(API.AUTOMATE.SCRIPT_ITEMS(1)).reply(200, data);
|
|
1400
|
+
mock.onGet(API.AUTH.PERMISSIONS()).reply(200, {
|
|
1401
|
+
max_conditions_per_automation: 1,
|
|
1402
|
+
});
|
|
1403
|
+
await act(async () => {
|
|
1404
|
+
tree = await create(wrapComponent(route));
|
|
1405
|
+
});
|
|
1406
|
+
const instance = tree.root;
|
|
1407
|
+
const text_number = instance.find(
|
|
1408
|
+
(el) =>
|
|
1409
|
+
el.props.accessibilityLabel ===
|
|
1410
|
+
AccessibilityLabel.AUTOMATE_NUMBER_CONDITION && el.type === Text
|
|
1411
|
+
);
|
|
1412
|
+
expect(text_number.props.children).toEqual('Available [0] condition');
|
|
1413
|
+
const buttonAddCondition = instance.find(
|
|
1414
|
+
(el) =>
|
|
1415
|
+
el.props.accessibilityLabel ===
|
|
1416
|
+
AccessibilityLabel.BUTTON_ADD_CONDITION &&
|
|
1417
|
+
el.type === TouchableOpacity
|
|
1418
|
+
);
|
|
1419
|
+
await act(async () => {
|
|
1420
|
+
await buttonAddCondition.props.onPress();
|
|
1421
|
+
});
|
|
1422
|
+
|
|
1423
|
+
const model = instance.findByType(ModalAddCondition);
|
|
1424
|
+
expect(model.props.isVisible).toBe(false);
|
|
1425
|
+
});
|
|
1032
1426
|
});
|