@eohjsc/react-native-smart-city 0.7.21 → 0.7.23
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/default_end_device.png +0 -0
- 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/Dashboard/MyUnit/index.js +19 -20
- package/src/commons/DevMode/Search.js +1 -1
- package/src/commons/Device/RainningSensor/CurrentRainSensor.js +5 -5
- 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 +9 -11
- package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +2 -2
- package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +1 -1
- package/src/configs/API.js +10 -0
- package/src/configs/AccessibilityLabel.js +5 -1
- package/src/configs/Images.js +1 -0
- package/src/navigations/AddMemberStack.js +3 -3
- package/src/screens/ActivityLog/__test__/index.test.js +10 -0
- package/src/screens/ActivityLog/hooks/index.js +1 -1
- package/src/screens/AddCommon/SelectUnit.js +3 -2
- package/src/screens/AddLocationMaps/__test__/index.test.js +13 -13
- 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__/ChooseConfig.test.js +9 -11
- 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__/AddAutomationTypeSmart.test.js +31 -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 -35
- 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/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +69 -13
- package/src/screens/ConfirmUnitDeletion/index.js +14 -14
- 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/screens/Sharing/Components/ConfigItem.js +34 -0
- package/src/screens/Sharing/Components/DeviceItem.js +77 -0
- package/src/screens/Sharing/Components/ItemChangeRole.js +3 -4
- package/src/screens/Sharing/Components/ShareDeviceSelector.js +255 -0
- package/src/screens/Sharing/Components/Styles/CheckBoxCustomStyles.js +1 -1
- package/src/screens/Sharing/Components/Styles/DeviceItemStyles.js +11 -27
- package/src/screens/Sharing/{Styles/SelectPermissionStyles.js → Components/Styles/ShareDeviceSelectorStyles.js} +3 -11
- package/src/screens/Sharing/Components/SubUnitItem.js +28 -0
- package/src/screens/Sharing/Components/SubUnitTreeView.js +68 -0
- package/src/screens/Sharing/Components/TitleCheckBox.js +23 -41
- package/src/screens/Sharing/Components/__test__/ItemChangeRole.test.js +7 -7
- package/src/screens/Sharing/Components/__test__/ShareDeviceSelector.test.js +298 -0
- package/src/screens/Sharing/Components/index.js +14 -1
- package/src/screens/Sharing/InfoMemberUnit.js +20 -20
- package/src/screens/Sharing/SelectShareDevice.js +11 -255
- package/src/screens/Sharing/SelectUser.js +12 -12
- package/src/screens/Sharing/UpdateShareDevice.js +45 -301
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +58 -11
- package/src/screens/Sharing/__test__/SelectShareDevice.test.js +51 -160
- package/src/screens/Sharing/__test__/SelectUser.test.js +72 -10
- package/src/screens/Sharing/__test__/UpdateShareDevice.test.js +49 -209
- package/src/utils/Apis/axios.js +6 -0
- package/src/utils/I18n/translations/en.js +9 -1
- package/src/utils/I18n/translations/vi.js +10 -2
- package/src/commons/Sharing/StationDevicePermissions.js +0 -204
- package/src/screens/Automate/constants.js +0 -0
- package/src/screens/Sharing/Components/CheckBoxConfig.js +0 -44
- package/src/screens/Sharing/Components/CheckBoxSubUnit.js +0 -35
- package/src/screens/Sharing/Components/EndDevice.js +0 -93
- package/src/screens/Sharing/Components/Styles/CheckBoxConfigStyles.js +0 -18
- package/src/screens/Sharing/Components/Styles/TitleCheckBoxStyles.js +0 -21
- package/src/screens/Sharing/Components/__test__/TitleCheckBox.test.js +0 -31
|
@@ -8,9 +8,8 @@ import AccessibilityLabel from '../../../../configs/AccessibilityLabel';
|
|
|
8
8
|
import { SCProvider } from '../../../../context';
|
|
9
9
|
import { mockSCStore } from '../../../../context/mockStore';
|
|
10
10
|
import Routes from '../../../../utils/Route';
|
|
11
|
-
import RepeatOptionsPopup
|
|
12
|
-
|
|
13
|
-
} from '../components/RepeatOptionsPopup';
|
|
11
|
+
import RepeatOptionsPopup from '../components/RepeatOptionsPopup';
|
|
12
|
+
import { REPEAT_OPTIONS, TIME_RANGE_REPEAT_OPTIONS } from '../../Constants';
|
|
14
13
|
|
|
15
14
|
import RowItem from '../components/RowItem';
|
|
16
15
|
import SelectWeekday from '../components/SelectWeekday';
|
|
@@ -20,6 +19,7 @@ import NewActionWrapper from '../../AddNewAction/NewActionWrapper';
|
|
|
20
19
|
import { API } from '../../../../configs';
|
|
21
20
|
import MockAdapter from 'axios-mock-adapter';
|
|
22
21
|
import api from '../../../../utils/Apis/axios';
|
|
22
|
+
import _TextInput from '../../../../commons/Form/TextInput';
|
|
23
23
|
|
|
24
24
|
const wrapComponent = (route) => {
|
|
25
25
|
useRoute.mockReturnValue(route);
|
|
@@ -53,6 +53,7 @@ describe('Test AddEditConditionSchedule', () => {
|
|
|
53
53
|
const mockedNavigate = useNavigation().navigate;
|
|
54
54
|
|
|
55
55
|
beforeEach(() => {
|
|
56
|
+
mock.reset();
|
|
56
57
|
mockedNavigate.mockClear();
|
|
57
58
|
Date.now = jest.fn(() => new Date('2025-01-01T19:00:00.000Z'));
|
|
58
59
|
});
|
|
@@ -63,25 +64,39 @@ describe('Test AddEditConditionSchedule', () => {
|
|
|
63
64
|
});
|
|
64
65
|
const instance = tree.root;
|
|
65
66
|
const rowItems = instance.findAllByType(RowItem);
|
|
66
|
-
const
|
|
67
|
-
const
|
|
67
|
+
const intervalInput = instance.findAllByType(_TextInput);
|
|
68
|
+
const timePicker = instance.findAllByType(WheelDateTimePicker);
|
|
69
|
+
const popup = instance.findAllByType(RepeatOptionsPopup);
|
|
68
70
|
const calendar = instance.findByType(Calendar);
|
|
69
71
|
const header = instance.findByProps({
|
|
70
72
|
accessibilityLabel: AccessibilityLabel.ICON_CLOSE,
|
|
71
73
|
});
|
|
74
|
+
expect(rowItems).toHaveLength(3);
|
|
75
|
+
expect(intervalInput).toHaveLength(0);
|
|
76
|
+
expect(timePicker).toHaveLength(3);
|
|
77
|
+
expect(popup).toHaveLength(2);
|
|
72
78
|
|
|
79
|
+
expect(popup[0].props.isVisible).toBeFalsy();
|
|
80
|
+
expect(popup[1].props.isVisible).toBeFalsy();
|
|
73
81
|
await act(async () => {
|
|
74
82
|
await rowItems[0].props.onPress();
|
|
75
83
|
});
|
|
76
|
-
expect(
|
|
84
|
+
expect(popup[0].props.isVisible).toBeTruthy();
|
|
85
|
+
expect(popup[1].props.isVisible).toBeFalsy();
|
|
77
86
|
|
|
87
|
+
expect(timePicker[0].props.isVisible).toBeFalsy();
|
|
88
|
+
expect(timePicker[1].props.isVisible).toBeFalsy();
|
|
89
|
+
expect(timePicker[2].props.isVisible).toBeFalsy();
|
|
78
90
|
await act(async () => {
|
|
79
|
-
await rowItems[
|
|
91
|
+
await rowItems[1].props.onPress();
|
|
80
92
|
});
|
|
81
|
-
expect(
|
|
93
|
+
expect(timePicker[0].props.isVisible).toBeTruthy();
|
|
94
|
+
expect(timePicker[1].props.isVisible).toBeFalsy();
|
|
95
|
+
expect(timePicker[2].props.isVisible).toBeFalsy();
|
|
82
96
|
|
|
97
|
+
expect(calendar.props.isVisible).toBeFalsy();
|
|
83
98
|
await act(async () => {
|
|
84
|
-
await rowItems[
|
|
99
|
+
await rowItems[2].props.onPress();
|
|
85
100
|
});
|
|
86
101
|
expect(calendar.props.isVisible).toBeTruthy();
|
|
87
102
|
|
|
@@ -108,18 +123,19 @@ describe('Test AddEditConditionSchedule', () => {
|
|
|
108
123
|
tree = await create(wrapComponent(route));
|
|
109
124
|
});
|
|
110
125
|
const instance = tree.root;
|
|
111
|
-
const popup = instance.
|
|
126
|
+
const popup = instance.findAllByType(RepeatOptionsPopup);
|
|
112
127
|
let rowItems = instance.findAllByType(RowItem);
|
|
113
128
|
expect(rowItems).toHaveLength(3);
|
|
129
|
+
expect(popup).toHaveLength(2);
|
|
114
130
|
|
|
115
131
|
await act(async () => {
|
|
116
|
-
await popup.props.onSetRepeat(REPEAT_OPTIONS.EVERYDAY);
|
|
132
|
+
await popup[0].props.onSetRepeat(REPEAT_OPTIONS.EVERYDAY);
|
|
117
133
|
});
|
|
118
134
|
rowItems = instance.findAllByType(RowItem);
|
|
119
135
|
expect(rowItems).toHaveLength(2);
|
|
120
136
|
|
|
121
137
|
await act(async () => {
|
|
122
|
-
await popup.props.onSetRepeat(REPEAT_OPTIONS.EVERYWEEK);
|
|
138
|
+
await popup[0].props.onSetRepeat(REPEAT_OPTIONS.EVERYWEEK);
|
|
123
139
|
});
|
|
124
140
|
const selectWeekday = instance.findByType(SelectWeekday);
|
|
125
141
|
rowItems = instance.findAllByType(RowItem);
|
|
@@ -132,23 +148,25 @@ describe('Test AddEditConditionSchedule', () => {
|
|
|
132
148
|
tree = await create(wrapComponent(route));
|
|
133
149
|
});
|
|
134
150
|
const instance = tree.root;
|
|
135
|
-
const timePicker = instance.
|
|
151
|
+
const timePicker = instance.findAllByType(WheelDateTimePicker);
|
|
136
152
|
const calendar = instance.findByType(Calendar);
|
|
137
153
|
const rowItems = instance.findAllByType(RowItem);
|
|
154
|
+
expect(timePicker).toHaveLength(3);
|
|
155
|
+
expect(rowItems).toHaveLength(3);
|
|
138
156
|
|
|
139
157
|
const time = moment();
|
|
140
158
|
const date = moment();
|
|
141
|
-
expect(rowItems[
|
|
142
|
-
expect(rowItems[
|
|
159
|
+
expect(rowItems[1].props.value).toBe('19:00');
|
|
160
|
+
expect(rowItems[2].props.value).toBe(date.format('[Today], D MMMM YYYY '));
|
|
143
161
|
|
|
144
162
|
time.hour(10).minute(30);
|
|
145
163
|
date.add(1, 'days');
|
|
146
164
|
await act(async () => {
|
|
147
|
-
await timePicker.props.onPicked(time);
|
|
165
|
+
await timePicker[0].props.onPicked(time);
|
|
148
166
|
await calendar.props.onConfirm(date);
|
|
149
167
|
});
|
|
150
|
-
expect(rowItems[
|
|
151
|
-
expect(rowItems[
|
|
168
|
+
expect(rowItems[1].props.value).toBe(time.format('HH:mm'));
|
|
169
|
+
expect(rowItems[2].props.value).toBe(date.format('ddd, D MMMM YYYY'));
|
|
152
170
|
});
|
|
153
171
|
|
|
154
172
|
it('test save isUpdateCondition', async () => {
|
|
@@ -174,10 +192,11 @@ describe('Test AddEditConditionSchedule', () => {
|
|
|
174
192
|
tree = await create(wrapComponent(route));
|
|
175
193
|
});
|
|
176
194
|
const instance = tree.root;
|
|
177
|
-
const popup = instance.
|
|
195
|
+
const popup = instance.findAllByType(RepeatOptionsPopup);
|
|
196
|
+
expect(popup).toHaveLength(2);
|
|
178
197
|
|
|
179
198
|
await act(async () => {
|
|
180
|
-
await popup.props.onSetRepeat(REPEAT_OPTIONS.EVERYWEEK);
|
|
199
|
+
await popup[0].props.onSetRepeat(REPEAT_OPTIONS.EVERYWEEK);
|
|
181
200
|
});
|
|
182
201
|
const button = instance.findByType(NewActionWrapper);
|
|
183
202
|
|
|
@@ -187,8 +206,7 @@ describe('Test AddEditConditionSchedule', () => {
|
|
|
187
206
|
expect(global.mockedNavigate).toBeDefined();
|
|
188
207
|
});
|
|
189
208
|
|
|
190
|
-
it('test
|
|
191
|
-
// route.params.condition = {};
|
|
209
|
+
it('test add schedule once', async () => {
|
|
192
210
|
route.params = {
|
|
193
211
|
automate: { id: 1 },
|
|
194
212
|
closeScreen: Routes.ScriptDetail,
|
|
@@ -203,6 +221,293 @@ describe('Test AddEditConditionSchedule', () => {
|
|
|
203
221
|
await act(async () => {
|
|
204
222
|
await button.props.onNext();
|
|
205
223
|
});
|
|
224
|
+
expect(mock.history.post).toHaveLength(1);
|
|
225
|
+
expect(mock.history.post[0].url).toEqual(API.AUTOMATE.ADD_CONDITION(1));
|
|
226
|
+
expect(mock.history.post[0].data).toEqual(
|
|
227
|
+
JSON.stringify({
|
|
228
|
+
type: AUTOMATE_TYPE.SCHEDULE,
|
|
229
|
+
repeat: REPEAT_OPTIONS.ONCE,
|
|
230
|
+
time_repeat: '19:00:00',
|
|
231
|
+
date_repeat: '2025-01-01',
|
|
232
|
+
weekday_repeat: null,
|
|
233
|
+
})
|
|
234
|
+
);
|
|
235
|
+
expect(global.mockedNavigate).toHaveBeenCalledWith({
|
|
236
|
+
name: 'ScriptDetail',
|
|
237
|
+
params: { preAutomate: { id: 1 } },
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('test add schedule time range', async () => {
|
|
242
|
+
route.params = {
|
|
243
|
+
automate: { id: 1 },
|
|
244
|
+
closeScreen: Routes.ScriptDetail,
|
|
245
|
+
};
|
|
246
|
+
mock.onPost(API.AUTOMATE.ADD_CONDITION(1)).reply(200);
|
|
247
|
+
await act(async () => {
|
|
248
|
+
tree = await create(wrapComponent(route));
|
|
249
|
+
});
|
|
250
|
+
const instance = tree.root;
|
|
251
|
+
let rowItems = instance.findAllByType(RowItem);
|
|
252
|
+
let intervalInput = instance.findAllByType(_TextInput);
|
|
253
|
+
let selectWeekday = instance.findAllByType(SelectWeekday);
|
|
254
|
+
const timePicker = instance.findAllByType(WheelDateTimePicker);
|
|
255
|
+
const popup = instance.findAllByType(RepeatOptionsPopup);
|
|
256
|
+
const calendar = instance.findByType(Calendar);
|
|
257
|
+
expect(rowItems).toHaveLength(3);
|
|
258
|
+
expect(intervalInput).toHaveLength(0);
|
|
259
|
+
expect(selectWeekday).toHaveLength(0);
|
|
260
|
+
expect(timePicker).toHaveLength(3);
|
|
261
|
+
expect(popup).toHaveLength(2);
|
|
262
|
+
|
|
263
|
+
expect(popup[0].props.isVisible).toBeFalsy();
|
|
264
|
+
expect(popup[1].props.isVisible).toBeFalsy();
|
|
265
|
+
await act(async () => {
|
|
266
|
+
await rowItems[0].props.onPress();
|
|
267
|
+
});
|
|
268
|
+
expect(popup[0].props.isVisible).toBeTruthy();
|
|
269
|
+
expect(popup[1].props.isVisible).toBeFalsy();
|
|
270
|
+
|
|
271
|
+
await act(async () => {
|
|
272
|
+
await popup[0].props.onSetRepeat(REPEAT_OPTIONS.TIMERANGE);
|
|
273
|
+
});
|
|
274
|
+
rowItems = instance.findAllByType(RowItem);
|
|
275
|
+
expect(rowItems).toHaveLength(4);
|
|
276
|
+
intervalInput = instance.findAllByType(_TextInput);
|
|
277
|
+
expect(intervalInput).toHaveLength(0);
|
|
278
|
+
expect(timePicker[0].props.isVisible).toBeFalsy();
|
|
279
|
+
expect(timePicker[1].props.isVisible).toBeFalsy();
|
|
280
|
+
expect(timePicker[2].props.isVisible).toBeFalsy();
|
|
281
|
+
expect(calendar.props.isVisible).toBeFalsy();
|
|
282
|
+
|
|
283
|
+
await act(async () => {
|
|
284
|
+
await rowItems[2].props.onPress();
|
|
285
|
+
});
|
|
286
|
+
expect(timePicker[0].props.isVisible).toBeFalsy();
|
|
287
|
+
expect(timePicker[1].props.isVisible).toBeTruthy();
|
|
288
|
+
expect(timePicker[2].props.isVisible).toBeFalsy();
|
|
289
|
+
await act(async () => {
|
|
290
|
+
await timePicker[1].props.onPicked(moment('2025-01-01T20:30:00.000Z'));
|
|
291
|
+
await timePicker[1]
|
|
292
|
+
.findByProps({
|
|
293
|
+
accessibilityLabelPrefix:
|
|
294
|
+
AccessibilityLabel.WHEEL_DATE_TIME_PICKER_BUTTON,
|
|
295
|
+
})
|
|
296
|
+
.props.onRightClick();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
await act(async () => {
|
|
300
|
+
await rowItems[3].props.onPress();
|
|
301
|
+
});
|
|
302
|
+
expect(timePicker[0].props.isVisible).toBeFalsy();
|
|
303
|
+
expect(timePicker[1].props.isVisible).toBeFalsy();
|
|
304
|
+
expect(timePicker[2].props.isVisible).toBeTruthy();
|
|
305
|
+
await act(async () => {
|
|
306
|
+
await timePicker[2].props.onPicked(moment('2025-01-01T22:30:00.000Z'));
|
|
307
|
+
await timePicker[2]
|
|
308
|
+
.findByProps({
|
|
309
|
+
accessibilityLabelPrefix:
|
|
310
|
+
AccessibilityLabel.WHEEL_DATE_TIME_PICKER_BUTTON,
|
|
311
|
+
})
|
|
312
|
+
.props.onRightClick();
|
|
313
|
+
});
|
|
314
|
+
expect(timePicker[0].props.isVisible).toBeFalsy();
|
|
315
|
+
expect(timePicker[1].props.isVisible).toBeFalsy();
|
|
316
|
+
expect(timePicker[2].props.isVisible).toBeFalsy();
|
|
317
|
+
|
|
318
|
+
const button = instance.findByType(NewActionWrapper);
|
|
319
|
+
await act(async () => {
|
|
320
|
+
await button.props.onNext();
|
|
321
|
+
});
|
|
322
|
+
expect(mock.history.post).toHaveLength(1);
|
|
323
|
+
expect(mock.history.post[0].url).toEqual(API.AUTOMATE.ADD_CONDITION(1));
|
|
324
|
+
expect(mock.history.post[0].data).toEqual(
|
|
325
|
+
JSON.stringify({
|
|
326
|
+
type: AUTOMATE_TYPE.SCHEDULE,
|
|
327
|
+
repeat: REPEAT_OPTIONS.TIMERANGE,
|
|
328
|
+
time_start: '20:30:00',
|
|
329
|
+
time_end: '22:30:00',
|
|
330
|
+
weekday_repeat: null,
|
|
331
|
+
})
|
|
332
|
+
);
|
|
333
|
+
expect(global.mockedNavigate).toHaveBeenCalledWith({
|
|
334
|
+
name: 'ScriptDetail',
|
|
335
|
+
params: { preAutomate: { id: 1 } },
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('test add schedule time range with weekday', async () => {
|
|
340
|
+
route.params = {
|
|
341
|
+
automate: { id: 1 },
|
|
342
|
+
closeScreen: Routes.ScriptDetail,
|
|
343
|
+
};
|
|
344
|
+
mock.onPost(API.AUTOMATE.ADD_CONDITION(1)).reply(200);
|
|
345
|
+
await act(async () => {
|
|
346
|
+
tree = await create(wrapComponent(route));
|
|
347
|
+
});
|
|
348
|
+
const instance = tree.root;
|
|
349
|
+
let rowItems = instance.findAllByType(RowItem);
|
|
350
|
+
let intervalInput = instance.findAllByType(_TextInput);
|
|
351
|
+
let selectWeekday = instance.findAllByType(SelectWeekday);
|
|
352
|
+
const timePicker = instance.findAllByType(WheelDateTimePicker);
|
|
353
|
+
const popup = instance.findAllByType(RepeatOptionsPopup);
|
|
354
|
+
const calendar = instance.findByType(Calendar);
|
|
355
|
+
expect(rowItems).toHaveLength(3);
|
|
356
|
+
expect(intervalInput).toHaveLength(0);
|
|
357
|
+
expect(selectWeekday).toHaveLength(0);
|
|
358
|
+
expect(timePicker).toHaveLength(3);
|
|
359
|
+
expect(popup).toHaveLength(2);
|
|
360
|
+
|
|
361
|
+
expect(popup[0].props.isVisible).toBeFalsy();
|
|
362
|
+
expect(popup[1].props.isVisible).toBeFalsy();
|
|
363
|
+
await act(async () => {
|
|
364
|
+
await rowItems[0].props.onPress();
|
|
365
|
+
});
|
|
366
|
+
expect(popup[0].props.isVisible).toBeTruthy();
|
|
367
|
+
expect(popup[1].props.isVisible).toBeFalsy();
|
|
368
|
+
|
|
369
|
+
await act(async () => {
|
|
370
|
+
await popup[0].props.onSetRepeat(REPEAT_OPTIONS.TIMERANGE);
|
|
371
|
+
});
|
|
372
|
+
expect(popup[0].props.isVisible).toBeFalsy();
|
|
373
|
+
rowItems = instance.findAllByType(RowItem);
|
|
374
|
+
expect(rowItems).toHaveLength(4);
|
|
375
|
+
intervalInput = instance.findAllByType(_TextInput);
|
|
376
|
+
expect(intervalInput).toHaveLength(0);
|
|
377
|
+
expect(timePicker[0].props.isVisible).toBeFalsy();
|
|
378
|
+
expect(timePicker[1].props.isVisible).toBeFalsy();
|
|
379
|
+
expect(timePicker[2].props.isVisible).toBeFalsy();
|
|
380
|
+
expect(calendar.props.isVisible).toBeFalsy();
|
|
381
|
+
|
|
382
|
+
await act(async () => {
|
|
383
|
+
await rowItems[2].props.onPress();
|
|
384
|
+
});
|
|
385
|
+
expect(timePicker[0].props.isVisible).toBeFalsy();
|
|
386
|
+
expect(timePicker[1].props.isVisible).toBeTruthy();
|
|
387
|
+
expect(timePicker[2].props.isVisible).toBeFalsy();
|
|
388
|
+
await act(async () => {
|
|
389
|
+
await timePicker[1].props.onPicked(moment('2025-01-01T20:30:00.000Z'));
|
|
390
|
+
await timePicker[1]
|
|
391
|
+
.findByProps({
|
|
392
|
+
accessibilityLabelPrefix:
|
|
393
|
+
AccessibilityLabel.WHEEL_DATE_TIME_PICKER_BUTTON,
|
|
394
|
+
})
|
|
395
|
+
.props.onRightClick();
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
await act(async () => {
|
|
399
|
+
await rowItems[3].props.onPress();
|
|
400
|
+
});
|
|
401
|
+
expect(timePicker[0].props.isVisible).toBeFalsy();
|
|
402
|
+
expect(timePicker[1].props.isVisible).toBeFalsy();
|
|
403
|
+
expect(timePicker[2].props.isVisible).toBeTruthy();
|
|
404
|
+
await act(async () => {
|
|
405
|
+
await timePicker[2].props.onPicked(moment('2025-01-01T22:30:00.000Z'));
|
|
406
|
+
await timePicker[2]
|
|
407
|
+
.findByProps({
|
|
408
|
+
accessibilityLabelPrefix:
|
|
409
|
+
AccessibilityLabel.WHEEL_DATE_TIME_PICKER_BUTTON,
|
|
410
|
+
})
|
|
411
|
+
.props.onRightClick();
|
|
412
|
+
});
|
|
413
|
+
expect(timePicker[0].props.isVisible).toBeFalsy();
|
|
414
|
+
expect(timePicker[1].props.isVisible).toBeFalsy();
|
|
415
|
+
expect(timePicker[2].props.isVisible).toBeFalsy();
|
|
416
|
+
|
|
417
|
+
await act(async () => {
|
|
418
|
+
await rowItems[1].props.onPress();
|
|
419
|
+
});
|
|
420
|
+
expect(popup[0].props.isVisible).toBeFalsy();
|
|
421
|
+
expect(popup[1].props.isVisible).toBeTruthy();
|
|
422
|
+
|
|
423
|
+
await act(async () => {
|
|
424
|
+
await popup[1].props.onSetRepeat(TIME_RANGE_REPEAT_OPTIONS.EVERYWEEK);
|
|
425
|
+
});
|
|
426
|
+
expect(popup[1].props.isVisible).toBeFalsy();
|
|
427
|
+
selectWeekday = instance.findAllByType(SelectWeekday);
|
|
428
|
+
expect(selectWeekday).toHaveLength(1);
|
|
429
|
+
await act(async () => {
|
|
430
|
+
await selectWeekday[0].props.setWeekday(['1', '3']);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
const button = instance.findByType(NewActionWrapper);
|
|
434
|
+
await act(async () => {
|
|
435
|
+
await button.props.onNext();
|
|
436
|
+
});
|
|
437
|
+
expect(mock.history.post).toHaveLength(1);
|
|
438
|
+
expect(mock.history.post[0].url).toEqual(API.AUTOMATE.ADD_CONDITION(1));
|
|
439
|
+
expect(mock.history.post[0].data).toEqual(
|
|
440
|
+
JSON.stringify({
|
|
441
|
+
type: AUTOMATE_TYPE.SCHEDULE,
|
|
442
|
+
repeat: REPEAT_OPTIONS.TIMERANGE,
|
|
443
|
+
time_start: '20:30:00',
|
|
444
|
+
time_end: '22:30:00',
|
|
445
|
+
weekday_repeat: ['1', '3'],
|
|
446
|
+
})
|
|
447
|
+
);
|
|
448
|
+
expect(global.mockedNavigate).toHaveBeenCalledWith({
|
|
449
|
+
name: 'ScriptDetail',
|
|
450
|
+
params: { preAutomate: { id: 1 } },
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it('test add schedule interval', async () => {
|
|
455
|
+
route.params = {
|
|
456
|
+
automate: { id: 1 },
|
|
457
|
+
closeScreen: Routes.ScriptDetail,
|
|
458
|
+
};
|
|
459
|
+
mock.onPost(API.AUTOMATE.ADD_CONDITION(1)).reply(200);
|
|
460
|
+
await act(async () => {
|
|
461
|
+
tree = await create(wrapComponent(route));
|
|
462
|
+
});
|
|
463
|
+
const instance = tree.root;
|
|
464
|
+
let rowItems = instance.findAllByType(RowItem);
|
|
465
|
+
let intervalInput = instance.findAllByType(_TextInput);
|
|
466
|
+
const timePicker = instance.findAllByType(WheelDateTimePicker);
|
|
467
|
+
const popup = instance.findAllByType(RepeatOptionsPopup);
|
|
468
|
+
const calendar = instance.findByType(Calendar);
|
|
469
|
+
expect(rowItems).toHaveLength(3);
|
|
470
|
+
expect(intervalInput).toHaveLength(0);
|
|
471
|
+
expect(timePicker).toHaveLength(3);
|
|
472
|
+
expect(popup).toHaveLength(2);
|
|
473
|
+
|
|
474
|
+
expect(popup[0].props.isVisible).toBeFalsy();
|
|
475
|
+
expect(popup[1].props.isVisible).toBeFalsy();
|
|
476
|
+
await act(async () => {
|
|
477
|
+
await rowItems[0].props.onPress();
|
|
478
|
+
});
|
|
479
|
+
expect(popup[0].props.isVisible).toBeTruthy();
|
|
480
|
+
expect(popup[1].props.isVisible).toBeFalsy();
|
|
481
|
+
|
|
482
|
+
await act(async () => {
|
|
483
|
+
await popup[0].props.onSetRepeat(REPEAT_OPTIONS.INTERVAL);
|
|
484
|
+
});
|
|
485
|
+
rowItems = instance.findAllByType(RowItem);
|
|
486
|
+
expect(rowItems).toHaveLength(1);
|
|
487
|
+
expect(timePicker[0].props.isVisible).toBeFalsy();
|
|
488
|
+
expect(timePicker[1].props.isVisible).toBeFalsy();
|
|
489
|
+
expect(timePicker[2].props.isVisible).toBeFalsy();
|
|
490
|
+
expect(calendar.props.isVisible).toBeFalsy();
|
|
491
|
+
|
|
492
|
+
intervalInput = instance.findAllByType(_TextInput);
|
|
493
|
+
expect(intervalInput).toHaveLength(1);
|
|
494
|
+
await act(async () => {
|
|
495
|
+
await intervalInput[0].props.onChange(5);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
const button = instance.findByType(NewActionWrapper);
|
|
499
|
+
await act(async () => {
|
|
500
|
+
await button.props.onNext();
|
|
501
|
+
});
|
|
502
|
+
expect(mock.history.post).toHaveLength(1);
|
|
503
|
+
expect(mock.history.post[0].url).toEqual(API.AUTOMATE.ADD_CONDITION(1));
|
|
504
|
+
expect(mock.history.post[0].data).toEqual(
|
|
505
|
+
JSON.stringify({
|
|
506
|
+
type: AUTOMATE_TYPE.SCHEDULE,
|
|
507
|
+
repeat: REPEAT_OPTIONS.INTERVAL,
|
|
508
|
+
interval_repeat: 5,
|
|
509
|
+
})
|
|
510
|
+
);
|
|
206
511
|
expect(global.mockedNavigate).toHaveBeenCalledWith({
|
|
207
512
|
name: 'ScriptDetail',
|
|
208
513
|
params: { preAutomate: { id: 1 } },
|
|
@@ -9,9 +9,8 @@ import AccessibilityLabel from '../../../../configs/AccessibilityLabel';
|
|
|
9
9
|
import { SCProvider } from '../../../../context';
|
|
10
10
|
import { mockSCStore } from '../../../../context/mockStore';
|
|
11
11
|
import Routes from '../../../../utils/Route';
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
} from '../components/RepeatOptionsPopup';
|
|
12
|
+
import { REPEAT_OPTIONS } from '../../Constants';
|
|
13
|
+
import RepeatOptionsPopup from '../components/RepeatOptionsPopup';
|
|
15
14
|
import RowItem from '../components/RowItem';
|
|
16
15
|
import SelectWeekday from '../components/SelectWeekday';
|
|
17
16
|
import SetSchedule from '../index';
|
|
@@ -48,25 +47,31 @@ describe('Test SetSchedule', () => {
|
|
|
48
47
|
});
|
|
49
48
|
const instance = tree.root;
|
|
50
49
|
const rowItems = instance.findAllByType(RowItem);
|
|
51
|
-
const timePicker = instance.
|
|
52
|
-
const popup = instance.
|
|
50
|
+
const timePicker = instance.findAllByType(WheelDateTimePicker);
|
|
51
|
+
const popup = instance.findAllByType(RepeatOptionsPopup);
|
|
53
52
|
const calendar = instance.findByType(Calendar);
|
|
54
53
|
const header = instance.findByProps({
|
|
55
54
|
accessibilityLabel: AccessibilityLabel.ICON_CLOSE,
|
|
56
55
|
});
|
|
56
|
+
expect(rowItems).toHaveLength(3);
|
|
57
|
+
expect(timePicker).toHaveLength(3);
|
|
58
|
+
expect(popup).toHaveLength(2);
|
|
57
59
|
|
|
58
60
|
await act(async () => {
|
|
59
61
|
await rowItems[0].props.onPress();
|
|
60
62
|
});
|
|
61
|
-
expect(
|
|
63
|
+
expect(popup[0].props.isVisible).toBeTruthy();
|
|
64
|
+
expect(popup[1].props.isVisible).toBeFalsy();
|
|
62
65
|
|
|
63
66
|
await act(async () => {
|
|
64
|
-
await rowItems[
|
|
67
|
+
await rowItems[1].props.onPress();
|
|
65
68
|
});
|
|
66
|
-
expect(
|
|
69
|
+
expect(timePicker[0].props.isVisible).toBeTruthy();
|
|
70
|
+
expect(timePicker[1].props.isVisible).toBeFalsy();
|
|
71
|
+
expect(timePicker[2].props.isVisible).toBeFalsy();
|
|
67
72
|
|
|
68
73
|
await act(async () => {
|
|
69
|
-
await rowItems[
|
|
74
|
+
await rowItems[2].props.onPress();
|
|
70
75
|
});
|
|
71
76
|
expect(calendar.props.isVisible).toBeTruthy();
|
|
72
77
|
|
|
@@ -85,18 +90,19 @@ describe('Test SetSchedule', () => {
|
|
|
85
90
|
tree = await create(wrapComponent(route));
|
|
86
91
|
});
|
|
87
92
|
const instance = tree.root;
|
|
88
|
-
const popup = instance.
|
|
93
|
+
const popup = instance.findAllByType(RepeatOptionsPopup);
|
|
89
94
|
let rowItems = instance.findAllByType(RowItem);
|
|
90
95
|
expect(rowItems).toHaveLength(3);
|
|
96
|
+
expect(popup).toHaveLength(2);
|
|
91
97
|
|
|
92
98
|
await act(async () => {
|
|
93
|
-
await popup.props.onSetRepeat(REPEAT_OPTIONS.EVERYDAY);
|
|
99
|
+
await popup[0].props.onSetRepeat(REPEAT_OPTIONS.EVERYDAY);
|
|
94
100
|
});
|
|
95
101
|
rowItems = instance.findAllByType(RowItem);
|
|
96
102
|
expect(rowItems).toHaveLength(2);
|
|
97
103
|
|
|
98
104
|
await act(async () => {
|
|
99
|
-
await popup.props.onSetRepeat(REPEAT_OPTIONS.EVERYWEEK);
|
|
105
|
+
await popup[0].props.onSetRepeat(REPEAT_OPTIONS.EVERYWEEK);
|
|
100
106
|
});
|
|
101
107
|
const selectWeekday = instance.findByType(SelectWeekday);
|
|
102
108
|
rowItems = instance.findAllByType(RowItem);
|
|
@@ -109,23 +115,25 @@ describe('Test SetSchedule', () => {
|
|
|
109
115
|
tree = await create(wrapComponent(route));
|
|
110
116
|
});
|
|
111
117
|
const instance = tree.root;
|
|
112
|
-
const timePicker = instance.
|
|
118
|
+
const timePicker = instance.findAllByType(WheelDateTimePicker);
|
|
113
119
|
const calendar = instance.findByType(Calendar);
|
|
114
120
|
const rowItems = instance.findAllByType(RowItem);
|
|
121
|
+
expect(timePicker).toHaveLength(3);
|
|
122
|
+
expect(rowItems).toHaveLength(3);
|
|
115
123
|
|
|
116
124
|
const time = moment();
|
|
117
125
|
const date = moment();
|
|
118
|
-
expect(rowItems[
|
|
119
|
-
expect(rowItems[
|
|
126
|
+
expect(rowItems[1].props.value).toBe(time.format('HH:mm'));
|
|
127
|
+
expect(rowItems[2].props.value).toBe(date.format('[Today], D MMMM YYYY '));
|
|
120
128
|
|
|
121
129
|
time.hour(10).minute(30);
|
|
122
130
|
date.add(1, 'days');
|
|
123
131
|
await act(async () => {
|
|
124
|
-
await timePicker.props.onPicked(time);
|
|
132
|
+
await timePicker[0].props.onPicked(time);
|
|
125
133
|
await calendar.props.onConfirm(date);
|
|
126
134
|
});
|
|
127
|
-
expect(rowItems[
|
|
128
|
-
expect(rowItems[
|
|
135
|
+
expect(rowItems[1].props.value).toBe(time.format('HH:mm'));
|
|
136
|
+
expect(rowItems[2].props.value).toBe(date.format('ddd, D MMMM YYYY'));
|
|
129
137
|
});
|
|
130
138
|
|
|
131
139
|
it('test save', async () => {
|
|
@@ -140,11 +148,16 @@ describe('Test SetSchedule', () => {
|
|
|
140
148
|
});
|
|
141
149
|
expect(global.mockedNavigate).toHaveBeenCalledWith(Routes.ValueChangeName, {
|
|
142
150
|
automate: {
|
|
143
|
-
date_repeat: '2021-01-24',
|
|
144
|
-
repeat: 'once',
|
|
145
|
-
time_repeat: '12:00:00',
|
|
146
|
-
weekday_repeat: [],
|
|
147
151
|
type: 'schedule',
|
|
152
|
+
conditions: [
|
|
153
|
+
{
|
|
154
|
+
type: 'schedule',
|
|
155
|
+
repeat: 'once',
|
|
156
|
+
time_repeat: '12:00:00',
|
|
157
|
+
date_repeat: '2021-01-24',
|
|
158
|
+
weekday_repeat: null,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
148
161
|
unit: 1,
|
|
149
162
|
},
|
|
150
163
|
closeScreen: 'UnitDetail',
|
|
@@ -8,13 +8,7 @@ import styles from '../styles/RepeatOptionsPopupStyles';
|
|
|
8
8
|
import { Colors } from '../../../../configs';
|
|
9
9
|
import { ModalCustom } from '../../../../commons/Modal';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ONCE: 'once',
|
|
13
|
-
EVERYDAY: 'every_day',
|
|
14
|
-
EVERYWEEK: 'every_week',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const RepeatOptionsPopup = ({ isVisible, onHide, onSetRepeat }) => {
|
|
11
|
+
const RepeatOptionsPopup = ({ isVisible, onHide, onSetRepeat, options }) => {
|
|
18
12
|
const t = useTranslations();
|
|
19
13
|
|
|
20
14
|
const ItemRepeatOption = useCallback(
|
|
@@ -45,7 +39,7 @@ const RepeatOptionsPopup = ({ isVisible, onHide, onSetRepeat }) => {
|
|
|
45
39
|
style={styles.wrapPopup}
|
|
46
40
|
>
|
|
47
41
|
<View style={styles.popup}>
|
|
48
|
-
{Object.values(
|
|
42
|
+
{Object.values(options).map((item, index) => (
|
|
49
43
|
<ItemRepeatOption item={item} key={index} />
|
|
50
44
|
))}
|
|
51
45
|
</View>
|