@eohjsc/react-native-smart-city 0.7.22 → 0.7.24
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/commons/ActionGroup/TerminalBoxTemplate.js +3 -0
- package/src/commons/ActionTemplate/OnOffButtonAction.js +38 -4
- package/src/commons/ActionTemplate/OnOffSimpleAction.js +55 -15
- package/src/commons/ActionTemplate/OnOffSmartLockAction.js +46 -8
- package/src/commons/ActionTemplate/SwitchButtonAction.js +35 -4
- package/src/commons/ActionTemplate/ThreeButtonAction.js +13 -3
- package/src/commons/ActionTemplate/__test__/OnOffButtonAction.test.js +46 -7
- package/src/commons/ActionTemplate/__test__/OnOffSimpleAction.test.js +66 -6
- package/src/commons/ActionTemplate/__test__/OnOffSmartLockAction.test.js +53 -13
- package/src/commons/ActionTemplate/__test__/SwitchButtonAction.test.js +46 -7
- package/src/commons/ActionTemplate/__test__/index.test.js +6 -2
- package/src/commons/ActionTemplate/index.js +65 -10
- package/src/commons/MediaPlayerDetail/MediaPlayerFull.js +26 -32
- package/src/commons/OneTapTemplate/StatesGridActionTemplate.js +8 -6
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +6 -0
- package/src/commons/SubUnit/OneTap/index.js +5 -0
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +16 -12
- package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +3 -1
- package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +1 -1
- package/src/configs/API.js +6 -0
- package/src/configs/AccessibilityLabel.js +2 -0
- package/src/screens/ActivityLog/__test__/index.test.js +10 -0
- package/src/screens/ActivityLog/hooks/index.js +1 -1
- package/src/screens/Automate/AddNewAction/ChooseAction.js +15 -51
- package/src/screens/Automate/AddNewAction/SelectControlDevices.js +13 -3
- package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +74 -54
- package/src/screens/Automate/AddNewAction/__test__/ChooseAction.test.js +114 -4
- package/src/screens/Automate/AddNewAction/__test__/SetupConfigCondition.test.js +37 -8
- package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +5 -0
- package/src/screens/Automate/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +18 -2
- package/src/screens/Automate/Components/InputName.js +7 -6
- package/src/screens/Automate/Constants.js +12 -0
- package/src/screens/Automate/EditActionsList/UpdateActionScript.js +24 -55
- package/src/screens/Automate/EditActionsList/__tests__/UpdateActionScript.test.js +298 -41
- package/src/screens/Automate/EditActionsList/__tests__/index.test.js +2 -2
- package/src/screens/Automate/EditActionsList/index.js +26 -14
- package/src/screens/Automate/MultiUnits.js +9 -1
- package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +3 -3
- package/src/screens/Automate/ScriptDetail/Components/AddActionScript.js +4 -10
- package/src/screens/Automate/ScriptDetail/Components/DeleteScript.js +2 -4
- package/src/screens/Automate/ScriptDetail/__test__/index.test.js +78 -0
- package/src/screens/Automate/ScriptDetail/index.js +16 -10
- package/src/screens/Automate/ScriptDetail/utils.js +39 -15
- package/src/screens/Automate/SetSchedule/AddEditConditionSchedule.js +27 -160
- package/src/screens/Automate/SetSchedule/EditSchedule.js +269 -0
- package/src/screens/Automate/SetSchedule/__test__/AddEditConditionSchedule.test.js +327 -22
- package/src/screens/Automate/SetSchedule/__test__/index.test.js +35 -22
- package/src/screens/Automate/SetSchedule/components/RepeatOptionsPopup.js +2 -8
- package/src/screens/Automate/SetSchedule/index.js +15 -129
- package/src/screens/Automate/SetSchedule/styles/indexStyles.js +9 -0
- package/src/screens/Automate/__test__/MultiUnits.test.js +6 -1
- package/src/screens/Automate/hooks/useAction.js +222 -0
- package/src/screens/Device/__test__/detail.test.js +48 -1
- package/src/screens/Device/detail.js +46 -3
- package/src/screens/PlayBackCamera/__test__/index.test.js +48 -13
- package/src/screens/PlayBackCamera/index.js +1 -1
- package/src/utils/Apis/axios.js +6 -0
- package/src/utils/I18n/translations/en.js +8 -0
- package/src/utils/I18n/translations/vi.js +12 -4
- package/src/screens/Automate/constants.js +0 -0
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import React, { useCallback
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
2
|
import { View } from 'react-native';
|
|
3
3
|
import { useNavigation } from '@react-navigation/native';
|
|
4
4
|
|
|
5
5
|
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
6
|
-
import { axiosGet, axiosPost } from '../../../utils/Apis/axios';
|
|
7
|
-
import { API } from '../../../configs';
|
|
8
6
|
import Routes from '../../../utils/Route';
|
|
9
7
|
import NewActionWrapper from './NewActionWrapper';
|
|
10
8
|
import moment from 'moment';
|
|
11
9
|
import { ToastBottomHelper } from '../../../utils/Utils';
|
|
10
|
+
import useAction from '../hooks/useAction';
|
|
12
11
|
import RenderActionItem from './RenderActionItem';
|
|
13
12
|
|
|
14
13
|
const ChooseAction = ({ route }) => {
|
|
@@ -18,24 +17,16 @@ const ChooseAction = ({ route }) => {
|
|
|
18
17
|
unitId,
|
|
19
18
|
device,
|
|
20
19
|
automateId,
|
|
20
|
+
scriptItems,
|
|
21
21
|
numberActionCanAdd,
|
|
22
22
|
multiUnit = {},
|
|
23
23
|
} = route.params;
|
|
24
|
-
const [data, setData] = useState([]);
|
|
25
|
-
const [actions, setActions] = useState([]);
|
|
26
24
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
API.DEVICE.DISPLAY_ACTIONS(device.id)
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
if (success) {
|
|
33
|
-
setData(automateData);
|
|
34
|
-
}
|
|
35
|
-
}, [device.id]);
|
|
25
|
+
const { displayActions, saveActions, onSelectAction, onAddSubmit } =
|
|
26
|
+
useAction(device, scriptItems);
|
|
36
27
|
|
|
37
28
|
const onSave = useCallback(async () => {
|
|
38
|
-
if (
|
|
29
|
+
if (saveActions.length > numberActionCanAdd) {
|
|
39
30
|
ToastBottomHelper.error(
|
|
40
31
|
`${t('you_can_only_add_more', { number: numberActionCanAdd })} ${t(
|
|
41
32
|
numberActionCanAdd > 1 ? 'actions' : 'action'
|
|
@@ -45,18 +36,8 @@ const ChooseAction = ({ route }) => {
|
|
|
45
36
|
);
|
|
46
37
|
return;
|
|
47
38
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
action: item.action,
|
|
51
|
-
data: item.data,
|
|
52
|
-
}));
|
|
53
|
-
const { success } = await axiosPost(
|
|
54
|
-
API.AUTOMATE.ADD_SCRIPT_ACTION(automateId),
|
|
55
|
-
{
|
|
56
|
-
list_action,
|
|
57
|
-
unit: unitId || multiUnit.id,
|
|
58
|
-
}
|
|
59
|
-
);
|
|
39
|
+
|
|
40
|
+
const success = await onAddSubmit(automateId, unitId || multiUnit.id);
|
|
60
41
|
|
|
61
42
|
success &&
|
|
62
43
|
navigate({
|
|
@@ -65,50 +46,32 @@ const ChooseAction = ({ route }) => {
|
|
|
65
46
|
params: { saveAt: moment().valueOf() },
|
|
66
47
|
});
|
|
67
48
|
}, [
|
|
68
|
-
actions,
|
|
69
49
|
numberActionCanAdd,
|
|
70
50
|
automateId,
|
|
51
|
+
saveActions.length,
|
|
71
52
|
unitId,
|
|
72
53
|
multiUnit.id,
|
|
54
|
+
onAddSubmit,
|
|
73
55
|
navigate,
|
|
74
56
|
t,
|
|
75
57
|
]);
|
|
76
58
|
|
|
77
|
-
const handleOnSelectAction = (action) => {
|
|
78
|
-
setActions((prevActions) => {
|
|
79
|
-
const index = prevActions.findIndex(
|
|
80
|
-
(item) => item.index === action.index
|
|
81
|
-
);
|
|
82
|
-
if (index !== -1) {
|
|
83
|
-
const newActions = [...prevActions];
|
|
84
|
-
newActions[index] = action;
|
|
85
|
-
return newActions;
|
|
86
|
-
} else {
|
|
87
|
-
return [...prevActions, action];
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
fetchData();
|
|
94
|
-
}, [fetchData]);
|
|
95
|
-
|
|
96
59
|
return (
|
|
97
60
|
<NewActionWrapper
|
|
98
|
-
canNext={
|
|
61
|
+
canNext={saveActions.length}
|
|
99
62
|
onNext={onSave}
|
|
100
63
|
nextTitle={t('save')}
|
|
101
64
|
name={t('set_up {name}', { name: device?.name })}
|
|
102
65
|
>
|
|
103
66
|
<View>
|
|
104
|
-
{!!
|
|
105
|
-
|
|
67
|
+
{!!displayActions?.length &&
|
|
68
|
+
displayActions.map((item, index) => (
|
|
106
69
|
<RenderActionItem
|
|
107
70
|
key={`action_item_${index}`}
|
|
108
71
|
device={device}
|
|
109
72
|
item={item}
|
|
110
73
|
index={index}
|
|
111
|
-
handleOnSelectAction={
|
|
74
|
+
handleOnSelectAction={onSelectAction}
|
|
112
75
|
t={t}
|
|
113
76
|
/>
|
|
114
77
|
))}
|
|
@@ -116,4 +79,5 @@ const ChooseAction = ({ route }) => {
|
|
|
116
79
|
</NewActionWrapper>
|
|
117
80
|
);
|
|
118
81
|
};
|
|
82
|
+
|
|
119
83
|
export default ChooseAction;
|
|
@@ -10,8 +10,9 @@ const SelectControlDevices = ({ route }) => {
|
|
|
10
10
|
const t = useTranslations();
|
|
11
11
|
const {
|
|
12
12
|
unitId,
|
|
13
|
-
closeScreen,
|
|
14
13
|
automateId,
|
|
14
|
+
closeScreen,
|
|
15
|
+
scriptItems,
|
|
15
16
|
numberActionCanAdd,
|
|
16
17
|
multiUnit = {},
|
|
17
18
|
} = route.params || {};
|
|
@@ -54,13 +55,22 @@ const SelectControlDevices = ({ route }) => {
|
|
|
54
55
|
navigate(Routes.ChooseAction, {
|
|
55
56
|
unitId,
|
|
56
57
|
automateId,
|
|
57
|
-
device: selectedDevice,
|
|
58
58
|
closeScreen,
|
|
59
|
+
device: selectedDevice,
|
|
60
|
+
scriptItems,
|
|
59
61
|
numberActionCanAdd,
|
|
60
62
|
multiUnit,
|
|
61
63
|
});
|
|
62
64
|
},
|
|
63
|
-
[
|
|
65
|
+
[
|
|
66
|
+
navigate,
|
|
67
|
+
unitId,
|
|
68
|
+
automateId,
|
|
69
|
+
closeScreen,
|
|
70
|
+
scriptItems,
|
|
71
|
+
numberActionCanAdd,
|
|
72
|
+
multiUnit,
|
|
73
|
+
]
|
|
64
74
|
);
|
|
65
75
|
|
|
66
76
|
if (loading) {
|
|
@@ -52,6 +52,10 @@ const SetupConfigCondition = () => {
|
|
|
52
52
|
const { navigate } = useNavigation();
|
|
53
53
|
const { params = {} } = useRoute();
|
|
54
54
|
const { config, automate, closeScreen, unitId } = params;
|
|
55
|
+
const [conditionData, setConditionData] = useState({
|
|
56
|
+
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
57
|
+
config: automate.config,
|
|
58
|
+
});
|
|
55
59
|
const [selectedCondition, setSelectedCondition] = useState(undefined);
|
|
56
60
|
const [customCondition, setCustomCondition] = useState(undefined);
|
|
57
61
|
const [isShowModal, setIsShowModal] = useState(false);
|
|
@@ -86,67 +90,77 @@ const SetupConfigCondition = () => {
|
|
|
86
90
|
|
|
87
91
|
const setupCustomCondition = () => {
|
|
88
92
|
setSelectedCondition('custom');
|
|
89
|
-
|
|
93
|
+
setConditionData((prev) => ({
|
|
94
|
+
...prev,
|
|
95
|
+
value: NaN,
|
|
96
|
+
}));
|
|
90
97
|
setIsShowModal(true);
|
|
91
98
|
};
|
|
92
99
|
|
|
93
|
-
const handleNavigate = useCallback(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
value: automate.value,
|
|
107
|
-
};
|
|
108
|
-
const apiCall = isCreateCondition
|
|
109
|
-
? await axiosPost(API.AUTOMATE.ADD_CONDITION(automate.id), data)
|
|
110
|
-
: await axiosPut(
|
|
111
|
-
API.AUTOMATE.UPDATE_CONDITION(automate.id, isUpdateCondition),
|
|
112
|
-
data
|
|
113
|
-
);
|
|
100
|
+
const handleNavigate = useCallback(
|
|
101
|
+
async (data) => {
|
|
102
|
+
if (!isCreateCondition && !isUpdateCondition) {
|
|
103
|
+
navigate(Routes.ValueChangeName, {
|
|
104
|
+
automate: {
|
|
105
|
+
...automate,
|
|
106
|
+
conditions: [data],
|
|
107
|
+
},
|
|
108
|
+
closeScreen,
|
|
109
|
+
unitId,
|
|
110
|
+
});
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
114
113
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
114
|
+
const apiCall = isCreateCondition
|
|
115
|
+
? await axiosPost(API.AUTOMATE.ADD_CONDITION(automate.id), data)
|
|
116
|
+
: await axiosPut(
|
|
117
|
+
API.AUTOMATE.UPDATE_CONDITION(automate.id, isUpdateCondition),
|
|
118
|
+
data
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const { success } = apiCall;
|
|
122
|
+
|
|
123
|
+
if (success) {
|
|
124
|
+
ToastBottomHelper.success(
|
|
125
|
+
isCreateCondition
|
|
126
|
+
? t('add_condition_success')
|
|
127
|
+
: t('edit_condition_success')
|
|
128
|
+
);
|
|
129
|
+
navigate({
|
|
130
|
+
name: Routes.ScriptDetail,
|
|
131
|
+
params: { preAutomate: automate },
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
[
|
|
136
|
+
automate,
|
|
137
|
+
closeScreen,
|
|
138
|
+
isCreateCondition,
|
|
139
|
+
isUpdateCondition,
|
|
140
|
+
navigate,
|
|
141
|
+
t,
|
|
142
|
+
unitId,
|
|
143
|
+
]
|
|
144
|
+
);
|
|
137
145
|
|
|
138
146
|
const setupCondition = async (condition) => {
|
|
139
|
-
automate.condition = condition?.condition;
|
|
140
|
-
automate.value = condition?.value;
|
|
141
147
|
setSelectedCondition(condition);
|
|
142
|
-
|
|
148
|
+
const data = {
|
|
149
|
+
...conditionData,
|
|
150
|
+
condition: condition?.condition,
|
|
151
|
+
value: condition?.value,
|
|
152
|
+
};
|
|
153
|
+
handleNavigate(data);
|
|
143
154
|
};
|
|
144
155
|
|
|
145
156
|
const resetCustomizeCondition = useCallback(() => {
|
|
146
|
-
|
|
147
|
-
|
|
157
|
+
setConditionData((prev) => ({
|
|
158
|
+
...prev,
|
|
159
|
+
condition: null,
|
|
160
|
+
value: NaN,
|
|
161
|
+
}));
|
|
148
162
|
setCustomCondition(undefined);
|
|
149
|
-
}, [
|
|
163
|
+
}, []);
|
|
150
164
|
|
|
151
165
|
useFocusEffect(
|
|
152
166
|
useCallback(() => {
|
|
@@ -197,7 +211,10 @@ const SetupConfigCondition = () => {
|
|
|
197
211
|
<GridItem
|
|
198
212
|
key={`GridItem${index}`}
|
|
199
213
|
onPress={() => {
|
|
200
|
-
|
|
214
|
+
setConditionData((prev) => ({
|
|
215
|
+
...prev,
|
|
216
|
+
condition: item.value,
|
|
217
|
+
}));
|
|
201
218
|
setCustomCondition(item.value);
|
|
202
219
|
}}
|
|
203
220
|
selected={item.value === customCondition}
|
|
@@ -217,7 +234,10 @@ const SetupConfigCondition = () => {
|
|
|
217
234
|
placeholder={t('value')}
|
|
218
235
|
onChange={(value) => {
|
|
219
236
|
const floatValue = parseFloat(value.replace(',', '.'));
|
|
220
|
-
|
|
237
|
+
setConditionData((prev) => ({
|
|
238
|
+
...prev,
|
|
239
|
+
value: floatValue,
|
|
240
|
+
}));
|
|
221
241
|
}}
|
|
222
242
|
textInputStyle={styles.numberInput}
|
|
223
243
|
wrapStyle={styles.wrapTextInput}
|
|
@@ -229,12 +249,12 @@ const SetupConfigCondition = () => {
|
|
|
229
249
|
title={t('continue')}
|
|
230
250
|
accessibilityLabel={AccessibilityLabel.BUTTON_CONTINUE}
|
|
231
251
|
onPress={async () => {
|
|
232
|
-
if (isNaN(
|
|
252
|
+
if (isNaN(conditionData.value) || !conditionData.condition) {
|
|
233
253
|
ToastBottomHelper.error(t('please_enter_a_number'), '', 3000);
|
|
234
254
|
return;
|
|
235
255
|
}
|
|
236
256
|
setIsShowModal(false);
|
|
237
|
-
handleNavigate();
|
|
257
|
+
handleNavigate(conditionData);
|
|
238
258
|
}}
|
|
239
259
|
style={styles.buttonContinue}
|
|
240
260
|
textSemiBold={false}
|
|
@@ -38,16 +38,45 @@ describe('Test ChooseAction', () => {
|
|
|
38
38
|
stationName: 'stationName',
|
|
39
39
|
automateId: 1,
|
|
40
40
|
scriptName: 'scriptName test',
|
|
41
|
+
scriptItems: [],
|
|
41
42
|
},
|
|
42
43
|
};
|
|
43
44
|
});
|
|
44
45
|
|
|
45
46
|
test('test onSave have automateId', async () => {
|
|
47
|
+
const response = [
|
|
48
|
+
{
|
|
49
|
+
id: 1,
|
|
50
|
+
title: '',
|
|
51
|
+
template: 'on_off_button_action_template',
|
|
52
|
+
configuration: {
|
|
53
|
+
allow_config_store_value: true,
|
|
54
|
+
config: 1,
|
|
55
|
+
action_on: '94ae262d-46e3-42ff-9d10-516831ecc830',
|
|
56
|
+
action_off: '6b5e49ce-22b3-49c3-bf61-0202970ce587',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
|
|
46
61
|
mock.onPost(API.AUTOMATE.ADD_SCRIPT_ACTION(1)).reply(200);
|
|
47
62
|
await act(async () => {
|
|
48
63
|
tree = await renderer.create(wrapComponent(route));
|
|
49
64
|
});
|
|
50
65
|
const instance = tree.root;
|
|
66
|
+
|
|
67
|
+
const cards = instance.findAllByType(SelectActionCard);
|
|
68
|
+
await act(async () => {
|
|
69
|
+
cards.map((card) => card.props.onPress());
|
|
70
|
+
});
|
|
71
|
+
const onButton = instance.find(
|
|
72
|
+
(el) =>
|
|
73
|
+
el.props.accessibilityLabel === AccessibilityLabel.ON_BUTTON &&
|
|
74
|
+
el.type === TouchableOpacity
|
|
75
|
+
);
|
|
76
|
+
await act(async () => {
|
|
77
|
+
await onButton.props.onPress();
|
|
78
|
+
});
|
|
79
|
+
|
|
51
80
|
const bottomButton = instance.findByType(BottomButtonView);
|
|
52
81
|
await act(async () => {
|
|
53
82
|
bottomButton.props.onPressMain();
|
|
@@ -56,12 +85,39 @@ describe('Test ChooseAction', () => {
|
|
|
56
85
|
});
|
|
57
86
|
|
|
58
87
|
it('test onSave fail not permission', async () => {
|
|
88
|
+
const response = [
|
|
89
|
+
{
|
|
90
|
+
id: 1,
|
|
91
|
+
title: '',
|
|
92
|
+
template: 'on_off_button_action_template',
|
|
93
|
+
configuration: {
|
|
94
|
+
allow_config_store_value: true,
|
|
95
|
+
config: 1,
|
|
96
|
+
action_on: '94ae262d-46e3-42ff-9d10-516831ecc830',
|
|
97
|
+
action_off: '6b5e49ce-22b3-49c3-bf61-0202970ce587',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
|
|
59
102
|
mock.onPost(API.AUTOMATE.ADD_SCRIPT_ACTION(1)).reply(404);
|
|
60
103
|
await act(async () => {
|
|
61
104
|
tree = await renderer.create(wrapComponent(route));
|
|
62
105
|
});
|
|
63
106
|
const instance = tree.root;
|
|
64
107
|
|
|
108
|
+
const cards = instance.findAllByType(SelectActionCard);
|
|
109
|
+
await act(async () => {
|
|
110
|
+
cards.map((card) => card.props.onPress());
|
|
111
|
+
});
|
|
112
|
+
const onButton = instance.find(
|
|
113
|
+
(el) =>
|
|
114
|
+
el.props.accessibilityLabel === AccessibilityLabel.ON_BUTTON &&
|
|
115
|
+
el.type === TouchableOpacity
|
|
116
|
+
);
|
|
117
|
+
await act(async () => {
|
|
118
|
+
await onButton.props.onPress();
|
|
119
|
+
});
|
|
120
|
+
|
|
65
121
|
const bottomButton = instance.findByType(BottomButtonView);
|
|
66
122
|
await act(async () => {
|
|
67
123
|
bottomButton.props.onPressMain();
|
|
@@ -87,7 +143,8 @@ describe('Test ChooseAction', () => {
|
|
|
87
143
|
config2 = 2,
|
|
88
144
|
config3 = 3,
|
|
89
145
|
config4 = 4,
|
|
90
|
-
config5 = 5
|
|
146
|
+
config5 = 5,
|
|
147
|
+
config6 = 6;
|
|
91
148
|
const response = [
|
|
92
149
|
{
|
|
93
150
|
id: 1,
|
|
@@ -97,7 +154,7 @@ describe('Test ChooseAction', () => {
|
|
|
97
154
|
allow_config_store_value: true,
|
|
98
155
|
config: config1,
|
|
99
156
|
action_on: '94ae262d-46e3-42ff-9d10-516831ecc830',
|
|
100
|
-
action_off: '
|
|
157
|
+
action_off: 'd988f6f6-1347-480b-8912-e986d0b7fb76',
|
|
101
158
|
},
|
|
102
159
|
},
|
|
103
160
|
{
|
|
@@ -169,6 +226,17 @@ describe('Test ChooseAction', () => {
|
|
|
169
226
|
],
|
|
170
227
|
},
|
|
171
228
|
},
|
|
229
|
+
{
|
|
230
|
+
id: 6,
|
|
231
|
+
title: 'Power',
|
|
232
|
+
template: 'OnOffSimpleActionTemplate',
|
|
233
|
+
configuration: {
|
|
234
|
+
allow_config_store_value: true,
|
|
235
|
+
config: config6,
|
|
236
|
+
action_on: 'a9b9fcc5-a939-4163-95c9-03b0011d46c5',
|
|
237
|
+
action_off: '2863b435-788f-4a86-bca8-7005763709e5',
|
|
238
|
+
},
|
|
239
|
+
},
|
|
172
240
|
];
|
|
173
241
|
mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
|
|
174
242
|
await act(async () => {
|
|
@@ -182,14 +250,14 @@ describe('Test ChooseAction', () => {
|
|
|
182
250
|
cards.map((card) => card.props.onPress());
|
|
183
251
|
});
|
|
184
252
|
|
|
185
|
-
const simpleActionOn = instance.
|
|
253
|
+
const simpleActionOn = instance.findAll(
|
|
186
254
|
(el) =>
|
|
187
255
|
el.props.accessibilityLabel ===
|
|
188
256
|
AccessibilityLabel.ON_OFF_SIMPLE_ACTION_ON &&
|
|
189
257
|
el.type === TouchableOpacity
|
|
190
258
|
);
|
|
191
259
|
await act(async () => {
|
|
192
|
-
await simpleActionOn.props.onPress();
|
|
260
|
+
await simpleActionOn[0].props.onPress();
|
|
193
261
|
});
|
|
194
262
|
|
|
195
263
|
const selectOptions = instance.findAll(
|
|
@@ -243,7 +311,18 @@ describe('Test ChooseAction', () => {
|
|
|
243
311
|
await chooseMode.props.onPress(response[4].configuration.options[0]);
|
|
244
312
|
});
|
|
245
313
|
|
|
314
|
+
const simpleActionToggle = instance.findAll(
|
|
315
|
+
(el) =>
|
|
316
|
+
el.props.accessibilityLabel ===
|
|
317
|
+
AccessibilityLabel.ON_OFF_SIMPLE_ACTION_TOGGLE &&
|
|
318
|
+
el.type === TouchableOpacity
|
|
319
|
+
);
|
|
320
|
+
await act(async () => {
|
|
321
|
+
await simpleActionToggle[1].props.onPress();
|
|
322
|
+
});
|
|
323
|
+
|
|
246
324
|
mock.onPost(API.AUTOMATE.ADD_SCRIPT_ACTION(1)).reply(200);
|
|
325
|
+
mock.onPost(API.AUTOMATE.ADD_SCRIPT_TOGGLE(1)).reply(200);
|
|
247
326
|
const buttonSave = instance.find(
|
|
248
327
|
(el) =>
|
|
249
328
|
el.props.accessibilityLabel === AccessibilityLabel.BOTTOM_VIEW_MAIN &&
|
|
@@ -253,6 +332,8 @@ describe('Test ChooseAction', () => {
|
|
|
253
332
|
await buttonSave.props.onPress();
|
|
254
333
|
});
|
|
255
334
|
|
|
335
|
+
expect(mock.history.post).toHaveLength(2);
|
|
336
|
+
expect(mock.history.post[0].url).toEqual(API.AUTOMATE.ADD_SCRIPT_ACTION(1));
|
|
256
337
|
expect(mock.history.post[0].data).toEqual(
|
|
257
338
|
JSON.stringify({
|
|
258
339
|
list_action: [
|
|
@@ -263,6 +344,7 @@ describe('Test ChooseAction', () => {
|
|
|
263
344
|
config_id: config1,
|
|
264
345
|
config_value: 1,
|
|
265
346
|
},
|
|
347
|
+
order: 1,
|
|
266
348
|
},
|
|
267
349
|
{
|
|
268
350
|
action: '05195362-75de-4db5-9e5e-98fef9d4910c',
|
|
@@ -272,6 +354,7 @@ describe('Test ChooseAction', () => {
|
|
|
272
354
|
config_id: config2,
|
|
273
355
|
config_value: 1,
|
|
274
356
|
},
|
|
357
|
+
order: 2,
|
|
275
358
|
},
|
|
276
359
|
{
|
|
277
360
|
action: 'b498234c-6c1a-452d-a1d1-87a314c20528',
|
|
@@ -280,6 +363,7 @@ describe('Test ChooseAction', () => {
|
|
|
280
363
|
config_id: config3,
|
|
281
364
|
config_value: 29,
|
|
282
365
|
},
|
|
366
|
+
order: 3,
|
|
283
367
|
},
|
|
284
368
|
{
|
|
285
369
|
action: '11111111-6c1a-452d-a1d1-87a314c20528',
|
|
@@ -288,10 +372,35 @@ describe('Test ChooseAction', () => {
|
|
|
288
372
|
config_id: config4,
|
|
289
373
|
config_value: 28,
|
|
290
374
|
},
|
|
375
|
+
order: 4,
|
|
291
376
|
},
|
|
292
377
|
{
|
|
293
378
|
action: '800ff454-4e2a-4a38-bad6-1bded728193e',
|
|
294
379
|
data: { config_id: config5, config_value: 1 },
|
|
380
|
+
order: 5,
|
|
381
|
+
},
|
|
382
|
+
],
|
|
383
|
+
})
|
|
384
|
+
);
|
|
385
|
+
expect(mock.history.post[1].url).toEqual(API.AUTOMATE.ADD_SCRIPT_TOGGLE(1));
|
|
386
|
+
expect(mock.history.post[1].data).toEqual(
|
|
387
|
+
JSON.stringify({
|
|
388
|
+
list_action: [
|
|
389
|
+
{
|
|
390
|
+
action_on: 'a9b9fcc5-a939-4163-95c9-03b0011d46c5',
|
|
391
|
+
action_off: '2863b435-788f-4a86-bca8-7005763709e5',
|
|
392
|
+
config: config6,
|
|
393
|
+
action_on_data: {
|
|
394
|
+
state: 1,
|
|
395
|
+
config_id: config6,
|
|
396
|
+
config_value: 1,
|
|
397
|
+
},
|
|
398
|
+
action_off_data: {
|
|
399
|
+
state: 0,
|
|
400
|
+
config_id: config6,
|
|
401
|
+
config_value: 0,
|
|
402
|
+
},
|
|
403
|
+
order: 6,
|
|
295
404
|
},
|
|
296
405
|
],
|
|
297
406
|
})
|
|
@@ -365,6 +474,7 @@ describe('Test ChooseAction', () => {
|
|
|
365
474
|
config_id: config1,
|
|
366
475
|
config_value: 0,
|
|
367
476
|
},
|
|
477
|
+
order: 1,
|
|
368
478
|
},
|
|
369
479
|
],
|
|
370
480
|
})
|
|
@@ -14,6 +14,7 @@ import { ToastBottomHelper } from '../../../../utils/Utils';
|
|
|
14
14
|
import SetupConfigCondition from '../SetupConfigCondition';
|
|
15
15
|
import AccessibilityLabel from '../../../../configs/AccessibilityLabel';
|
|
16
16
|
import { API } from '../../../../configs';
|
|
17
|
+
import { AUTOMATE_TYPE } from '../../../../configs/Constants';
|
|
17
18
|
import api from '../../../../utils/Apis/axios';
|
|
18
19
|
import MockAdapter from 'axios-mock-adapter';
|
|
19
20
|
|
|
@@ -172,7 +173,9 @@ describe('Test SetupConfigCondition', () => {
|
|
|
172
173
|
);
|
|
173
174
|
useRoute.mockReturnValue({
|
|
174
175
|
params: {
|
|
175
|
-
automate: {
|
|
176
|
+
automate: {
|
|
177
|
+
config: 1,
|
|
178
|
+
},
|
|
176
179
|
config: {
|
|
177
180
|
id: 1,
|
|
178
181
|
name: 'config name',
|
|
@@ -193,12 +196,20 @@ describe('Test SetupConfigCondition', () => {
|
|
|
193
196
|
gridItems[0].findByType(TouchableWithoutFeedback).props.onPress();
|
|
194
197
|
});
|
|
195
198
|
|
|
196
|
-
expect(global.mockedNavigate).
|
|
199
|
+
expect(global.mockedNavigate).toHaveBeenCalledWith(Routes.ValueChangeName, {
|
|
197
200
|
automate: {
|
|
198
|
-
|
|
199
|
-
|
|
201
|
+
conditions: [
|
|
202
|
+
{
|
|
203
|
+
condition: 'value_evaluation',
|
|
204
|
+
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
205
|
+
config: 1,
|
|
206
|
+
value: [1, 0],
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
config: 1,
|
|
200
210
|
},
|
|
201
211
|
closeScreen: undefined,
|
|
212
|
+
unitId: undefined,
|
|
202
213
|
});
|
|
203
214
|
});
|
|
204
215
|
|
|
@@ -213,7 +224,9 @@ describe('Test SetupConfigCondition', () => {
|
|
|
213
224
|
);
|
|
214
225
|
useRoute.mockReturnValue({
|
|
215
226
|
params: {
|
|
216
|
-
automate: {
|
|
227
|
+
automate: {
|
|
228
|
+
config: 1,
|
|
229
|
+
},
|
|
217
230
|
config: {
|
|
218
231
|
id: 1,
|
|
219
232
|
name: 'config name',
|
|
@@ -262,10 +275,18 @@ describe('Test SetupConfigCondition', () => {
|
|
|
262
275
|
|
|
263
276
|
expect(global.mockedNavigate).toBeCalledWith(Routes.ValueChangeName, {
|
|
264
277
|
automate: {
|
|
265
|
-
|
|
266
|
-
|
|
278
|
+
conditions: [
|
|
279
|
+
{
|
|
280
|
+
condition: '<',
|
|
281
|
+
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
282
|
+
config: 1,
|
|
283
|
+
value: value,
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
config: 1,
|
|
267
287
|
},
|
|
268
288
|
closeScreen: undefined,
|
|
289
|
+
unitId: undefined,
|
|
269
290
|
});
|
|
270
291
|
};
|
|
271
292
|
|
|
@@ -395,10 +416,18 @@ describe('Test SetupConfigCondition', () => {
|
|
|
395
416
|
gridItems[0].props.onPress();
|
|
396
417
|
});
|
|
397
418
|
|
|
419
|
+
expect(mock.history.post).toHaveLength(1);
|
|
420
|
+
expect(mock.history.post[0].data).toEqual(
|
|
421
|
+
JSON.stringify({
|
|
422
|
+
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
423
|
+
condition: 'value_evaluation',
|
|
424
|
+
value: [1, 0],
|
|
425
|
+
})
|
|
426
|
+
);
|
|
398
427
|
expect(global.mockedNavigate).toBeCalledWith({
|
|
399
428
|
name: 'ScriptDetail',
|
|
400
429
|
params: {
|
|
401
|
-
preAutomate: {
|
|
430
|
+
preAutomate: { id: 1 },
|
|
402
431
|
},
|
|
403
432
|
});
|
|
404
433
|
});
|