@eohjsc/react-native-smart-city 0.7.15 → 0.7.17
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/Sms.svg +9 -0
- package/package.json +1 -1
- package/src/commons/Automate/ItemConditionScriptDetailStyles.js +1 -0
- package/src/commons/Unit/__test__/SharedUnit.test.js +57 -0
- package/src/configs/API.js +6 -1
- package/src/configs/AccessibilityLabel.js +4 -0
- package/src/hooks/Common/useBlockBack.js +10 -2
- package/src/navigations/UnitStack.js +24 -0
- package/src/screens/Automate/AddNewAction/SetupScriptReceiverSms.js +167 -0
- package/src/screens/Automate/AddNewAction/SetupScriptSms.js +73 -0
- package/src/screens/Automate/AddNewAction/Styles/SetupScriptEmailStyles.js +5 -0
- package/src/screens/Automate/AddNewAction/__test__/SetupScriptReceiverSms.test.js +105 -0
- package/src/screens/Automate/AddNewAction/__test__/SetupScriptSms.test.js +70 -0
- package/src/screens/Automate/EditActionsList/UpdateReceiverSmsScript.js +178 -0
- package/src/screens/Automate/EditActionsList/UpdateSmsScript.js +66 -0
- package/src/screens/Automate/EditActionsList/__tests__/UpdateReceiverSmsScript.test.js +82 -0
- package/src/screens/Automate/EditActionsList/__tests__/UpdateSmsScript.test.js +71 -0
- package/src/screens/Automate/EditActionsList/index.js +50 -1
- package/src/screens/Automate/ScriptDetail/Components/AddActionScript.js +52 -19
- package/src/screens/Automate/ScriptDetail/Styles/indexStyles.js +39 -2
- package/src/screens/Automate/ScriptDetail/__test__/index.test.js +295 -57
- package/src/screens/Automate/ScriptDetail/index.js +234 -32
- package/src/utils/I18n/translations/en.js +10 -0
- package/src/utils/I18n/translations/vi.js +10 -0
- package/src/utils/Route/index.js +3 -0
|
@@ -42,11 +42,16 @@ describe('Test ScriptDetail', () => {
|
|
|
42
42
|
const mockAddListener = useNavigation().addListener;
|
|
43
43
|
const mockedNavigate = useNavigation().navigate;
|
|
44
44
|
const mockedDispatch = useNavigation().dispatch;
|
|
45
|
+
const mockedGetState = useNavigation().getState;
|
|
46
|
+
|
|
45
47
|
beforeEach(() => {
|
|
46
48
|
mockGoBack.mockClear();
|
|
47
49
|
mockAddListener.mockClear();
|
|
48
50
|
mockedNavigate.mockClear();
|
|
49
51
|
mockedDispatch.mockClear();
|
|
52
|
+
mockedGetState.mockReturnValue({
|
|
53
|
+
routes: [{ name: 'Home' }],
|
|
54
|
+
});
|
|
50
55
|
global.mockedNavigate.mockClear();
|
|
51
56
|
mock.reset();
|
|
52
57
|
route = {
|
|
@@ -111,6 +116,43 @@ describe('Test ScriptDetail', () => {
|
|
|
111
116
|
};
|
|
112
117
|
});
|
|
113
118
|
|
|
119
|
+
afterEach(() => {
|
|
120
|
+
jest.useRealTimers();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const expectMockedDispatch = (screen, screenParams) => {
|
|
124
|
+
act(() => {
|
|
125
|
+
jest.runAllTimers();
|
|
126
|
+
});
|
|
127
|
+
expect(mockedDispatch).toHaveBeenCalledWith({
|
|
128
|
+
type: 'RESET',
|
|
129
|
+
payload: {
|
|
130
|
+
index: 2,
|
|
131
|
+
routes: [
|
|
132
|
+
{
|
|
133
|
+
name: 'Home',
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: Routes.ScriptDetail,
|
|
137
|
+
params: route.params,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: screen,
|
|
141
|
+
params: screenParams,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
expect(mockedDispatch).toHaveBeenCalledTimes(1);
|
|
147
|
+
mockedGetState.mockReturnValue({
|
|
148
|
+
routes: [
|
|
149
|
+
{ name: 'Home' },
|
|
150
|
+
{ name: Routes.ScriptDetail, params: route.params },
|
|
151
|
+
],
|
|
152
|
+
});
|
|
153
|
+
mockedDispatch.mockClear();
|
|
154
|
+
};
|
|
155
|
+
|
|
114
156
|
it('test rename script', async () => {
|
|
115
157
|
await act(async () => {
|
|
116
158
|
tree = await create(wrapComponent(route));
|
|
@@ -331,6 +373,7 @@ describe('Test ScriptDetail', () => {
|
|
|
331
373
|
});
|
|
332
374
|
|
|
333
375
|
it('test press add action', async () => {
|
|
376
|
+
jest.useFakeTimers();
|
|
334
377
|
data = [
|
|
335
378
|
{
|
|
336
379
|
id: 1,
|
|
@@ -370,56 +413,182 @@ describe('Test ScriptDetail', () => {
|
|
|
370
413
|
AccessibilityLabel.AUTOMATE_LIST_SCRIPT_ACTION &&
|
|
371
414
|
el.type === TouchableOpacity
|
|
372
415
|
);
|
|
373
|
-
expect(listScriptActions).toHaveLength(
|
|
416
|
+
expect(listScriptActions).toHaveLength(5);
|
|
374
417
|
await act(async () => {
|
|
375
418
|
await listScriptActions[0].props.onPress();
|
|
376
419
|
});
|
|
377
420
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
routeName: null,
|
|
386
|
-
}
|
|
387
|
-
);
|
|
388
|
-
mockedNavigate.mockClear();
|
|
421
|
+
expectMockedDispatch(Routes.SelectControlDevices, {
|
|
422
|
+
unitId: route.params.preAutomate.unit,
|
|
423
|
+
automateId: route.params.preAutomate.id,
|
|
424
|
+
numberActionCanAdd: 2,
|
|
425
|
+
closeScreen: undefined,
|
|
426
|
+
routeName: null,
|
|
427
|
+
});
|
|
389
428
|
await act(async () => {
|
|
390
429
|
await listScriptActions[1].props.onPress();
|
|
391
430
|
});
|
|
392
431
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
unitId: route.params.preAutomate.unit,
|
|
398
|
-
}
|
|
399
|
-
);
|
|
400
|
-
mockedNavigate.mockClear();
|
|
432
|
+
expectMockedDispatch(Routes.SetupScriptNotify, {
|
|
433
|
+
automate: route.params.preAutomate,
|
|
434
|
+
unitId: route.params.preAutomate.unit,
|
|
435
|
+
});
|
|
401
436
|
await act(async () => {
|
|
402
437
|
await listScriptActions[2].props.onPress();
|
|
403
438
|
});
|
|
404
439
|
|
|
405
|
-
|
|
406
|
-
|
|
440
|
+
expectMockedDispatch(Routes.SetupScriptDelay, {
|
|
441
|
+
automate: route.params.preAutomate,
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it('test press add email and sms', async () => {
|
|
446
|
+
jest.useFakeTimers();
|
|
447
|
+
data = [
|
|
407
448
|
{
|
|
408
|
-
|
|
409
|
-
|
|
449
|
+
id: 1,
|
|
450
|
+
unit: 1,
|
|
451
|
+
script_items: null,
|
|
452
|
+
},
|
|
453
|
+
];
|
|
454
|
+
mock.onGet(API.AUTOMATE.SCRIPT(1)).reply(200, data);
|
|
455
|
+
const auth = {
|
|
456
|
+
account: {
|
|
457
|
+
user: {
|
|
458
|
+
permissions: {
|
|
459
|
+
max_actions_per_automation: 2,
|
|
460
|
+
},
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
};
|
|
464
|
+
await act(async () => {
|
|
465
|
+
tree = await create(wrapComponent(route, { auth }));
|
|
466
|
+
});
|
|
467
|
+
const instance = tree.root;
|
|
468
|
+
const button = instance.find(
|
|
469
|
+
(el) =>
|
|
470
|
+
el.props.accessibilityLabel ===
|
|
471
|
+
AccessibilityLabel.BUTTON_ADD_SCRIPT_ACTION &&
|
|
472
|
+
el.type === TouchableOpacity
|
|
410
473
|
);
|
|
411
|
-
|
|
474
|
+
await act(async () => {
|
|
475
|
+
await button.props.onPress();
|
|
476
|
+
});
|
|
477
|
+
const texts = instance.findByType(AddActionScript);
|
|
478
|
+
expect(texts.props.isVisible).toBeTruthy();
|
|
479
|
+
|
|
480
|
+
const listScriptActions = instance.findAll(
|
|
481
|
+
(el) =>
|
|
482
|
+
el.props.accessibilityLabel ===
|
|
483
|
+
AccessibilityLabel.AUTOMATE_LIST_SCRIPT_ACTION &&
|
|
484
|
+
el.type === TouchableOpacity
|
|
485
|
+
);
|
|
486
|
+
expect(listScriptActions).toHaveLength(5);
|
|
412
487
|
await act(async () => {
|
|
413
488
|
await listScriptActions[3].props.onPress();
|
|
414
489
|
});
|
|
415
490
|
|
|
416
|
-
|
|
417
|
-
|
|
491
|
+
expectMockedDispatch(Routes.SetupScriptEmail, {
|
|
492
|
+
automate: route.params.preAutomate,
|
|
493
|
+
unitId: route.params.preAutomate.unit,
|
|
494
|
+
});
|
|
495
|
+
await act(async () => {
|
|
496
|
+
await listScriptActions[4].props.onPress();
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
expectMockedDispatch(Routes.SetupScriptSms, {
|
|
500
|
+
automate: route.params.preAutomate,
|
|
501
|
+
unitId: route.params.preAutomate.unit,
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
it('test press add action when has closeScreen is present in stacks', async () => {
|
|
506
|
+
jest.useFakeTimers();
|
|
507
|
+
data = [
|
|
418
508
|
{
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
509
|
+
id: 1,
|
|
510
|
+
unit: 1,
|
|
511
|
+
script_items: null,
|
|
512
|
+
},
|
|
513
|
+
];
|
|
514
|
+
mock.onGet(API.AUTOMATE.SCRIPT(1)).reply(200, data);
|
|
515
|
+
const auth = {
|
|
516
|
+
account: {
|
|
517
|
+
user: {
|
|
518
|
+
permissions: {
|
|
519
|
+
max_actions_per_automation: 2,
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
};
|
|
524
|
+
route.params.closeScreen = Routes.UnitDetail;
|
|
525
|
+
await act(async () => {
|
|
526
|
+
tree = await create(wrapComponent(route, { auth }));
|
|
527
|
+
});
|
|
528
|
+
const instance = tree.root;
|
|
529
|
+
const button = instance.find(
|
|
530
|
+
(el) =>
|
|
531
|
+
el.props.accessibilityLabel ===
|
|
532
|
+
AccessibilityLabel.BUTTON_ADD_SCRIPT_ACTION &&
|
|
533
|
+
el.type === TouchableOpacity
|
|
422
534
|
);
|
|
535
|
+
await act(async () => {
|
|
536
|
+
await button.props.onPress();
|
|
537
|
+
});
|
|
538
|
+
const texts = instance.findByType(AddActionScript);
|
|
539
|
+
expect(texts.props.isVisible).toBeTruthy();
|
|
540
|
+
|
|
541
|
+
const listScriptActions = instance.findAll(
|
|
542
|
+
(el) =>
|
|
543
|
+
el.props.accessibilityLabel ===
|
|
544
|
+
AccessibilityLabel.AUTOMATE_LIST_SCRIPT_ACTION &&
|
|
545
|
+
el.type === TouchableOpacity
|
|
546
|
+
);
|
|
547
|
+
expect(listScriptActions).toHaveLength(5);
|
|
548
|
+
|
|
549
|
+
mockedGetState.mockReturnValue({
|
|
550
|
+
routes: [
|
|
551
|
+
{ name: 'Home' },
|
|
552
|
+
{ name: Routes.UnitDetail, params: { unitId: 1 } },
|
|
553
|
+
{ name: Routes.ScriptDetail, params: route.params },
|
|
554
|
+
],
|
|
555
|
+
});
|
|
556
|
+
await act(async () => {
|
|
557
|
+
await listScriptActions[0].props.onPress();
|
|
558
|
+
});
|
|
559
|
+
await act(async () => {
|
|
560
|
+
jest.runAllTimers();
|
|
561
|
+
});
|
|
562
|
+
expect(mockedDispatch).toHaveBeenCalledWith({
|
|
563
|
+
type: 'RESET',
|
|
564
|
+
payload: {
|
|
565
|
+
index: 3,
|
|
566
|
+
routes: [
|
|
567
|
+
{
|
|
568
|
+
name: 'Home',
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
name: Routes.UnitDetail,
|
|
572
|
+
params: { unitId: 1 },
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
name: Routes.ScriptDetail,
|
|
576
|
+
params: route.params,
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
name: Routes.SelectControlDevices,
|
|
580
|
+
params: {
|
|
581
|
+
unitId: route.params.preAutomate.unit,
|
|
582
|
+
automateId: route.params.preAutomate.id,
|
|
583
|
+
numberActionCanAdd: 2,
|
|
584
|
+
closeScreen: undefined,
|
|
585
|
+
routeName: null,
|
|
586
|
+
},
|
|
587
|
+
},
|
|
588
|
+
],
|
|
589
|
+
},
|
|
590
|
+
});
|
|
591
|
+
expect(mockedDispatch).toHaveBeenCalledTimes(1);
|
|
423
592
|
});
|
|
424
593
|
|
|
425
594
|
it('test press disable script', async () => {
|
|
@@ -560,6 +729,7 @@ describe('Test ScriptDetail', () => {
|
|
|
560
729
|
_testGoToActivityLog(3, AUTOMATE_TYPE.VALUE_CHANGE, 'automate', undefined);
|
|
561
730
|
|
|
562
731
|
it('Test render textCondition value change >', async () => {
|
|
732
|
+
jest.useFakeTimers();
|
|
563
733
|
const automate = {
|
|
564
734
|
can_edit: true,
|
|
565
735
|
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
@@ -600,33 +770,10 @@ describe('Test ScriptDetail', () => {
|
|
|
600
770
|
menuActionMore.props.listMenuItem[2].doAction();
|
|
601
771
|
});
|
|
602
772
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
const updatedState = mockedDispatch.mock.calls[0][0](mockState);
|
|
607
|
-
expect(updatedState).toEqual({
|
|
608
|
-
type: 'RESET',
|
|
609
|
-
payload: {
|
|
610
|
-
index: 2,
|
|
611
|
-
routes: [
|
|
612
|
-
{
|
|
613
|
-
name: 'Home',
|
|
614
|
-
},
|
|
615
|
-
{
|
|
616
|
-
name: Routes.ScriptDetail,
|
|
617
|
-
params: route.params,
|
|
618
|
-
},
|
|
619
|
-
{
|
|
620
|
-
name: Routes.AddUnknownTypeSmart,
|
|
621
|
-
params: {
|
|
622
|
-
automate: automate,
|
|
623
|
-
closeScreen: undefined,
|
|
624
|
-
},
|
|
625
|
-
},
|
|
626
|
-
],
|
|
627
|
-
},
|
|
773
|
+
expectMockedDispatch(Routes.AddUnknownTypeSmart, {
|
|
774
|
+
automate: automate,
|
|
775
|
+
closeScreen: undefined,
|
|
628
776
|
});
|
|
629
|
-
expect(mockedDispatch).toHaveBeenCalledTimes(1);
|
|
630
777
|
|
|
631
778
|
expect(menuActionMore.props.listMenuItem[0].text).toEqual('Device display');
|
|
632
779
|
await act(async () => {
|
|
@@ -742,7 +889,10 @@ describe('Test ScriptDetail', () => {
|
|
|
742
889
|
|
|
743
890
|
// beforeRemove test when swipe to back
|
|
744
891
|
const navigation = useNavigation();
|
|
745
|
-
const beforeRemoveEvent = {
|
|
892
|
+
const beforeRemoveEvent = {
|
|
893
|
+
preventDefault: jest.fn(),
|
|
894
|
+
data: { action: { type: 'GO_BACK' } },
|
|
895
|
+
};
|
|
746
896
|
const beforeRemoveListener = navigation.addListener.mock.calls.find(
|
|
747
897
|
([event]) => event === 'beforeRemove'
|
|
748
898
|
)[1];
|
|
@@ -758,6 +908,34 @@ describe('Test ScriptDetail', () => {
|
|
|
758
908
|
});
|
|
759
909
|
});
|
|
760
910
|
|
|
911
|
+
it('test skip block back when navigate on ios', async () => {
|
|
912
|
+
Platform.OS = 'ios';
|
|
913
|
+
route.params.closeScreen = Routes.UnitDetail;
|
|
914
|
+
route.params.preAutomate.unit = 2;
|
|
915
|
+
|
|
916
|
+
await act(async () => {
|
|
917
|
+
await create(wrapComponent(route));
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
// beforeRemove test when navigate
|
|
921
|
+
const navigation = useNavigation();
|
|
922
|
+
const beforeRemoveEvent = {
|
|
923
|
+
preventDefault: jest.fn(),
|
|
924
|
+
data: { action: { type: 'NAVIGATE' } },
|
|
925
|
+
};
|
|
926
|
+
const beforeRemoveListener = navigation.addListener.mock.calls.find(
|
|
927
|
+
([event]) => event === 'beforeRemove'
|
|
928
|
+
)[1];
|
|
929
|
+
|
|
930
|
+
await act(async () => {
|
|
931
|
+
beforeRemoveListener(beforeRemoveEvent);
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
expect(mockAddListener).toHaveBeenCalled();
|
|
935
|
+
expect(beforeRemoveEvent.preventDefault).not.toHaveBeenCalled();
|
|
936
|
+
expect(mockedNavigate).not.toHaveBeenCalled();
|
|
937
|
+
});
|
|
938
|
+
|
|
761
939
|
it('test navigate to UnitDetail on event hardwareBackPress', async () => {
|
|
762
940
|
Platform.OS = 'android';
|
|
763
941
|
jest.spyOn(BackHandler, 'addEventListener');
|
|
@@ -784,4 +962,64 @@ describe('Test ScriptDetail', () => {
|
|
|
784
962
|
unitId: 2,
|
|
785
963
|
});
|
|
786
964
|
});
|
|
965
|
+
|
|
966
|
+
it('test enable local control', async () => {
|
|
967
|
+
mock.onPost(API.AUTOMATE.ENABLE_LOCAL_CONTROL(1)).reply(200);
|
|
968
|
+
mock
|
|
969
|
+
.onGet(API.DEV_MODE.GATEWAY.SHARED())
|
|
970
|
+
.reply(200, [{ name: 'Chip', id: 1 }]);
|
|
971
|
+
|
|
972
|
+
await act(async () => {
|
|
973
|
+
tree = await create(wrapComponent(route));
|
|
974
|
+
});
|
|
975
|
+
const instance = tree.root;
|
|
976
|
+
const show_local_control = instance.find(
|
|
977
|
+
(el) =>
|
|
978
|
+
el.props.accessibilityLabel ===
|
|
979
|
+
AccessibilityLabel.AUTOMATE_SHOW_LOCAL_CONTROL &&
|
|
980
|
+
el.type === TouchableOpacity
|
|
981
|
+
);
|
|
982
|
+
await act(async () => {
|
|
983
|
+
await show_local_control.props.onPress();
|
|
984
|
+
});
|
|
985
|
+
const disable = instance.find(
|
|
986
|
+
(el) =>
|
|
987
|
+
el.props.accessibilityLabel ===
|
|
988
|
+
AccessibilityLabel.AUTOMATE_ENABLE_LOCAL_CONTROL &&
|
|
989
|
+
el.type === TouchableOpacity
|
|
990
|
+
);
|
|
991
|
+
await act(async () => {
|
|
992
|
+
await disable.props.onPress();
|
|
993
|
+
});
|
|
994
|
+
|
|
995
|
+
expect(mock.history.post[0].url).toEqual(
|
|
996
|
+
API.AUTOMATE.ENABLE_LOCAL_CONTROL(1)
|
|
997
|
+
);
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
it('test disable local control', async () => {
|
|
1001
|
+
await act(async () => {
|
|
1002
|
+
tree = await create(wrapComponent(route));
|
|
1003
|
+
});
|
|
1004
|
+
const instance = tree.root;
|
|
1005
|
+
const show_local_control = instance.find(
|
|
1006
|
+
(el) =>
|
|
1007
|
+
el.props.accessibilityLabel ===
|
|
1008
|
+
AccessibilityLabel.AUTOMATE_SHOW_LOCAL_CONTROL &&
|
|
1009
|
+
el.type === TouchableOpacity
|
|
1010
|
+
);
|
|
1011
|
+
await act(async () => {
|
|
1012
|
+
await show_local_control.props.onPress();
|
|
1013
|
+
});
|
|
1014
|
+
const disable = instance.find(
|
|
1015
|
+
(el) =>
|
|
1016
|
+
el.props.accessibilityLabel ===
|
|
1017
|
+
AccessibilityLabel.AUTOMATE_DISABLE_LOCAL_CONTROL &&
|
|
1018
|
+
el.type === TouchableOpacity
|
|
1019
|
+
);
|
|
1020
|
+
await act(async () => {
|
|
1021
|
+
await disable.props.onPress();
|
|
1022
|
+
});
|
|
1023
|
+
expect(mock.history.post.length).toBe(0);
|
|
1024
|
+
});
|
|
787
1025
|
});
|