@eohjsc/react-native-smart-city 0.2.26 → 0.2.27
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/Illustrations.svg +83 -0
- package/assets/images/{WeatherChange.svg → ValueChange.svg} +0 -0
- package/index.js +2 -0
- package/package.json +3 -1
- package/src/Images/Common/file.png +0 -0
- package/src/Images/Common/fullscreen.png +0 -0
- package/src/commons/ActionGroup/OnOffTemplate/index.js +5 -0
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +294 -0
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplateWithNullConfigValue.test.js +60 -0
- package/src/commons/AlertAction/__test__/AlertAction.test.js +6 -6
- package/src/commons/AlertAction/index.js +2 -0
- package/src/commons/Automate/ItemAutomate.js +7 -1
- package/src/commons/Automate/__test__/ItemAutomate.test.js +16 -0
- package/src/commons/Automate/__test__/ItemScriptAction.test.js +16 -0
- package/src/commons/BackDefault/__test__/BackDefault.test.js +21 -0
- package/src/commons/BottomScrollPicker/index.js +5 -1
- package/src/commons/BottomSheet/index.js +10 -5
- package/src/commons/ButtonPopup/__test__/__snapshots__/ButtonPopup.test.js.snap +2 -0
- package/src/commons/ButtonPopup/index.js +2 -0
- package/src/commons/Calendar/index.js +72 -0
- package/src/commons/Calendar/styles.js +11 -0
- package/src/commons/Device/ItemAddNew/index.js +2 -2
- package/src/commons/Explore/__test__/HeaderExplore.test.js +25 -0
- package/src/commons/Explore/__test__/LocationItem.test.js +31 -0
- package/src/commons/Header/HeaderCustom.js +7 -3
- package/src/commons/HeaderAni/index.js +31 -3
- package/src/commons/HorizontalPicker/index.js +134 -0
- package/src/commons/HorizontalPicker/styles.js +56 -0
- package/src/commons/Modal/__test__/ModalBottom.test.js +39 -0
- package/src/commons/RowItem/__test__/RowItem.test.js +16 -0
- package/src/commons/RowItem/index.js +61 -0
- package/src/commons/RowItem/styles.js +53 -0
- package/src/commons/Sharing/WrapHeaderScrollable.js +78 -74
- package/src/commons/SubUnit/OneTap/ItemOneTap.js +73 -69
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +47 -1
- package/src/commons/SubUnit/OneTap/index.js +2 -2
- package/src/commons/Unit/__test__/SharedUnit.test.js +330 -0
- package/src/commons/WheelDateTimePicker/index.js +16 -8
- package/src/commons/index.js +2 -0
- package/src/configs/API.js +5 -1
- package/src/configs/Constants.js +18 -3
- package/src/configs/Theme.js +20 -0
- package/src/context/SCContext.tsx +2 -2
- package/src/context/mockStore.ts +3 -1
- package/src/hooks/Common/__test__/useStatusbar.test.js +28 -0
- package/src/navigations/AutomateStack.js +45 -0
- package/src/navigations/UnitStack.js +33 -14
- package/src/navigations/utils.js +8 -0
- package/src/screens/AddNewAction/Components/LoadingSelectAction.js +40 -0
- package/src/screens/AddNewAction/Components/index.js +3 -0
- package/src/screens/AddNewAction/SelectAction.js +147 -62
- package/src/screens/AddNewAction/{SelectDevice.js → SelectSensorDevices.js} +42 -12
- package/src/screens/AddNewAction/SetupSensor.js +221 -0
- package/src/screens/AddNewAction/Styles/SelectActionStyles.js +43 -5
- package/src/screens/AddNewAction/Styles/{SelectDeviceStyles.js → SelectSensorDevicesStyles.js} +0 -0
- package/src/screens/AddNewAction/Styles/SetupSensorStyles.js +76 -0
- package/src/screens/AddNewAction/__test__/SelectAction.test.js +0 -19
- package/src/screens/AddNewAction/__test__/{SelectDevice.test.js → SelectSensorDevices.test.js} +3 -3
- package/src/screens/AddNewAction/__test__/SetupSensor.test.js +125 -0
- package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +69 -12
- package/src/screens/AddNewAutoSmart/index.js +42 -14
- package/src/screens/AddNewOneTap/AddNewOneTapStyles.js +4 -3
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +1 -0
- package/src/screens/AddNewOneTap/index.js +7 -4
- package/src/screens/AllCamera/__test__/index.test.js +103 -0
- package/src/screens/Automate/Components/Loading.js +64 -0
- package/src/screens/Automate/Styles/indexStyles.js +64 -0
- package/src/screens/Automate/__test__/Loading.test.js +16 -0
- package/src/screens/Automate/__test__/index.test.js +93 -0
- package/src/screens/Automate/index.js +148 -0
- package/src/screens/Device/__test__/detail.test.js +64 -0
- package/src/screens/Device/detail.js +17 -7
- package/src/screens/EditActionsList/index.js +2 -2
- package/src/screens/GuestInfo/__test__/index.test.js +176 -0
- package/src/screens/GuestInfo/components/AccessScheduleItem.js +6 -1
- package/src/screens/GuestInfo/components/AccessScheduleSheet.js +26 -15
- package/src/screens/GuestInfo/components/HeaderGuestInfo.js +6 -1
- package/src/screens/GuestInfo/components/RecurringDetail.js +9 -2
- package/src/screens/GuestInfo/components/TemporaryDetail.js +9 -2
- package/src/screens/GuestInfo/constant.js +2 -2
- package/src/screens/GuestInfo/index.js +4 -5
- package/src/screens/PlayBackCamera/Timer.js +1 -1
- package/src/screens/ScriptDetail/Styles/indexStyles.js +14 -0
- package/src/screens/ScriptDetail/__test__/index.test.js +119 -0
- package/src/screens/ScriptDetail/hooks/index.js +55 -0
- package/src/screens/ScriptDetail/index.js +124 -23
- package/src/screens/SelectUnit/Styles/indexStyles.js +55 -0
- package/src/screens/SelectUnit/__test__/index.test.js +85 -0
- package/src/screens/SelectUnit/index.js +100 -0
- package/src/screens/SetSchedule/__test__/index.test.js +97 -0
- package/src/screens/SetSchedule/components/RepeatOptionsPopup.js +56 -0
- package/src/screens/SetSchedule/components/RowItem.js +27 -0
- package/src/screens/SetSchedule/components/SelectWeekday.js +65 -0
- package/src/screens/SetSchedule/index.js +139 -0
- package/src/screens/SetSchedule/styles/RepeatOptionsPopupStyles.js +22 -0
- package/src/screens/SetSchedule/styles/RowItemStyles.js +29 -0
- package/src/screens/SetSchedule/styles/SelectWeekdayStyles.js +26 -0
- package/src/screens/{AddNewScriptAction/AddNewScriptActionStyles.js → SetSchedule/styles/indexStyles.js} +6 -12
- package/src/screens/Sharing/__test__/MemberList.test.js +21 -28
- package/src/screens/SubUnit/EditSubUnit.js +274 -0
- package/src/screens/SubUnit/EditSubUnitStyles.js +119 -0
- package/src/screens/SubUnit/ManageSubUnit.js +112 -370
- package/src/screens/SubUnit/ManageSubUnitStyles.js +40 -0
- package/src/screens/SubUnit/__test__/EditSubUnit.test.js +427 -0
- package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +42 -386
- package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +85 -0
- package/src/screens/SubUnit/hooks/useManageSubUnit.js +35 -0
- package/src/screens/Unit/Detail.js +3 -2
- package/src/screens/Unit/ManageUnit.js +10 -0
- package/src/screens/Unit/components/SearchLocation/__test__/RowLocation.test.js +36 -0
- package/src/screens/Unit/components/__test__/MyUnit.test.js +35 -0
- package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +32 -0
- package/src/screens/UnitSummary/components/__test__/UnitSummary.test.js +67 -0
- package/src/screens/UnitSummary/components/__test__/index.test.js +48 -0
- package/src/screens/UnitSummary/components/index.js +1 -37
- package/src/screens/UnitSummary/components/indexstyles.js +39 -0
- package/src/utils/Apis/axios.js +0 -4
- package/src/utils/I18n/translations/en.json +30 -4
- package/src/utils/I18n/translations/vi.json +29 -3
- package/src/utils/Route/index.js +6 -1
- package/src/utils/__test__/InitData.test.js +20 -0
- package/src/commons/Automate/ItemAddNewScriptAction.js +0 -30
- package/src/screens/AddNewScriptAction/index.js +0 -100
|
@@ -1,46 +1,69 @@
|
|
|
1
|
-
import React, { memo, useState } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { memo, useState, useCallback } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { useNavigation } from '@react-navigation/native';
|
|
3
4
|
import { HeaderCustom } from '../../commons/Header';
|
|
4
5
|
import styles from './styles/AddNewAutoSmartStyles';
|
|
5
6
|
import Text from '../../commons/Text';
|
|
6
7
|
import BottomButtonView from '../../commons/BottomButtonView';
|
|
7
8
|
import ItemAutomate from '../../commons/Automate/ItemAutomate';
|
|
8
|
-
import {
|
|
9
|
-
|
|
9
|
+
import {
|
|
10
|
+
AUTOMATE_SELECT,
|
|
11
|
+
AUTOMATE_TYPE,
|
|
12
|
+
TESTID,
|
|
13
|
+
} from '../../configs/Constants';
|
|
10
14
|
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
15
|
+
import Routes from '../../utils/Route';
|
|
11
16
|
|
|
12
17
|
const AddNewAutoSmart = memo(({ route }) => {
|
|
13
18
|
const t = useTranslations();
|
|
14
|
-
const {
|
|
19
|
+
const { navigate, goBack } = useNavigation();
|
|
20
|
+
const { type, unit, isScript } = route.params;
|
|
15
21
|
const typeAutoSmart = {
|
|
16
22
|
automate: [
|
|
17
23
|
{
|
|
18
24
|
type: AUTOMATE_TYPE.ONE_TAP,
|
|
25
|
+
route: Routes.AddNewOneTap,
|
|
19
26
|
},
|
|
20
27
|
{
|
|
21
28
|
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
29
|
+
route: Routes.SelectSensorDevices,
|
|
30
|
+
data: {
|
|
31
|
+
title: AUTOMATE_SELECT.SELECT_SENSOR,
|
|
32
|
+
},
|
|
22
33
|
},
|
|
23
34
|
{
|
|
24
35
|
type: AUTOMATE_TYPE.SCHEDULE,
|
|
36
|
+
route: Routes.SetSchedule,
|
|
25
37
|
},
|
|
26
38
|
],
|
|
27
39
|
value_change: [
|
|
28
40
|
{
|
|
29
41
|
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
42
|
+
route: Routes.SelectSensorDevices,
|
|
43
|
+
data: {
|
|
44
|
+
title: AUTOMATE_SELECT.SELECT_SENSOR,
|
|
45
|
+
},
|
|
30
46
|
},
|
|
31
47
|
{
|
|
32
48
|
type: AUTOMATE_TYPE.SCHEDULE,
|
|
49
|
+
route: Routes.SetSchedule,
|
|
33
50
|
},
|
|
34
51
|
],
|
|
35
52
|
};
|
|
36
|
-
|
|
37
|
-
// eslint-disable-next-line no-alert
|
|
38
|
-
const onPress = () => {
|
|
39
|
-
Alert.alert(t('feature_under_development'));
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const [selectedIndex, setSelectedIndex] = useState(-1);
|
|
43
53
|
const [data] = useState(typeAutoSmart[type]);
|
|
54
|
+
const [selectedIndex, setSelectedIndex] = useState(-1);
|
|
55
|
+
|
|
56
|
+
const handleOnContinue = useCallback(() => {
|
|
57
|
+
const automate = data[selectedIndex];
|
|
58
|
+
if (automate?.route) {
|
|
59
|
+
navigate(automate.route, {
|
|
60
|
+
type: automate.type,
|
|
61
|
+
unit: unit,
|
|
62
|
+
...(automate.data || {}),
|
|
63
|
+
isScript,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}, [navigate, selectedIndex, data, unit, isScript]);
|
|
44
67
|
|
|
45
68
|
const handleSelectIndex = (index) => {
|
|
46
69
|
if (index !== selectedIndex) {
|
|
@@ -50,9 +73,14 @@ const AddNewAutoSmart = memo(({ route }) => {
|
|
|
50
73
|
}
|
|
51
74
|
};
|
|
52
75
|
|
|
76
|
+
const onClose = useCallback(() => {
|
|
77
|
+
isScript ? goBack() : alert(t('feature_under_development'));
|
|
78
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
79
|
+
}, [isScript]);
|
|
80
|
+
|
|
53
81
|
return (
|
|
54
82
|
<View style={styles.wrap}>
|
|
55
|
-
<HeaderCustom isShowClose />
|
|
83
|
+
<HeaderCustom isShowClose onClose={onClose} />
|
|
56
84
|
<View style={styles.container}>
|
|
57
85
|
<Text semibold type={'H2'} style={styles.titleCreate}>
|
|
58
86
|
{t('create_smart')}
|
|
@@ -73,7 +101,7 @@ const AddNewAutoSmart = memo(({ route }) => {
|
|
|
73
101
|
</View>
|
|
74
102
|
<BottomButtonView
|
|
75
103
|
testIDPrefix={TESTID.PREFIX.BUTTON_ADD_AUTO_SMART}
|
|
76
|
-
onPressMain={
|
|
104
|
+
onPressMain={handleOnContinue}
|
|
77
105
|
style={styles.bottomButton}
|
|
78
106
|
mainTitle={t('continue')}
|
|
79
107
|
typeMain={selectedIndex === -1 ? 'disabled' : 'primary'}
|
|
@@ -35,9 +35,10 @@ export default StyleSheet.create({
|
|
|
35
35
|
bottom: 0,
|
|
36
36
|
left: 0,
|
|
37
37
|
right: 0,
|
|
38
|
-
paddingBottom: getBottomSpace() > 0 ? getBottomSpace() :
|
|
39
|
-
paddingTop:
|
|
38
|
+
paddingBottom: getBottomSpace() > 0 ? getBottomSpace() : 32,
|
|
39
|
+
paddingTop: 24,
|
|
40
40
|
backgroundColor: Colors.White,
|
|
41
|
-
|
|
41
|
+
borderColor: Colors.ShadownTransparent,
|
|
42
|
+
borderTopWidth: 1,
|
|
42
43
|
},
|
|
43
44
|
});
|
|
@@ -14,16 +14,17 @@ import { axiosPost } from '../../utils/Apis/axios';
|
|
|
14
14
|
import Routes from '../../utils/Route';
|
|
15
15
|
|
|
16
16
|
const AddNewOneTap = memo(({ route }) => {
|
|
17
|
-
const { type, unit } = route.params;
|
|
17
|
+
const { type, unit, automateData = {} } = route.params;
|
|
18
18
|
const t = useTranslations();
|
|
19
19
|
const { navigate } = useNavigation();
|
|
20
|
-
const [name, setName] = useState(
|
|
20
|
+
const [name, setName] = useState('');
|
|
21
21
|
|
|
22
22
|
const handleContinue = useCallback(async () => {
|
|
23
23
|
const { success, data } = await axiosPost(API.AUTOMATE.CREATE_AUTOMATE(), {
|
|
24
24
|
unit: unit.id,
|
|
25
25
|
type: type,
|
|
26
26
|
name: name,
|
|
27
|
+
...automateData,
|
|
27
28
|
});
|
|
28
29
|
if (success) {
|
|
29
30
|
navigate(Routes.ScriptDetail, {
|
|
@@ -32,9 +33,10 @@ const AddNewOneTap = memo(({ route }) => {
|
|
|
32
33
|
name: name,
|
|
33
34
|
type: type,
|
|
34
35
|
havePermission: true,
|
|
36
|
+
isCreateScriptSuccess: true,
|
|
35
37
|
});
|
|
36
38
|
}
|
|
37
|
-
}, [type, name, unit, navigate]);
|
|
39
|
+
}, [type, name, unit, automateData, navigate]);
|
|
38
40
|
|
|
39
41
|
const onChangeName = useCallback((text) => {
|
|
40
42
|
setName(text);
|
|
@@ -70,8 +72,9 @@ const AddNewOneTap = memo(({ route }) => {
|
|
|
70
72
|
</ScrollView>
|
|
71
73
|
<BottomButtonView
|
|
72
74
|
style={styles.viewBottomFixed}
|
|
73
|
-
mainTitle={t('
|
|
75
|
+
mainTitle={t('save')}
|
|
74
76
|
onPressMain={handleContinue}
|
|
77
|
+
typeMain={name !== '' ? 'primary' : 'disabled'}
|
|
75
78
|
/>
|
|
76
79
|
</SafeAreaView>
|
|
77
80
|
);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TouchableOpacity } from 'react-native';
|
|
3
|
+
import AllCamera from '..';
|
|
4
|
+
import { act, create } from 'react-test-renderer';
|
|
5
|
+
import { SCProvider } from '../../../context';
|
|
6
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
7
|
+
import { ModalFullVideo } from '../../../commons/Modal';
|
|
8
|
+
import Carousel from 'react-native-snap-carousel';
|
|
9
|
+
|
|
10
|
+
const arrCameras = [
|
|
11
|
+
{
|
|
12
|
+
id: 41,
|
|
13
|
+
order: 1,
|
|
14
|
+
template: 'camera',
|
|
15
|
+
type: 'camera',
|
|
16
|
+
configuration: {
|
|
17
|
+
id: 4,
|
|
18
|
+
name: 'Camera cửa nhà xe',
|
|
19
|
+
uri: 'rtsp://admin:hd543211@203.205.32.86:10555/ISAPI/Streaming/Channels/101/',
|
|
20
|
+
preview_uri:
|
|
21
|
+
'rtsp://admin:hd543211@203.205.32.86:10555/ISAPI/Streaming/Channels/101/',
|
|
22
|
+
playback:
|
|
23
|
+
'rtsp://admin:4tpg2SnnmChdh8TK@203.205.32.86:11024/Streaming/tracks/101/?starttime=20210901T110000Z',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const mockSetState = jest.fn();
|
|
29
|
+
|
|
30
|
+
jest.mock('react', () => {
|
|
31
|
+
return {
|
|
32
|
+
...jest.requireActual('react'),
|
|
33
|
+
useState: (init) => [init, mockSetState],
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
jest.mock('@react-navigation/core', () => {
|
|
38
|
+
return {
|
|
39
|
+
...jest.requireActual('@react-navigation/core'),
|
|
40
|
+
useRoute: jest.fn().mockReturnValue({
|
|
41
|
+
params: {
|
|
42
|
+
arrCameras: [
|
|
43
|
+
{
|
|
44
|
+
id: 41,
|
|
45
|
+
order: 1,
|
|
46
|
+
template: 'camera',
|
|
47
|
+
type: 'camera',
|
|
48
|
+
configuration: {
|
|
49
|
+
id: 4,
|
|
50
|
+
name: 'Camera cửa nhà xe',
|
|
51
|
+
uri: 'rtsp://admin:hd543211@203.205.32.86:10555/ISAPI/Streaming/Channels/101/',
|
|
52
|
+
preview_uri:
|
|
53
|
+
'rtsp://admin:hd543211@203.205.32.86:10555/ISAPI/Streaming/Channels/101/',
|
|
54
|
+
playback:
|
|
55
|
+
'rtsp://admin:4tpg2SnnmChdh8TK@203.205.32.86:11024/Streaming/tracks/101/?starttime=20210901T110000Z',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
thumbnail: {
|
|
60
|
+
uri: 'https://eoh-gateway-backend.eoh.io/image-asset.jpeg',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const wrapComponent = () => (
|
|
68
|
+
<SCProvider initState={mockSCStore({})}>
|
|
69
|
+
<AllCamera />
|
|
70
|
+
</SCProvider>
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
describe('Test AllCamera screen', () => {
|
|
74
|
+
let tree;
|
|
75
|
+
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
mockSetState.mockClear();
|
|
78
|
+
jest.useFakeTimers();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('Test render', async () => {
|
|
82
|
+
mockSetState.mockImplementation((init) => [init, mockSetState]);
|
|
83
|
+
mockSetState.mockImplementation((init) => [arrCameras, mockSetState]);
|
|
84
|
+
mockSetState.mockImplementation((init) => [init, mockSetState]);
|
|
85
|
+
mockSetState.mockImplementation((init) => [init, mockSetState]);
|
|
86
|
+
mockSetState.mockImplementation((init) => [init, mockSetState]);
|
|
87
|
+
mockSetState.mockImplementation((init) => [init, mockSetState]);
|
|
88
|
+
await act(() => {
|
|
89
|
+
tree = create(wrapComponent());
|
|
90
|
+
});
|
|
91
|
+
const instance = tree.root;
|
|
92
|
+
const TouchableOpacities = instance.findAllByType(TouchableOpacity);
|
|
93
|
+
expect(TouchableOpacities).toHaveLength(12);
|
|
94
|
+
const ModalFullVideos = instance.findAllByType(ModalFullVideo);
|
|
95
|
+
expect(ModalFullVideos).toHaveLength(1);
|
|
96
|
+
act(() => {
|
|
97
|
+
ModalFullVideos[0].props.onClose();
|
|
98
|
+
});
|
|
99
|
+
expect(mockSetState).toBeCalledWith(false);
|
|
100
|
+
const Carousels = instance.findAllByType(Carousel);
|
|
101
|
+
expect(Carousels).toHaveLength(1);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import ContentLoader, { Rect } from 'react-content-loader/native';
|
|
4
|
+
import { Constants } from '../../../configs';
|
|
5
|
+
|
|
6
|
+
const Loading = ({ style }) => (
|
|
7
|
+
<View style={style}>
|
|
8
|
+
<ContentLoader>
|
|
9
|
+
<Rect x="16" y="24" rx="10" ry="10" width={120} height="28" />
|
|
10
|
+
<Rect
|
|
11
|
+
x="16"
|
|
12
|
+
y="68"
|
|
13
|
+
rx="10"
|
|
14
|
+
ry="10"
|
|
15
|
+
width={(Constants.width - 40) / 2}
|
|
16
|
+
height="106"
|
|
17
|
+
/>
|
|
18
|
+
<Rect
|
|
19
|
+
x={(Constants.width - 40) / 2 + 24}
|
|
20
|
+
y="68"
|
|
21
|
+
rx="10"
|
|
22
|
+
ry="10"
|
|
23
|
+
width={(Constants.width - 40) / 2}
|
|
24
|
+
height="106"
|
|
25
|
+
/>
|
|
26
|
+
<Rect x="16" y="200" rx="10" ry="10" width={120} height="28" />
|
|
27
|
+
<Rect
|
|
28
|
+
x="16"
|
|
29
|
+
y="244"
|
|
30
|
+
rx="10"
|
|
31
|
+
ry="10"
|
|
32
|
+
width={(Constants.width - 40) / 2}
|
|
33
|
+
height="106"
|
|
34
|
+
/>
|
|
35
|
+
<Rect
|
|
36
|
+
x={(Constants.width - 40) / 2 + 24}
|
|
37
|
+
y="244"
|
|
38
|
+
rx="10"
|
|
39
|
+
ry="10"
|
|
40
|
+
width={(Constants.width - 40) / 2}
|
|
41
|
+
height="106"
|
|
42
|
+
/>
|
|
43
|
+
<Rect x="16" y="374" rx="10" ry="10" width={120} height="28" />
|
|
44
|
+
<Rect
|
|
45
|
+
x="16"
|
|
46
|
+
y="418"
|
|
47
|
+
rx="10"
|
|
48
|
+
ry="10"
|
|
49
|
+
width={(Constants.width - 40) / 2}
|
|
50
|
+
height="106"
|
|
51
|
+
/>
|
|
52
|
+
<Rect
|
|
53
|
+
x={(Constants.width - 40) / 2 + 24}
|
|
54
|
+
y="418"
|
|
55
|
+
rx="10"
|
|
56
|
+
ry="10"
|
|
57
|
+
width={(Constants.width - 40) / 2}
|
|
58
|
+
height="106"
|
|
59
|
+
/>
|
|
60
|
+
</ContentLoader>
|
|
61
|
+
</View>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
export default Loading;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors, Constants } from '../../../configs';
|
|
3
|
+
import { getBottomSpace } from 'react-native-iphone-x-helper';
|
|
4
|
+
|
|
5
|
+
export default StyleSheet.create({
|
|
6
|
+
wrap: {
|
|
7
|
+
flex: 1,
|
|
8
|
+
backgroundColor: Colors.White,
|
|
9
|
+
},
|
|
10
|
+
buttonAdd: {
|
|
11
|
+
paddingRight: 16,
|
|
12
|
+
},
|
|
13
|
+
titleItem: {
|
|
14
|
+
flexDirection: 'row',
|
|
15
|
+
justifyContent: 'space-between',
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
},
|
|
18
|
+
contentContainerStyle: {
|
|
19
|
+
paddingLeft: 16,
|
|
20
|
+
paddingTop: 16,
|
|
21
|
+
paddingBottom: 80 + getBottomSpace(),
|
|
22
|
+
},
|
|
23
|
+
arrowRightButon: {
|
|
24
|
+
width: 40,
|
|
25
|
+
height: 40,
|
|
26
|
+
justifyContent: 'center',
|
|
27
|
+
alignItems: 'center',
|
|
28
|
+
},
|
|
29
|
+
arrowRight: {
|
|
30
|
+
transform: [
|
|
31
|
+
{
|
|
32
|
+
rotate: '180deg',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
tintColor: Colors.Gray7,
|
|
36
|
+
width: 8,
|
|
37
|
+
height: 12,
|
|
38
|
+
},
|
|
39
|
+
wrapAutomateItem: {
|
|
40
|
+
backgroundColor: Colors.White,
|
|
41
|
+
height: 106,
|
|
42
|
+
width: (Constants.width - 40) / 2,
|
|
43
|
+
borderRadius: 8,
|
|
44
|
+
marginRight: 8,
|
|
45
|
+
shadowColor: Colors.Shadow,
|
|
46
|
+
shadowOffset: {
|
|
47
|
+
width: 0,
|
|
48
|
+
height: 1.5,
|
|
49
|
+
},
|
|
50
|
+
shadowOpacity: 0.2,
|
|
51
|
+
shadowRadius: 3,
|
|
52
|
+
elevation: 2,
|
|
53
|
+
marginVertical: 5,
|
|
54
|
+
},
|
|
55
|
+
wrapUniItem: {
|
|
56
|
+
marginBottom: 16,
|
|
57
|
+
},
|
|
58
|
+
contentContainerStyle2: {
|
|
59
|
+
paddingLeft: 2,
|
|
60
|
+
},
|
|
61
|
+
addNewItem: {
|
|
62
|
+
marginTop: 7,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { act, create } from 'react-test-renderer';
|
|
4
|
+
import Loading from '../Components/Loading';
|
|
5
|
+
|
|
6
|
+
describe('Test Loading', () => {
|
|
7
|
+
let tree;
|
|
8
|
+
it('Test render', async () => {
|
|
9
|
+
await act(() => {
|
|
10
|
+
tree = create(<Loading />);
|
|
11
|
+
});
|
|
12
|
+
const instance = tree.root;
|
|
13
|
+
const Views = instance.findAllByType(View);
|
|
14
|
+
expect(Views).toHaveLength(1);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { FlatList } from 'react-native';
|
|
3
|
+
import { act, create } from 'react-test-renderer';
|
|
4
|
+
import axios from 'axios';
|
|
5
|
+
import Automate from '../';
|
|
6
|
+
import { SCProvider } from '../../../context';
|
|
7
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
8
|
+
import ItemOneTap from '../../../commons/SubUnit/OneTap/ItemOneTap';
|
|
9
|
+
|
|
10
|
+
jest.mock('axios');
|
|
11
|
+
const mockedNavigate = jest.fn();
|
|
12
|
+
const mockSetState = jest.fn();
|
|
13
|
+
|
|
14
|
+
jest.mock('@react-navigation/native', () => {
|
|
15
|
+
return {
|
|
16
|
+
...jest.requireActual('@react-navigation/native'),
|
|
17
|
+
useNavigation: () => ({
|
|
18
|
+
navigate: mockedNavigate,
|
|
19
|
+
setOptions: () => ({
|
|
20
|
+
headerRight: jest.fn(),
|
|
21
|
+
}),
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
jest.mock('react', () => {
|
|
27
|
+
return {
|
|
28
|
+
...jest.requireActual('react'),
|
|
29
|
+
memo: (x) => x,
|
|
30
|
+
useState: jest.fn((init) => [init, mockSetState]),
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const wrapComponent = () => (
|
|
35
|
+
<SCProvider initState={mockSCStore({})}>
|
|
36
|
+
<Automate />
|
|
37
|
+
</SCProvider>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
describe('Test Automate', () => {
|
|
41
|
+
let tree;
|
|
42
|
+
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
axios.get.mockClear();
|
|
45
|
+
mockedNavigate.mockClear();
|
|
46
|
+
mockSetState.mockClear();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('Test success get Automate', async () => {
|
|
50
|
+
const response = {
|
|
51
|
+
status: 200,
|
|
52
|
+
data: [
|
|
53
|
+
{
|
|
54
|
+
type: 'MultiUnit',
|
|
55
|
+
automates: [
|
|
56
|
+
{
|
|
57
|
+
id: 1,
|
|
58
|
+
user: 2,
|
|
59
|
+
type: 'one_tap',
|
|
60
|
+
activate_at: '2021-09-17T05:30:00Z',
|
|
61
|
+
script: {
|
|
62
|
+
id: 1,
|
|
63
|
+
name: 'script',
|
|
64
|
+
icon: undefined,
|
|
65
|
+
icon_kit: undefined,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
await axios.get.mockImplementation(async () => {
|
|
73
|
+
return response;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
useState.mockImplementation(() => [false, mockSetState]);
|
|
77
|
+
useState.mockImplementation(() => [response.data, mockSetState]);
|
|
78
|
+
|
|
79
|
+
await act(() => {
|
|
80
|
+
tree = create(wrapComponent());
|
|
81
|
+
});
|
|
82
|
+
expect(mockSetState).toBeCalledWith(true);
|
|
83
|
+
const instance = tree.root;
|
|
84
|
+
const FlatLists = instance.findAllByType(FlatList);
|
|
85
|
+
expect(FlatLists).toHaveLength(2);
|
|
86
|
+
const ItemOneTaps = instance.findAllByType(ItemOneTap);
|
|
87
|
+
expect(ItemOneTaps).toHaveLength(1);
|
|
88
|
+
act(() => {
|
|
89
|
+
ItemOneTaps[0].props.onPressItem();
|
|
90
|
+
});
|
|
91
|
+
expect(mockedNavigate).toBeCalled();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useLayoutEffect,
|
|
5
|
+
useMemo,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import { View, TouchableOpacity, FlatList, Image } from 'react-native';
|
|
9
|
+
import { IconFill } from '@ant-design/icons-react-native/es';
|
|
10
|
+
import { useNavigation } from '@react-navigation/native';
|
|
11
|
+
|
|
12
|
+
import styles from './Styles/indexStyles';
|
|
13
|
+
import { API, Colors, Images } from '../../configs';
|
|
14
|
+
import { axiosGet } from '../../utils/Apis/axios';
|
|
15
|
+
import Text from '../../commons/Text';
|
|
16
|
+
import ItemOneTap from '../../commons/SubUnit/OneTap/ItemOneTap';
|
|
17
|
+
import Routes from '../../utils/Route';
|
|
18
|
+
import Loading from './Components/Loading';
|
|
19
|
+
import ItemAddNew from '../../commons/Device/ItemAddNew';
|
|
20
|
+
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
21
|
+
|
|
22
|
+
const keyExtractor = (item) => item.id;
|
|
23
|
+
const MULTI_UNIT = 'MultiUnit';
|
|
24
|
+
|
|
25
|
+
const Automate = () => {
|
|
26
|
+
const t = useTranslations();
|
|
27
|
+
const { setOptions, navigate } = useNavigation();
|
|
28
|
+
const [automatesData, setAutomatesData] = useState([]);
|
|
29
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
30
|
+
|
|
31
|
+
const getAutomates = useCallback(async () => {
|
|
32
|
+
setIsLoading(true);
|
|
33
|
+
const { success, data } = await axiosGet(API.AUTOMATE.GET_AUTOMATES());
|
|
34
|
+
if (success && data && data.length) {
|
|
35
|
+
setAutomatesData(data);
|
|
36
|
+
}
|
|
37
|
+
const timeout = setTimeout(() => {
|
|
38
|
+
setIsLoading(false);
|
|
39
|
+
clearTimeout(timeout);
|
|
40
|
+
}, 1000);
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
const onPressItem = (item) => () => {
|
|
44
|
+
navigate(Routes.UnitStack, {
|
|
45
|
+
screen: Routes.ScriptDetail,
|
|
46
|
+
params: {
|
|
47
|
+
id: item?.id,
|
|
48
|
+
name: item?.script?.name,
|
|
49
|
+
type: item?.type,
|
|
50
|
+
havePermission: true,
|
|
51
|
+
unit: {},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handleOnAddNew = useCallback(() => {
|
|
57
|
+
alert(t('feature_under_development'));
|
|
58
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
59
|
+
}, []);
|
|
60
|
+
|
|
61
|
+
const renderItemAutomate = useCallback(
|
|
62
|
+
({ item }) => {
|
|
63
|
+
return (
|
|
64
|
+
<ItemOneTap
|
|
65
|
+
isOwner={true}
|
|
66
|
+
automate={item}
|
|
67
|
+
wrapSyles={styles.wrapAutomateItem}
|
|
68
|
+
onPressItem={onPressItem(item)}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
},
|
|
72
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
73
|
+
[automatesData]
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const renderItem = useCallback(
|
|
77
|
+
({ item = {} }) => {
|
|
78
|
+
const { type = '', unit_name = '', automates = [] } = item;
|
|
79
|
+
return (
|
|
80
|
+
<View style={styles.wrapUniItem}>
|
|
81
|
+
<View style={styles.titleItem}>
|
|
82
|
+
<Text type="H3" semibold>
|
|
83
|
+
{type === MULTI_UNIT ? 'Multi Units' : unit_name}
|
|
84
|
+
</Text>
|
|
85
|
+
<TouchableOpacity style={styles.arrowRightButon}>
|
|
86
|
+
<Image source={Images.arrowBack} style={styles.arrowRight} />
|
|
87
|
+
</TouchableOpacity>
|
|
88
|
+
</View>
|
|
89
|
+
<FlatList
|
|
90
|
+
horizontal
|
|
91
|
+
keyExtractor={keyExtractor}
|
|
92
|
+
data={automates}
|
|
93
|
+
renderItem={renderItemAutomate}
|
|
94
|
+
showsHorizontalScrollIndicator={false}
|
|
95
|
+
contentContainerStyle={styles.contentContainerStyle2}
|
|
96
|
+
ListFooterComponent={renderListFooterComponent}
|
|
97
|
+
/>
|
|
98
|
+
</View>
|
|
99
|
+
);
|
|
100
|
+
},
|
|
101
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
102
|
+
[automatesData]
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const renderListFooterComponent = useMemo(
|
|
106
|
+
() => (
|
|
107
|
+
<ItemAddNew
|
|
108
|
+
title={t('add_new')}
|
|
109
|
+
onAddNew={handleOnAddNew}
|
|
110
|
+
wrapStyle={styles.addNewItem}
|
|
111
|
+
/>
|
|
112
|
+
),
|
|
113
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
114
|
+
[]
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
useLayoutEffect(() => {
|
|
118
|
+
setOptions({
|
|
119
|
+
headerRight: () => (
|
|
120
|
+
<TouchableOpacity style={styles.buttonAdd}>
|
|
121
|
+
<IconFill name={'plus-circle'} size={28} color={Colors.Orange} />
|
|
122
|
+
</TouchableOpacity>
|
|
123
|
+
),
|
|
124
|
+
});
|
|
125
|
+
}, [setOptions]);
|
|
126
|
+
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
getAutomates();
|
|
129
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
130
|
+
}, []);
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<View style={styles.wrap}>
|
|
134
|
+
{isLoading && <Loading />}
|
|
135
|
+
<FlatList
|
|
136
|
+
keyExtractor={keyExtractor}
|
|
137
|
+
data={automatesData}
|
|
138
|
+
extraData={automatesData}
|
|
139
|
+
renderItem={renderItem}
|
|
140
|
+
contentContainerStyle={styles.contentContainerStyle}
|
|
141
|
+
refreshing={false}
|
|
142
|
+
onRefresh={getAutomates}
|
|
143
|
+
/>
|
|
144
|
+
</View>
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export default Automate;
|