@eohjsc/react-native-smart-city 0.2.58 → 0.2.59
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/buttonLeftCurtain.png +0 -0
- package/src/Images/Common/buttonPause-center-curtain.png +0 -0
- package/src/Images/Common/buttonRightCurtain.png +0 -0
- package/src/commons/ActionGroup/CurtainButtonTemplate.js +139 -0
- package/src/commons/ActionGroup/CurtainButtonTemplateStyle.js +58 -0
- package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +72 -0
- package/src/commons/ActionGroup/index.js +3 -0
- package/src/commons/Form/CurrencyInput.js +7 -1
- package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +4 -0
- package/src/commons/MediaPlayerDetail/index.js +73 -39
- package/src/commons/SearchLocation/index.js +0 -1
- package/src/commons/SubUnit/ShortDetail.js +1 -1
- package/src/configs/API.js +5 -3
- package/src/configs/Constants.js +5 -1
- package/src/configs/Images.js +3 -0
- package/src/context/actionType.ts +5 -0
- package/src/context/mockStore.ts +3 -0
- package/src/context/reducer.ts +14 -0
- package/src/navigations/UnitStack.js +26 -4
- package/src/screens/ActivityLog/FilterPopup.js +1 -1
- package/src/screens/AddLocationMaps/index.js +137 -44
- package/src/screens/AddLocationMaps/indexStyle.js +14 -12
- package/src/screens/AddNewAction/SelectAction.js +1 -0
- package/src/screens/Automate/MultiUnits.js +8 -8
- package/src/screens/Automate/__test__/MultiUnits.test.js +2 -2
- package/src/screens/Automate/__test__/index.test.js +2 -0
- package/src/screens/Automate/index.js +4 -2
- package/src/screens/Device/detail.js +6 -3
- package/src/screens/Notification/__test__/Notification.test.js +3 -3
- package/src/screens/Notification/components/NotificationItem.js +3 -6
- package/src/screens/Notification/index.js +2 -2
- package/src/screens/ScriptDetail/__test__/index.test.js +13 -0
- package/src/screens/ScriptDetail/index.js +20 -17
- package/src/screens/SelectUnit/index.js +2 -0
- package/src/screens/SubUnit/AddSubUnit.js +4 -3
- package/src/screens/SubUnit/__test__/AddSubUnit.test.js +4 -3
- package/src/screens/Unit/ChooseLocation.js +100 -0
- package/src/screens/Unit/ChooseLocationStyles.js +29 -0
- package/src/screens/Unit/Detail.js +8 -2
- package/src/screens/Unit/ManageUnit.js +1 -1
- package/src/screens/Unit/SelectAddress.js +240 -0
- package/src/screens/Unit/SelectAddressStyles.js +48 -0
- package/src/screens/Unit/__test__/ChooseLocation.test.js +112 -0
- package/src/screens/Unit/__test__/SelectAddress.test.js +216 -0
- package/src/screens/Unit/components/MyUnitDevice/index.js +21 -5
- package/src/utils/I18n/translations/en.json +6 -2
- package/src/utils/I18n/translations/vi.json +8 -4
- package/src/utils/Route/index.js +2 -1
- package/assets/images/AddLocationMaps/PinLocation.svg +0 -3
- package/assets/images/AddLocationMaps/Point.svg +0 -3
- package/src/screens/Unit/ManageUnit/index.js +0 -286
- package/src/screens/Unit/ManageUnit/index.test.js +0 -34
- package/src/screens/Unit/SelectLocation.js +0 -161
- package/src/screens/Unit/SelectLocationStyles.js +0 -114
|
@@ -112,10 +112,11 @@ const AddSubUnit = ({ route }) => {
|
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
114
114
|
navigate(Routes.UnitStack, {
|
|
115
|
-
screen: Routes.
|
|
115
|
+
screen: Routes.UnitDetail,
|
|
116
116
|
params: {
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
unitId: unit.id,
|
|
118
|
+
unitData: data,
|
|
119
|
+
isAddSubUnit: true,
|
|
119
120
|
},
|
|
120
121
|
});
|
|
121
122
|
} else {
|
|
@@ -158,10 +158,11 @@ describe('Test AddSubUnit', () => {
|
|
|
158
158
|
});
|
|
159
159
|
expect(axios.post).toHaveBeenCalled();
|
|
160
160
|
expect(mockedNavigate).toHaveBeenCalledWith(Routes.UnitStack, {
|
|
161
|
-
screen: Routes.
|
|
161
|
+
screen: Routes.UnitDetail,
|
|
162
162
|
params: {
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
unitId: route.params.unit.id,
|
|
164
|
+
unitData: response.data,
|
|
165
|
+
isAddSubUnit: true,
|
|
165
166
|
},
|
|
166
167
|
});
|
|
167
168
|
expect(Toast.show).toHaveBeenCalledWith({
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
+
import React, { memo, useCallback, useRef, useState } from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';
|
|
5
|
+
import { useNavigation } from '@react-navigation/native';
|
|
6
|
+
import { IconFill, IconOutline } from '@ant-design/icons-react-native';
|
|
7
|
+
|
|
8
|
+
import BottomButtonView from '../../commons/BottomButtonView';
|
|
9
|
+
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
10
|
+
|
|
11
|
+
navigator.geolocation = require('@react-native-community/geolocation');
|
|
12
|
+
|
|
13
|
+
import styles from './ChooseLocationStyles';
|
|
14
|
+
import { API, Colors } from '../../configs';
|
|
15
|
+
import { axiosGet } from '../../utils/Apis/axios';
|
|
16
|
+
import { SCConfig } from '../../configs';
|
|
17
|
+
|
|
18
|
+
const initialRegion = {
|
|
19
|
+
latitudeDelta: 0.0922,
|
|
20
|
+
longitudeDelta: 0.0421,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const DEFAULT_LATITUDE = 10.7974046; // EoH center
|
|
24
|
+
const DEFAULT_LONGITUDE = 106.7035663;
|
|
25
|
+
|
|
26
|
+
const ChooseLocation = memo(({ route }) => {
|
|
27
|
+
const t = useTranslations();
|
|
28
|
+
const { location, setAddress, setLocation } = route.params;
|
|
29
|
+
const { goBack } = useNavigation();
|
|
30
|
+
const [currentLocation, setCurrentLocation] = useState(location);
|
|
31
|
+
const mapRef = useRef(null);
|
|
32
|
+
|
|
33
|
+
const onDone = useCallback(async () => {
|
|
34
|
+
if (!currentLocation) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const { latitude, longitude } = currentLocation;
|
|
38
|
+
const { success, data } = await axiosGet(
|
|
39
|
+
API.EXTERNAL.GOOGLE_MAP.GET_LOCATION_FROM_LAT_LNG,
|
|
40
|
+
{
|
|
41
|
+
params: {
|
|
42
|
+
latlng: `${latitude},${longitude}`,
|
|
43
|
+
key: SCConfig.GOOGLE_MAP_API_KEY,
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
if (success && data.results.length > 0) {
|
|
48
|
+
const result = data.results[0];
|
|
49
|
+
setAddress(result.formatted_address);
|
|
50
|
+
setLocation({
|
|
51
|
+
description: result.formatted_address,
|
|
52
|
+
latitude: result.geometry.location.lat,
|
|
53
|
+
longitude: result.geometry.location.lng,
|
|
54
|
+
});
|
|
55
|
+
goBack();
|
|
56
|
+
}
|
|
57
|
+
}, [currentLocation, setAddress, setLocation, goBack]);
|
|
58
|
+
|
|
59
|
+
const onRegionChange = useCallback(
|
|
60
|
+
(region) => {
|
|
61
|
+
setCurrentLocation({
|
|
62
|
+
latitude: region.latitude,
|
|
63
|
+
longitude: region.longitude,
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
[setCurrentLocation]
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<View style={styles.wrap}>
|
|
71
|
+
<MapView
|
|
72
|
+
ref={mapRef}
|
|
73
|
+
provider={PROVIDER_GOOGLE}
|
|
74
|
+
style={styles.mapView}
|
|
75
|
+
initialRegion={{
|
|
76
|
+
...initialRegion,
|
|
77
|
+
latitude: location?.latitude || DEFAULT_LATITUDE,
|
|
78
|
+
longitude: location?.longitude || DEFAULT_LONGITUDE,
|
|
79
|
+
}}
|
|
80
|
+
followUserLocation={true}
|
|
81
|
+
onRegionChangeComplete={onRegionChange}
|
|
82
|
+
/>
|
|
83
|
+
<View style={styles.wrapMarker}>
|
|
84
|
+
<>
|
|
85
|
+
<IconFill name="environment" size={27} color={Colors.Blue10} />
|
|
86
|
+
<IconOutline name="close" size={14} color={Colors.Gray9} />
|
|
87
|
+
</>
|
|
88
|
+
</View>
|
|
89
|
+
<BottomButtonView
|
|
90
|
+
rowButton
|
|
91
|
+
style={styles.bottomButton}
|
|
92
|
+
mainTitle={t('done')}
|
|
93
|
+
onPressMain={onDone}
|
|
94
|
+
typeMain="primaryText"
|
|
95
|
+
/>
|
|
96
|
+
</View>
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export default ChooseLocation;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors } from '../../configs';
|
|
3
|
+
|
|
4
|
+
export default StyleSheet.create({
|
|
5
|
+
wrap: {
|
|
6
|
+
flex: 1,
|
|
7
|
+
},
|
|
8
|
+
mapView: {
|
|
9
|
+
position: 'absolute',
|
|
10
|
+
top: 0,
|
|
11
|
+
left: 0,
|
|
12
|
+
right: 0,
|
|
13
|
+
bottom: 0,
|
|
14
|
+
},
|
|
15
|
+
bottomButton: {
|
|
16
|
+
backgroundColor: Colors.White,
|
|
17
|
+
},
|
|
18
|
+
wrapMarker: {
|
|
19
|
+
flex: 1,
|
|
20
|
+
alignItems: 'center',
|
|
21
|
+
justifyContent: 'center',
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
top: 0,
|
|
24
|
+
bottom: 0,
|
|
25
|
+
left: 0,
|
|
26
|
+
right: 0,
|
|
27
|
+
paddingBottom: 24,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
@@ -30,7 +30,7 @@ import { AUTOMATE_TYPE } from '../../configs/Constants';
|
|
|
30
30
|
|
|
31
31
|
const UnitDetail = ({ route }) => {
|
|
32
32
|
const t = useTranslations();
|
|
33
|
-
const { unitId, unitData, isOneTap, routeName } = route.params;
|
|
33
|
+
const { unitId, unitData, isOneTap, routeName, isAddSubUnit } = route.params;
|
|
34
34
|
const isFocused = useIsFocused();
|
|
35
35
|
const { stateData, setAction } = useContext(SCContext);
|
|
36
36
|
const { navigate } = useNavigation();
|
|
@@ -69,7 +69,7 @@ const UnitDetail = ({ route }) => {
|
|
|
69
69
|
(rawUnitData) => {
|
|
70
70
|
rawUnitData.stations.unshift({
|
|
71
71
|
isOneTap: true,
|
|
72
|
-
name: t('
|
|
72
|
+
name: t('smart'),
|
|
73
73
|
});
|
|
74
74
|
rawUnitData.stations.unshift({
|
|
75
75
|
isFavorites: true,
|
|
@@ -222,6 +222,12 @@ const UnitDetail = ({ route }) => {
|
|
|
222
222
|
isOneTap && setIndexStation(1);
|
|
223
223
|
}, [isOneTap]);
|
|
224
224
|
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
if (listMenuItem.length && isAddSubUnit) {
|
|
227
|
+
setIndexStation(listMenuItem.length - 1);
|
|
228
|
+
}
|
|
229
|
+
}, [listMenuItem.length, isAddSubUnit]);
|
|
230
|
+
|
|
225
231
|
const onSnapToItem = useCallback(
|
|
226
232
|
(item, index) => {
|
|
227
233
|
setStation(unit.stations[index]);
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
+
import React, { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { TouchableOpacity, View, ScrollView } from 'react-native';
|
|
4
|
+
import MapView, { Marker, Circle, PROVIDER_GOOGLE } from 'react-native-maps';
|
|
5
|
+
import { useNavigation } from '@react-navigation/native';
|
|
6
|
+
import { IconOutline, IconFill } from '@ant-design/icons-react-native';
|
|
7
|
+
|
|
8
|
+
import BottomButtonView from '../../commons/BottomButtonView';
|
|
9
|
+
import SearchBarLocation from '../../commons/SearchLocation';
|
|
10
|
+
import RowLocation from '../../commons/SearchLocation/RowLocation';
|
|
11
|
+
import Text from '../../commons/Text';
|
|
12
|
+
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
13
|
+
|
|
14
|
+
navigator.geolocation = require('@react-native-community/geolocation');
|
|
15
|
+
|
|
16
|
+
import styles from './SelectAddressStyles';
|
|
17
|
+
import { API, Colors, SCConfig } from '../../configs';
|
|
18
|
+
import { axiosGet } from '../../utils/Apis/axios';
|
|
19
|
+
import Routes from '../../utils/Route';
|
|
20
|
+
import { TESTID } from '../../configs/Constants';
|
|
21
|
+
|
|
22
|
+
const initialRegion = {
|
|
23
|
+
latitudeDelta: 0.0922,
|
|
24
|
+
longitudeDelta: 0.0421,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const DEFAULT_LATITUDE = 10.7974046; // EoH center
|
|
28
|
+
const DEFAULT_LONGITUDE = 106.7035663;
|
|
29
|
+
|
|
30
|
+
const SelectAddress = memo(({ route }) => {
|
|
31
|
+
const t = useTranslations();
|
|
32
|
+
const { updateLocation } = route.params;
|
|
33
|
+
const { navigate, goBack } = useNavigation();
|
|
34
|
+
const [input, setInput] = useState('');
|
|
35
|
+
const [searchData, setSearchData] = useState([]);
|
|
36
|
+
const [searchedLocation, setSearchedLocation] = useState(null);
|
|
37
|
+
const mapRef = useRef(null);
|
|
38
|
+
|
|
39
|
+
const onDone = useCallback(() => {
|
|
40
|
+
if (!searchedLocation) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
updateLocation(searchedLocation.description);
|
|
44
|
+
goBack();
|
|
45
|
+
}, [goBack, updateLocation, searchedLocation]);
|
|
46
|
+
|
|
47
|
+
const onTextInput = useCallback(async (input) => {
|
|
48
|
+
setInput(input);
|
|
49
|
+
if (input === '') {
|
|
50
|
+
setSearchData([]);
|
|
51
|
+
setSearchedLocation(null);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const config = {
|
|
56
|
+
params: {
|
|
57
|
+
input: input,
|
|
58
|
+
key: SCConfig.GOOGLE_MAP_API_KEY,
|
|
59
|
+
sessiontoken: 123456324,
|
|
60
|
+
strictBounds: false,
|
|
61
|
+
types: ['establishment'],
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const { success, data } = await axiosGet(
|
|
66
|
+
API.EXTERNAL.GOOGLE_MAP.AUTO_COMPLETE,
|
|
67
|
+
config
|
|
68
|
+
);
|
|
69
|
+
if (success) {
|
|
70
|
+
setSearchData(data.predictions);
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {}
|
|
73
|
+
}, []);
|
|
74
|
+
|
|
75
|
+
const animateToRegion = useCallback((lat, lng) => {
|
|
76
|
+
if (!mapRef || !mapRef.current) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
mapRef.current.animateToRegion(
|
|
81
|
+
{
|
|
82
|
+
latitude: lat,
|
|
83
|
+
longitude: lng,
|
|
84
|
+
...initialRegion,
|
|
85
|
+
},
|
|
86
|
+
600
|
|
87
|
+
);
|
|
88
|
+
}, []);
|
|
89
|
+
|
|
90
|
+
const onPressRowLocation = useCallback(async (item) => {
|
|
91
|
+
setInput(item.description);
|
|
92
|
+
setSearchData([]);
|
|
93
|
+
const body = {
|
|
94
|
+
params: {
|
|
95
|
+
place_id: item.place_id,
|
|
96
|
+
key: SCConfig.GOOGLE_MAP_API_KEY,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const { success, data } = await axiosGet(
|
|
101
|
+
API.EXTERNAL.GOOGLE_MAP.GET_LAT_LNG_BY_PLACE_ID,
|
|
102
|
+
body
|
|
103
|
+
);
|
|
104
|
+
if (success) {
|
|
105
|
+
const { location } = data.result.geometry;
|
|
106
|
+
setSearchedLocation({
|
|
107
|
+
description: item.description,
|
|
108
|
+
latitude: location.lat,
|
|
109
|
+
longitude: location.lng,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}, []);
|
|
113
|
+
|
|
114
|
+
const getCurrentPosition = useCallback(() => {
|
|
115
|
+
navigator.geolocation.getCurrentPosition(
|
|
116
|
+
async (position) => {
|
|
117
|
+
const currentLatitude = JSON.stringify(position.coords.latitude);
|
|
118
|
+
const currentLongitude = JSON.stringify(position.coords.longitude);
|
|
119
|
+
const { success, data } = await axiosGet(
|
|
120
|
+
API.EXTERNAL.GOOGLE_MAP.GET_LOCATION_FROM_LAT_LNG,
|
|
121
|
+
{
|
|
122
|
+
params: {
|
|
123
|
+
latlng: `${currentLatitude},${currentLongitude}`,
|
|
124
|
+
key: SCConfig.GOOGLE_MAP_API_KEY,
|
|
125
|
+
},
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
if (success && data.results.length > 0) {
|
|
129
|
+
const result = data.results[0];
|
|
130
|
+
setInput(result.formatted_address);
|
|
131
|
+
setSearchedLocation({
|
|
132
|
+
description: result.formatted_address,
|
|
133
|
+
latitude: result.geometry.location.lat,
|
|
134
|
+
longitude: result.geometry.location.lng,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
(error) => {},
|
|
139
|
+
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
|
|
140
|
+
);
|
|
141
|
+
}, []);
|
|
142
|
+
|
|
143
|
+
const chooseOnMap = useCallback(() => {
|
|
144
|
+
navigate(Routes.ChooseLocation, {
|
|
145
|
+
location: searchedLocation,
|
|
146
|
+
setAddress: setInput,
|
|
147
|
+
setLocation: setSearchedLocation,
|
|
148
|
+
});
|
|
149
|
+
}, [navigate, searchedLocation, setInput, setSearchedLocation]);
|
|
150
|
+
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (searchedLocation) {
|
|
153
|
+
animateToRegion(searchedLocation.latitude, searchedLocation.longitude);
|
|
154
|
+
}
|
|
155
|
+
}, [animateToRegion, searchedLocation]);
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<View style={styles.wrap}>
|
|
159
|
+
<View style={styles.searchLocation}>
|
|
160
|
+
<SearchBarLocation input={input} onTextInput={onTextInput} />
|
|
161
|
+
<ScrollView style={styles.searchData}>
|
|
162
|
+
{searchData.map((item, index) => (
|
|
163
|
+
<RowLocation key={index} item={item} onPress={onPressRowLocation} />
|
|
164
|
+
))}
|
|
165
|
+
</ScrollView>
|
|
166
|
+
{searchData.length === 0 && (
|
|
167
|
+
<>
|
|
168
|
+
<TouchableOpacity
|
|
169
|
+
onPress={getCurrentPosition}
|
|
170
|
+
style={styles.button}
|
|
171
|
+
testID={TESTID.BUTTON_YOUR_LOCATION}
|
|
172
|
+
>
|
|
173
|
+
<IconOutline name="aim" size={27} color={Colors.Primary} />
|
|
174
|
+
<Text type="Body" color={Colors.Gray9} style={styles.text} bold>
|
|
175
|
+
{t('your_location')}
|
|
176
|
+
</Text>
|
|
177
|
+
</TouchableOpacity>
|
|
178
|
+
<View style={styles.separated} />
|
|
179
|
+
<TouchableOpacity
|
|
180
|
+
onPress={chooseOnMap}
|
|
181
|
+
style={styles.button}
|
|
182
|
+
testID={TESTID.BUTTON_CHOOSE_ON_MAP}
|
|
183
|
+
>
|
|
184
|
+
<IconFill name="environment" size={27} color={Colors.Primary} />
|
|
185
|
+
<Text type="Body" color={Colors.Gray9} style={styles.text} bold>
|
|
186
|
+
{t('choose_on_map')}
|
|
187
|
+
</Text>
|
|
188
|
+
</TouchableOpacity>
|
|
189
|
+
</>
|
|
190
|
+
)}
|
|
191
|
+
</View>
|
|
192
|
+
<MapView
|
|
193
|
+
ref={mapRef}
|
|
194
|
+
provider={PROVIDER_GOOGLE}
|
|
195
|
+
style={styles.mapView}
|
|
196
|
+
initialRegion={{
|
|
197
|
+
...initialRegion,
|
|
198
|
+
latitude: DEFAULT_LATITUDE,
|
|
199
|
+
longitude: DEFAULT_LONGITUDE,
|
|
200
|
+
}}
|
|
201
|
+
followUserLocation={true}
|
|
202
|
+
>
|
|
203
|
+
{searchedLocation && (
|
|
204
|
+
<>
|
|
205
|
+
<Circle
|
|
206
|
+
center={{
|
|
207
|
+
latitude: searchedLocation.latitude,
|
|
208
|
+
longitude: searchedLocation.longitude,
|
|
209
|
+
}}
|
|
210
|
+
radius={1000}
|
|
211
|
+
fillColor={Colors.BlueTransparent5}
|
|
212
|
+
strokeColor={Colors.Blue10}
|
|
213
|
+
/>
|
|
214
|
+
<Marker
|
|
215
|
+
coordinate={{
|
|
216
|
+
latitude: searchedLocation.latitude,
|
|
217
|
+
longitude: searchedLocation.longitude,
|
|
218
|
+
}}
|
|
219
|
+
tracksViewChanges={false}
|
|
220
|
+
>
|
|
221
|
+
<IconFill name="environment" size={27} color={Colors.Blue10} />
|
|
222
|
+
</Marker>
|
|
223
|
+
</>
|
|
224
|
+
)}
|
|
225
|
+
</MapView>
|
|
226
|
+
<BottomButtonView
|
|
227
|
+
rowButton
|
|
228
|
+
style={styles.bottomButton}
|
|
229
|
+
mainTitle={t('done')}
|
|
230
|
+
onPressMain={onDone}
|
|
231
|
+
secondaryTitle={t('cancel')}
|
|
232
|
+
onPressSecondary={goBack}
|
|
233
|
+
typeMain="primaryText"
|
|
234
|
+
typeSecondary="primaryText"
|
|
235
|
+
/>
|
|
236
|
+
</View>
|
|
237
|
+
);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
export default SelectAddress;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors } from '../../configs';
|
|
3
|
+
|
|
4
|
+
export default StyleSheet.create({
|
|
5
|
+
wrap: {
|
|
6
|
+
flex: 1,
|
|
7
|
+
},
|
|
8
|
+
mapView: {
|
|
9
|
+
position: 'absolute',
|
|
10
|
+
top: 0,
|
|
11
|
+
left: 0,
|
|
12
|
+
right: 0,
|
|
13
|
+
bottom: 0,
|
|
14
|
+
},
|
|
15
|
+
bottomButton: {
|
|
16
|
+
backgroundColor: Colors.White,
|
|
17
|
+
},
|
|
18
|
+
searchLocation: {
|
|
19
|
+
paddingVertical: 8,
|
|
20
|
+
position: 'absolute',
|
|
21
|
+
zIndex: 1,
|
|
22
|
+
minHeight: 48,
|
|
23
|
+
top: 0,
|
|
24
|
+
left: 0,
|
|
25
|
+
right: 0,
|
|
26
|
+
flex: 1,
|
|
27
|
+
backgroundColor: Colors.White,
|
|
28
|
+
},
|
|
29
|
+
searchData: {
|
|
30
|
+
paddingHorizontal: 16,
|
|
31
|
+
position: 'relative',
|
|
32
|
+
width: '100%',
|
|
33
|
+
maxHeight: 100,
|
|
34
|
+
},
|
|
35
|
+
button: {
|
|
36
|
+
flexDirection: 'row',
|
|
37
|
+
alignItems: 'center',
|
|
38
|
+
padding: 16,
|
|
39
|
+
},
|
|
40
|
+
separated: {
|
|
41
|
+
height: 1,
|
|
42
|
+
backgroundColor: Colors.Gray3,
|
|
43
|
+
marginHorizontal: 16,
|
|
44
|
+
},
|
|
45
|
+
text: {
|
|
46
|
+
marginLeft: 12,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { act, create } from 'react-test-renderer';
|
|
3
|
+
import { SCProvider } from '../../../context';
|
|
4
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
5
|
+
import ChooseLocation from '../ChooseLocation';
|
|
6
|
+
import axios from 'axios';
|
|
7
|
+
import { API, SCConfig } from '../../../configs';
|
|
8
|
+
import BottomButtonView from '../../../commons/BottomButtonView';
|
|
9
|
+
|
|
10
|
+
const wrapComponent = (route) => (
|
|
11
|
+
<SCProvider initState={mockSCStore({})}>
|
|
12
|
+
<ChooseLocation route={route} />
|
|
13
|
+
</SCProvider>
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const mockGoBack = jest.fn();
|
|
17
|
+
jest.mock('@react-navigation/native', () => {
|
|
18
|
+
return {
|
|
19
|
+
...jest.requireActual('@react-navigation/native'),
|
|
20
|
+
useNavigation: () => ({
|
|
21
|
+
goBack: mockGoBack,
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
jest.mock('react', () => {
|
|
27
|
+
return {
|
|
28
|
+
...jest.requireActual('react'),
|
|
29
|
+
memo: (x) => x,
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
jest.mock('react-native-maps', () => {
|
|
34
|
+
const { forwardRef } = require('react');
|
|
35
|
+
const { View } = require('react-native');
|
|
36
|
+
const MockMapView = forwardRef((props, ref) => (
|
|
37
|
+
<View refs={ref}>{props.children}</View>
|
|
38
|
+
));
|
|
39
|
+
return {
|
|
40
|
+
__esModule: true,
|
|
41
|
+
default: MockMapView,
|
|
42
|
+
PROVIDER_GOOGLE: 'google',
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
jest.mock('axios');
|
|
47
|
+
|
|
48
|
+
describe('Test ChooseLocation', () => {
|
|
49
|
+
let tree;
|
|
50
|
+
let route;
|
|
51
|
+
const mockSetAddress = jest.fn();
|
|
52
|
+
const mockSetLocation = jest.fn();
|
|
53
|
+
|
|
54
|
+
beforeAll(() => {
|
|
55
|
+
axios.get.mockClear();
|
|
56
|
+
route = {
|
|
57
|
+
params: {
|
|
58
|
+
location: {
|
|
59
|
+
latitude: 10,
|
|
60
|
+
longitude: 10,
|
|
61
|
+
},
|
|
62
|
+
setAddress: mockSetAddress,
|
|
63
|
+
setLocation: mockSetLocation,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('test done choose location', async () => {
|
|
69
|
+
await act(async () => {
|
|
70
|
+
tree = await create(wrapComponent(route));
|
|
71
|
+
});
|
|
72
|
+
const instance = tree.root;
|
|
73
|
+
const buttonBottom = instance.findByType(BottomButtonView);
|
|
74
|
+
|
|
75
|
+
const response = {
|
|
76
|
+
status: 200,
|
|
77
|
+
data: {
|
|
78
|
+
results: [
|
|
79
|
+
{
|
|
80
|
+
formatted_address: 'address',
|
|
81
|
+
geometry: {
|
|
82
|
+
location: {
|
|
83
|
+
lat: 20,
|
|
84
|
+
lng: 20,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
axios.get.mockImplementation(async () => response);
|
|
92
|
+
await act(async () => {
|
|
93
|
+
await buttonBottom.props.onPressMain();
|
|
94
|
+
});
|
|
95
|
+
expect(axios.get).toBeCalledWith(
|
|
96
|
+
API.EXTERNAL.GOOGLE_MAP.GET_LOCATION_FROM_LAT_LNG,
|
|
97
|
+
{
|
|
98
|
+
params: {
|
|
99
|
+
latlng: '10,10',
|
|
100
|
+
key: SCConfig.GOOGLE_MAP_API_KEY,
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
expect(mockSetAddress).toBeCalledWith('address');
|
|
105
|
+
expect(mockSetLocation).toBeCalledWith({
|
|
106
|
+
description: 'address',
|
|
107
|
+
latitude: 20,
|
|
108
|
+
longitude: 20,
|
|
109
|
+
});
|
|
110
|
+
expect(mockGoBack).toBeCalled();
|
|
111
|
+
});
|
|
112
|
+
});
|