@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.
Files changed (61) hide show
  1. package/package.json +1 -1
  2. package/src/commons/ActionGroup/TerminalBoxTemplate.js +3 -0
  3. package/src/commons/ActionTemplate/OnOffButtonAction.js +38 -4
  4. package/src/commons/ActionTemplate/OnOffSimpleAction.js +55 -15
  5. package/src/commons/ActionTemplate/OnOffSmartLockAction.js +46 -8
  6. package/src/commons/ActionTemplate/SwitchButtonAction.js +35 -4
  7. package/src/commons/ActionTemplate/ThreeButtonAction.js +13 -3
  8. package/src/commons/ActionTemplate/__test__/OnOffButtonAction.test.js +46 -7
  9. package/src/commons/ActionTemplate/__test__/OnOffSimpleAction.test.js +66 -6
  10. package/src/commons/ActionTemplate/__test__/OnOffSmartLockAction.test.js +53 -13
  11. package/src/commons/ActionTemplate/__test__/SwitchButtonAction.test.js +46 -7
  12. package/src/commons/ActionTemplate/__test__/index.test.js +6 -2
  13. package/src/commons/ActionTemplate/index.js +65 -10
  14. package/src/commons/MediaPlayerDetail/MediaPlayerFull.js +26 -32
  15. package/src/commons/OneTapTemplate/StatesGridActionTemplate.js +8 -6
  16. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +6 -0
  17. package/src/commons/SubUnit/OneTap/index.js +5 -0
  18. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +16 -12
  19. package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +3 -1
  20. package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +1 -1
  21. package/src/configs/API.js +6 -0
  22. package/src/configs/AccessibilityLabel.js +2 -0
  23. package/src/screens/ActivityLog/__test__/index.test.js +10 -0
  24. package/src/screens/ActivityLog/hooks/index.js +1 -1
  25. package/src/screens/Automate/AddNewAction/ChooseAction.js +15 -51
  26. package/src/screens/Automate/AddNewAction/SelectControlDevices.js +13 -3
  27. package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +74 -54
  28. package/src/screens/Automate/AddNewAction/__test__/ChooseAction.test.js +114 -4
  29. package/src/screens/Automate/AddNewAction/__test__/SetupConfigCondition.test.js +37 -8
  30. package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +5 -0
  31. package/src/screens/Automate/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +18 -2
  32. package/src/screens/Automate/Components/InputName.js +7 -6
  33. package/src/screens/Automate/Constants.js +12 -0
  34. package/src/screens/Automate/EditActionsList/UpdateActionScript.js +24 -55
  35. package/src/screens/Automate/EditActionsList/__tests__/UpdateActionScript.test.js +298 -41
  36. package/src/screens/Automate/EditActionsList/__tests__/index.test.js +2 -2
  37. package/src/screens/Automate/EditActionsList/index.js +26 -14
  38. package/src/screens/Automate/MultiUnits.js +9 -1
  39. package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +3 -3
  40. package/src/screens/Automate/ScriptDetail/Components/AddActionScript.js +4 -10
  41. package/src/screens/Automate/ScriptDetail/Components/DeleteScript.js +2 -4
  42. package/src/screens/Automate/ScriptDetail/__test__/index.test.js +78 -0
  43. package/src/screens/Automate/ScriptDetail/index.js +16 -10
  44. package/src/screens/Automate/ScriptDetail/utils.js +39 -15
  45. package/src/screens/Automate/SetSchedule/AddEditConditionSchedule.js +27 -160
  46. package/src/screens/Automate/SetSchedule/EditSchedule.js +269 -0
  47. package/src/screens/Automate/SetSchedule/__test__/AddEditConditionSchedule.test.js +327 -22
  48. package/src/screens/Automate/SetSchedule/__test__/index.test.js +35 -22
  49. package/src/screens/Automate/SetSchedule/components/RepeatOptionsPopup.js +2 -8
  50. package/src/screens/Automate/SetSchedule/index.js +15 -129
  51. package/src/screens/Automate/SetSchedule/styles/indexStyles.js +9 -0
  52. package/src/screens/Automate/__test__/MultiUnits.test.js +6 -1
  53. package/src/screens/Automate/hooks/useAction.js +222 -0
  54. package/src/screens/Device/__test__/detail.test.js +48 -1
  55. package/src/screens/Device/detail.js +46 -3
  56. package/src/screens/PlayBackCamera/__test__/index.test.js +48 -13
  57. package/src/screens/PlayBackCamera/index.js +1 -1
  58. package/src/utils/Apis/axios.js +6 -0
  59. package/src/utils/I18n/translations/en.js +8 -0
  60. package/src/utils/I18n/translations/vi.js +12 -4
  61. package/src/screens/Automate/constants.js +0 -0
@@ -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
- REPEAT_OPTIONS,
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 timePicker = instance.findByType(WheelDateTimePicker);
67
- const popup = instance.findByType(RepeatOptionsPopup);
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(timePicker.props.isVisible).toBeTruthy();
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[2].props.onPress();
91
+ await rowItems[1].props.onPress();
80
92
  });
81
- expect(popup.props.isVisible).toBeTruthy();
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[1].props.onPress();
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.findByType(RepeatOptionsPopup);
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.findByType(WheelDateTimePicker);
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[0].props.value).toBe('19:00');
142
- expect(rowItems[1].props.value).toBe(date.format('[Today], D MMMM YYYY '));
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[0].props.value).toBe(time.format('HH:mm'));
151
- expect(rowItems[1].props.value).toBe(date.format('ddd, D MMMM YYYY'));
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.findByType(RepeatOptionsPopup);
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 save isAddCondition', async () => {
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 RepeatOptionsPopup, {
13
- REPEAT_OPTIONS,
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.findByType(WheelDateTimePicker);
52
- const popup = instance.findByType(RepeatOptionsPopup);
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(timePicker.props.isVisible).toBeTruthy();
63
+ expect(popup[0].props.isVisible).toBeTruthy();
64
+ expect(popup[1].props.isVisible).toBeFalsy();
62
65
 
63
66
  await act(async () => {
64
- await rowItems[2].props.onPress();
67
+ await rowItems[1].props.onPress();
65
68
  });
66
- expect(popup.props.isVisible).toBeTruthy();
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[1].props.onPress();
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.findByType(RepeatOptionsPopup);
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.findByType(WheelDateTimePicker);
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[0].props.value).toBe(time.format('HH:mm'));
119
- expect(rowItems[1].props.value).toBe(date.format('[Today], D MMMM YYYY '));
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[0].props.value).toBe(time.format('HH:mm'));
128
- expect(rowItems[1].props.value).toBe(date.format('ddd, D MMMM YYYY'));
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
- export const REPEAT_OPTIONS = {
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(REPEAT_OPTIONS).map((item, index) => (
42
+ {Object.values(options).map((item, index) => (
49
43
  <ItemRepeatOption item={item} key={index} />
50
44
  ))}
51
45
  </View>