@eohjsc/react-native-smart-city 0.2.67 → 0.2.71
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/Popover/Dashboard/SmartAccount.svg +5 -0
- package/assets/images/scan-qr-gateway.svg +14 -0
- package/assets/images/wifi-gateway.svg +18 -0
- package/assets/images/wifi.svg +3 -0
- package/package.json +3 -1
- package/src/Images/Common/buttonLeftCurtain@2x.png +0 -0
- package/src/Images/Common/buttonLeftCurtain@3x.png +0 -0
- package/src/Images/Common/{buttonPause-center-curtain.png → buttonPauseCurtain.png} +0 -0
- package/src/Images/Common/buttonPauseCurtain@2x.png +0 -0
- package/src/Images/Common/buttonPauseCurtain@3x.png +0 -0
- package/src/Images/Common/buttonRightCurtain@2x.png +0 -0
- package/src/Images/Common/buttonRightCurtain@3x.png +0 -0
- package/src/commons/Action/ItemQuickAction.js +4 -3
- package/src/commons/ActionGroup/CurtainButtonTemplate.js +0 -30
- package/src/commons/ActionGroup/CurtainButtonTemplateStyle.js +0 -12
- package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +1 -1
- package/src/commons/AlertAction/index.js +4 -3
- package/src/commons/CameraDevice/index.js +1 -1
- package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +70 -0
- package/src/commons/Device/HistoryChart.js +18 -18
- package/src/commons/Device/HorizontalBarChart.js +1 -2
- package/src/commons/Device/ItemDevice.js +1 -13
- package/src/commons/Device/LinearChart.js +13 -3
- package/src/commons/Device/WaterQualitySensor/QualityIndicatorsItem.js +1 -1
- package/src/commons/SubUnit/OneTap/OneTapStyles.js +14 -5
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +5 -68
- package/src/commons/SubUnit/OneTap/index.js +24 -33
- package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +29 -0
- package/src/commons/UnitSummary/ConfigHistoryChart.js +4 -6
- package/src/commons/ViewButtonBottom/index.js +4 -0
- package/src/configs/API.js +2 -0
- package/src/configs/BLE.js +3 -0
- package/src/configs/Constants.js +2 -0
- package/src/configs/Images.js +1 -1
- package/src/context/SCContext.tsx +2 -0
- package/src/iot/RemoteControl/Bluetooth.js +34 -6
- package/src/iot/RemoteControl/__test__/Bluetooth.test.js +1 -0
- package/src/iot/RemoteControl/__test__/index.mock.js +1 -0
- package/src/iot/RemoteControl/index.js +7 -2
- package/src/navigations/AddDeviceStack.js +2 -0
- package/src/navigations/AddGatewayStack.js +11 -0
- package/src/navigations/AddLGDeviceStack.js +2 -0
- package/src/navigations/AddMemberStack.js +2 -0
- package/src/navigations/AddSubUnitStack.js +2 -0
- package/src/navigations/AddUnitStack.js +2 -0
- package/src/navigations/EmergencyContactsStack.js +2 -0
- package/src/navigations/SharedStack.js +2 -0
- package/src/navigations/UnitStack.js +2 -0
- package/src/navigations/utils.js +3 -0
- package/src/screens/AddCommon/SelectSubUnit.js +12 -2
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +190 -0
- package/src/screens/AddNewGateway/PlugAndPlay/FirstWarning.js +73 -0
- package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +154 -0
- package/src/screens/AddNewGateway/PlugAndPlay/__test__/FirstWarning.test.js +60 -0
- package/src/screens/AddNewGateway/PlugAndPlay/__test__/GatewayWifiList.test.js +35 -0
- package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +90 -0
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +0 -22
- package/src/screens/AddNewOneTap/index.js +15 -13
- package/src/screens/Device/components/SensorDisplayItem.js +4 -2
- package/src/screens/Notification/components/NotificationItem.js +24 -1
- package/src/screens/Notification/styles/NotificationItemStyles.js +1 -1
- package/src/screens/ScanChipQR/hooks/index.js +14 -5
- package/src/screens/SharedUnit/index.js +7 -5
- package/src/screens/Sharing/Components/SensorItem.js +27 -12
- package/src/screens/Sharing/Components/Styles/SensorItemStyles.js +4 -0
- package/src/screens/Sharing/SelectPermission.js +44 -32
- package/src/screens/Sharing/SelectUser.js +13 -1
- package/src/screens/Sharing/__test__/SelectPermission.test.js +2 -1
- package/src/screens/SubUnit/AddSubUnit.js +4 -1
- package/src/screens/Unit/AddMenu.js +15 -0
- package/src/screens/Unit/Detail.js +15 -4
- package/src/screens/Unit/SmartAccount.js +36 -15
- package/src/screens/Unit/SmartAccountStyles.js +20 -0
- package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +10 -6
- package/src/screens/Unit/hook/useStateAlertRemove.js +4 -6
- package/src/screens/UnitSummary/components/PowerConsumption/index.js +2 -4
- package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +10 -6
- package/src/utils/I18n/translations/en.json +33 -4
- package/src/utils/I18n/translations/vi.json +34 -4
- package/src/utils/Route/index.js +4 -0
- package/src/utils/Utils.js +0 -4
- package/src/commons/ActionGroup/__test__/MenuActionAddSchedule.test.js +0 -71
- package/src/commons/ActionGroup/hooks/AccessScheduleDetailStyles.js +0 -41
- package/src/commons/ActionGroup/hooks/MenuActionAddSchedule.js +0 -110
- package/src/commons/ActionGroup/hooks/MenuActionAddScheduleStyle.js +0 -69
- package/src/commons/ActionGroup/hooks/RecurringDetail.js +0 -97
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import React, { memo, useEffect, useState, useCallback } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
Text,
|
|
6
|
+
PermissionsAndroid,
|
|
7
|
+
Platform,
|
|
8
|
+
ActivityIndicator,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import WifiManager from 'react-native-wifi-reborn';
|
|
11
|
+
import { useNavigation } from '@react-navigation/native';
|
|
12
|
+
import { ToastBottomHelper } from '../../../utils/Utils';
|
|
13
|
+
import dgram from 'react-native-udp';
|
|
14
|
+
import { HeaderCustom } from '../../../commons/Header';
|
|
15
|
+
import ScanQrGateway from '../../../../assets/images/scan-qr-gateway.svg';
|
|
16
|
+
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
17
|
+
import { getBottomSpace } from 'react-native-iphone-x-helper';
|
|
18
|
+
import BottomButtonView from '../../../commons/BottomButtonView';
|
|
19
|
+
import { Colors, API } from '../../../configs';
|
|
20
|
+
import { axiosPost } from '../../../utils/Apis/axios';
|
|
21
|
+
import Routes from '../../../utils/Route';
|
|
22
|
+
|
|
23
|
+
const socket = dgram.createSocket({ type: 'udp4' });
|
|
24
|
+
|
|
25
|
+
socket.once('listening', function () {
|
|
26
|
+
socket.send(
|
|
27
|
+
JSON.stringify({ type: 'scan', data: { wifi: '' } }),
|
|
28
|
+
undefined,
|
|
29
|
+
undefined,
|
|
30
|
+
54321,
|
|
31
|
+
'192.168.27.1',
|
|
32
|
+
undefined
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const ConnectWifiWarning = memo(({ route }) => {
|
|
37
|
+
const { wifi_ssid, wifi_pass, unit_id, chip_id } = route.params;
|
|
38
|
+
const t = useTranslations();
|
|
39
|
+
const { navigate } = useNavigation();
|
|
40
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
41
|
+
|
|
42
|
+
socket.on('message', function (msg, rinfo) {
|
|
43
|
+
const data = JSON.parse(msg.toString());
|
|
44
|
+
if (data.hasOwnProperty('wifi')) {
|
|
45
|
+
navigate(Routes.GatewayWifiList, {
|
|
46
|
+
list_wifi: data.wifi,
|
|
47
|
+
unit_id: unit_id,
|
|
48
|
+
chip_id: chip_id,
|
|
49
|
+
socket: socket,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (data.hasOwnProperty('gateway')) {
|
|
53
|
+
navigate(Routes.Dashboard);
|
|
54
|
+
ToastBottomHelper.success(t('completed'));
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
socket.on('error', () => {
|
|
59
|
+
ToastBottomHelper.error(t('server_error'));
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const getPermissionWifiAndroid = useCallback(async () => {
|
|
63
|
+
const granted = await PermissionsAndroid.request(
|
|
64
|
+
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
|
|
65
|
+
{
|
|
66
|
+
title: t('location_permission_required_wifi_title'),
|
|
67
|
+
message: t('location_permission_required_wifi_message'),
|
|
68
|
+
buttonNegative: t('deny'),
|
|
69
|
+
buttonPositive: t('allow'),
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
|
|
73
|
+
ToastBottomHelper.success('GRANTED');
|
|
74
|
+
} else {
|
|
75
|
+
ToastBottomHelper.error('DENIED');
|
|
76
|
+
}
|
|
77
|
+
}, [t]);
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
Platform.OS === 'android' && getPermissionWifiAndroid();
|
|
81
|
+
socket.bind(54321);
|
|
82
|
+
}, [getPermissionWifiAndroid]);
|
|
83
|
+
|
|
84
|
+
const handleSend = async () => {
|
|
85
|
+
await socket.send(
|
|
86
|
+
JSON.stringify({ type: 'scan', data: { wifi: '' } }),
|
|
87
|
+
undefined,
|
|
88
|
+
undefined,
|
|
89
|
+
54321,
|
|
90
|
+
'192.168.27.1',
|
|
91
|
+
undefined
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (isLoading) {
|
|
97
|
+
handleSend();
|
|
98
|
+
}
|
|
99
|
+
}, [isLoading]);
|
|
100
|
+
|
|
101
|
+
const handleConnectWifiGateway = async () => {
|
|
102
|
+
setIsLoading(true);
|
|
103
|
+
const { success } = await axiosPost(API.UNIT.ADD_GATEWAY(unit_id), {
|
|
104
|
+
chip: chip_id,
|
|
105
|
+
});
|
|
106
|
+
if (success) {
|
|
107
|
+
ToastBottomHelper.success(t('add_gateway_success'));
|
|
108
|
+
}
|
|
109
|
+
// eslint-disable-next-line promise/prefer-await-to-then
|
|
110
|
+
WifiManager.connectToProtectedSSID(wifi_ssid, wifi_pass, false).then(
|
|
111
|
+
() => {
|
|
112
|
+
handleSend();
|
|
113
|
+
},
|
|
114
|
+
(e) => {
|
|
115
|
+
ToastBottomHelper.error('Connection failed!');
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<View style={styles.screen}>
|
|
122
|
+
{!isLoading ? (
|
|
123
|
+
<>
|
|
124
|
+
<HeaderCustom title={t('scan_qr')} isShowSeparator />
|
|
125
|
+
<View style={styles.container}>
|
|
126
|
+
<ScanQrGateway />
|
|
127
|
+
<View style={styles.content}>
|
|
128
|
+
<Text style={styles.text}>
|
|
129
|
+
{t('connecting_gateway_warning_1')}
|
|
130
|
+
</Text>
|
|
131
|
+
<Text style={styles.text}>
|
|
132
|
+
{t('connecting_gateway_warning_2')}
|
|
133
|
+
</Text>
|
|
134
|
+
</View>
|
|
135
|
+
</View>
|
|
136
|
+
<BottomButtonView
|
|
137
|
+
style={styles.viewBottomFixed}
|
|
138
|
+
mainTitle={t('ok')}
|
|
139
|
+
onPressMain={handleConnectWifiGateway}
|
|
140
|
+
typeMain={'primary'}
|
|
141
|
+
/>
|
|
142
|
+
</>
|
|
143
|
+
) : (
|
|
144
|
+
<View style={styles.centerLoading}>
|
|
145
|
+
<ActivityIndicator color={Colors.Primary} size={'small'} />
|
|
146
|
+
<Text>{t('connecting')}</Text>
|
|
147
|
+
</View>
|
|
148
|
+
)}
|
|
149
|
+
</View>
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
export default ConnectWifiWarning;
|
|
154
|
+
|
|
155
|
+
const styles = StyleSheet.create({
|
|
156
|
+
viewBottomFixed: {
|
|
157
|
+
position: 'absolute',
|
|
158
|
+
bottom: 0,
|
|
159
|
+
left: 0,
|
|
160
|
+
right: 0,
|
|
161
|
+
paddingBottom: getBottomSpace() > 0 ? getBottomSpace() : 32,
|
|
162
|
+
paddingTop: 24,
|
|
163
|
+
backgroundColor: Colors.Gray2,
|
|
164
|
+
borderColor: Colors.ShadownTransparent,
|
|
165
|
+
borderTopWidth: 1,
|
|
166
|
+
},
|
|
167
|
+
screen: {
|
|
168
|
+
flex: 1,
|
|
169
|
+
backgroundColor: Colors.Gray2,
|
|
170
|
+
},
|
|
171
|
+
container: {
|
|
172
|
+
flex: 1,
|
|
173
|
+
alignItems: 'center',
|
|
174
|
+
marginTop: 50,
|
|
175
|
+
},
|
|
176
|
+
content: {
|
|
177
|
+
alignItems: 'center',
|
|
178
|
+
width: '80%',
|
|
179
|
+
marginTop: 50,
|
|
180
|
+
},
|
|
181
|
+
text: {
|
|
182
|
+
textAlign: 'center',
|
|
183
|
+
lineHeight: 24,
|
|
184
|
+
},
|
|
185
|
+
centerLoading: {
|
|
186
|
+
flex: 1,
|
|
187
|
+
justifyContent: 'center',
|
|
188
|
+
alignItems: 'center',
|
|
189
|
+
},
|
|
190
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React, { memo, useCallback } from 'react';
|
|
2
|
+
import { View, StyleSheet, Text } from 'react-native';
|
|
3
|
+
import { HeaderCustom } from '../../../commons/Header';
|
|
4
|
+
import { useNavigation } from '@react-navigation/native';
|
|
5
|
+
import Routes from '../../../utils/Route';
|
|
6
|
+
import WifiGateway from '../../../../assets/images/wifi-gateway.svg';
|
|
7
|
+
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
8
|
+
import { ViewButtonBottom } from '../../../commons';
|
|
9
|
+
import { Colors } from '../../../configs';
|
|
10
|
+
|
|
11
|
+
const FirstWarning = memo(({ route }) => {
|
|
12
|
+
const { unit_id } = route.params;
|
|
13
|
+
const t = useTranslations();
|
|
14
|
+
const { goBack, navigate } = useNavigation();
|
|
15
|
+
|
|
16
|
+
const onRight = useCallback(() => {
|
|
17
|
+
navigate(Routes.ScanChipQR, {
|
|
18
|
+
unit_id: unit_id,
|
|
19
|
+
});
|
|
20
|
+
}, [navigate, unit_id]);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<View style={styles.screen}>
|
|
24
|
+
<HeaderCustom title={t('add_new_device')} isShowSeparator />
|
|
25
|
+
<View style={styles.container}>
|
|
26
|
+
<Text style={styles.warningBetaTest}>
|
|
27
|
+
{t('warning_beta_test_feature')}
|
|
28
|
+
</Text>
|
|
29
|
+
<WifiGateway />
|
|
30
|
+
<View style={styles.content}>
|
|
31
|
+
<Text style={styles.text}>{t('gateway_warning_content_1')}</Text>
|
|
32
|
+
<Text style={styles.text}>{t('gateway_warning_content_2')}</Text>
|
|
33
|
+
<Text style={styles.text}>{t('gateway_warning_content_3')}</Text>
|
|
34
|
+
<Text style={styles.text}>{t('gateway_warning_content_4')}</Text>
|
|
35
|
+
</View>
|
|
36
|
+
</View>
|
|
37
|
+
<ViewButtonBottom
|
|
38
|
+
leftTitle={t('text_back')}
|
|
39
|
+
onLeftClick={goBack}
|
|
40
|
+
rightTitle={t('text_next')}
|
|
41
|
+
onRightClick={onRight}
|
|
42
|
+
/>
|
|
43
|
+
</View>
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export default FirstWarning;
|
|
48
|
+
|
|
49
|
+
const styles = StyleSheet.create({
|
|
50
|
+
screen: {
|
|
51
|
+
flex: 1,
|
|
52
|
+
},
|
|
53
|
+
container: {
|
|
54
|
+
flex: 1,
|
|
55
|
+
alignItems: 'center',
|
|
56
|
+
marginTop: 50,
|
|
57
|
+
},
|
|
58
|
+
content: {
|
|
59
|
+
alignItems: 'center',
|
|
60
|
+
width: '80%',
|
|
61
|
+
marginTop: 50,
|
|
62
|
+
},
|
|
63
|
+
text: {
|
|
64
|
+
textAlign: 'center',
|
|
65
|
+
lineHeight: 24,
|
|
66
|
+
},
|
|
67
|
+
warningBetaTest: {
|
|
68
|
+
textAlign: 'center',
|
|
69
|
+
lineHeight: 24,
|
|
70
|
+
paddingBottom: 30,
|
|
71
|
+
color: Colors.Red,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import React, { memo, useState, useCallback } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
TouchableOpacity,
|
|
6
|
+
ScrollView,
|
|
7
|
+
TextInput,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import { HeaderCustom } from '../../../commons/Header';
|
|
10
|
+
import { Colors } from '../../../configs';
|
|
11
|
+
import Text from '../../../commons/Text';
|
|
12
|
+
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
13
|
+
import WifiIcon from '../../../../assets/images/wifi.svg';
|
|
14
|
+
import ButtonPopup from '../../../commons/ButtonPopup';
|
|
15
|
+
|
|
16
|
+
const GatewayWifiList = memo(({ route }) => {
|
|
17
|
+
const { list_wifi, socket } = route.params;
|
|
18
|
+
const t = useTranslations();
|
|
19
|
+
|
|
20
|
+
const [isShowPopupPassword, setIsShowPopupPassword] = useState(false);
|
|
21
|
+
const [password, setPassword] = useState('');
|
|
22
|
+
const [selectedWifi, setSelectedWifi] = useState('');
|
|
23
|
+
|
|
24
|
+
const showPopupPassword = (ssid) => {
|
|
25
|
+
setIsShowPopupPassword(true);
|
|
26
|
+
setSelectedWifi(ssid);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const onPasswordChange = useCallback(
|
|
30
|
+
(password) => {
|
|
31
|
+
setPassword(password.toString());
|
|
32
|
+
},
|
|
33
|
+
[setPassword]
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const connectWifi = async () => {
|
|
37
|
+
await socket.send(
|
|
38
|
+
JSON.stringify({
|
|
39
|
+
type: 'connect',
|
|
40
|
+
data: { wifi: { ssid: selectedWifi, pass: password } },
|
|
41
|
+
}),
|
|
42
|
+
undefined,
|
|
43
|
+
undefined,
|
|
44
|
+
54321,
|
|
45
|
+
'192.168.27.1',
|
|
46
|
+
undefined
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<View style={styles.screen}>
|
|
52
|
+
<HeaderCustom title={t('connect_device')} isShowSeparator />
|
|
53
|
+
<View>
|
|
54
|
+
<Text style={styles.title} semibold type="H3">
|
|
55
|
+
{t('set_network')}
|
|
56
|
+
</Text>
|
|
57
|
+
<Text style={styles.subTitle} type="Body">
|
|
58
|
+
{t('select_wifi')}
|
|
59
|
+
</Text>
|
|
60
|
+
|
|
61
|
+
<ScrollView style={styles.listContainer}>
|
|
62
|
+
{!!list_wifi.length &&
|
|
63
|
+
list_wifi.map((item, index) => (
|
|
64
|
+
<TouchableOpacity
|
|
65
|
+
key={index}
|
|
66
|
+
style={styles.listItem}
|
|
67
|
+
onPress={() => showPopupPassword(item.ssid)}
|
|
68
|
+
>
|
|
69
|
+
<Text type="H4" style={styles.textItem}>
|
|
70
|
+
{item.ssid}
|
|
71
|
+
</Text>
|
|
72
|
+
<View style={styles.wifiIcon}>
|
|
73
|
+
<WifiIcon />
|
|
74
|
+
</View>
|
|
75
|
+
</TouchableOpacity>
|
|
76
|
+
))}
|
|
77
|
+
</ScrollView>
|
|
78
|
+
</View>
|
|
79
|
+
|
|
80
|
+
<ButtonPopup
|
|
81
|
+
visible={isShowPopupPassword}
|
|
82
|
+
mainTitle={t('connect')}
|
|
83
|
+
onPressMain={() => connectWifi()}
|
|
84
|
+
secondaryTitle={t('cancel')}
|
|
85
|
+
onPressSecondary={() => setIsShowPopupPassword(false)}
|
|
86
|
+
hideClose={true}
|
|
87
|
+
>
|
|
88
|
+
<>
|
|
89
|
+
<Text>{t('enter_wifi_password')}</Text>
|
|
90
|
+
<TextInput
|
|
91
|
+
secureTextEntry={true}
|
|
92
|
+
style={styles.input}
|
|
93
|
+
onChangeText={onPasswordChange}
|
|
94
|
+
value={password}
|
|
95
|
+
/>
|
|
96
|
+
</>
|
|
97
|
+
</ButtonPopup>
|
|
98
|
+
</View>
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
export default GatewayWifiList;
|
|
103
|
+
|
|
104
|
+
const styles = StyleSheet.create({
|
|
105
|
+
screen: {
|
|
106
|
+
flex: 1,
|
|
107
|
+
backgroundColor: Colors.Gray2,
|
|
108
|
+
},
|
|
109
|
+
title: {
|
|
110
|
+
marginVertical: 16,
|
|
111
|
+
marginLeft: 16,
|
|
112
|
+
},
|
|
113
|
+
subTitle: {
|
|
114
|
+
marginBottom: 16,
|
|
115
|
+
marginLeft: 16,
|
|
116
|
+
},
|
|
117
|
+
listContainer: {
|
|
118
|
+
borderWidth: 1,
|
|
119
|
+
backgroundColor: Colors.White,
|
|
120
|
+
borderRadius: 20,
|
|
121
|
+
borderColor: Colors.Gray4,
|
|
122
|
+
},
|
|
123
|
+
listItem: {
|
|
124
|
+
borderBottomColor: Colors.Gray4,
|
|
125
|
+
flex: 1,
|
|
126
|
+
flexDirection: 'row',
|
|
127
|
+
justifyContent: 'space-between',
|
|
128
|
+
alignItems: 'center',
|
|
129
|
+
},
|
|
130
|
+
textItem: {
|
|
131
|
+
paddingVertical: 16,
|
|
132
|
+
paddingLeft: 16,
|
|
133
|
+
},
|
|
134
|
+
firstItem: {
|
|
135
|
+
paddingTop: 32,
|
|
136
|
+
paddingBottom: 16,
|
|
137
|
+
paddingLeft: 16,
|
|
138
|
+
},
|
|
139
|
+
lastItem: {
|
|
140
|
+
paddingBottom: 32,
|
|
141
|
+
paddingTop: 16,
|
|
142
|
+
paddingLeft: 16,
|
|
143
|
+
},
|
|
144
|
+
wifiIcon: {
|
|
145
|
+
paddingRight: 16,
|
|
146
|
+
},
|
|
147
|
+
input: {
|
|
148
|
+
height: 40,
|
|
149
|
+
marginVertical: 12,
|
|
150
|
+
borderWidth: 1,
|
|
151
|
+
padding: 10,
|
|
152
|
+
borderColor: Colors.Gray5,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer, { act, create } from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import FirstWarning from '../FirstWarning';
|
|
5
|
+
import { Text } from 'react-native';
|
|
6
|
+
import { getTranslate } from '../../../../utils/I18n';
|
|
7
|
+
import { SCProvider } from '../../../../context';
|
|
8
|
+
import { mockSCStore } from '../../../../context/mockStore';
|
|
9
|
+
import { ViewButtonBottom } from '../../../../commons';
|
|
10
|
+
|
|
11
|
+
const mockedGoBack = jest.fn();
|
|
12
|
+
const mockedNavigate = jest.fn();
|
|
13
|
+
jest.mock('@react-navigation/native', () => {
|
|
14
|
+
return {
|
|
15
|
+
...jest.requireActual('@react-navigation/native'),
|
|
16
|
+
useNavigation: () => ({
|
|
17
|
+
navigate: mockedNavigate,
|
|
18
|
+
goBack: mockedGoBack,
|
|
19
|
+
}),
|
|
20
|
+
useIsFocused: () => ({}),
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const wrapComponent = (route) => (
|
|
25
|
+
<SCProvider initState={mockSCStore({})}>
|
|
26
|
+
<FirstWarning route={route} />
|
|
27
|
+
</SCProvider>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
describe('Test FirstWarning', () => {
|
|
31
|
+
let tree;
|
|
32
|
+
let route = { params: { unit_id: 1 } };
|
|
33
|
+
|
|
34
|
+
test('create', async () => {
|
|
35
|
+
await act(async () => {
|
|
36
|
+
tree = await create(wrapComponent(route));
|
|
37
|
+
});
|
|
38
|
+
const instance = tree.root;
|
|
39
|
+
const texts = instance.findAllByType(Text);
|
|
40
|
+
expect(texts).toHaveLength(8);
|
|
41
|
+
expect(texts[1].props.children).toEqual(
|
|
42
|
+
getTranslate('en', 'warning_beta_test_feature')
|
|
43
|
+
);
|
|
44
|
+
expect(texts[2].props.children).toEqual(
|
|
45
|
+
getTranslate('en', 'gateway_warning_content_1')
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('test ViewButtonBottom onRightClick', async () => {
|
|
50
|
+
await act(async () => {
|
|
51
|
+
tree = renderer.create(wrapComponent(route));
|
|
52
|
+
});
|
|
53
|
+
const instance = tree.root;
|
|
54
|
+
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
55
|
+
act(() => {
|
|
56
|
+
viewButtonBottom.props.onRightClick();
|
|
57
|
+
});
|
|
58
|
+
expect(mockedNavigate).toHaveBeenCalled();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { act, create } from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import GatewayWifiList from '../GatewayWifiList';
|
|
5
|
+
import { Text } from 'react-native';
|
|
6
|
+
import { getTranslate } from '../../../../utils/I18n';
|
|
7
|
+
import { SCProvider } from '../../../../context';
|
|
8
|
+
import { mockSCStore } from '../../../../context/mockStore';
|
|
9
|
+
|
|
10
|
+
const wrapComponent = (route) => (
|
|
11
|
+
<SCProvider initState={mockSCStore({})}>
|
|
12
|
+
<GatewayWifiList route={route} />
|
|
13
|
+
</SCProvider>
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
describe('Test GatewayWifiList', () => {
|
|
17
|
+
let tree;
|
|
18
|
+
let route = {
|
|
19
|
+
params: {
|
|
20
|
+
list_wifi: [{ ssid: 'eoh@io' }, { ssid: 'eoh@ras.io' }],
|
|
21
|
+
socket: { send: jest.fn() },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
test('create', async () => {
|
|
26
|
+
await act(async () => {
|
|
27
|
+
tree = await create(wrapComponent(route));
|
|
28
|
+
});
|
|
29
|
+
const instance = tree.root;
|
|
30
|
+
const texts = instance.findAllByType(Text);
|
|
31
|
+
expect(texts).toHaveLength(8);
|
|
32
|
+
expect(texts[1].props.children).toEqual(getTranslate('en', 'set_network'));
|
|
33
|
+
expect(texts[3].props.children).toEqual('eoh@io');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { act, create } from 'react-test-renderer';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
|
|
5
|
+
import { TESTID } from '../../../configs/Constants';
|
|
6
|
+
import { SCProvider } from '../../../context';
|
|
7
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
8
|
+
import SetupGatewayWifi from '../SetupGatewayWifi';
|
|
9
|
+
import DisplayChecking from '../../../commons/DisplayChecking';
|
|
10
|
+
|
|
11
|
+
const wrapComponent = (route) => (
|
|
12
|
+
<SCProvider initState={mockSCStore({})}>
|
|
13
|
+
<SetupGatewayWifi route={route} />
|
|
14
|
+
</SCProvider>
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
jest.mock('axios');
|
|
18
|
+
|
|
19
|
+
jest.mock('react', () => {
|
|
20
|
+
return { ...jest.requireActual('react'), memo: (x) => x };
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const mockedNavigate = jest.fn();
|
|
24
|
+
const mockedGoBack = jest.fn();
|
|
25
|
+
|
|
26
|
+
jest.mock('@react-navigation/native', () => {
|
|
27
|
+
return {
|
|
28
|
+
...jest.requireActual('@react-navigation/native'),
|
|
29
|
+
useNavigation: () => ({
|
|
30
|
+
navigate: mockedNavigate,
|
|
31
|
+
goBack: mockedGoBack,
|
|
32
|
+
}),
|
|
33
|
+
useIsFocused: () => ({}),
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
jest.mock('../../../iot/RemoteControl/Bluetooth', () => {
|
|
38
|
+
const device = {
|
|
39
|
+
name: '1234567',
|
|
40
|
+
cancelConnection: jest.fn(),
|
|
41
|
+
connect: async () => ({
|
|
42
|
+
discoverAllServicesAndCharacteristics: async () => ({
|
|
43
|
+
writeCharacteristicWithResponseForService: async () => ({}),
|
|
44
|
+
monitorCharacteristicForService: async (x) => x,
|
|
45
|
+
}),
|
|
46
|
+
}),
|
|
47
|
+
monitorCharacteristicForService: async (x) => x,
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
...jest.requireActual('../../../iot/RemoteControl/Bluetooth'),
|
|
51
|
+
getDeviceByName: (x) => device,
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('Test SetupGatewayWifi', () => {
|
|
56
|
+
let tree;
|
|
57
|
+
let route;
|
|
58
|
+
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
axios.get.mockClear();
|
|
61
|
+
mockedNavigate.mockClear();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
route = {
|
|
66
|
+
params: {
|
|
67
|
+
unit_id: 1,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const getText = (instance, id) => {
|
|
73
|
+
return instance.find((el) => el.props.testID === id);
|
|
74
|
+
};
|
|
75
|
+
test('check displayLoadingConnect', async () => {
|
|
76
|
+
await act(async () => {
|
|
77
|
+
tree = await create(wrapComponent(route));
|
|
78
|
+
});
|
|
79
|
+
const instance = tree.root;
|
|
80
|
+
const rightButton = getText(
|
|
81
|
+
instance,
|
|
82
|
+
TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON
|
|
83
|
+
);
|
|
84
|
+
await act(async () => {
|
|
85
|
+
await rightButton.props.onPress();
|
|
86
|
+
});
|
|
87
|
+
const displayLoadingConnect = instance.findByType(DisplayChecking);
|
|
88
|
+
expect(displayLoadingConnect.props.visible).toBeTruthy();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -99,28 +99,6 @@ describe('test AddNewOneTap', () => {
|
|
|
99
99
|
await act(async () => {
|
|
100
100
|
await item[0].props.onPress();
|
|
101
101
|
});
|
|
102
|
-
expect(mockedNavigate).toHaveBeenCalledWith(Routes.ScriptDetail, {
|
|
103
|
-
havePermission: true,
|
|
104
|
-
id: 1,
|
|
105
|
-
type: 'one_tap',
|
|
106
|
-
name: 'Tap to up',
|
|
107
|
-
unit: {
|
|
108
|
-
id: 1,
|
|
109
|
-
},
|
|
110
|
-
isCreateScriptSuccess: true,
|
|
111
|
-
automate: {
|
|
112
|
-
id: 1,
|
|
113
|
-
script: {
|
|
114
|
-
id: 1,
|
|
115
|
-
name: 'William Miller',
|
|
116
|
-
},
|
|
117
|
-
type: 'one_tap',
|
|
118
|
-
unit: 1,
|
|
119
|
-
weekday_repeat: [],
|
|
120
|
-
},
|
|
121
|
-
isAutomateTab: false,
|
|
122
|
-
isMultiUnits: false,
|
|
123
|
-
});
|
|
124
102
|
});
|
|
125
103
|
test('create AddNewOneTap fail', async () => {
|
|
126
104
|
Platform.OS = 'android';
|
|
@@ -12,7 +12,7 @@ import Text from '../../commons/Text';
|
|
|
12
12
|
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
13
13
|
import { axiosPost, axiosPut } from '../../utils/Apis/axios';
|
|
14
14
|
import Routes from '../../utils/Route';
|
|
15
|
-
import { popAction } from '../../navigations/utils';
|
|
15
|
+
import { popAction, replace } from '../../navigations/utils';
|
|
16
16
|
import { AUTOMATE_TYPE } from '../../configs/Constants';
|
|
17
17
|
|
|
18
18
|
const AddNewOneTap = memo(({ route }) => {
|
|
@@ -41,17 +41,19 @@ const AddNewOneTap = memo(({ route }) => {
|
|
|
41
41
|
? await axiosPut(API.AUTOMATE.UPDATE_AUTOMATE(automateId), params)
|
|
42
42
|
: await axiosPost(API.AUTOMATE.CREATE_AUTOMATE(), params);
|
|
43
43
|
if (success) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
dispatch(
|
|
45
|
+
replace(Routes.ScriptDetail, {
|
|
46
|
+
unit: unit,
|
|
47
|
+
id: data.id,
|
|
48
|
+
name: name,
|
|
49
|
+
type: type,
|
|
50
|
+
automate: { ...automate, ...data },
|
|
51
|
+
havePermission: true,
|
|
52
|
+
isCreateScriptSuccess: true,
|
|
53
|
+
isAutomateTab: isAutomateTab,
|
|
54
|
+
isMultiUnits,
|
|
55
|
+
})
|
|
56
|
+
);
|
|
55
57
|
}
|
|
56
58
|
}, [
|
|
57
59
|
isMultiUnits,
|
|
@@ -61,7 +63,7 @@ const AddNewOneTap = memo(({ route }) => {
|
|
|
61
63
|
automateData,
|
|
62
64
|
automate,
|
|
63
65
|
automateId,
|
|
64
|
-
|
|
66
|
+
dispatch,
|
|
65
67
|
isAutomateTab,
|
|
66
68
|
]);
|
|
67
69
|
|