@eohjsc/react-native-smart-city 0.3.48 → 0.3.49

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 (164) hide show
  1. package/package.json +4 -4
  2. package/src/Images/DevMode/file_copy.svg +3 -0
  3. package/src/Images/DevMode/inforCode.png +0 -0
  4. package/src/Images/DevMode/inforCode@2x.png +0 -0
  5. package/src/Images/DevMode/inforCode@3x.png +0 -0
  6. package/src/commons/Action/__test__/ItemQuickAction.test.js +0 -7
  7. package/src/commons/ActionGroup/__test__/ColorPickerTemplate.test.js +1 -8
  8. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +1 -1
  9. package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +1 -8
  10. package/src/commons/ActionTemplate/__test__/index.test.js +0 -7
  11. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +3 -3
  12. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +1 -1
  13. package/src/commons/Dashboard/MyUnit/index.js +30 -4
  14. package/src/commons/DevMode/Styles/ItemStyles.js +1 -1
  15. package/src/commons/Device/PMSensor/PMSensorIndicatior.js +2 -1
  16. package/src/commons/FourButtonFilterHistory/__test__/FourButtonFilterHistory.test.js +0 -7
  17. package/src/commons/Header/HeaderCustom.js +13 -6
  18. package/src/commons/MediaPlayer/__test__/index.test.js +0 -7
  19. package/src/commons/MediaPlayerDetail/__test__/MediaPlayerFull.test.js +0 -1
  20. package/src/commons/MenuActionMore/index.js +4 -1
  21. package/src/commons/NavBar/index.js +1 -1
  22. package/src/commons/OneTapTemplate/OptionsDropdownActionTemplate.js +1 -1
  23. package/src/commons/OneTapTemplate/__test__/NumberUpDownActionTemplate.test.js +0 -7
  24. package/src/commons/OneTapTemplate/__test__/OptionsDropdownActionTemplate.test.js +0 -7
  25. package/src/commons/OneTapTemplate/__test__/StatesGridActionTemplate.test.js +0 -7
  26. package/src/commons/RowItem/index.js +6 -1
  27. package/src/commons/SelectUnit/index.js +4 -1
  28. package/src/commons/StatusBox/styles.js +8 -3
  29. package/src/commons/SubUnit/__test__/Favorites.test.js +0 -7
  30. package/src/commons/SubUnit/__test__/ShortDetail.test.js +0 -7
  31. package/src/commons/Tabbar/__test__/index.test.js +0 -7
  32. package/src/commons/Unit/__test__/HeaderUnit.test.js +0 -5
  33. package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +0 -7
  34. package/src/configs/API.js +28 -0
  35. package/src/configs/AccessibilityLabel.js +13 -0
  36. package/src/configs/Colors.js +4 -0
  37. package/src/configs/Constants.js +6 -0
  38. package/src/configs/Images.js +1 -0
  39. package/src/context/actionType.ts +8 -1
  40. package/src/context/mockStore.ts +8 -2
  41. package/src/context/reducer.ts +27 -4
  42. package/src/hooks/IoT/__test__/useWatchConfigs.test.js +46 -0
  43. package/src/hooks/IoT/useBluetoothConnection.js +78 -4
  44. package/src/hooks/IoT/useBluetoothDeviceConnected.js +1 -1
  45. package/src/iot/RemoteControl/Bluetooth.js +0 -16
  46. package/src/iot/RemoteControl/__test__/Bluetooth.test.js +0 -25
  47. package/src/navigations/Main.js +39 -0
  48. package/src/navigations/UnitStack.js +18 -5
  49. package/src/screens/ActivityLog/__test__/FilterPopup.test.js +0 -7
  50. package/src/screens/ActivityLog/__test__/ItemLog.test.js +0 -7
  51. package/src/screens/ActivityLog/__test__/index.test.js +0 -7
  52. package/src/screens/AddLocationMaps/__test__/index.test.js +0 -7
  53. package/src/screens/AddNewAction/SelectAction.js +22 -18
  54. package/src/screens/AddNewAction/__test__/SelectAction.test.js +35 -16
  55. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +0 -7
  56. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +0 -4
  57. package/src/screens/AddNewGateway/ConnectingZigbeeDevice.js +17 -4
  58. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +0 -4
  59. package/src/screens/AddNewGateway/__test__/ConnectingModbusDevice.test.js +0 -4
  60. package/src/screens/AddNewGateway/__test__/ConnectingWifiDevice.test.js +0 -4
  61. package/src/screens/AddNewGateway/__test__/ConnectingZigbeeDevice.test.js +4 -7
  62. package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +0 -7
  63. package/src/screens/AddNewGateway/__test__/SelectDeviceType.test.js +0 -4
  64. package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +0 -4
  65. package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +0 -4
  66. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +0 -7
  67. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +0 -1
  68. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +0 -7
  69. package/src/screens/Device/__test__/detail.test.js +1 -1
  70. package/src/screens/Device/detail.js +11 -3
  71. package/src/screens/Device/hooks/useDisconnectedDevice.js +26 -7
  72. package/src/screens/EmergencyContacts/__test__/hooks.test.js +79 -0
  73. package/src/screens/Gateway/DetailConfigActionModbus/__test__/index.test.js +138 -0
  74. package/src/screens/Gateway/DetailConfigActionModbus/index.js +180 -0
  75. package/src/screens/Gateway/DetailConfigActionModbus/styles.js +9 -0
  76. package/src/screens/Gateway/DetailConfigActionZigbee/__test__/index.test.js +73 -0
  77. package/src/screens/Gateway/DetailConfigActionZigbee/index.js +62 -0
  78. package/src/screens/Gateway/DetailConfigActionZigbee/styles.js +9 -0
  79. package/src/screens/Gateway/DeviceGatewayInfo/__test__/index.test.js +73 -0
  80. package/src/screens/Gateway/DeviceGatewayInfo/index.js +96 -0
  81. package/src/screens/Gateway/DeviceGatewayInfo/styles.js +9 -0
  82. package/src/screens/Gateway/DeviceModbusDetail/__test__/index.test.js +393 -0
  83. package/src/screens/Gateway/DeviceModbusDetail/index.js +176 -0
  84. package/src/screens/Gateway/DeviceModbusDetail/styles.js +12 -0
  85. package/src/screens/Gateway/DeviceZigbeeDetail/__test__/index.test.js +265 -0
  86. package/src/screens/Gateway/DeviceZigbeeDetail/index.js +148 -0
  87. package/src/screens/Gateway/DeviceZigbeeDetail/styles.js +12 -0
  88. package/src/screens/Gateway/GatewayConnectionMethods/__test__/index.test.js +37 -0
  89. package/src/screens/Gateway/GatewayConnectionMethods/index.js +73 -0
  90. package/src/screens/Gateway/GatewayConnectionMethods/styles.js +45 -0
  91. package/src/screens/Gateway/GatewayDetail/__test__/index.test.js +298 -0
  92. package/src/screens/Gateway/GatewayDetail/index.js +148 -0
  93. package/src/screens/Gateway/GatewayDetail/styles.js +12 -0
  94. package/src/screens/Gateway/GatewayInfo/__test__/index.test.js +137 -0
  95. package/src/screens/Gateway/GatewayInfo/index.js +115 -0
  96. package/src/screens/Gateway/GatewayInfo/styles.js +9 -0
  97. package/src/screens/Gateway/__test__/index.test.js +58 -0
  98. package/src/screens/Gateway/components/Detail/__test__/index.test.js +46 -0
  99. package/src/screens/Gateway/components/Detail/index.js +62 -0
  100. package/src/screens/Gateway/components/Detail/styles.js +27 -0
  101. package/src/screens/Gateway/components/DetailActionModbus/__test__/index.test.js +49 -0
  102. package/src/screens/Gateway/components/DetailActionModbus/index.js +52 -0
  103. package/src/screens/Gateway/components/DetailActionModbus/styles.js +32 -0
  104. package/src/screens/Gateway/components/DetailConfigAction/__test__/index.test.js +59 -0
  105. package/src/screens/Gateway/components/DetailConfigAction/index.js +69 -0
  106. package/src/screens/Gateway/components/DetailConfigAction/styles.js +21 -0
  107. package/src/screens/Gateway/components/GatewayItem/__test__/index.test.js +1 -1
  108. package/src/screens/Gateway/components/GatewayItem/styles.js +4 -33
  109. package/src/screens/Gateway/components/Information/__test__/index.test.js +70 -0
  110. package/src/screens/Gateway/components/Information/index.js +116 -0
  111. package/src/screens/Gateway/components/Information/styles.js +59 -0
  112. package/src/screens/Gateway/components/RowItem/__test__/index.test.js +67 -0
  113. package/src/screens/Gateway/components/RowItem/index.js +65 -0
  114. package/src/screens/Gateway/components/RowItem/styles.js +25 -0
  115. package/src/screens/Gateway/components/TabPaneCT/__test__/index.test.js +98 -0
  116. package/src/screens/Gateway/components/TabPaneCT/index.js +134 -0
  117. package/src/screens/Gateway/components/TabPaneCT/styles.js +58 -0
  118. package/src/screens/Gateway/hooks/__test__/index.test.js +93 -0
  119. package/src/screens/Gateway/hooks/useGateway.js +110 -16
  120. package/src/screens/Gateway/index.js +19 -3
  121. package/src/screens/Gateway/styles.js +6 -8
  122. package/src/screens/Gateway/utils/index.js +16 -0
  123. package/src/screens/GuestInfo/__test__/index.test.js +0 -7
  124. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +0 -7
  125. package/src/screens/HanetCamera/__test__/Detail.test.js +0 -7
  126. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +0 -7
  127. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +0 -7
  128. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +0 -6
  129. package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +0 -7
  130. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +0 -7
  131. package/src/screens/Notification/__test__/Notification.test.js +0 -7
  132. package/src/screens/PlayBackCamera/__test__/index.test.js +0 -1
  133. package/src/screens/ScriptDetail/__test__/index.test.js +0 -7
  134. package/src/screens/SelectUnit/__test__/index.test.js +0 -1
  135. package/src/screens/SetSchedule/__test__/index.test.js +0 -7
  136. package/src/screens/Sharing/Components/__test__/DeviceItem.test.js +0 -7
  137. package/src/screens/Sharing/Components/__test__/ItemChangeRole.test.js +0 -7
  138. package/src/screens/Sharing/Components/__test__/TitleCheckBox.test.js +0 -7
  139. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +0 -6
  140. package/src/screens/Sharing/hooks/__test__/index.test.js +80 -0
  141. package/src/screens/SmartAccount/ListDevice/__test__/DeviceItem.test.js +0 -7
  142. package/src/screens/SmartIr/__test__/ButtonsBottom.test.js +0 -6
  143. package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +1 -6
  144. package/src/screens/SmartIr/__test__/SelectBrand.test.js +1 -6
  145. package/src/screens/SmartIr/__test__/SelectDeviceType.test.js +1 -6
  146. package/src/screens/SubUnit/AddSubUnit.js +1 -0
  147. package/src/screens/SubUnit/ManageSubUnit.js +4 -1
  148. package/src/screens/SubUnit/hooks/__test__/useEmergencyContacts.test.js +34 -0
  149. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +0 -7
  150. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +0 -7
  151. package/src/screens/Unit/__test__/AddMenu.test.js +0 -7
  152. package/src/screens/Unit/__test__/CheckSendEmail.test.js +1 -1
  153. package/src/screens/Unit/__test__/ChooseLocation.test.js +0 -7
  154. package/src/screens/Unit/__test__/Detail.test.js +1 -8
  155. package/src/screens/Unit/__test__/SelectAddToFavorites.test.js +0 -7
  156. package/src/screens/Unit/__test__/SelectAddress.test.js +0 -7
  157. package/src/screens/Unit/__test__/SmartAccount.test.js +0 -7
  158. package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -7
  159. package/src/screens/Unit/__test__/Summaries.test.js +0 -7
  160. package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +4 -3
  161. package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +2 -2
  162. package/src/utils/I18n/translations/en.json +28 -0
  163. package/src/utils/I18n/translations/vi.json +28 -0
  164. package/src/utils/Route/index.js +8 -0
@@ -23,13 +23,6 @@ jest.mock('@react-navigation/native', () => {
23
23
  };
24
24
  });
25
25
 
26
- jest.mock('react', () => {
27
- return {
28
- ...jest.requireActual('react'),
29
- memo: (x) => x,
30
- };
31
- });
32
-
33
26
  const wrapComponent = (route) => (
34
27
  <SCProvider initState={mockSCStore({})}>
35
28
  <SelectAction route={route} />
@@ -101,7 +94,8 @@ describe('Test SelectAction', () => {
101
94
  const config1 = 1,
102
95
  config2 = 2,
103
96
  config3 = 3,
104
- config4 = 4;
97
+ config4 = 4,
98
+ config5 = 5;
105
99
  const response = {
106
100
  status: 200,
107
101
  success: true,
@@ -152,13 +146,25 @@ describe('Test SelectAction', () => {
152
146
  text_format: '{number} \u00b0C',
153
147
  },
154
148
  },
149
+ {
150
+ title: '',
151
+ template: 'NumberUpDownActionTemplate',
152
+ configuration: {
153
+ config: config4,
154
+ allow_config_store_value: true,
155
+ action: '11111111-6c1a-452d-a1d1-87a314c20528',
156
+ min_value: 12,
157
+ max_value: 20,
158
+ text_format: '{number} \u00b0C',
159
+ },
160
+ },
155
161
  {
156
162
  title: '',
157
163
  template: 'StatesGridActionTemplate',
158
164
  configuration: {
159
165
  options: [
160
166
  {
161
- config: config4,
167
+ config: config5,
162
168
  is_on_value: 1,
163
169
  action: '800ff454-4e2a-4a38-bad6-1bded728193e',
164
170
  allow_config_store_value: true,
@@ -179,7 +185,7 @@ describe('Test SelectAction', () => {
179
185
  const renderActionItem = instance.find(
180
186
  (el) => el.props.accessibilityLabel === AccessibilityLabel.ACTION_ITEM
181
187
  );
182
- expect(renderActionItem.props.data.length).toBe(4);
188
+ expect(renderActionItem.props.data.length).toBe(5);
183
189
 
184
190
  const simpleActionOn = instance.find(
185
191
  (el) =>
@@ -209,22 +215,27 @@ describe('Test SelectAction', () => {
209
215
  await touchOpacity.props.onPress();
210
216
  });
211
217
 
212
- const buttonNumberUp = instance.find(
218
+ const buttonNumberUp = instance.findAll(
213
219
  (item) =>
214
220
  item.props.accessibilityLabel ===
215
221
  AccessibilityLabel.NUMBER_UP_DOWN_ACTION_UP &&
216
222
  item.type === TouchableOpacity
217
223
  );
218
- const buttonSaveNumberAction = instance.find(
224
+ expect(buttonNumberUp).toHaveLength(2);
225
+
226
+ const buttonSaveNumberAction = instance.findAll(
219
227
  (item) =>
220
228
  item.props.accessibilityLabel ===
221
229
  AccessibilityLabel.NUMBER_UP_DOWN_ACTION_DONE &&
222
230
  item.type === TouchableOpacity
223
231
  );
232
+ expect(buttonSaveNumberAction).toHaveLength(2);
224
233
 
225
234
  await act(async () => {
226
- await buttonNumberUp.props.onPress();
227
- await buttonSaveNumberAction.props.onPress();
235
+ await buttonNumberUp[0].props.onPress();
236
+ await buttonNumberUp[1].props.onPress();
237
+ await buttonSaveNumberAction[0].props.onPress();
238
+ await buttonSaveNumberAction[1].props.onPress();
228
239
  });
229
240
 
230
241
  const chooseMode = instance.find(
@@ -234,7 +245,7 @@ describe('Test SelectAction', () => {
234
245
  item.type === TouchableOpacity
235
246
  );
236
247
  await act(async () => {
237
- await chooseMode.props.onPress(response.data[3].configuration.options[0]);
248
+ await chooseMode.props.onPress(response.data[4].configuration.options[0]);
238
249
  });
239
250
 
240
251
  mock.onPost(API.AUTOMATE.ADD_SCRIPT_ACTION(1)).reply(200);
@@ -275,9 +286,17 @@ describe('Test SelectAction', () => {
275
286
  config_value: 29,
276
287
  },
277
288
  },
289
+ {
290
+ action: '11111111-6c1a-452d-a1d1-87a314c20528',
291
+ data: {
292
+ temperature: 28,
293
+ config_id: config4,
294
+ config_value: 28,
295
+ },
296
+ },
278
297
  {
279
298
  action: '800ff454-4e2a-4a38-bad6-1bded728193e',
280
- data: { config_id: config4, config_value: 1 },
299
+ data: { config_id: config5, config_value: 1 },
281
300
  },
282
301
  ],
283
302
  unit: 1,
@@ -32,13 +32,6 @@ jest.mock('@react-navigation/native', () => {
32
32
  };
33
33
  });
34
34
 
35
- jest.mock('react', () => {
36
- return {
37
- ...jest.requireActual('react'),
38
- memo: (x) => x,
39
- };
40
- });
41
-
42
35
  const wrapComponent = (route) => (
43
36
  <SCProvider initState={mockSCStore({})}>
44
37
  <SelectSensorDevices route={route} />
@@ -22,10 +22,6 @@ const wrapComponent = (route) => (
22
22
 
23
23
  const mock = new MockAdapter(api.axiosInstance);
24
24
 
25
- jest.mock('react', () => {
26
- return { ...jest.requireActual('react'), memo: (x) => x };
27
- });
28
-
29
25
  const mockedNavigate = jest.fn();
30
26
  const mockedGoBack = jest.fn();
31
27
 
@@ -1,5 +1,5 @@
1
1
  import { useNavigation } from '@react-navigation/native';
2
- import React, { useCallback, useState } from 'react';
2
+ import React, { useCallback, useEffect, useState } from 'react';
3
3
  import { Alert } from 'react-native';
4
4
  import API from '../../configs/API';
5
5
  import { useTranslations } from '../../hooks/Common/useTranslations';
@@ -17,7 +17,7 @@ const ConnectingZigbeeDevice = ({ route }) => {
17
17
  Alert.alert(t('fail_add_zigbee_device'), message, [
18
18
  {
19
19
  text: t('ok'),
20
- onPress: () => goBack(),
20
+ onPress: goBack,
21
21
  },
22
22
  ]);
23
23
  },
@@ -39,11 +39,24 @@ const ConnectingZigbeeDevice = ({ route }) => {
39
39
  fail(JSON.stringify(problem || data));
40
40
  return;
41
41
  }
42
- setSensorId(data.id);
43
42
  },
44
- [chipId, fail, subUnit, unitId]
43
+ [chipId, fail, subUnit?.id, unitId]
45
44
  );
46
45
 
46
+ useEffect(() => {
47
+ const timeOut = setTimeout(() => {
48
+ setSensorId((value) => {
49
+ if (!value) {
50
+ fail(t('no_zigbee_device_join_timeout'));
51
+ }
52
+ return value;
53
+ });
54
+ }, 120 * 1000); // when test, it takes more than 1 min
55
+ return () => {
56
+ clearTimeout(timeOut);
57
+ };
58
+ }, [fail, t]);
59
+
47
60
  return (
48
61
  <ConnectingDevice
49
62
  title={t('connect_device')}
@@ -20,10 +20,6 @@ const wrapComponent = (route) => (
20
20
 
21
21
  const mock = new MockAdapter(api.axiosInstance);
22
22
 
23
- jest.mock('react', () => {
24
- return { ...jest.requireActual('react'), memo: (x) => x };
25
- });
26
-
27
23
  const mockedNavigate = jest.fn();
28
24
  const mockedGoBack = jest.fn();
29
25
 
@@ -15,10 +15,6 @@ const wrapComponent = (route) => (
15
15
 
16
16
  const mock = new MockAdapter(api.axiosInstance);
17
17
 
18
- jest.mock('react', () => {
19
- return { ...jest.requireActual('react'), memo: (x) => x };
20
- });
21
-
22
18
  const mockedNavigate = jest.fn();
23
19
  const mockedGoBack = jest.fn();
24
20
 
@@ -18,10 +18,6 @@ const wrapComponent = (route) => (
18
18
 
19
19
  const mock = new MockAdapter(api.axiosInstance);
20
20
 
21
- jest.mock('react', () => {
22
- return { ...jest.requireActual('react'), memo: (x) => x };
23
- });
24
-
25
21
  const mockedNavigate = jest.fn();
26
22
  const mockedGoBack = jest.fn();
27
23
 
@@ -17,10 +17,6 @@ const wrapComponent = (route) => (
17
17
 
18
18
  const mock = new MockAdapter(api.axiosInstance);
19
19
 
20
- jest.mock('react', () => {
21
- return { ...jest.requireActual('react'), memo: (x) => x };
22
- });
23
-
24
20
  const mockedNavigate = jest.fn();
25
21
  const mockedGoBack = jest.fn();
26
22
 
@@ -67,9 +63,7 @@ describe('Test connecting modbus device', () => {
67
63
  });
68
64
 
69
65
  it('receive sensor-id from channel then rename sensor-id', async () => {
70
- mock.onPost().reply(200, {
71
- id: 1,
72
- });
66
+ mock.onPost().reply(200, {});
73
67
  await act(async () => {
74
68
  tree = await create(wrapComponent(route));
75
69
  });
@@ -80,6 +74,9 @@ describe('Test connecting modbus device', () => {
80
74
  channel = channels[key];
81
75
  }
82
76
  }
77
+ await act(async () => {
78
+ await channel.trigger('progress', { data: { sensorId: 1 } });
79
+ });
83
80
  await act(async () => {
84
81
  await channel.trigger('progress', { success: 1 });
85
82
  });
@@ -18,13 +18,6 @@ const wrapComponent = (route) => (
18
18
 
19
19
  const mock = new MockAdapter(api.axiosInstance);
20
20
 
21
- jest.mock('react', () => {
22
- return {
23
- ...jest.requireActual('react'),
24
- memo: (x) => x,
25
- };
26
- });
27
-
28
21
  const mockedNavigate = jest.fn();
29
22
  const mockedGoBack = jest.fn();
30
23
 
@@ -15,10 +15,6 @@ const wrapComponent = (route) => (
15
15
  </SCProvider>
16
16
  );
17
17
 
18
- jest.mock('react', () => {
19
- return { ...jest.requireActual('react'), memo: (x) => x };
20
- });
21
-
22
18
  const mockedNavigate = jest.fn();
23
19
  const mockedGoBack = jest.fn();
24
20
 
@@ -13,10 +13,6 @@ const wrapComponent = (route) => (
13
13
  </SCProvider>
14
14
  );
15
15
 
16
- jest.mock('react', () => {
17
- return { ...jest.requireActual('react'), memo: (x) => x };
18
- });
19
-
20
16
  const mockedNavigate = jest.fn();
21
17
  const mockedGoBack = jest.fn();
22
18
 
@@ -13,10 +13,6 @@ const wrapComponent = (route) => (
13
13
  </SCProvider>
14
14
  );
15
15
 
16
- jest.mock('react', () => {
17
- return { ...jest.requireActual('react'), memo: (x) => x };
18
- });
19
-
20
16
  const mockedNavigate = jest.fn();
21
17
  const mockedGoBack = jest.fn();
22
18
 
@@ -36,13 +36,6 @@ jest.mock('@react-navigation/native', () => {
36
36
  };
37
37
  });
38
38
 
39
- jest.mock('react', () => {
40
- return {
41
- ...jest.requireActual('react'),
42
- memo: (x) => x,
43
- };
44
- });
45
-
46
39
  let tree;
47
40
 
48
41
  describe('test AddNewOneTap', () => {
@@ -35,7 +35,6 @@ jest.mock('react', () => {
35
35
  return {
36
36
  ...jest.requireActual('react'),
37
37
  useState: jest.fn((init) => [init, mockSetState]),
38
- memo: (x) => x,
39
38
  };
40
39
  });
41
40
 
@@ -23,13 +23,6 @@ const wrapComponent = (route) => (
23
23
 
24
24
  const mock = new MockAdapter(api.axiosInstance);
25
25
 
26
- jest.mock('react', () => {
27
- return {
28
- ...jest.requireActual('react'),
29
- memo: (x) => x,
30
- };
31
- });
32
-
33
26
  const mockPop = jest.fn();
34
27
  const mockSetSensorDetail = jest.fn();
35
28
  jest.mock('@react-navigation/native', () => {
@@ -735,7 +735,7 @@ describe('test DeviceDetail', () => {
735
735
  });
736
736
 
737
737
  it('Open popup ble when server down', async () => {
738
- store.app.isBluetoothEnabled = false;
738
+ store.bluetooth.isEnabled = false;
739
739
  data_sensor_display.items[1].configuration.configuration.action1_data.command_prefer_over_bluetooth = true;
740
740
  const responseDisplay = {
741
741
  status: 200,
@@ -101,7 +101,7 @@ const DeviceDetail = ({ route }) => {
101
101
  (state) => state.app.isNetworkConnected
102
102
  );
103
103
  const isBluetoothEnabled = useSCContextSelector((state) => {
104
- return state.app.isBluetoothEnabled;
104
+ return state.bluetooth.isEnabled;
105
105
  });
106
106
 
107
107
  const { isConnected: isEoHBackendConnected } =
@@ -181,7 +181,15 @@ const DeviceDetail = ({ route }) => {
181
181
 
182
182
  const { connectHomeAssistant } = useHomeAssistantConnection();
183
183
 
184
- const { bluetoothScanDevices } = useBluetoothConnection();
184
+ const {
185
+ permissionsGranted: bluetoothPermGranted,
186
+ requestPerm: requestBluetoothPerm,
187
+ bluetoothScanDevices,
188
+ } = useBluetoothConnection();
189
+
190
+ useEffect(() => {
191
+ isDeviceHasBle && isBluetoothEnabled && requestBluetoothPerm();
192
+ }, [isDeviceHasBle, isBluetoothEnabled, requestBluetoothPerm]);
185
193
 
186
194
  useEffect(() => {
187
195
  if (
@@ -202,7 +210,7 @@ const DeviceDetail = ({ route }) => {
202
210
  bluetoothScanDevices([bluetooth.address]);
203
211
  }
204
212
  // eslint-disable-next-line react-hooks/exhaustive-deps
205
- }, [isBluetoothEnabled, controlOptions, unit]);
213
+ }, [isBluetoothEnabled, bluetoothPermGranted, controlOptions, unit]);
206
214
 
207
215
  const fetchSensorDetail = useCallback(async () => {
208
216
  const { success, data, resp_status } = await axiosGet(
@@ -1,10 +1,12 @@
1
1
  import { useNavigation } from '@react-navigation/native';
2
- import { useCallback, useEffect } from 'react';
3
- import { Alert, Linking, Platform } from 'react-native';
2
+ import { useState, useCallback, useEffect } from 'react';
3
+ import { Linking, Platform } from 'react-native';
4
+ import AlertAsync from 'react-native-alert-async';
4
5
  import { useTranslations } from '../../../hooks/Common/useTranslations';
5
6
  import { useSCContextSelector } from '../../../context';
6
- import { enableBluetoothForAndroid } from '../../../iot/RemoteControl/Bluetooth';
7
7
  import { ToastBottomHelper } from '../../../utils/Utils';
8
+ import { enableBluetoothForAndroid } from '../../../iot/RemoteControl/Bluetooth';
9
+ import { useBluetoothConnection } from '../../../hooks/IoT';
8
10
 
9
11
  export const useDisconnectedDevice = (
10
12
  sensorName,
@@ -12,10 +14,27 @@ export const useDisconnectedDevice = (
12
14
  serverDown
13
15
  ) => {
14
16
  const t = useTranslations();
17
+ const { goBack } = useNavigation();
18
+ const [allowEnableBluetooth, setAllowEnableBluetooth] = useState(false);
19
+
15
20
  const openBluetoothIOS = () => {
16
21
  Linking.openURL('App-Prefs:Bluetooth');
17
22
  };
18
- const { goBack } = useNavigation();
23
+
24
+ const {
25
+ permissionsGranted: bluetoothPermGranted,
26
+ requestPerm: requestBluetoothPerm,
27
+ } = useBluetoothConnection();
28
+
29
+ useEffect(() => {
30
+ allowEnableBluetooth && bluetoothPermGranted && enableBluetoothForAndroid();
31
+ }, [allowEnableBluetooth, bluetoothPermGranted]);
32
+
33
+ const enableBluetooth = async () => {
34
+ setAllowEnableBluetooth(true);
35
+ !bluetoothPermGranted && (await requestBluetoothPerm());
36
+ };
37
+
19
38
  const actions =
20
39
  Platform.OS === 'ios'
21
40
  ? [
@@ -35,12 +54,12 @@ export const useDisconnectedDevice = (
35
54
  },
36
55
  {
37
56
  text: 'Open',
38
- onPress: () => enableBluetoothForAndroid(),
57
+ onPress: () => enableBluetooth(),
39
58
  },
40
59
  ];
41
60
 
42
61
  const isBluetoothEnabled = useSCContextSelector(
43
- (state) => state.app.isBluetoothEnabled
62
+ (state) => state.bluetooth.isEnabled
44
63
  );
45
64
  const isNetworkConnected = useSCContextSelector(
46
65
  (state) => state.app.isNetworkConnected
@@ -61,7 +80,7 @@ export const useDisconnectedDevice = (
61
80
  })
62
81
  );
63
82
  } else if (isBluetoothEnabled === false) {
64
- Alert.alert(
83
+ AlertAsync(
65
84
  '',
66
85
  t(
67
86
  'your_connection_to_the_server_was_disconnected_please_open_the_bluetooth_to_continue'
@@ -0,0 +1,79 @@
1
+ import React from 'react';
2
+ import { act, renderHook } from '@testing-library/react-hooks';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+ import { useAlertRemoveEmergencyContact, useEmeragencyContacts } from '../hook';
5
+ import API from '../../../configs/API';
6
+ import api from '../../../utils/Apis/axios';
7
+ import { SCProvider } from '../../../context';
8
+ import { mockSCStore } from '../../../context/mockStore';
9
+
10
+ const mock = new MockAdapter(api.axiosInstance);
11
+
12
+ const mockedSetAction = jest.fn();
13
+
14
+ const wrapper = ({ children }) => <SCProvider>{children}</SCProvider>;
15
+
16
+ const mockUseContext = jest.fn().mockImplementation(() => ({
17
+ stateData: mockSCStore({}),
18
+ setAction: mockedSetAction,
19
+ }));
20
+
21
+ React.useContext = mockUseContext;
22
+
23
+ describe('Test EmergencyContacts', () => {
24
+ it('render useAlertRemoveEmergencyContact onPressRemoveContact', async () => {
25
+ const { result } = renderHook(() => useAlertRemoveEmergencyContact(), {
26
+ wrapper,
27
+ });
28
+ expect(result.current.stateAlertRemoveContact).toEqual({
29
+ leftButton: 'Cancel',
30
+ member: {},
31
+ message: '',
32
+ rightButton: '',
33
+ title: '',
34
+ visible: false,
35
+ });
36
+ await act(async () => {
37
+ await result.current.onPressRemoveContact({ id: 1, name: 123 })();
38
+ });
39
+ expect(result.current.stateAlertRemoveContact).toEqual({
40
+ leftButton: 'Cancel',
41
+ member: { id: 1, name: 123 },
42
+ message: '',
43
+ rightButton: 'Remove',
44
+ title: 'Remove 123?',
45
+ visible: true,
46
+ });
47
+ });
48
+
49
+ it('render useAlertRemoveEmergencyContact hideAlertRemoveContact', async () => {
50
+ const { result } = renderHook(() => useAlertRemoveEmergencyContact(), {
51
+ wrapper,
52
+ });
53
+ await act(() => {
54
+ result.current.stateAlertRemoveContact = {
55
+ ...result.current.stateAlertRemoveContact,
56
+ visible: true,
57
+ };
58
+ });
59
+ await act(async () => {
60
+ await result.current.hideAlertRemoveContact();
61
+ });
62
+ expect(result.current.stateAlertRemoveContact.visible).toEqual(false);
63
+ });
64
+
65
+ it('render useEmeragencyContacts getListContacts', async () => {
66
+ mock
67
+ .onGet(API.EMERGENCY_BUTTON.CONTACTS(), {
68
+ params: {
69
+ group: 1,
70
+ },
71
+ })
72
+ .reply(200, [{ id: 1, name: 'json' }]);
73
+ const { result } = renderHook(() => useEmeragencyContacts());
74
+ await act(async () => {
75
+ await result.current.getListContacts(1);
76
+ });
77
+ expect(result.current.listContacts).toEqual([{ id: 1, name: 'json' }]);
78
+ });
79
+ });
@@ -0,0 +1,138 @@
1
+ import React from 'react';
2
+ import { create, act } from 'react-test-renderer';
3
+ import { useRoute } from '@react-navigation/native';
4
+
5
+ import { SCProvider } from '../../../../context';
6
+ import { mockSCStore } from '../../../../context/mockStore';
7
+ import DetailConfigAction from '../../components/DetailConfigAction';
8
+ import DetailActionModbus from '../../components/DetailActionModbus';
9
+ import Routes from '../../../../utils/Route';
10
+ import DetailConfigActionModbus from '..';
11
+
12
+ const wrapComponent = () => (
13
+ <SCProvider initState={mockSCStore({})}>
14
+ <DetailConfigActionModbus />
15
+ </SCProvider>
16
+ );
17
+
18
+ jest.mock('@react-navigation/native', () => {
19
+ return {
20
+ ...jest.requireActual('@react-navigation/native'),
21
+ useRoute: jest.fn(),
22
+ };
23
+ });
24
+
25
+ const mockNavigate = jest.fn();
26
+ jest.mock('@react-navigation/native', () => {
27
+ return {
28
+ ...jest.requireActual('@react-navigation/native'),
29
+ useNavigation: () => ({
30
+ navigate: mockNavigate,
31
+ pop: jest.fn(),
32
+ }),
33
+ useRoute: jest.fn(),
34
+ useIsFocused: () => true,
35
+ };
36
+ });
37
+
38
+ describe('Test DetailConfigActionZigbee', () => {
39
+ let tree;
40
+ it('test render DetailConfigActionZigbee isConfigRead', async () => {
41
+ useRoute.mockReturnValue({
42
+ params: {
43
+ isConfigRead: true,
44
+ isConfigWrite: false,
45
+ isAction: false,
46
+ isChildAction: false,
47
+ itemActionConfig: {
48
+ id: 1,
49
+ name: 'config1',
50
+ func: 5,
51
+ sa1: 1,
52
+ sa2: 2,
53
+ len1: 1,
54
+ len2: 1,
55
+ },
56
+ },
57
+ });
58
+ await act(async () => {
59
+ tree = await create(wrapComponent());
60
+ });
61
+ const instance = tree.root;
62
+ const detailConfigAction = instance?.findAllByType(DetailConfigAction);
63
+ expect(detailConfigAction).toHaveLength(1);
64
+ });
65
+ it('test render DetailConfigActionZigbee isConfigWrite', async () => {
66
+ useRoute.mockReturnValue({
67
+ params: {
68
+ isConfigRead: false,
69
+ isConfigWrite: true,
70
+ isAction: false,
71
+ isChildAction: false,
72
+ itemActionConfig: {
73
+ id: 1,
74
+ name: 'config1',
75
+ func: 5,
76
+ sa1: 1,
77
+ sa2: 2,
78
+ len1: 1,
79
+ len2: 1,
80
+ },
81
+ },
82
+ });
83
+ await act(async () => {
84
+ tree = await create(wrapComponent());
85
+ });
86
+ const instance = tree.root;
87
+ const detailConfigAction = instance?.findAllByType(DetailConfigAction);
88
+ expect(detailConfigAction).toHaveLength(1);
89
+ });
90
+ it('test render DetailConfigActionZigbee isAction', async () => {
91
+ useRoute.mockReturnValue({
92
+ params: {
93
+ isConfigRead: false,
94
+ isConfigWrite: false,
95
+ isAction: true,
96
+ isChildAction: false,
97
+ itemActionConfig: {
98
+ actionName: '123',
99
+ config: { id: 1, delay: 5, index: 1, ex: '', len1: 1, len2: 1 },
100
+ },
101
+ },
102
+ });
103
+ await act(async () => {
104
+ tree = await create(wrapComponent());
105
+ });
106
+ const instance = tree.root;
107
+ const detailActionModbus = instance?.findAllByType(DetailActionModbus);
108
+ expect(detailActionModbus).toHaveLength(1);
109
+ await act(async () => {
110
+ await detailActionModbus[0].props.onPressRow({
111
+ id: 1,
112
+ actionName: 'action',
113
+ })();
114
+ });
115
+ expect(detailActionModbus).toHaveLength(1);
116
+ expect(mockNavigate).toBeCalledWith(Routes.DetailChildConfigActionModbus, {
117
+ isChildAction: true,
118
+ itemActionConfig: { actionName: 'action', id: 1 },
119
+ });
120
+ });
121
+ it('test render DetailConfigActionZigbee isChildAction', async () => {
122
+ useRoute.mockReturnValue({
123
+ params: {
124
+ isConfigRead: false,
125
+ isConfigWrite: false,
126
+ isAction: false,
127
+ isChildAction: true,
128
+ itemActionConfig: { config: { id: 1, name: 'config1' } },
129
+ },
130
+ });
131
+ await act(async () => {
132
+ tree = await create(wrapComponent());
133
+ });
134
+ const instance = tree.root;
135
+ const detailConfigAction = instance?.findAllByType(DetailConfigAction);
136
+ expect(detailConfigAction).toHaveLength(1);
137
+ });
138
+ });