@eohjsc/react-native-smart-city 0.2.58 → 0.2.62
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/README.md +115 -68
- package/assets/images/Map/MarkerGeolocation.svg +4 -0
- package/package.json +2 -2
- 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 +147 -0
- package/src/commons/ActionGroup/CurtainButtonTemplateStyle.js +58 -0
- package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +72 -0
- package/src/commons/ActionGroup/__test__/MenuActionAddSchedule.test.js +71 -0
- package/src/commons/ActionGroup/hooks/AccessScheduleDetailStyles.js +41 -0
- package/src/commons/ActionGroup/hooks/MenuActionAddSchedule.js +110 -0
- package/src/commons/ActionGroup/hooks/MenuActionAddScheduleStyle.js +69 -0
- package/src/commons/ActionGroup/hooks/RecurringDetail.js +97 -0
- package/src/commons/ActionGroup/index.js +3 -0
- package/src/commons/DateTimeRangeChange/DateTimeButton.js +7 -2
- package/src/commons/Device/HistoryChart.js +80 -81
- package/src/commons/Device/HorizontalBarChart.js +48 -31
- package/src/commons/Device/LinearChart.js +28 -1
- package/src/commons/Form/CurrencyInput.js +8 -1
- package/src/commons/FourButtonFilterHistory/__test__/FourButtonFilterHistory.test.js +48 -0
- package/src/commons/FourButtonFilterHistory/index.js +72 -0
- package/src/commons/FourButtonFilterHistory/styles.js +22 -0
- package/src/commons/ImagePicker/index.js +27 -33
- package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +14 -0
- package/src/commons/MediaPlayerDetail/index.js +84 -41
- package/src/commons/SearchLocation/index.js +0 -1
- package/src/commons/SubUnit/OneTap/OneTapStyles.js +20 -1
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +151 -40
- package/src/commons/SubUnit/OneTap/index.js +64 -12
- package/src/commons/SubUnit/ShortDetail.js +1 -1
- package/src/commons/UnitSummary/AirQuality/index.js +9 -7
- package/src/commons/UnitSummary/ConfigHistoryChart.js +2 -1
- package/src/configs/API.js +8 -3
- package/src/configs/Constants.js +20 -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/iot/RemoteControl/Bluetooth.js +6 -3
- package/src/iot/RemoteControl/GoogleHome.js +6 -3
- package/src/iot/RemoteControl/Internet.js +1 -0
- package/src/iot/RemoteControl/LG.js +2 -1
- package/src/iot/RemoteControl/index.js +13 -6
- package/src/navigations/SharedStack.js +11 -9
- package/src/navigations/UnitStack.js +52 -6
- package/src/screens/ActivityLog/FilterPopup.js +1 -1
- package/src/screens/ActivityLog/ItemLog.js +3 -3
- package/src/screens/ActivityLog/__test__/ItemLog.test.js +5 -2
- package/src/screens/ActivityLog/hooks/index.js +2 -1
- package/src/screens/ActivityLog/index.js +0 -1
- package/src/screens/AddLocationMaps/index.js +139 -44
- package/src/screens/AddLocationMaps/indexStyle.js +14 -12
- package/src/screens/AddNewAction/SelectAction.js +1 -0
- package/src/screens/AddNewAction/SelectSensorDevices.js +18 -11
- package/src/screens/AddNewAction/Styles/SelectSensorDevicesStyles.js +5 -1
- package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +6 -1
- package/src/screens/Automate/MultiUnits.js +12 -9
- package/src/screens/Automate/__test__/MultiUnits.test.js +1 -1
- package/src/screens/Automate/__test__/index.test.js +14 -0
- package/src/screens/Automate/index.js +4 -2
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +61 -0
- package/src/screens/ConfirmUnitDeletion/index.js +64 -0
- package/src/screens/ConfirmUnitDeletion/styles.js +37 -0
- package/src/screens/Device/__test__/detail.test.js +3 -2
- package/src/screens/Device/detail.js +50 -14
- package/src/screens/Device/hooks/useDisconnectedDevice.js +2 -1
- package/src/screens/Device/styles.js +3 -3
- package/src/screens/EmergencySetting/__test__/DropDownItem.test.js +59 -0
- package/src/screens/EmergencySetting/__test__/index.test.js +27 -0
- package/src/screens/EmergencySetting/components/DropDownItem.js +54 -0
- package/src/screens/EmergencySetting/index.js +92 -0
- package/src/screens/EmergencySetting/styles/DropDownItem.js +38 -0
- package/src/screens/EmergencySetting/styles.js +25 -0
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +126 -0
- package/src/screens/MoveToAnotherSubUnit/index.js +88 -0
- package/src/screens/MoveToAnotherSubUnit/styles/MoveToAnotherSubUnitStyles.js +50 -0
- 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/Styles/indexStyles.js +0 -1
- package/src/screens/ScriptDetail/__test__/index.test.js +13 -0
- package/src/screens/ScriptDetail/index.js +21 -17
- package/src/screens/SelectUnit/index.js +2 -0
- package/src/screens/SubUnit/AddSubUnit.js +7 -6
- package/src/screens/SubUnit/AddSubUnitStyles.js +0 -2
- package/src/screens/SubUnit/EditSubUnit.js +16 -7
- package/src/screens/SubUnit/EditSubUnitStyles.js +2 -3
- package/src/screens/SubUnit/__test__/AddSubUnit.test.js +4 -3
- package/src/screens/SubUnit/__test__/EditSubUnit.test.js +2 -2
- package/src/screens/TDSGuide/index.js +1 -1
- package/src/screens/Unit/ChooseLocation.js +96 -0
- package/src/screens/Unit/ChooseLocationStyles.js +26 -0
- package/src/screens/Unit/Detail.js +24 -8
- package/src/screens/Unit/ManageUnit.js +21 -27
- package/src/screens/Unit/SelectAddress.js +240 -0
- package/src/screens/Unit/SelectAddressStyles.js +48 -0
- package/src/screens/Unit/SmartAccount.js +25 -41
- package/src/screens/Unit/SmartAccountItem.js +2 -1
- package/src/screens/Unit/SmartAccountStyles.js +0 -1
- package/src/screens/Unit/__test__/ChooseLocation.test.js +112 -0
- package/src/screens/Unit/__test__/ManageUnit.test.js +0 -6
- package/src/screens/Unit/__test__/SelectAddress.test.js +216 -0
- package/src/screens/Unit/__test__/SmartAccount.test.js +24 -0
- package/src/screens/Unit/__test__/SmartAccountItem.test.js +72 -0
- package/src/screens/Unit/components/MyUnitDevice/index.js +21 -5
- package/src/screens/UnitSummary/components/3PPowerConsumption/index.js +58 -59
- package/src/screens/UnitSummary/components/PowerConsumption/index.js +26 -22
- package/src/screens/UnitSummary/components/Temperature/ItemTemperature/index.js +2 -2
- package/src/screens/UnitSummary/components/Temperature/index.js +15 -14
- package/src/screens/UnitSummary/components/UvIndex/index.js +6 -5
- package/src/screens/UnitSummary/components/WaterQuality/index.js +9 -7
- package/src/screens/UnitSummary/index.js +11 -7
- package/src/screens/WaterQualityGuide/index.js +1 -0
- package/src/utils/Apis/axios.js +4 -4
- package/src/utils/I18n/translations/en.json +25 -3
- package/src/utils/I18n/translations/vi.json +28 -5
- package/src/utils/Route/index.js +5 -1
- package/src/utils/Utils.js +4 -0
- package/assets/images/AddLocationMaps/PinLocation.svg +0 -3
- package/assets/images/AddLocationMaps/Point.svg +0 -3
- package/src/commons/ThreeButtonHistory/CalendarHeader.js +0 -35
- package/src/commons/ThreeButtonHistory/CalendarHeaderStyles.js +0 -17
- package/src/commons/ThreeButtonHistory/SelectMonth.js +0 -53
- package/src/commons/ThreeButtonHistory/SelectMonthStyles.js +0 -29
- package/src/commons/ThreeButtonHistory/__test__/SelectMonth.test.js +0 -37
- package/src/commons/ThreeButtonHistory/__test__/ThreeButtonHistory.test.js +0 -240
- package/src/commons/ThreeButtonHistory/index.js +0 -310
- package/src/commons/ThreeButtonHistory/styles.js +0 -65
- 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
|
@@ -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
|
+
});
|
|
@@ -7,17 +7,16 @@ import React, {
|
|
|
7
7
|
useState,
|
|
8
8
|
memo,
|
|
9
9
|
} from 'react';
|
|
10
|
-
import { View } from 'react-native';
|
|
10
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
11
11
|
import styles from './SmartAccountStyles';
|
|
12
12
|
import { API, Colors } from '../../configs';
|
|
13
13
|
import Routes from '../../utils/Route';
|
|
14
14
|
import { useNavigation } from '@react-navigation/native';
|
|
15
15
|
import { axiosDelete, axiosGet } from '../../utils/Apis/axios';
|
|
16
16
|
import { SmartAccountItem } from './SmartAccountItem';
|
|
17
|
-
import { usePopover
|
|
18
|
-
import {
|
|
17
|
+
import { usePopover } from '../../hooks/Common';
|
|
18
|
+
import { MenuActionMore } from '../../commons';
|
|
19
19
|
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
20
|
-
import { useStateAlertRemove } from '../Unit/hook/useStateAlertRemove';
|
|
21
20
|
|
|
22
21
|
const ListSmartAccount = ({ route }) => {
|
|
23
22
|
const { unitId } = route?.params || {};
|
|
@@ -38,10 +37,6 @@ const ListSmartAccount = ({ route }) => {
|
|
|
38
37
|
const { childRef, showingPopover, showPopoverWithRef, hidePopover } =
|
|
39
38
|
usePopover();
|
|
40
39
|
|
|
41
|
-
const [lockShowing, acquireLockShowing, releaseLockShowing] = useBoolean();
|
|
42
|
-
const { stateAlertRemove, onShowRemoveAlert, hideAlertAction } =
|
|
43
|
-
useStateAlertRemove();
|
|
44
|
-
|
|
45
40
|
useEffect(() => {
|
|
46
41
|
getAllSmartAccounts();
|
|
47
42
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -55,21 +50,7 @@ const ListSmartAccount = ({ route }) => {
|
|
|
55
50
|
[showPopoverWithRef]
|
|
56
51
|
);
|
|
57
52
|
|
|
58
|
-
const onItemClick = useCallback(
|
|
59
|
-
(item) => {
|
|
60
|
-
if (!smartAccountRef?.current) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (item.action === 'delete') {
|
|
64
|
-
acquireLockShowing();
|
|
65
|
-
onShowRemoveAlert(smartAccountRef.current.brand)();
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
[acquireLockShowing, onShowRemoveAlert]
|
|
69
|
-
);
|
|
70
|
-
|
|
71
53
|
const deleteSmartAccount = useCallback(async () => {
|
|
72
|
-
hideAlertAction();
|
|
73
54
|
if (!smartAccountRef?.current) {
|
|
74
55
|
return;
|
|
75
56
|
}
|
|
@@ -78,10 +59,22 @@ const ListSmartAccount = ({ route }) => {
|
|
|
78
59
|
API.SMART_ACCOUNT.REMOVE_SMART_ACCOUNT(id)
|
|
79
60
|
);
|
|
80
61
|
success && getAllSmartAccounts();
|
|
81
|
-
}, [
|
|
62
|
+
}, [getAllSmartAccounts]);
|
|
63
|
+
|
|
64
|
+
const onItemClick = useCallback(
|
|
65
|
+
(item) => {
|
|
66
|
+
if (!smartAccountRef?.current) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (item.action === 'remove') {
|
|
70
|
+
deleteSmartAccount();
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
[deleteSmartAccount]
|
|
74
|
+
);
|
|
82
75
|
|
|
83
76
|
const listMenuItem = useMemo(() => {
|
|
84
|
-
return [{ action: '
|
|
77
|
+
return [{ action: 'remove', text: t('remove_account') }];
|
|
85
78
|
}, [t]);
|
|
86
79
|
|
|
87
80
|
const gotoSmartAccountDetail = useCallback(
|
|
@@ -104,33 +97,24 @@ const ListSmartAccount = ({ route }) => {
|
|
|
104
97
|
headerAniStyle={styles.headerAniStyle}
|
|
105
98
|
>
|
|
106
99
|
<View style={styles.wrapContent}>
|
|
107
|
-
{data.map((item) => {
|
|
100
|
+
{data.map((item, index) => {
|
|
108
101
|
return (
|
|
109
|
-
<
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
102
|
+
<TouchableOpacity key={index}>
|
|
103
|
+
<SmartAccountItem
|
|
104
|
+
gotoSmartAccountDetail={gotoSmartAccountDetail}
|
|
105
|
+
item={item}
|
|
106
|
+
onShowMenuMore={onShowMenuMore}
|
|
107
|
+
/>
|
|
108
|
+
</TouchableOpacity>
|
|
114
109
|
);
|
|
115
110
|
})}
|
|
116
111
|
</View>
|
|
117
|
-
<AlertAction
|
|
118
|
-
visible={stateAlertRemove.visible && !lockShowing}
|
|
119
|
-
hideModal={hideAlertAction}
|
|
120
|
-
title={stateAlertRemove.title}
|
|
121
|
-
message={stateAlertRemove.message}
|
|
122
|
-
leftButtonTitle={stateAlertRemove.leftButton}
|
|
123
|
-
leftButtonClick={hideAlertAction}
|
|
124
|
-
rightButtonTitle={stateAlertRemove.rightButton}
|
|
125
|
-
rightButtonClick={deleteSmartAccount}
|
|
126
|
-
/>
|
|
127
112
|
<MenuActionMore
|
|
128
113
|
isVisible={showingPopover}
|
|
129
114
|
hideMore={hidePopover}
|
|
130
115
|
listMenuItem={listMenuItem}
|
|
131
116
|
childRef={childRef}
|
|
132
117
|
onItemClick={onItemClick}
|
|
133
|
-
hideComplete={releaseLockShowing}
|
|
134
118
|
/>
|
|
135
119
|
</WrapHeaderScrollable>
|
|
136
120
|
</View>
|
|
@@ -23,6 +23,7 @@ export const SmartAccountItem = memo(
|
|
|
23
23
|
<TouchableOpacity
|
|
24
24
|
style={styles.wrapText}
|
|
25
25
|
onPress={onPressGotoSmartAccountDetail}
|
|
26
|
+
testID={TESTID.SMART_ACCOUNT_ITEM}
|
|
26
27
|
>
|
|
27
28
|
<FImage
|
|
28
29
|
source={{ uri: item?.logo }}
|
|
@@ -39,7 +40,7 @@ export const SmartAccountItem = memo(
|
|
|
39
40
|
</View>
|
|
40
41
|
</TouchableOpacity>
|
|
41
42
|
<TouchableOpacity
|
|
42
|
-
testID={TESTID.
|
|
43
|
+
testID={TESTID.SMART_ACCOUNT_ITEM_PRESSMORE}
|
|
43
44
|
onPress={onPressMore}
|
|
44
45
|
ref={buttonMoreRef}
|
|
45
46
|
>
|
|
@@ -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
|
+
});
|
|
@@ -3,7 +3,6 @@ import { act, create } from 'react-test-renderer';
|
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
|
|
5
5
|
import { ToastBottomHelper } from '../../../utils/Utils';
|
|
6
|
-
import API from '../../../configs/API';
|
|
7
6
|
import { TESTID } from '../../../configs/Constants';
|
|
8
7
|
|
|
9
8
|
import ManageUnit from '../ManageUnit';
|
|
@@ -131,7 +130,6 @@ describe('Test Manage Unit', () => {
|
|
|
131
130
|
});
|
|
132
131
|
|
|
133
132
|
test('remove Unit success', async () => {
|
|
134
|
-
const spyToast = jest.spyOn(ToastBottomHelper, 'success');
|
|
135
133
|
await act(async () => {
|
|
136
134
|
tree = create(wrapComponent(route));
|
|
137
135
|
});
|
|
@@ -165,11 +163,7 @@ describe('Test Manage Unit', () => {
|
|
|
165
163
|
await bottomButton.props.onPress();
|
|
166
164
|
});
|
|
167
165
|
|
|
168
|
-
expect(axios.delete).toBeCalledWith(API.UNIT.MANAGE_UNIT(1));
|
|
169
166
|
expect(mockedDispatch).not.toBeCalled();
|
|
170
|
-
expect(spyToast).toBeCalled();
|
|
171
|
-
spyToast.mockReset();
|
|
172
|
-
spyToast.mockRestore();
|
|
173
167
|
});
|
|
174
168
|
|
|
175
169
|
test('rename Unit sucess', async () => {
|
|
@@ -0,0 +1,216 @@
|
|
|
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 SelectAddress from '../SelectAddress';
|
|
6
|
+
import SearchBarLocation from '../../../commons/SearchLocation';
|
|
7
|
+
import RowLocation from '../../../commons/SearchLocation/RowLocation';
|
|
8
|
+
import BottomButtonView from '../../../commons/BottomButtonView';
|
|
9
|
+
import axios from 'axios';
|
|
10
|
+
import { API, SCConfig } from '../../../configs';
|
|
11
|
+
import { TESTID } from '../../../configs/Constants';
|
|
12
|
+
|
|
13
|
+
const wrapComponent = (route) => (
|
|
14
|
+
<SCProvider initState={mockSCStore({})}>
|
|
15
|
+
<SelectAddress route={route} />
|
|
16
|
+
</SCProvider>
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const mockNavigate = jest.fn();
|
|
20
|
+
const mockGoBack = jest.fn();
|
|
21
|
+
jest.mock('@react-navigation/native', () => {
|
|
22
|
+
return {
|
|
23
|
+
...jest.requireActual('@react-navigation/native'),
|
|
24
|
+
useNavigation: () => ({
|
|
25
|
+
navigate: mockNavigate,
|
|
26
|
+
goBack: mockGoBack,
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
jest.mock('react', () => {
|
|
32
|
+
return {
|
|
33
|
+
...jest.requireActual('react'),
|
|
34
|
+
memo: (x) => x,
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
jest.mock('react-native-maps', () => {
|
|
39
|
+
const { forwardRef } = require('react');
|
|
40
|
+
const { View } = require('react-native');
|
|
41
|
+
const MockMapView = forwardRef((props, ref) => (
|
|
42
|
+
<View refs={ref}>{props.children}</View>
|
|
43
|
+
));
|
|
44
|
+
const MockMarker = (props) => <View>{props.children}</View>;
|
|
45
|
+
const MockCircle = (props) => <View>{props.children}</View>;
|
|
46
|
+
return {
|
|
47
|
+
__esModule: true,
|
|
48
|
+
default: MockMapView,
|
|
49
|
+
Marker: MockMarker,
|
|
50
|
+
Circle: MockCircle,
|
|
51
|
+
PROVIDER_GOOGLE: 'google',
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
jest.mock('@react-native-community/geolocation', () => {
|
|
56
|
+
const position = {
|
|
57
|
+
coords: {
|
|
58
|
+
latitude: 100,
|
|
59
|
+
longitude: 100,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
getCurrentPosition: (onSuccess, onError, options) => {
|
|
64
|
+
onSuccess(position);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
jest.mock('axios');
|
|
70
|
+
|
|
71
|
+
describe('Test SelectAddress', () => {
|
|
72
|
+
let tree;
|
|
73
|
+
let route;
|
|
74
|
+
const mockUpdateLocation = jest.fn();
|
|
75
|
+
|
|
76
|
+
beforeAll(() => {
|
|
77
|
+
axios.get.mockClear();
|
|
78
|
+
route = {
|
|
79
|
+
params: {
|
|
80
|
+
updateLocation: mockUpdateLocation,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('test search location', async () => {
|
|
86
|
+
await act(async () => {
|
|
87
|
+
tree = await create(wrapComponent(route));
|
|
88
|
+
});
|
|
89
|
+
const instance = tree.root;
|
|
90
|
+
const searchBars = instance.findAllByType(SearchBarLocation);
|
|
91
|
+
expect(searchBars).toHaveLength(1);
|
|
92
|
+
|
|
93
|
+
let response = {
|
|
94
|
+
status: 200,
|
|
95
|
+
data: {
|
|
96
|
+
predictions: [
|
|
97
|
+
{ place_id: 1, description: '1' },
|
|
98
|
+
{ place_id: 2, description: '2' },
|
|
99
|
+
{ place_id: 3, description: '3' },
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
axios.get.mockImplementation(async () => response);
|
|
104
|
+
|
|
105
|
+
await act(async () => {
|
|
106
|
+
await searchBars[0].props.onTextInput('');
|
|
107
|
+
});
|
|
108
|
+
let rowLocations = instance.findAllByType(RowLocation);
|
|
109
|
+
expect(rowLocations).toHaveLength(0);
|
|
110
|
+
|
|
111
|
+
await act(async () => {
|
|
112
|
+
await searchBars[0].props.onTextInput('input');
|
|
113
|
+
});
|
|
114
|
+
expect(axios.get).toBeCalledWith(API.EXTERNAL.GOOGLE_MAP.AUTO_COMPLETE, {
|
|
115
|
+
params: {
|
|
116
|
+
input: 'input',
|
|
117
|
+
key: SCConfig.GOOGLE_MAP_API_KEY,
|
|
118
|
+
sessiontoken: 123456324,
|
|
119
|
+
strictBounds: false,
|
|
120
|
+
types: ['establishment'],
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
rowLocations = instance.findAllByType(RowLocation);
|
|
124
|
+
expect(rowLocations).toHaveLength(3);
|
|
125
|
+
|
|
126
|
+
axios.get.mockClear();
|
|
127
|
+
response = {
|
|
128
|
+
status: 200,
|
|
129
|
+
data: {
|
|
130
|
+
result: {
|
|
131
|
+
geometry: {
|
|
132
|
+
location: {
|
|
133
|
+
lat: 10,
|
|
134
|
+
lng: 10,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
axios.get.mockImplementation(async () => response);
|
|
141
|
+
|
|
142
|
+
await act(async () => {
|
|
143
|
+
await rowLocations[0].props.onPress({ place_id: 1, description: '1' });
|
|
144
|
+
});
|
|
145
|
+
expect(axios.get).toBeCalledWith(
|
|
146
|
+
API.EXTERNAL.GOOGLE_MAP.GET_LAT_LNG_BY_PLACE_ID,
|
|
147
|
+
{
|
|
148
|
+
params: {
|
|
149
|
+
place_id: 1,
|
|
150
|
+
key: SCConfig.GOOGLE_MAP_API_KEY,
|
|
151
|
+
},
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const bottomButton = instance.findByType(BottomButtonView);
|
|
156
|
+
await act(async () => {
|
|
157
|
+
await bottomButton.props.onPressMain();
|
|
158
|
+
});
|
|
159
|
+
expect(mockUpdateLocation).toBeCalledWith('1');
|
|
160
|
+
expect(mockGoBack).toBeCalled();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('test get current location', async () => {
|
|
164
|
+
await act(async () => {
|
|
165
|
+
tree = await create(wrapComponent(route));
|
|
166
|
+
});
|
|
167
|
+
const instance = tree.root;
|
|
168
|
+
const button = instance.find(
|
|
169
|
+
(el) => el.props.testID === TESTID.BUTTON_YOUR_LOCATION
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const response = {
|
|
173
|
+
status: 200,
|
|
174
|
+
data: {
|
|
175
|
+
results: [
|
|
176
|
+
{
|
|
177
|
+
formatted_address: 'address',
|
|
178
|
+
geometry: {
|
|
179
|
+
location: {
|
|
180
|
+
lat: 10,
|
|
181
|
+
lng: 10,
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
axios.get.mockImplementation(async () => response);
|
|
189
|
+
await act(async () => {
|
|
190
|
+
await button.props.onPress();
|
|
191
|
+
});
|
|
192
|
+
expect(axios.get).toBeCalledWith(
|
|
193
|
+
API.EXTERNAL.GOOGLE_MAP.GET_LOCATION_FROM_LAT_LNG,
|
|
194
|
+
{
|
|
195
|
+
params: {
|
|
196
|
+
latlng: '100,100',
|
|
197
|
+
key: SCConfig.GOOGLE_MAP_API_KEY,
|
|
198
|
+
},
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('test choose on map', async () => {
|
|
204
|
+
await act(async () => {
|
|
205
|
+
tree = await create(wrapComponent(route));
|
|
206
|
+
});
|
|
207
|
+
const instance = tree.root;
|
|
208
|
+
const button = instance.find(
|
|
209
|
+
(el) => el.props.testID === TESTID.BUTTON_CHOOSE_ON_MAP
|
|
210
|
+
);
|
|
211
|
+
await act(async () => {
|
|
212
|
+
await button.props.onPress();
|
|
213
|
+
});
|
|
214
|
+
expect(mockNavigate).toBeCalled();
|
|
215
|
+
});
|
|
216
|
+
});
|
|
@@ -6,6 +6,7 @@ import { SCProvider } from '../../../context';
|
|
|
6
6
|
import { mockSCStore } from '../../../context/mockStore';
|
|
7
7
|
import ListSmartAccount from '../SmartAccount';
|
|
8
8
|
import { SmartAccountItem } from '../SmartAccountItem';
|
|
9
|
+
import { MenuActionMore } from '../../../commons';
|
|
9
10
|
|
|
10
11
|
const wrapComponent = (route, navigation) => (
|
|
11
12
|
<SCProvider initState={mockSCStore({})}>
|
|
@@ -13,6 +14,17 @@ const wrapComponent = (route, navigation) => (
|
|
|
13
14
|
</SCProvider>
|
|
14
15
|
);
|
|
15
16
|
|
|
17
|
+
const mockedNavigate = jest.fn();
|
|
18
|
+
|
|
19
|
+
jest.mock('@react-navigation/native', () => {
|
|
20
|
+
return {
|
|
21
|
+
...jest.requireActual('@react-navigation/native'),
|
|
22
|
+
useNavigation: () => ({
|
|
23
|
+
goBack: mockedNavigate,
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
|
|
16
28
|
jest.mock('react', () => {
|
|
17
29
|
return {
|
|
18
30
|
...jest.requireActual('react'),
|
|
@@ -55,4 +67,16 @@ describe('Test SmartAccount', () => {
|
|
|
55
67
|
const smartAccountItem = instance.findAllByType(SmartAccountItem);
|
|
56
68
|
expect(smartAccountItem.length).toEqual(3);
|
|
57
69
|
});
|
|
70
|
+
|
|
71
|
+
test('test render SmartAccountItem', async () => {
|
|
72
|
+
await act(async () => {
|
|
73
|
+
tree = await renderer.create(wrapComponent());
|
|
74
|
+
});
|
|
75
|
+
const instance = tree.root;
|
|
76
|
+
const menuActionMore = instance.findByType(MenuActionMore);
|
|
77
|
+
await act(async () => {
|
|
78
|
+
menuActionMore.props.onItemClick();
|
|
79
|
+
});
|
|
80
|
+
expect(menuActionMore.props.isVisible).toEqual(false);
|
|
81
|
+
});
|
|
58
82
|
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer, { act } from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import { SCProvider } from '../../../context';
|
|
5
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
6
|
+
import { SmartAccountItem } from '../SmartAccountItem';
|
|
7
|
+
import { TouchableOpacity } from 'react-native';
|
|
8
|
+
import { TESTID } from '../../../configs/Constants';
|
|
9
|
+
|
|
10
|
+
const mockedOnShowMenuMore = jest.fn();
|
|
11
|
+
const mockedGotoSmartAccountDetail = jest.fn();
|
|
12
|
+
|
|
13
|
+
const wrapComponent = (route) => (
|
|
14
|
+
<SCProvider initState={mockSCStore({})}>
|
|
15
|
+
<SmartAccountItem
|
|
16
|
+
onShowMenuMore={mockedOnShowMenuMore}
|
|
17
|
+
gotoSmartAccountDetail={mockedGotoSmartAccountDetail}
|
|
18
|
+
/>
|
|
19
|
+
</SCProvider>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const mockedNavigate = jest.fn();
|
|
23
|
+
|
|
24
|
+
jest.mock('@react-navigation/native', () => {
|
|
25
|
+
return {
|
|
26
|
+
...jest.requireActual('@react-navigation/native'),
|
|
27
|
+
useNavigation: () => ({
|
|
28
|
+
goBack: mockedNavigate,
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
jest.mock('react', () => {
|
|
34
|
+
return {
|
|
35
|
+
...jest.requireActual('react'),
|
|
36
|
+
memo: (x) => x,
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
jest.mock('axios');
|
|
41
|
+
describe('Test SmartAccountItem', () => {
|
|
42
|
+
let tree;
|
|
43
|
+
test('test render SmartAccountItem', async () => {
|
|
44
|
+
await act(async () => {
|
|
45
|
+
tree = await renderer.create(wrapComponent());
|
|
46
|
+
});
|
|
47
|
+
const instance = tree.root;
|
|
48
|
+
|
|
49
|
+
const onPressGotoSmartAccountDetail = instance.find(
|
|
50
|
+
(el) =>
|
|
51
|
+
el.props.testID === TESTID.SMART_ACCOUNT_ITEM &&
|
|
52
|
+
el.type === TouchableOpacity
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
await act(async () => {
|
|
56
|
+
onPressGotoSmartAccountDetail.props.onPress();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(mockedGotoSmartAccountDetail).toHaveBeenCalled();
|
|
60
|
+
|
|
61
|
+
const onPressMore = instance.find(
|
|
62
|
+
(el) =>
|
|
63
|
+
el.props.testID === TESTID.SMART_ACCOUNT_ITEM_PRESSMORE &&
|
|
64
|
+
el.type === TouchableOpacity
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
await act(async () => {
|
|
68
|
+
onPressMore.props.onPress();
|
|
69
|
+
});
|
|
70
|
+
expect(mockedOnShowMenuMore).toHaveBeenCalled();
|
|
71
|
+
});
|
|
72
|
+
});
|