@eohjsc/react-native-smart-city 0.7.14 → 0.7.16
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/Widgets/IFrame/IFrame.js +2 -2
- package/src/commons/Widgets/IFrame/IFrameStyles.js +5 -0
- package/src/configs/API.js +8 -2
- package/src/hooks/Common/useBlockBack.js +36 -21
- package/src/hooks/Common/useDevicesStatus.js +16 -13
- package/src/navigations/UnitStack.js +24 -0
- package/src/screens/AddNewGateway/ScanDeviceLocal.js +14 -16
- package/src/screens/AddNewGateway/ScanDeviceLocalStyles.js +6 -1
- package/src/screens/AddNewGateway/__test__/ScanDeviceLocal.test.js +4 -13
- 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 +106 -38
- package/src/screens/Automate/ScriptDetail/index.js +227 -10
- package/src/screens/SharedUnit/__test__/ShareUnit.test.js +22 -1
- package/src/screens/Sharing/UnitMemberList.js +1 -1
- package/src/screens/Sharing/__test__/UnitMemberList.test.js +10 -0
- package/src/screens/Unit/__test__/Detail.test.js +1 -1
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { memo, useMemo } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useRoute } from '@react-navigation/native';
|
|
4
4
|
|
|
5
5
|
import { ModalCustom } from '../../../../commons/Modal';
|
|
6
6
|
import { StyleSheet, View } from 'react-native';
|
|
@@ -11,17 +11,25 @@ import Event from '../../../../../assets/images/Event.svg';
|
|
|
11
11
|
import Notify from '../../../../../assets/images/Notify.svg';
|
|
12
12
|
import Delay from '../../../../../assets/images/Delay.svg';
|
|
13
13
|
import Email from '../../../../../assets/images/Email.svg';
|
|
14
|
+
import Sms from '../../../../../assets/images/Sms.svg';
|
|
14
15
|
import { TouchableOpacity } from 'react-native';
|
|
15
16
|
import { IconOutline } from '@ant-design/icons-react-native';
|
|
16
17
|
import { Text } from '../../../../commons';
|
|
17
18
|
import Routes from '../../../../utils/Route';
|
|
18
19
|
import AccessibilityLabel from '../../../../configs/AccessibilityLabel';
|
|
20
|
+
import { AUTOMATE_TYPE } from '../../../../configs/Constants';
|
|
19
21
|
|
|
20
22
|
const AddActionScript = memo(
|
|
21
|
-
({
|
|
23
|
+
({
|
|
24
|
+
automate,
|
|
25
|
+
isVisible,
|
|
26
|
+
setIsVisible,
|
|
27
|
+
numberActionAdded,
|
|
28
|
+
type,
|
|
29
|
+
navigate,
|
|
30
|
+
}) => {
|
|
22
31
|
const t = useTranslations();
|
|
23
32
|
const { id, unit } = automate;
|
|
24
|
-
const { navigate } = useNavigation();
|
|
25
33
|
|
|
26
34
|
const { name: currentScreenName } = useRoute();
|
|
27
35
|
const permissions = useBackendPermission();
|
|
@@ -99,6 +107,26 @@ const AddActionScript = memo(
|
|
|
99
107
|
}
|
|
100
108
|
},
|
|
101
109
|
},
|
|
110
|
+
{
|
|
111
|
+
id: 'sms_alarm',
|
|
112
|
+
text: t('sms_alarm'),
|
|
113
|
+
image: <Sms />,
|
|
114
|
+
describe: t('only_in_local_control'),
|
|
115
|
+
onClick: () => {
|
|
116
|
+
setIsVisible(false);
|
|
117
|
+
if (unit) {
|
|
118
|
+
navigate(Routes.SetupScriptSms, {
|
|
119
|
+
automate,
|
|
120
|
+
unitId: unit,
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
123
|
+
navigate(Routes.SelectUnit, {
|
|
124
|
+
automate,
|
|
125
|
+
routeName: Routes.SetupScriptSms,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
},
|
|
102
130
|
];
|
|
103
131
|
}, [
|
|
104
132
|
automate,
|
|
@@ -126,22 +154,27 @@ const AddActionScript = memo(
|
|
|
126
154
|
<View style={styles.modalHeader}>
|
|
127
155
|
<Text style={styles.modalHeaderText}>{t('add_action')}</Text>
|
|
128
156
|
</View>
|
|
129
|
-
{listItem.map((item, index) =>
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
157
|
+
{listItem.map((item, index) => {
|
|
158
|
+
if (item.id === 'sms_alarm' && type === AUTOMATE_TYPE.ONE_TAP) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
return (
|
|
162
|
+
<View style={styles.rowItem} key={`rowItem-${index}`}>
|
|
163
|
+
<TouchableOpacity
|
|
164
|
+
onPress={item.onClick}
|
|
165
|
+
accessibilityLabel={
|
|
166
|
+
AccessibilityLabel.AUTOMATE_LIST_SCRIPT_ACTION
|
|
167
|
+
}
|
|
168
|
+
>
|
|
169
|
+
<View style={styles.wapItem}>
|
|
170
|
+
<View style={styles.imageItem}>{item.image}</View>
|
|
171
|
+
<Text style={styles.textItem}>{item.text}</Text>
|
|
172
|
+
<IconOutline name="right" />
|
|
173
|
+
</View>
|
|
174
|
+
</TouchableOpacity>
|
|
175
|
+
</View>
|
|
176
|
+
);
|
|
177
|
+
})}
|
|
145
178
|
</View>
|
|
146
179
|
</View>
|
|
147
180
|
</ModalCustom>
|
|
@@ -53,8 +53,7 @@ export default StyleSheet.create({
|
|
|
53
53
|
flexDirection: 'row',
|
|
54
54
|
alignItems: 'center',
|
|
55
55
|
justifyContent: 'space-between',
|
|
56
|
-
|
|
57
|
-
marginBottom: 16,
|
|
56
|
+
marginBottom: 7,
|
|
58
57
|
},
|
|
59
58
|
editButton: {
|
|
60
59
|
height: 40,
|
|
@@ -184,4 +183,42 @@ export default StyleSheet.create({
|
|
|
184
183
|
justifyContent: 'center',
|
|
185
184
|
alignItems: 'center',
|
|
186
185
|
},
|
|
186
|
+
width40: {
|
|
187
|
+
width: '40%',
|
|
188
|
+
},
|
|
189
|
+
popoverStyle: {
|
|
190
|
+
width: '100%',
|
|
191
|
+
backgroundColor: Colors.White,
|
|
192
|
+
borderRadius: 5,
|
|
193
|
+
},
|
|
194
|
+
localControl: {
|
|
195
|
+
flexDirection: 'row',
|
|
196
|
+
alignItems: 'center',
|
|
197
|
+
maxWidth: 190,
|
|
198
|
+
marginRight: 5,
|
|
199
|
+
},
|
|
200
|
+
card: {
|
|
201
|
+
marginRight: 0,
|
|
202
|
+
padding: 10,
|
|
203
|
+
},
|
|
204
|
+
marginLeft5: {
|
|
205
|
+
marginLeft: 5,
|
|
206
|
+
},
|
|
207
|
+
textDisable: {
|
|
208
|
+
marginLeft: 15,
|
|
209
|
+
marginTop: 15,
|
|
210
|
+
marginBottom: 15,
|
|
211
|
+
flexDirection: 'row',
|
|
212
|
+
justifyContent: 'space-between',
|
|
213
|
+
},
|
|
214
|
+
listChip: {
|
|
215
|
+
marginLeft: 15,
|
|
216
|
+
marginBottom: 15,
|
|
217
|
+
flexDirection: 'row',
|
|
218
|
+
justifyContent: 'space-between',
|
|
219
|
+
},
|
|
220
|
+
checked: {
|
|
221
|
+
marginRight: 15,
|
|
222
|
+
color: Colors.Primary,
|
|
223
|
+
},
|
|
187
224
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { BackHandler, Platform } from 'react-native';
|
|
2
3
|
import { create, act } from 'react-test-renderer';
|
|
3
4
|
import Toast from 'react-native-toast-message';
|
|
4
5
|
import { useNavigation } from '@react-navigation/native';
|
|
@@ -40,10 +41,12 @@ describe('Test ScriptDetail', () => {
|
|
|
40
41
|
const mockGoBack = useNavigation().goBack;
|
|
41
42
|
const mockAddListener = useNavigation().addListener;
|
|
42
43
|
const mockedNavigate = useNavigation().navigate;
|
|
44
|
+
const mockedDispatch = useNavigation().dispatch;
|
|
43
45
|
beforeEach(() => {
|
|
44
46
|
mockGoBack.mockClear();
|
|
45
47
|
mockAddListener.mockClear();
|
|
46
48
|
mockedNavigate.mockClear();
|
|
49
|
+
mockedDispatch.mockClear();
|
|
47
50
|
global.mockedNavigate.mockClear();
|
|
48
51
|
mock.reset();
|
|
49
52
|
route = {
|
|
@@ -108,6 +111,34 @@ describe('Test ScriptDetail', () => {
|
|
|
108
111
|
};
|
|
109
112
|
});
|
|
110
113
|
|
|
114
|
+
const expectMockedDispatch = (screen, screenParams) => {
|
|
115
|
+
const mockState = {
|
|
116
|
+
routes: [{ name: 'Home' }],
|
|
117
|
+
};
|
|
118
|
+
const updatedState = mockedDispatch.mock.calls[0][0](mockState);
|
|
119
|
+
expect(updatedState).toEqual({
|
|
120
|
+
type: 'RESET',
|
|
121
|
+
payload: {
|
|
122
|
+
index: 2,
|
|
123
|
+
routes: [
|
|
124
|
+
{
|
|
125
|
+
name: 'Home',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: Routes.ScriptDetail,
|
|
129
|
+
params: route.params,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: screen,
|
|
133
|
+
params: screenParams,
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
expect(mockedDispatch).toHaveBeenCalledTimes(1);
|
|
139
|
+
mockedDispatch.mockClear();
|
|
140
|
+
};
|
|
141
|
+
|
|
111
142
|
it('test rename script', async () => {
|
|
112
143
|
await act(async () => {
|
|
113
144
|
tree = await create(wrapComponent(route));
|
|
@@ -367,56 +398,41 @@ describe('Test ScriptDetail', () => {
|
|
|
367
398
|
AccessibilityLabel.AUTOMATE_LIST_SCRIPT_ACTION &&
|
|
368
399
|
el.type === TouchableOpacity
|
|
369
400
|
);
|
|
370
|
-
expect(listScriptActions).toHaveLength(
|
|
401
|
+
expect(listScriptActions).toHaveLength(5);
|
|
371
402
|
await act(async () => {
|
|
372
403
|
await listScriptActions[0].props.onPress();
|
|
373
404
|
});
|
|
374
405
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
routeName: null,
|
|
383
|
-
}
|
|
384
|
-
);
|
|
385
|
-
mockedNavigate.mockClear();
|
|
406
|
+
expectMockedDispatch(Routes.SelectControlDevices, {
|
|
407
|
+
unitId: route.params.preAutomate.unit,
|
|
408
|
+
automateId: route.params.preAutomate.id,
|
|
409
|
+
numberActionCanAdd: 2,
|
|
410
|
+
closeScreen: undefined,
|
|
411
|
+
routeName: null,
|
|
412
|
+
});
|
|
386
413
|
await act(async () => {
|
|
387
414
|
await listScriptActions[1].props.onPress();
|
|
388
415
|
});
|
|
389
416
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
unitId: route.params.preAutomate.unit,
|
|
395
|
-
}
|
|
396
|
-
);
|
|
397
|
-
mockedNavigate.mockClear();
|
|
417
|
+
expectMockedDispatch(Routes.SetupScriptNotify, {
|
|
418
|
+
automate: route.params.preAutomate,
|
|
419
|
+
unitId: route.params.preAutomate.unit,
|
|
420
|
+
});
|
|
398
421
|
await act(async () => {
|
|
399
422
|
await listScriptActions[2].props.onPress();
|
|
400
423
|
});
|
|
401
424
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
automate: route.params.preAutomate,
|
|
406
|
-
}
|
|
407
|
-
);
|
|
408
|
-
mockedNavigate.mockClear();
|
|
425
|
+
expectMockedDispatch(Routes.SetupScriptDelay, {
|
|
426
|
+
automate: route.params.preAutomate,
|
|
427
|
+
});
|
|
409
428
|
await act(async () => {
|
|
410
429
|
await listScriptActions[3].props.onPress();
|
|
411
430
|
});
|
|
412
431
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
unitId: route.params.preAutomate.unit,
|
|
418
|
-
}
|
|
419
|
-
);
|
|
432
|
+
expectMockedDispatch(Routes.SetupScriptEmail, {
|
|
433
|
+
automate: route.params.preAutomate,
|
|
434
|
+
unitId: route.params.preAutomate.unit,
|
|
435
|
+
});
|
|
420
436
|
});
|
|
421
437
|
|
|
422
438
|
it('test press disable script', async () => {
|
|
@@ -596,11 +612,35 @@ describe('Test ScriptDetail', () => {
|
|
|
596
612
|
menuActionMore.props.onItemClick({ doAction: jest.fn() });
|
|
597
613
|
menuActionMore.props.listMenuItem[2].doAction();
|
|
598
614
|
});
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
615
|
+
|
|
616
|
+
const mockState = {
|
|
617
|
+
routes: [{ name: 'Home' }],
|
|
618
|
+
};
|
|
619
|
+
const updatedState = mockedDispatch.mock.calls[0][0](mockState);
|
|
620
|
+
expect(updatedState).toEqual({
|
|
621
|
+
type: 'RESET',
|
|
622
|
+
payload: {
|
|
623
|
+
index: 2,
|
|
624
|
+
routes: [
|
|
625
|
+
{
|
|
626
|
+
name: 'Home',
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
name: Routes.ScriptDetail,
|
|
630
|
+
params: route.params,
|
|
631
|
+
},
|
|
632
|
+
{
|
|
633
|
+
name: Routes.AddUnknownTypeSmart,
|
|
634
|
+
params: {
|
|
635
|
+
automate: automate,
|
|
636
|
+
closeScreen: undefined,
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
],
|
|
640
|
+
},
|
|
602
641
|
});
|
|
603
|
-
|
|
642
|
+
expect(mockedDispatch).toHaveBeenCalledTimes(1);
|
|
643
|
+
|
|
604
644
|
expect(menuActionMore.props.listMenuItem[0].text).toEqual('Device display');
|
|
605
645
|
await act(async () => {
|
|
606
646
|
menuActionMore.props.listMenuItem[0].doAction();
|
|
@@ -705,6 +745,7 @@ describe('Test ScriptDetail', () => {
|
|
|
705
745
|
});
|
|
706
746
|
|
|
707
747
|
it('test navigate to UnitDetail on event beforeRemove', async () => {
|
|
748
|
+
Platform.OS = 'ios';
|
|
708
749
|
route.params.closeScreen = Routes.UnitDetail;
|
|
709
750
|
route.params.preAutomate.unit = 2;
|
|
710
751
|
|
|
@@ -729,4 +770,31 @@ describe('Test ScriptDetail', () => {
|
|
|
729
770
|
unitId: 2,
|
|
730
771
|
});
|
|
731
772
|
});
|
|
773
|
+
|
|
774
|
+
it('test navigate to UnitDetail on event hardwareBackPress', async () => {
|
|
775
|
+
Platform.OS = 'android';
|
|
776
|
+
jest.spyOn(BackHandler, 'addEventListener');
|
|
777
|
+
route.params.closeScreen = Routes.UnitDetail;
|
|
778
|
+
route.params.preAutomate.unit = 2;
|
|
779
|
+
|
|
780
|
+
await act(async () => {
|
|
781
|
+
await create(wrapComponent(route));
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
expect(BackHandler.addEventListener).toHaveBeenCalledWith(
|
|
785
|
+
'hardwareBackPress',
|
|
786
|
+
expect.any(Function)
|
|
787
|
+
);
|
|
788
|
+
const backPressHandler = BackHandler.addEventListener.mock.calls.find(
|
|
789
|
+
([eventName]) => eventName === 'hardwareBackPress'
|
|
790
|
+
)[1];
|
|
791
|
+
|
|
792
|
+
await act(async () => {
|
|
793
|
+
backPressHandler();
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
expect(mockedNavigate).toHaveBeenCalledWith(Routes.UnitDetail, {
|
|
797
|
+
unitId: 2,
|
|
798
|
+
});
|
|
799
|
+
});
|
|
732
800
|
});
|