@eohjsc/react-native-smart-city 0.6.0-rc5 → 0.6.0-rc6

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 (32) hide show
  1. package/package.json +1 -1
  2. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +2 -2
  3. package/src/commons/ActionGroup/__test__/ColorPickerTemplate.test.js +4 -9
  4. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +6 -6
  5. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +1 -11
  6. package/src/commons/Calendar/__test__/Calendar.test.js +0 -7
  7. package/src/commons/CircleButton/__test__/CircleButton.test.js +2 -2
  8. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +10 -13
  9. package/src/commons/DateTimeRangeChange/__test__/DateTimeButton.test.js +4 -4
  10. package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +5 -5
  11. package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +9 -9
  12. package/src/commons/GroupCheckBox/__test__/GroupCheckBox.test.js +1 -22
  13. package/src/commons/MediaPlayerDetail/MediaPlayerFull.js +1 -1
  14. package/src/commons/MediaPlayerDetail/__test__/MediaPlayerFull.test.js +12 -48
  15. package/src/commons/Sharing/__test__/ButtonRemoveMember.test.js +2 -2
  16. package/src/commons/Unit/HeaderUnit/index.js +82 -83
  17. package/src/commons/Unit/__test__/HeaderUnit.test.js +26 -37
  18. package/src/commons/WrapParallaxScrollView/index.js +21 -50
  19. package/src/hooks/Common/useIsOwnerOfUnit.js +1 -1
  20. package/src/hooks/IoT/__test__/useWatchConfigs.test.js +6 -14
  21. package/src/screens/Automate/__test__/MultiUnits.test.js +2 -2
  22. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +1 -11
  23. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +2 -2
  24. package/src/screens/SelectUnit/__test__/index.test.js +8 -8
  25. package/src/screens/Template/__test__/EditTemplate.test.js +2 -2
  26. package/src/screens/Template/__test__/detail.test.js +4 -4
  27. package/src/screens/Template/__test__/index.test.js +2 -2
  28. package/src/screens/Unit/Detail.js +12 -53
  29. package/src/screens/Unit/Station/__test__/index.test.js +2 -2
  30. package/src/screens/Unit/__test__/Detail.test.js +10 -8
  31. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +8 -13
  32. package/src/screens/UnitSummary/components/__test__/UnitSummary.test.js +8 -8
@@ -1,17 +1,15 @@
1
1
  import React, {
2
2
  useCallback,
3
- useEffect,
4
- useState,
5
3
  useContext,
4
+ useEffect,
6
5
  useMemo,
6
+ useState,
7
7
  } from 'react';
8
- import { RefreshControl, View, Platform } from 'react-native';
9
- import { useIsFocused } from '@react-navigation/native';
8
+ import { Platform, View } from 'react-native';
9
+ import { useIsFocused, useNavigation } from '@react-navigation/native';
10
10
 
11
11
  import { useTranslations } from '../../hooks/Common/useTranslations';
12
12
  import styles from './styles';
13
- import AddMenu from './AddMenu';
14
- import MoreMenu from './MoreMenu';
15
13
  import Summaries from './Summaries';
16
14
 
17
15
  import Text from '../../commons/Text';
@@ -20,7 +18,6 @@ import {
20
18
  useBlockBackAndroid,
21
19
  useBoolean,
22
20
  useIsOwnerOfUnit,
23
- usePopover,
24
21
  } from '../../hooks/Common';
25
22
  import { useFavorites } from './hook/useFavorites';
26
23
  import { useUnitConnectRemoteDevices } from './hook/useUnitConnectRemoteDevices';
@@ -32,20 +29,19 @@ import WrapParallaxScrollView from '../../commons/WrapParallaxScrollView';
32
29
  import { SCContext, useSCContextSelector } from '../../context';
33
30
  import { Action } from '../../context/actionType';
34
31
  import CameraDevice from '../../commons/CameraDevice';
35
- import { useNavigation } from '@react-navigation/native';
36
32
  import Routes from '../../utils/Route';
37
33
  import SubUnitAutomate from '../../commons/SubUnit/OneTap';
38
34
  import SubUnitFavorites from '../../commons/SubUnit/Favorites';
39
35
  import {
36
+ AccessibilityLabel,
37
+ AUTOMATE_TABS,
40
38
  AUTOMATE_TYPE,
41
39
  Constants,
42
40
  NOTIFICATION_TYPES,
43
- AccessibilityLabel,
44
- AUTOMATE_TABS,
45
41
  } from '../../configs/Constants';
46
42
  import {
47
- watchNotificationData,
48
43
  unwatchNotificationData,
44
+ watchNotificationData,
49
45
  } from '../../utils/Monitor';
50
46
  import PreventAccess from '../../commons/PreventAccess';
51
47
  import MediaPlayerDetail from '../../commons/MediaPlayerDetail';
@@ -197,7 +193,6 @@ const UnitDetail = ({ route }) => {
197
193
  const {
198
194
  unitId,
199
195
  unitData,
200
- routeName,
201
196
  isOneTap,
202
197
  stationId,
203
198
  isAddSubUnit,
@@ -218,19 +213,16 @@ const UnitDetail = ({ route }) => {
218
213
  isSuccessfullyConnected ? RouterHardware(Routes.Dashboard) : goBack
219
214
  );
220
215
  const user = useSCContextSelector((state) => state?.auth?.account?.user);
221
- const { isLavidaSource, isFirstOpenCamera, appState } = useSCContextSelector(
216
+ const { isFirstOpenCamera, appState } = useSCContextSelector(
222
217
  (state) => state.app
223
218
  );
224
219
 
225
220
  const [unit, setUnit] = useState(unitData || { id: unitId });
226
221
  const [listAutomate, setListAutomate] = useState([]);
227
- const [showAdd, setShowAdd, setHideAdd] = useBoolean();
222
+
228
223
  const [showPreventAccess, setShowPreventAccess, setHidePreventAccess] =
229
224
  useBoolean(false);
230
225
 
231
- const { childRef, showingPopover, showPopoverWithRef, hidePopover } =
232
- usePopover();
233
-
234
226
  const { isOwner } = useIsOwnerOfUnit(unit.user_id);
235
227
 
236
228
  const prepareData = useCallback(
@@ -317,14 +309,6 @@ const UnitDetail = ({ route }) => {
317
309
  }
318
310
  }, [fetchDetails, isFocused]);
319
311
 
320
- const onBack = useCallback(() => {
321
- navigate(isLavidaSource ? Routes.SmartHomeDashboard : routeName);
322
- }, [navigate, routeName, isLavidaSource]);
323
-
324
- const Dashboard = useCallback(() => {
325
- navigate(isLavidaSource ? Routes.SmartHomeDashboard : Routes.Dashboard);
326
- }, [isLavidaSource, navigate]);
327
-
328
312
  useEffect(() => {
329
313
  watchNotificationData(user, onRefresh);
330
314
  return () => unwatchNotificationData(user);
@@ -342,19 +326,9 @@ const UnitDetail = ({ route }) => {
342
326
 
343
327
  return (
344
328
  <WrapParallaxScrollView
345
- uriImg={unit.background}
346
- title={t('Welcome {name}', {
347
- name: unit.name ? unit.name : '',
348
- })}
349
- refreshControl={
350
- <RefreshControl refreshing={false} onRefresh={onRefresh} />
351
- }
352
- onAdd={setShowAdd}
353
- onMore={showPopoverWithRef}
354
- hideRightPlus={!isOwner}
355
- onBack={(isSuccessfullyConnected && Dashboard) || (routeName && onBack)}
356
- accessibilityLabel={AccessibilityLabel.UNIT_DETAIL_PARALLAX_SCROLLVIEW}
357
- idButtonMore={AccessibilityLabel.UNIT_DETAIL_PARALLAX_BUTTON_MORE}
329
+ unit={unit}
330
+ unitData={unitData}
331
+ onRefresh={onRefresh}
358
332
  >
359
333
  {isFirstOpenCamera && isIOS && (
360
334
  <MediaPlayerDetail
@@ -375,21 +349,6 @@ const UnitDetail = ({ route }) => {
375
349
  isAddSubUnit={isAddSubUnit}
376
350
  isEditSubUnit={isEditSubUnit}
377
351
  />
378
- <AddMenu
379
- unit={unit}
380
- afterItemClick={hidePopover}
381
- showAdd={showAdd}
382
- setHideAdd={setHideAdd}
383
- />
384
- <MoreMenu
385
- unit={unit}
386
- hidePopover={hidePopover}
387
- isOwner={isOwner}
388
- childRef={childRef}
389
- showingPopover={showingPopover}
390
- idLabelPopover={AccessibilityLabel.UNIT_DETAIL_POPUP_MORE}
391
- idLabelItem={AccessibilityLabel.UNIT_DETAIL_POPUP_MORE_ITEM}
392
- />
393
352
  <PreventAccess
394
353
  visible={showPreventAccess}
395
354
  hidePreventAccess={setHidePreventAccess}
@@ -50,8 +50,8 @@ describe('Test Station', () => {
50
50
  zoomScale: 1,
51
51
  },
52
52
  });
53
- const TouchableOpacities = instance.findAllByType(TouchableOpacity);
54
- await TouchableOpacities[0].props.onPress();
53
+ const touchableOpacities = instance.findAllByType(TouchableOpacity);
54
+ await touchableOpacities[0].props.onPress();
55
55
  expect(mockOnSnapToItem).toBeCalled();
56
56
  });
57
57
  });
@@ -8,6 +8,7 @@ import {
8
8
  useIsFocused,
9
9
  useNavigation,
10
10
  useFocusEffect,
11
+ useRoute,
11
12
  } from '@react-navigation/native';
12
13
  import AsyncStorage from '@react-native-async-storage/async-storage';
13
14
  import UnitDetail from '../Detail';
@@ -497,8 +498,9 @@ describe('Test UnitDetail', () => {
497
498
 
498
499
  it('test get automate onPress goBack', async () => {
499
500
  Platform.OS = 'ios';
500
- route.params.isSuccessfullyConnected = true;
501
+ route.params.routeName = Routes.Dashboard;
501
502
  jest.useFakeTimers();
503
+
502
504
  mock.onGet(getAutomates).reply(200, [{}]);
503
505
  await act(async () => {
504
506
  tree = await renderer.create(wrapComponent(route, account));
@@ -509,23 +511,23 @@ describe('Test UnitDetail', () => {
509
511
  const instance = tree.root;
510
512
  const preventAccess = instance.findByType(PreventAccess);
511
513
  expect(preventAccess).toBeDefined();
512
- const TouchableOpacities = instance.findAllByType(TouchableOpacity);
514
+
515
+ const touchableOpacities = instance.findAllByType(TouchableOpacity);
513
516
  await act(async () => {
514
- await TouchableOpacities[0].props.onPress();
517
+ await touchableOpacities[0].props.onPress();
515
518
  });
516
- expect(global.mockedNavigate).toBeCalled();
519
+ expect(global.mockedGoBack).toBeCalled();
517
520
  });
518
521
 
519
522
  it('test onPress goBack with routeName', async () => {
520
- route.params.routeName = 'test';
521
- route.params.isSuccessfullyConnected = false;
523
+ useRoute.mockReturnValue({ params: { routeName: Routes.Dashboard } });
522
524
  await act(async () => {
523
525
  tree = await renderer.create(wrapComponent(route, account));
524
526
  });
525
527
  const instance = tree.root;
526
- const TouchableOpacities = instance.findAllByType(TouchableOpacity);
528
+ const touchableOpacities = instance.findAllByType(TouchableOpacity);
527
529
  await act(async () => {
528
- await TouchableOpacities[0].props.onPress();
530
+ await touchableOpacities[0].props.onPress();
529
531
  });
530
532
  expect(global.mockedNavigate).toBeCalled();
531
533
  });
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react';
1
+ import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
3
  import { AccessibilityLabel } from '../../../../../configs/Constants';
4
4
  import { API } from '../../../../../configs';
@@ -7,18 +7,9 @@ import { SCProvider } from '../../../../../context';
7
7
  import { mockSCStore } from '../../../../../context/mockStore';
8
8
  import MockAdapter from 'axios-mock-adapter';
9
9
  import api from '../../../../../utils/Apis/axios';
10
+ import PMSensorIndicator from '../../../../../commons/Device/PMSensor/PMSensorIndicator';
10
11
 
11
12
  const mock = new MockAdapter(api.axiosInstance);
12
- const mockSetState = jest.fn();
13
-
14
- jest.mock('react', () => {
15
- return {
16
- ...jest.requireActual('react'),
17
- useState: jest.fn(),
18
- };
19
- });
20
-
21
- useState.mockImplementation((init) => [init, mockSetState]);
22
13
 
23
14
  const wrapComponent = (summaryDetail) => (
24
15
  <SCProvider initState={mockSCStore({})}>
@@ -47,7 +38,6 @@ describe('Test 3PPowerConsumption', () => {
47
38
  power_factor_1: 8,
48
39
  power_factor_2: 9,
49
40
  power_factor_3: 10,
50
- total_power: 11,
51
41
  },
52
42
  };
53
43
  await act(async () => {
@@ -73,6 +63,9 @@ describe('Test 3PPowerConsumption', () => {
73
63
  { id: 10, color: '#52C41A', title: 'Power Factor 3', measure: '' },
74
64
  ];
75
65
  expect(listIndicator.props.data).toEqual(resultList);
66
+
67
+ const indicator = instance.findByType(PMSensorIndicator);
68
+ expect(indicator.props.data).toHaveLength(0);
76
69
  });
77
70
 
78
71
  it('render 3PPowerConsumption with total_power', async () => {
@@ -88,6 +81,8 @@ describe('Test 3PPowerConsumption', () => {
88
81
  await act(async () => {
89
82
  tree = await renderer.create(wrapComponent(summaryDetail));
90
83
  });
91
- expect(mockSetState).toHaveBeenCalledWith([{}]);
84
+ const instance = tree.root;
85
+ const indicator = instance.findByType(PMSensorIndicator);
86
+ expect(indicator.props.data).toHaveLength(1);
92
87
  });
93
88
  });
@@ -22,8 +22,8 @@ describe('Test UnitSummary', () => {
22
22
  tree = await create(<UnitSummary {...defaultProps} index={0} />);
23
23
  });
24
24
  const instance = tree.root;
25
- const TouchableOpacities = instance.findAllByType(TouchableOpacity);
26
- expect(TouchableOpacities[0].props.style).toEqual([
25
+ const touchableOpacities = instance.findAllByType(TouchableOpacity);
26
+ expect(touchableOpacities[0].props.style).toEqual([
27
27
  styles.summaryContainer,
28
28
  { borderTopLeftRadius: 10 },
29
29
  ]);
@@ -34,8 +34,8 @@ describe('Test UnitSummary', () => {
34
34
  tree = await create(<UnitSummary {...defaultProps} index={1} />);
35
35
  });
36
36
  const instance = tree.root;
37
- const TouchableOpacities = instance.findAllByType(TouchableOpacity);
38
- expect(TouchableOpacities[0].props.style).toEqual([
37
+ const touchableOpacities = instance.findAllByType(TouchableOpacity);
38
+ expect(touchableOpacities[0].props.style).toEqual([
39
39
  styles.summaryContainer,
40
40
  { borderTopRightRadius: 10 },
41
41
  ]);
@@ -46,8 +46,8 @@ describe('Test UnitSummary', () => {
46
46
  tree = await create(<UnitSummary {...defaultProps} index={1} len={2} />);
47
47
  });
48
48
  const instance = tree.root;
49
- const TouchableOpacities = instance.findAllByType(TouchableOpacity);
50
- expect(TouchableOpacities[0].props.style).toEqual([
49
+ const touchableOpacities = instance.findAllByType(TouchableOpacity);
50
+ expect(touchableOpacities[0].props.style).toEqual([
51
51
  styles.summaryContainer,
52
52
  { borderBottomRightRadius: 10 },
53
53
  ]);
@@ -58,8 +58,8 @@ describe('Test UnitSummary', () => {
58
58
  tree = await create(<UnitSummary {...defaultProps} index={2} len={3} />);
59
59
  });
60
60
  const instance = tree.root;
61
- const TouchableOpacities = instance.findAllByType(TouchableOpacity);
62
- expect(TouchableOpacities[0].props.style).toEqual([
61
+ const touchableOpacities = instance.findAllByType(TouchableOpacity);
62
+ expect(touchableOpacities[0].props.style).toEqual([
63
63
  styles.summaryContainer,
64
64
  { borderBottomLeftRadius: 10 },
65
65
  ]);