@eohjsc/react-native-smart-city 0.3.0 → 0.3.3

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 (134) hide show
  1. package/README.md +1 -1
  2. package/package.json +4 -4
  3. package/react-native-smart-city.podspec +1 -0
  4. package/src/commons/Action/ItemQuickAction.js +11 -2
  5. package/src/commons/Action/__test__/ItemQuickAction.test.js +11 -6
  6. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +31 -20
  7. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +3 -2
  8. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +0 -1
  9. package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +45 -48
  10. package/src/commons/ActionGroup/__test__/index.test.js +2 -2
  11. package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +7 -3
  12. package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +8 -11
  13. package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +3 -2
  14. package/src/commons/ConnectingProcess/index.js +71 -24
  15. package/src/commons/Device/ConnectedViewHeader.js +1 -1
  16. package/src/commons/Device/HistoryChart.js +3 -3
  17. package/src/commons/Device/ItemDevice.js +15 -11
  18. package/src/commons/Device/SonosSpeaker/index.js +1 -1
  19. package/src/commons/FieldTemplate/ScheduleField/index.js +2 -2
  20. package/src/commons/Header/HeaderCustom.js +2 -1
  21. package/src/commons/HorizontalPicker/index.js +2 -2
  22. package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +0 -6
  23. package/src/commons/MediaPlayerDetail/index.js +24 -55
  24. package/src/commons/SubUnit/Favorites/index.js +2 -3
  25. package/src/commons/SubUnit/ShortDetail.js +25 -9
  26. package/src/commons/SubUnit/__test__/Item.test.js +0 -1
  27. package/src/commons/SubUnit/__test__/ShortDetail.test.js +8 -1
  28. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +2 -13
  29. package/src/commons/UnitSummary/ConfigHistoryChart.js +22 -13
  30. package/src/commons/WheelDateTimePicker/index.js +2 -2
  31. package/src/configs/API.js +7 -12
  32. package/src/configs/Constants.js +13 -0
  33. package/src/context/actionType.ts +8 -0
  34. package/src/context/mockStore.ts +10 -0
  35. package/src/context/reducer.ts +38 -2
  36. package/src/hooks/Common/index.js +2 -0
  37. package/src/hooks/Common/useGGHomeDeviceConnected.js +16 -0
  38. package/src/hooks/Common/useGetIdUser.js +1 -5
  39. package/src/hooks/Common/useSensorsStatus.js +4 -4
  40. package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +198 -0
  41. package/src/hooks/IoT/__test__/useRemoteControl.test.js +198 -0
  42. package/src/hooks/IoT/index.js +4 -0
  43. package/src/hooks/IoT/useGGHomeConnection.js +91 -0
  44. package/src/hooks/IoT/useRemoteControl.js +79 -0
  45. package/src/hooks/index.js +4 -0
  46. package/src/hooks/useReceiveNotifications.js +9 -5
  47. package/src/iot/Monitor.js +3 -2
  48. package/src/iot/RemoteControl/Bluetooth.js +1 -1
  49. package/src/iot/RemoteControl/GoogleHome.js +75 -49
  50. package/src/iot/RemoteControl/Internet.js +1 -1
  51. package/src/iot/RemoteControl/__test__/GoogleHome.test.js +90 -21
  52. package/src/iot/RemoteControl/__test__/Internet.test.js +4 -4
  53. package/src/iot/RemoteControl/__test__/LgThinq.test.js +5 -5
  54. package/src/iot/RemoteControl/index.js +52 -52
  55. package/src/screens/ActivityLog/hooks/__test__/index.test.js +3 -3
  56. package/src/screens/ActivityLog/hooks/index.js +1 -1
  57. package/src/screens/AddLocationMaps/index.js +5 -4
  58. package/src/screens/AddNewAction/SelectAction.js +8 -8
  59. package/src/screens/AddNewAction/SetupSensor.js +7 -7
  60. package/src/screens/AddNewAction/__test__/SelectAction.test.js +2 -2
  61. package/src/screens/AddNewDevice/ConnectingDevices.js +1 -1
  62. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +2 -2
  63. package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
  64. package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +23 -17
  65. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +3 -3
  66. package/src/screens/AddNewGateway/SetupGatewayWifi.js +1 -0
  67. package/src/screens/AllCamera/index.js +4 -4
  68. package/src/screens/Automate/MultiUnits.js +8 -8
  69. package/src/screens/Automate/index.js +3 -3
  70. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +4 -4
  71. package/src/screens/Device/EditDevice/index.js +2 -2
  72. package/src/screens/Device/__test__/detail.test.js +13 -5
  73. package/src/screens/Device/components/DetailHistoryChart.js +1 -1
  74. package/src/screens/Device/components/SensorConnectStatusViewHeader.js +1 -0
  75. package/src/screens/Device/components/SensorDisplayItem.js +5 -2
  76. package/src/screens/Device/detail.js +49 -16
  77. package/src/screens/Device/hooks/useDisconnectedDevice.js +4 -4
  78. package/src/screens/EditActionsList/index.js +1 -1
  79. package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
  80. package/src/screens/HanetCamera/Detail.js +1 -1
  81. package/src/screens/HanetCamera/__test__/Detail.test.js +2 -2
  82. package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +3 -2
  83. package/src/screens/HanetCamera/hooks/useHanetCheckinData.js +11 -11
  84. package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +11 -11
  85. package/src/screens/ManageAccess/hooks/index.js +7 -4
  86. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +2 -2
  87. package/src/screens/MoveToAnotherSubUnit/index.js +1 -1
  88. package/src/screens/Notification/__test__/NotificationItem.test.js +4 -4
  89. package/src/screens/Notification/components/NotificationItem.js +17 -20
  90. package/src/screens/Notification/index.js +9 -2
  91. package/src/screens/PlayBackCamera/Timer.js +2 -2
  92. package/src/screens/PlayBackCamera/index.js +3 -3
  93. package/src/screens/ScanChipQR/hooks/index.js +15 -16
  94. package/src/screens/ScriptDetail/index.js +14 -10
  95. package/src/screens/SelectUnit/index.js +4 -2
  96. package/src/screens/SetSchedule/index.js +9 -9
  97. package/src/screens/Sharing/Components/SensorItem.js +10 -12
  98. package/src/screens/Sharing/SelectPermission.js +14 -6
  99. package/src/screens/SideMenuDetail/__test__/index.test.js +4 -4
  100. package/src/screens/SideMenuDetail/index.js +2 -3
  101. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +3 -2
  102. package/src/screens/SubUnit/Detail.js +1 -2
  103. package/src/screens/SubUnit/ManageSubUnit.js +12 -7
  104. package/src/screens/SubUnit/__test__/Detail.test.js +1 -1
  105. package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +27 -1
  106. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +1 -1
  107. package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
  108. package/src/screens/Unit/ChooseLocation.js +6 -13
  109. package/src/screens/Unit/Detail.js +30 -75
  110. package/src/screens/Unit/SelectAddress.js +34 -21
  111. package/src/screens/Unit/SmartAccount.js +4 -4
  112. package/src/screens/Unit/Summaries.js +17 -1
  113. package/src/screens/Unit/__test__/CheckSendEmail.test.js +9 -1
  114. package/src/screens/Unit/__test__/Detail.test.js +16 -15
  115. package/src/screens/Unit/__test__/SelectAddress.test.js +72 -13
  116. package/src/screens/Unit/__test__/SmartAccount.test.js +1 -1
  117. package/src/screens/Unit/__test__/Summaries.test.js +100 -0
  118. package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +50 -0
  119. package/src/screens/Unit/styles.js +4 -0
  120. package/src/screens/UnitSummary/__test__/index.test.js +55 -1
  121. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +31 -2
  122. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +2 -13
  123. package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +0 -1
  124. package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +11 -2
  125. package/src/screens/UnitSummary/components/RunningDevices/index.js +7 -10
  126. package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
  127. package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +10 -2
  128. package/src/screens/UnitSummary/index.js +15 -1
  129. package/src/utils/Apis/axios.js +16 -25
  130. package/src/utils/Converter/time.js +0 -18
  131. package/src/utils/I18n/translations/en.json +4 -1
  132. package/src/utils/I18n/translations/vi.json +5 -1
  133. package/src/utils/Permission/common.js +67 -0
  134. package/src/utils/Utils.js +5 -1
@@ -5,6 +5,7 @@ import Routes from '../../utils/Route';
5
5
  import { useIsFocused, useNavigation } from '@react-navigation/native';
6
6
  import { axiosGet } from '../../utils/Apis/axios';
7
7
  import { API } from '../../configs';
8
+ import { useReceiveNotifications } from '../../hooks';
8
9
 
9
10
  const Summaries = memo(({ unit }) => {
10
11
  const [unitSummaries, setUnitSummaries] = useState([]);
@@ -33,6 +34,8 @@ const Summaries = memo(({ unit }) => {
33
34
  const goToSummary = useCallback(
34
35
  (summary) => {
35
36
  navigation.navigate(Routes.UnitSummary, {
37
+ summaryId: summary.id,
38
+ unitId: unit.id,
36
39
  summaryData: summary,
37
40
  unitData: unit,
38
41
  });
@@ -50,7 +53,7 @@ const Summaries = memo(({ unit }) => {
50
53
  if (success) {
51
54
  localState.timeoutId = setTimeout(() => {
52
55
  continuousFetchSummary();
53
- }, 5000);
56
+ }, 10000);
54
57
  }
55
58
  }, [localState, fetchUnitSummary]);
56
59
 
@@ -82,6 +85,19 @@ const Summaries = memo(({ unit }) => {
82
85
  };
83
86
  }, [localState, continuousFetchSummary, isFocused]);
84
87
 
88
+ const { dataNotification } = useReceiveNotifications();
89
+
90
+ useEffect(() => {
91
+ if (dataNotification) {
92
+ const { params = {} } = dataNotification;
93
+ const { summary_id } = params;
94
+ if (summary_id) {
95
+ fetchUnitSummary();
96
+ }
97
+ }
98
+ // eslint-disable-next-line react-hooks/exhaustive-deps
99
+ }, [dataNotification]);
100
+
85
101
  return (
86
102
  <>
87
103
  {!unitSummaries || !unitSummaries.length ? null : (
@@ -24,7 +24,9 @@ jest.mock('react-redux', () => ({
24
24
 
25
25
  jest.mock('../../../iot/RemoteControl/GoogleHome', () => ({
26
26
  ...jest.requireActual('../../../iot/RemoteControl/GoogleHome'),
27
- googleHomeConnect: jest.fn(() => false),
27
+ googleHomeConnect: jest.fn(async () => ({
28
+ [1]: {},
29
+ })),
28
30
  }));
29
31
 
30
32
  jest.mock('@react-native-community/netinfo', () => {
@@ -37,6 +39,12 @@ jest.mock('@react-native-community/netinfo', () => {
37
39
  };
38
40
  });
39
41
 
42
+ jest.mock('react-native-onesignal', () => {
43
+ return {
44
+ setNotificationWillShowInForegroundHandler: jest.fn(),
45
+ };
46
+ });
47
+
40
48
  const wrapComponent = (route, unitData, account) => (
41
49
  <SCProvider initState={mockSCStore({})}>
42
50
  <UnitDetail
@@ -2,7 +2,6 @@ import React from 'react';
2
2
  import { TouchableOpacity, View } from 'react-native';
3
3
  import MockAdapter from 'axios-mock-adapter';
4
4
  import renderer, { act } from 'react-test-renderer';
5
- import { createConnection, getStates } from 'home-assistant-js-websocket';
6
5
  import ParallaxScrollView from '../../../libs/react-native-parallax-scroll-view';
7
6
  import { BleManager } from 'react-native-ble-plx';
8
7
  import { useIsFocused } from '@react-navigation/native';
@@ -55,11 +54,19 @@ jest.mock('@react-navigation/native', () => {
55
54
  };
56
55
  });
57
56
 
58
- jest.mock('home-assistant-js-websocket', () => {
57
+ const mockConnectGoogleHome = jest.fn();
58
+ jest.mock('../../../hooks/IoT', () => {
59
59
  return {
60
- ...jest.requireActual('home-assistant-js-websocket'),
61
- createConnection: jest.fn(),
62
- getStates: jest.fn(),
60
+ ...jest.requireActual('../../../hooks/IoT'),
61
+ useGGHomeConnection: () => ({
62
+ connectGoogleHome: mockConnectGoogleHome,
63
+ }),
64
+ };
65
+ });
66
+
67
+ jest.mock('react-native-onesignal', () => {
68
+ return {
69
+ setNotificationWillShowInForegroundHandler: jest.fn(),
63
70
  };
64
71
  });
65
72
 
@@ -197,21 +204,12 @@ describe('Test UnitDetail', () => {
197
204
  ],
198
205
  },
199
206
  };
200
- jest.useFakeTimers();
201
-
202
- createConnection.mockImplementation(async () => ({
203
- subscribeEvents: jest.fn(),
204
- addEventListener: jest.fn(),
205
- }));
206
-
207
207
  await act(async () => {
208
208
  renderer.create(
209
209
  wrapComponent({ params: { ...route.params, unitData } }, account)
210
210
  );
211
211
  });
212
-
213
- expect(createConnection).toHaveBeenCalled();
214
- expect(getStates).toHaveBeenCalled();
212
+ expect(mockConnectGoogleHome).toBeCalled();
215
213
  });
216
214
 
217
215
  test('when unit has bluetooth action then scan for devices', async () => {
@@ -361,6 +359,7 @@ describe('Test UnitDetail', () => {
361
359
  expect(fullView).toHaveLength(1);
362
360
  expect(fullView[0].props.isVisible).toEqual(false);
363
361
  });
362
+
364
363
  test('onPress subunit camera devices', async () => {
365
364
  const unitData = {
366
365
  stations: [
@@ -405,6 +404,7 @@ describe('Test UnitDetail', () => {
405
404
  });
406
405
  expect(mockedNavigate).not.toHaveBeenCalled();
407
406
  });
407
+
408
408
  test('render subunit favorites', async () => {
409
409
  const unitData = {
410
410
  stations: [
@@ -423,6 +423,7 @@ describe('Test UnitDetail', () => {
423
423
  const favorites = instance.findAllByType(SubUnitFavorites);
424
424
  expect(favorites).toHaveLength(1);
425
425
  });
426
+
426
427
  test('render navbar', async () => {
427
428
  mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
428
429
  stations: [],
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
3
  import MockAdapter from 'axios-mock-adapter';
4
+ import RNP from 'react-native-permissions';
4
5
 
5
6
  import { SCProvider } from '../../../context';
6
7
  import { mockSCStore } from '../../../context/mockStore';
@@ -11,6 +12,11 @@ import BottomButtonView from '../../../commons/BottomButtonView';
11
12
  import { API } from '../../../configs';
12
13
  import { TESTID } from '../../../configs/Constants';
13
14
  import api from '../../../utils/Apis/axios';
15
+ import {
16
+ GEOLOCATION_ERROR,
17
+ OpenSetting,
18
+ } from '../../../utils/Permission/common';
19
+ import { RESULTS } from 'react-native-permissions';
14
20
 
15
21
  const wrapComponent = (route) => (
16
22
  <SCProvider initState={mockSCStore({})}>
@@ -56,18 +62,23 @@ jest.mock('react-native-maps', () => {
56
62
  };
57
63
  });
58
64
 
59
- jest.mock('@react-native-community/geolocation', () => {
60
- const position = {
61
- coords: {
62
- latitude: 100,
63
- longitude: 100,
64
- },
65
- };
66
- return {
67
- getCurrentPosition: (onSuccess, onError, options) => {
68
- onSuccess(position);
69
- },
70
- };
65
+ jest.mock('../../../utils/Permission/common');
66
+
67
+ const position = {
68
+ coords: {
69
+ latitude: 100,
70
+ longitude: 100,
71
+ },
72
+ };
73
+ const mockGeolocation = {
74
+ getCurrentPosition: (onSuccess, onError, options) => {
75
+ onSuccess(position);
76
+ },
77
+ };
78
+ global.navigator.geolocation = mockGeolocation;
79
+
80
+ jest.mock('react-native-permissions', () => {
81
+ return require('react-native-permissions/mock');
71
82
  });
72
83
 
73
84
  describe('Test SelectAddress', () => {
@@ -76,6 +87,7 @@ describe('Test SelectAddress', () => {
76
87
  const mockUpdateLocation = jest.fn();
77
88
 
78
89
  beforeAll(() => {
90
+ RNP.check.mockClear();
79
91
  route = {
80
92
  params: {
81
93
  updateLocation: mockUpdateLocation,
@@ -141,7 +153,7 @@ describe('Test SelectAddress', () => {
141
153
  expect(mockGoBack).toBeCalled();
142
154
  });
143
155
 
144
- test('test get current location', async () => {
156
+ test('test get current location success', async () => {
145
157
  await act(async () => {
146
158
  tree = await create(wrapComponent(route));
147
159
  });
@@ -174,6 +186,53 @@ describe('Test SelectAddress', () => {
174
186
  });
175
187
  });
176
188
 
189
+ test('test get current location failed permission denied', async () => {
190
+ await act(async () => {
191
+ tree = await create(wrapComponent(route));
192
+ });
193
+ const instance = tree.root;
194
+ const button = instance.find(
195
+ (el) => el.props.testID === TESTID.BUTTON_YOUR_LOCATION
196
+ );
197
+
198
+ global.navigator.geolocation = {
199
+ getCurrentPosition: (onSuccess, onError, options) => {
200
+ onError({ code: GEOLOCATION_ERROR.PERMISSION_DENIED });
201
+ },
202
+ };
203
+ RNP.check.mockImplementationOnce(() => RESULTS.BLOCKED);
204
+ OpenSetting.mockImplementationOnce(() => {});
205
+
206
+ await act(async () => {
207
+ await button.props.onPress();
208
+ });
209
+ OpenSetting.mockClear();
210
+ });
211
+
212
+ test('test get current failed error not handle', async () => {
213
+ await act(async () => {
214
+ tree = await create(wrapComponent(route));
215
+ });
216
+ const instance = tree.root;
217
+ const button = instance.find(
218
+ (el) => el.props.testID === TESTID.BUTTON_YOUR_LOCATION
219
+ );
220
+
221
+ global.navigator.geolocation = {
222
+ getCurrentPosition: (onSuccess, onError, options) => {
223
+ onError({ code: GEOLOCATION_ERROR.TIMEOUT });
224
+ },
225
+ };
226
+ RNP.check.mockImplementationOnce(() => RESULTS.DENIED);
227
+ OpenSetting.mockImplementationOnce(() => {});
228
+
229
+ await act(async () => {
230
+ await button.props.onPress();
231
+ });
232
+ expect(OpenSetting).toBeCalledTimes(0);
233
+ OpenSetting.mockClear();
234
+ });
235
+
177
236
  test('test choose on map', async () => {
178
237
  await act(async () => {
179
238
  tree = await create(wrapComponent(route));
@@ -69,7 +69,7 @@ describe('Test SmartAccount', () => {
69
69
  ],
70
70
  };
71
71
  mock
72
- .onGet(API.SMART_ACCOUNT.LIST_SMART_ACCOUNT())
72
+ .onGet(API.SMART_ACCOUNT.LIST_SMART_ACCOUNT(1))
73
73
  .reply(response.status, response.data);
74
74
  await act(async () => {
75
75
  tree = await renderer.create(wrapComponent(route));
@@ -0,0 +1,100 @@
1
+ import React from 'react';
2
+ import { ScrollView } from 'react-native';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+ import renderer, { act } from 'react-test-renderer';
5
+ import { API } from '../../../configs';
6
+ import { SCProvider } from '../../../context';
7
+ import { mockSCStore } from '../../../context/mockStore';
8
+ import Summaries from '../Summaries';
9
+ import SummaryItem from '../../../commons/SummaryItem';
10
+ import api from '../../../utils/Apis/axios';
11
+ import { useReceiveNotifications } from '../../../hooks';
12
+
13
+ const mock = new MockAdapter(api.axiosInstance);
14
+
15
+ const wrapComponent = (props) => (
16
+ <SCProvider initState={mockSCStore({})}>
17
+ <Summaries {...props} />
18
+ </SCProvider>
19
+ );
20
+
21
+ jest.mock('react', () => {
22
+ return {
23
+ ...jest.requireActual('react'),
24
+ memo: (x) => x,
25
+ };
26
+ });
27
+
28
+ const mockedNavigate = jest.fn();
29
+ jest.mock('@react-navigation/native', () => {
30
+ return {
31
+ ...jest.requireActual('@react-navigation/native'),
32
+ useIsFocused: jest.fn(),
33
+ useNavigation: () => ({
34
+ navigate: mockedNavigate,
35
+ }),
36
+ };
37
+ });
38
+
39
+ jest.mock('react-native-onesignal', () => {
40
+ return {
41
+ setNotificationWillShowInForegroundHandler: jest.fn(),
42
+ };
43
+ });
44
+
45
+ jest.mock('../../../hooks', () => {
46
+ return {
47
+ ...jest.requireActual('../../../hooks'),
48
+ useReceiveNotifications: jest.fn(() => ({ dataNotification: null })),
49
+ };
50
+ });
51
+
52
+ describe('Test Summaries', () => {
53
+ let tree, props;
54
+
55
+ beforeEach(() => {
56
+ props = {
57
+ unit: {
58
+ id: 1,
59
+ },
60
+ };
61
+ });
62
+
63
+ test('render Summaries receive noti with summary_id then reload', async () => {
64
+ mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200, [{ id: 1 }]);
65
+ const dataNotification = {
66
+ params: {
67
+ summary_id: 1,
68
+ },
69
+ };
70
+ useReceiveNotifications.mockImplementationOnce(() => ({
71
+ dataNotification,
72
+ }));
73
+ await act(async () => {
74
+ tree = await renderer.create(wrapComponent(props));
75
+ });
76
+ const instance = tree.root;
77
+ const scrollview = instance.findByType(ScrollView);
78
+ expect(scrollview).toBeDefined();
79
+ const items = instance.findAllByType(SummaryItem);
80
+ await act(async () => {
81
+ items[0].props.goToSummary({ id: 1 });
82
+ });
83
+ expect(mockedNavigate).toBeCalled();
84
+ });
85
+
86
+ test('render Summaries receive noti with summary_id then not reload', async () => {
87
+ mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200, [{ id: 1 }]);
88
+ const dataNotification = {
89
+ params: {
90
+ unit_id: 1,
91
+ },
92
+ };
93
+ useReceiveNotifications.mockImplementationOnce(() => ({
94
+ dataNotification,
95
+ }));
96
+ await act(async () => {
97
+ tree = await renderer.create(wrapComponent(props));
98
+ });
99
+ });
100
+ });
@@ -0,0 +1,50 @@
1
+ import { useEffect, useCallback } from 'react';
2
+ import { scanBluetoothDevices } from '../../../iot/RemoteControl/Bluetooth';
3
+ import { lgThinqConnect } from '../../../iot/RemoteControl/LG';
4
+ import { useGGHomeConnection } from '../../../hooks/IoT';
5
+ import { useSCContextSelector } from '../../../context';
6
+
7
+ export const useUnitConnectRemoteDevices = (unit) => {
8
+ const { isNetworkConnected } = useSCContextSelector((state) => state.app);
9
+
10
+ const { connectGoogleHome } = useGGHomeConnection();
11
+
12
+ let lgThinqConnected = false;
13
+
14
+ const handleLgThinqConnect = useCallback(async (options) => {
15
+ if (lgThinqConnected) {
16
+ return;
17
+ }
18
+ // eslint-disable-next-line react-hooks/exhaustive-deps
19
+ lgThinqConnected = true;
20
+ await lgThinqConnect(options);
21
+ }, []);
22
+
23
+ useEffect(() => {
24
+ if (unit.remote_control_options && unit.remote_control_options.bluetooth) {
25
+ scanBluetoothDevices(unit.remote_control_options.bluetooth);
26
+ }
27
+ }, [unit]);
28
+
29
+ useEffect(() => {
30
+ if (
31
+ unit.remote_control_options &&
32
+ unit.remote_control_options.googlehome?.length &&
33
+ isNetworkConnected
34
+ ) {
35
+ (async () => {
36
+ await connectGoogleHome(unit.remote_control_options.googlehome);
37
+ })();
38
+ }
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, [unit, isNetworkConnected]);
41
+
42
+ useEffect(() => {
43
+ if (unit.remote_control_options && unit.remote_control_options.lg_thinq) {
44
+ (async () => {
45
+ await handleLgThinqConnect(unit.remote_control_options.lg_thinq);
46
+ })();
47
+ }
48
+ // eslint-disable-next-line react-hooks/exhaustive-deps
49
+ }, [unit]);
50
+ };
@@ -80,4 +80,8 @@ export default StyleSheet.create({
80
80
  height: heightItem,
81
81
  marginVertical: 0,
82
82
  },
83
+ camera: {
84
+ width: 1,
85
+ height: 1,
86
+ },
83
87
  });
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
3
  import MockAdapter from 'axios-mock-adapter';
4
+ import { RefreshControl } from 'react-native';
4
5
 
5
6
  import Routes from '../../../utils/Route';
6
7
  import UnitSummary from '..';
7
8
  import { API } from '../../../configs';
8
- import { RefreshControl } from 'react-native';
9
9
  import { TESTID } from '../../../configs/Constants';
10
10
  import { TouchableOpacity } from 'react-native';
11
11
  import AirQuality from '../../../commons/UnitSummary/AirQuality';
@@ -15,6 +15,7 @@ import RunningDevices from '../components/RunningDevices';
15
15
  import Temperature from '../components/Temperature';
16
16
  import UvIndex from '../components/UvIndex';
17
17
  import WaterQuality from '../components/WaterQuality';
18
+ import { useReceiveNotifications } from '../../../hooks';
18
19
  import { SCProvider } from '../../../context';
19
20
  import { mockSCStore } from '../../../context/mockStore';
20
21
  import api from '../../../utils/Apis/axios';
@@ -32,6 +33,19 @@ jest.mock('@react-navigation/native', () => {
32
33
  };
33
34
  });
34
35
 
36
+ jest.mock('react-native-onesignal', () => {
37
+ return {
38
+ setNotificationWillShowInForegroundHandler: jest.fn(),
39
+ };
40
+ });
41
+
42
+ jest.mock('../../../hooks', () => {
43
+ return {
44
+ ...jest.requireActual('../../../hooks'),
45
+ useReceiveNotifications: jest.fn(() => ({ dataNotification: null })),
46
+ };
47
+ });
48
+
35
49
  const wrapComponent = (route) => (
36
50
  <SCProvider initState={mockSCStore({})}>
37
51
  <UnitSummary route={route} />
@@ -42,6 +56,7 @@ describe('Test UnitSummary', () => {
42
56
  let route;
43
57
 
44
58
  beforeEach(() => {
59
+ mock.resetHistory();
45
60
  Date.now = jest.fn(() => new Date('2021-01-24T12:00:00.000Z'));
46
61
  route = {
47
62
  params: {
@@ -49,6 +64,7 @@ describe('Test UnitSummary', () => {
49
64
  unitData: {
50
65
  id: 1,
51
66
  },
67
+ summaryId: 1,
52
68
  summaryData: {
53
69
  id: 1,
54
70
  name: '',
@@ -121,6 +137,44 @@ describe('Test UnitSummary', () => {
121
137
  expect(refreshControl).toBeDefined();
122
138
  });
123
139
 
140
+ test('test receive notification with summary_id then reload data', async () => {
141
+ jest.useFakeTimers();
142
+ mock.onGet(API.UNIT.UNIT_SUMMARY_DETAIL(1, 1)).reply(200);
143
+ const dataNotification = {
144
+ params: {
145
+ summary_id: 1,
146
+ },
147
+ };
148
+ useReceiveNotifications.mockImplementationOnce(() => ({
149
+ dataNotification,
150
+ }));
151
+ act(() => {
152
+ tree = create(wrapComponent(route));
153
+ });
154
+ act(() => {
155
+ jest.runOnlyPendingTimers();
156
+ });
157
+ });
158
+
159
+ test('test receive notification with other summary_id then not reload data', async () => {
160
+ jest.useFakeTimers();
161
+ mock.onGet(API.UNIT.UNIT_SUMMARY_DETAIL(1, 1)).reply(200);
162
+ const dataNotification = {
163
+ params: {
164
+ summary_id: 2,
165
+ },
166
+ };
167
+ useReceiveNotifications.mockImplementationOnce(() => ({
168
+ dataNotification,
169
+ }));
170
+ act(() => {
171
+ tree = create(wrapComponent(route));
172
+ });
173
+ act(() => {
174
+ jest.runOnlyPendingTimers();
175
+ });
176
+ });
177
+
124
178
  let list_value = [
125
179
  Routes.AirQuality,
126
180
  Routes.PowerConsumption,
@@ -1,10 +1,23 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
3
  import { TESTID } from '../../../../../configs/Constants';
4
- import { Colors } from '../../../../../configs';
4
+ import { API, Colors } from '../../../../../configs';
5
5
  import PowerConsumption from '../index';
6
6
  import { SCProvider } from '../../../../../context';
7
7
  import { mockSCStore } from '../../../../../context/mockStore';
8
+ import MockAdapter from 'axios-mock-adapter';
9
+ import api from '../../../../../utils/Apis/axios';
10
+
11
+ 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
+ useState.mockImplementation((init) => [init, mockSetState]);
8
21
 
9
22
  const wrapComponent = (summaryDetail) => (
10
23
  <SCProvider initState={mockSCStore({})}>
@@ -64,4 +77,20 @@ describe('Test 3PPowerConsumption', () => {
64
77
  ];
65
78
  expect(listIndicator.props.data).toEqual(resultList);
66
79
  });
80
+
81
+ test('render 3PPowerConsumption with total_power', async () => {
82
+ mock.onGet(API.VALUE_CONSUME.DISPLAY_HISTORY()).reply(200, [{}]);
83
+ const summaryDetail = {
84
+ volt1Value: 200,
85
+ current1Value: 20,
86
+ activePowerValue: 10,
87
+ powerFactor1Value: 30,
88
+ totalPowerValue: 20,
89
+ listConfigs: { total_power: 1 },
90
+ };
91
+ await act(async () => {
92
+ tree = await renderer.create(wrapComponent(summaryDetail));
93
+ });
94
+ expect(mockSetState).toHaveBeenCalledWith([{}]);
95
+ });
67
96
  });
@@ -4,6 +4,7 @@ import moment from 'moment';
4
4
  import { API } from '../../../../configs';
5
5
  import HistoryChart from '../../../../commons/Device/HistoryChart';
6
6
  import { axiosGet } from '../../../../utils/Apis/axios';
7
+ import { updateConfigChart } from '../../../../commons/UnitSummary/ConfigHistoryChart';
7
8
 
8
9
  export const dateTimeType = {
9
10
  date: 'date',
@@ -30,19 +31,7 @@ const ConfigHistoryChart = memo(({ configs }) => {
30
31
  const { success, data } = await axiosGet(API.CONFIG.DISPLAY_HISTORY, {
31
32
  params,
32
33
  });
33
- if (success) {
34
- for (let i = 0; i < data.length; i++) {
35
- for (let j = 0; j < data[i].data.length; j++) {
36
- data[i].data[j].x = moment(data[i].data[j].x).toDate();
37
- }
38
- }
39
- setChartData(
40
- configuration.map((config) => {
41
- config.data = data.find((k) => k.config === config.id).data;
42
- return config;
43
- })
44
- );
45
- }
34
+ updateConfigChart(success, data, configuration, setChartData);
46
35
  };
47
36
  fetchData();
48
37
  }, [startDate, endDate, configs]);
@@ -1,4 +1,3 @@
1
- /* eslint-disable promise/prefer-await-to-callbacks */
2
1
  import React from 'react';
3
2
  import { act, create } from 'react-test-renderer';
4
3
  import Text from '../../../../../commons/Text';
@@ -13,7 +13,6 @@ const wrapComponent = (unit, summaryDetail) => (
13
13
  );
14
14
 
15
15
  const mockedNavigate = jest.fn();
16
-
17
16
  jest.mock('@react-navigation/native', () => {
18
17
  return {
19
18
  ...jest.requireActual('@react-navigation/native'),
@@ -23,6 +22,16 @@ jest.mock('@react-navigation/native', () => {
23
22
  };
24
23
  });
25
24
 
25
+ const mockConnectGoogleHome = jest.fn();
26
+ jest.mock('../../../../../hooks/IoT', () => {
27
+ return {
28
+ ...jest.requireActual('../../../../../hooks/IoT'),
29
+ useGGHomeConnection: () => ({
30
+ connectGoogleHome: mockConnectGoogleHome,
31
+ }),
32
+ };
33
+ });
34
+
26
35
  describe('test RunningDevices', () => {
27
36
  afterEach(() => {
28
37
  mockedNavigate.mockClear();
@@ -73,6 +82,7 @@ describe('test RunningDevices', () => {
73
82
  act(() => {
74
83
  button[0].props.onPress();
75
84
  });
85
+ expect(mockConnectGoogleHome).toBeCalled();
76
86
  });
77
87
  });
78
88
 
@@ -112,7 +122,6 @@ describe('test RunningDevices', () => {
112
122
  button[0].props.onPress();
113
123
  });
114
124
  expect(mockedNavigate).toBeCalledWith('DeviceDetail', {
115
- isGGHomeConnected: false,
116
125
  sensorData: summaryDetail.devices[0],
117
126
  station: 'station',
118
127
  title: undefined,