@eohjsc/react-native-smart-city 0.2.99 → 0.3.2

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 (224) hide show
  1. package/README.md +1 -1
  2. package/package.json +6 -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/CurtainButtonTemplate.js +10 -5
  7. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +31 -20
  8. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
  9. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
  10. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +24 -0
  11. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +14 -0
  12. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +1 -1
  13. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +3 -2
  14. package/src/commons/ActionGroup/StatesGridActionTemplate.js +8 -4
  15. package/src/commons/ActionGroup/TimerActionTemplate.js +2 -2
  16. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +0 -1
  17. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
  18. package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +45 -48
  19. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
  20. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
  21. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
  22. package/src/commons/ActionGroup/__test__/index.test.js +137 -2
  23. package/src/commons/Automate/ItemAutomate.js +1 -3
  24. package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
  25. package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
  26. package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +7 -3
  27. package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +8 -11
  28. package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
  29. package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +3 -2
  30. package/src/commons/ConnectingProcess/index.js +72 -25
  31. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
  32. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
  33. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
  34. package/src/commons/Device/ConnectedViewHeader.js +1 -1
  35. package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
  36. package/src/commons/Device/HistoryChart.js +3 -3
  37. package/src/commons/Device/ItemDevice.js +15 -11
  38. package/src/commons/Device/LinearChart.js +15 -0
  39. package/src/commons/Device/SonosSpeaker/index.js +1 -1
  40. package/src/commons/Explore/__test__/CityItem.test.js +33 -54
  41. package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +19 -14
  42. package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +0 -3
  43. package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +0 -3
  44. package/src/commons/FieldTemplate/ScheduleField/index.js +2 -2
  45. package/src/commons/Header/HeaderCustom.js +2 -1
  46. package/src/commons/HorizontalPicker/index.js +2 -2
  47. package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +0 -6
  48. package/src/commons/MediaPlayerDetail/index.js +24 -55
  49. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
  50. package/src/commons/SubUnit/Favorites/index.js +2 -3
  51. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
  52. package/src/commons/SubUnit/OneTap/index.js +1 -2
  53. package/src/commons/SubUnit/ShortDetail.js +25 -9
  54. package/src/commons/SubUnit/__test__/Item.test.js +0 -1
  55. package/src/commons/SubUnit/__test__/ShortDetail.test.js +8 -1
  56. package/src/commons/Unit/SharedUnit.js +1 -0
  57. package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
  58. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +2 -13
  59. package/src/commons/UnitSummary/ConfigHistoryChart.js +22 -13
  60. package/src/commons/WheelDateTimePicker/index.js +2 -2
  61. package/src/configs/API.js +85 -144
  62. package/src/configs/Constants.js +24 -0
  63. package/src/configs/SCConfig.js +2 -0
  64. package/src/context/actionType.ts +8 -0
  65. package/src/context/mockStore.ts +10 -0
  66. package/src/context/reducer.ts +38 -2
  67. package/src/hooks/Common/index.js +2 -0
  68. package/src/hooks/Common/useGGHomeDeviceConnected.js +16 -0
  69. package/src/hooks/Common/useGetIdUser.js +1 -5
  70. package/src/hooks/Common/useSensorsStatus.js +4 -4
  71. package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +198 -0
  72. package/src/hooks/IoT/__test__/useRemoteControl.test.js +198 -0
  73. package/src/hooks/IoT/index.js +4 -0
  74. package/src/hooks/IoT/useGGHomeConnection.js +91 -0
  75. package/src/hooks/IoT/useRemoteControl.js +79 -0
  76. package/src/hooks/index.js +4 -0
  77. package/src/hooks/useReceiveNotifications.js +9 -5
  78. package/src/iot/Monitor.js +3 -2
  79. package/src/iot/RemoteControl/Bluetooth.js +1 -1
  80. package/src/iot/RemoteControl/GoogleHome.js +75 -49
  81. package/src/iot/RemoteControl/Internet.js +1 -1
  82. package/src/iot/RemoteControl/__test__/GoogleHome.test.js +95 -48
  83. package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
  84. package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
  85. package/src/iot/RemoteControl/index.js +52 -52
  86. package/src/screens/ActivityLog/__test__/index.test.js +38 -23
  87. package/src/screens/ActivityLog/hooks/__test__/index.test.js +51 -90
  88. package/src/screens/ActivityLog/hooks/index.js +1 -1
  89. package/src/screens/ActivityLog/index.js +2 -2
  90. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
  91. package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
  92. package/src/screens/AddLocationMaps/index.js +5 -4
  93. package/src/screens/AddNewAction/SelectAction.js +8 -8
  94. package/src/screens/AddNewAction/SetupSensor.js +7 -7
  95. package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
  96. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
  97. package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
  98. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -33
  99. package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
  100. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +21 -21
  101. package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
  102. package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +23 -17
  103. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +3 -3
  104. package/src/screens/AddNewGateway/SetupGatewayWifi.js +1 -0
  105. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
  106. package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
  107. package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
  108. package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
  109. package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
  110. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +9 -23
  111. package/src/screens/AllCamera/index.js +4 -4
  112. package/src/screens/Automate/MultiUnits.js +8 -8
  113. package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
  114. package/src/screens/Automate/__test__/index.test.js +7 -12
  115. package/src/screens/Automate/index.js +3 -3
  116. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
  117. package/src/screens/ConfirmUnitDeletion/index.js +7 -1
  118. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
  119. package/src/screens/Device/EditDevice/index.js +2 -2
  120. package/src/screens/Device/__test__/detail.test.js +32 -85
  121. package/src/screens/Device/components/DetailHistoryChart.js +1 -1
  122. package/src/screens/Device/components/SensorConnectStatusViewHeader.js +1 -0
  123. package/src/screens/Device/components/SensorDisplayItem.js +5 -2
  124. package/src/screens/Device/detail.js +53 -22
  125. package/src/screens/Device/hooks/useDisconnectedDevice.js +4 -4
  126. package/src/screens/Device/hooks/useFavoriteDevice.js +5 -9
  127. package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
  128. package/src/screens/EditActionsList/index.js +1 -1
  129. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +1 -1
  130. package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
  131. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +18 -14
  132. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +30 -31
  133. package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
  134. package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
  135. package/src/screens/GuestInfo/__test__/index.test.js +13 -40
  136. package/src/screens/HanetCamera/Detail.js +1 -1
  137. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +8 -12
  138. package/src/screens/HanetCamera/__test__/Detail.test.js +27 -42
  139. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +8 -5
  140. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -32
  141. package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +3 -2
  142. package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +43 -35
  143. package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
  144. package/src/screens/HanetCamera/hooks/useHanetCheckinData.js +11 -11
  145. package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +11 -11
  146. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +33 -22
  147. package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +44 -45
  148. package/src/screens/ManageAccess/hooks/index.js +7 -4
  149. package/src/screens/ManageAccess/index.js +1 -1
  150. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
  151. package/src/screens/MoveToAnotherSubUnit/index.js +5 -5
  152. package/src/screens/Notification/__test__/Notification.test.js +14 -25
  153. package/src/screens/Notification/__test__/NotificationItem.test.js +8 -7
  154. package/src/screens/Notification/components/NotificationItem.js +17 -20
  155. package/src/screens/Notification/index.js +9 -2
  156. package/src/screens/PlayBackCamera/Timer.js +2 -2
  157. package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
  158. package/src/screens/PlayBackCamera/index.js +22 -6
  159. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
  160. package/src/screens/ScanChipQR/hooks/index.js +15 -16
  161. package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +8 -24
  162. package/src/screens/ScriptDetail/__test__/index.test.js +17 -86
  163. package/src/screens/ScriptDetail/index.js +16 -11
  164. package/src/screens/SelectUnit/__test__/index.test.js +11 -54
  165. package/src/screens/SelectUnit/index.js +4 -2
  166. package/src/screens/SetSchedule/index.js +9 -9
  167. package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
  168. package/src/screens/Sharing/Components/SensorItem.js +10 -12
  169. package/src/screens/Sharing/InfoMemberUnit.js +1 -1
  170. package/src/screens/Sharing/SelectPermission.js +121 -76
  171. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
  172. package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
  173. package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
  174. package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
  175. package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
  176. package/src/screens/SideMenuDetail/__test__/index.test.js +12 -23
  177. package/src/screens/SideMenuDetail/index.js +2 -3
  178. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +3 -2
  179. package/src/screens/SubUnit/Detail.js +1 -2
  180. package/src/screens/SubUnit/ManageSubUnit.js +12 -7
  181. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +21 -67
  182. package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
  183. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
  184. package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +27 -1
  185. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +48 -45
  186. package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
  187. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +14 -90
  188. package/src/screens/Unit/ChooseLocation.js +7 -14
  189. package/src/screens/Unit/Detail.js +30 -75
  190. package/src/screens/Unit/ManageUnit.js +1 -0
  191. package/src/screens/Unit/SelectAddress.js +34 -21
  192. package/src/screens/Unit/SmartAccount.js +4 -4
  193. package/src/screens/Unit/Summaries.js +17 -1
  194. package/src/screens/Unit/__test__/CheckSendEmail.test.js +24 -29
  195. package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
  196. package/src/screens/Unit/__test__/Detail.test.js +99 -200
  197. package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
  198. package/src/screens/Unit/__test__/SelectAddress.test.js +84 -51
  199. package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
  200. package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
  201. package/src/screens/Unit/__test__/Summaries.test.js +100 -0
  202. package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
  203. package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
  204. package/src/screens/Unit/components/SharedUnit/index.js +1 -0
  205. package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
  206. package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +50 -0
  207. package/src/screens/Unit/styles.js +4 -0
  208. package/src/screens/UnitSummary/__test__/index.test.js +70 -41
  209. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +31 -2
  210. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
  211. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +2 -13
  212. package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +0 -1
  213. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
  214. package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +11 -2
  215. package/src/screens/UnitSummary/components/RunningDevices/index.js +7 -10
  216. package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
  217. package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +10 -2
  218. package/src/screens/UnitSummary/index.js +15 -1
  219. package/src/utils/Apis/axios.js +46 -31
  220. package/src/utils/Converter/time.js +0 -18
  221. package/src/utils/I18n/translations/en.json +4 -1
  222. package/src/utils/I18n/translations/vi.json +5 -1
  223. package/src/utils/Permission/common.js +67 -0
  224. package/src/utils/Utils.js +11 -7
@@ -5,13 +5,19 @@ import Text from '../../Text';
5
5
  import { SCProvider } from '../../../context';
6
6
  import { mockSCStore } from '../../../context/mockStore';
7
7
 
8
- const wrapComponent = (route) => (
8
+ const wrapComponent = (route, isLoading, isConnect, isPercentConnect) => (
9
9
  <SCProvider initState={mockSCStore({})}>
10
- <Connecting route={route} />
10
+ <Connecting
11
+ route={route}
12
+ isLoading={isLoading}
13
+ isConnect={isConnect}
14
+ isPercentConnect={isPercentConnect}
15
+ />
11
16
  </SCProvider>
12
17
  );
13
18
  describe('Test Connecting', () => {
14
19
  let tree;
20
+
15
21
  test('create Connecting', () => {
16
22
  act(() => {
17
23
  tree = renderer.create(wrapComponent());
@@ -20,4 +26,15 @@ describe('Test Connecting', () => {
20
26
  const text = instance.findAllByType(Text);
21
27
  expect(text).toHaveLength(4);
22
28
  });
29
+
30
+ test('isLoading = true', () => {
31
+ jest.useFakeTimers();
32
+ act(() => {
33
+ tree = renderer.create(wrapComponent({}, true));
34
+ });
35
+ jest.runAllTimers();
36
+ const instance = tree.root;
37
+ const text = instance.findAllByType(Text);
38
+ expect(text).toHaveLength(4);
39
+ });
23
40
  });
@@ -2,13 +2,17 @@ import React, { memo } from 'react';
2
2
  import { View } from 'react-native';
3
3
  import styles from './DeviceItemStyles';
4
4
  import FImage from '../../FImage';
5
- import Text from '../../Text';
5
+ import _TextInput from '../../Form/TextInput';
6
6
 
7
- const DeviceItem = memo(({ icon, name }) => {
7
+ const DeviceItem = memo(({ icon, name, setNewName }) => {
8
8
  return (
9
9
  <View style={styles.container}>
10
10
  {!!icon && <FImage source={{ uri: icon }} style={styles.iconSensor} />}
11
- <Text style={styles.textItem}>{name}</Text>
11
+ <_TextInput
12
+ value={name}
13
+ textInputStyle={styles.textItem}
14
+ onChange={setNewName}
15
+ />
12
16
  </View>
13
17
  );
14
18
  });
@@ -1,23 +1,14 @@
1
1
  import { StyleSheet } from 'react-native';
2
- import { Constants, Colors } from '../../../configs';
3
-
4
- const marginItem = 12;
5
- const marginHorizontal = 5;
6
- const widthItem = (Constants.width - marginHorizontal * 2 - marginItem) / 2;
7
- const heightItem = (widthItem / 166) * 60;
2
+ import { Colors } from '../../../configs';
8
3
 
9
4
  export default StyleSheet.create({
10
5
  container: {
11
- paddingHorizontal: 15,
12
6
  borderRadius: 10,
13
7
  width: 250,
14
- height: heightItem,
15
8
  borderWidth: 1,
16
9
  borderColor: Colors.Gray4,
17
10
  backgroundColor: Colors.White,
18
11
  justifyContent: 'center',
19
- alignItems: 'center',
20
- marginBottom: 16,
21
12
  flexDirection: 'row',
22
13
  shadowColor: Colors.Shadow,
23
14
  shadowOffset: {
@@ -36,7 +27,13 @@ export default StyleSheet.create({
36
27
  resizeMode: 'contain',
37
28
  },
38
29
  textItem: {
39
- marginLeft: 15,
30
+ borderWidth: 0,
31
+ borderBottomWidth: 1,
32
+ borderBottomColor: Colors.Primary,
33
+ textAlign: 'center',
34
+ marginTop: -10,
35
+ padding: 5,
40
36
  fontSize: 16,
37
+ height: 50,
41
38
  },
42
39
  });
@@ -1,18 +1,35 @@
1
1
  import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+
3
5
  import ConnectingProcess from '../index';
4
6
  import { SafeAreaView } from 'react-native';
5
7
  import { SCProvider } from '../../../context';
6
8
  import { mockSCStore } from '../../../context/mockStore';
9
+ import api from '../../../utils/Apis/axios';
10
+ import { API } from '../../../configs';
7
11
 
8
12
  const wrapComponent = (route) => (
9
13
  <SCProvider initState={mockSCStore({})}>
10
14
  <ConnectingProcess route={route} />
11
15
  </SCProvider>
12
16
  );
17
+
18
+ const mock = new MockAdapter(api.axiosInstance);
19
+
13
20
  describe('Test ConnectingProcess', () => {
14
21
  let tree;
15
- test('create ConnectingProcess', () => {
22
+
23
+ test('render without params', () => {
24
+ act(() => {
25
+ tree = renderer.create(wrapComponent({}));
26
+ });
27
+ const instance = tree.root;
28
+ const safeAreaView = instance.findAllByType(SafeAreaView);
29
+ expect(safeAreaView).toHaveLength(1);
30
+ });
31
+
32
+ test('create ConnectingProcess with devicePrefixName = SENSOR call api success', async () => {
16
33
  const scan_sensor_data = { imei: 'SENSOR-afasdfas' };
17
34
  const devicePrefixName = 'SENSOR';
18
35
  const gateway = { id: 1, name: 'gateway' };
@@ -20,8 +37,124 @@ describe('Test ConnectingProcess', () => {
20
37
  const route = {
21
38
  params: { scan_sensor_data, gateway, station, devicePrefixName },
22
39
  };
23
- act(() => {
24
- tree = renderer.create(wrapComponent(route));
40
+ mock.onPost(API.SUB_UNIT.SENSOR_SCAN(1)).reply(200);
41
+ await act(async () => {
42
+ tree = await renderer.create(wrapComponent(route));
43
+ });
44
+ const instance = tree.root;
45
+ const safeAreaView = instance.findAllByType(SafeAreaView);
46
+ expect(safeAreaView).toHaveLength(1);
47
+ });
48
+
49
+ test('create ConnectingProcess with devicePrefixName = SENSOR call api fail', async () => {
50
+ const scan_sensor_data = { imei: 'SENSOR-afasdfas' };
51
+ const devicePrefixName = 'SENSOR';
52
+ const gateway = { id: 1, name: 'gateway' };
53
+ const station = { id: 1, icon_kit: 'a', name: 'station' };
54
+ const route = {
55
+ params: { scan_sensor_data, gateway, station, devicePrefixName },
56
+ };
57
+ mock.onPost(API.SUB_UNIT.SENSOR_SCAN(1)).reply(400);
58
+ await act(async () => {
59
+ tree = await renderer.create(wrapComponent(route));
60
+ });
61
+ const instance = tree.root;
62
+ const safeAreaView = instance.findAllByType(SafeAreaView);
63
+ expect(safeAreaView).toHaveLength(1);
64
+ });
65
+
66
+ test('create ConnectingProcess with devicePrefixName = ROBOT call api success', async () => {
67
+ const scan_sensor_data = { imei: 'SENSOR-afasdfas' };
68
+ const devicePrefixName = 'ROBOT';
69
+ const gateway = { id: 1, name: 'gateway' };
70
+ const station = { id: 1, icon_kit: 'a', name: 'station' };
71
+ const route = {
72
+ params: {
73
+ scan_sensor_data,
74
+ gateway,
75
+ station,
76
+ devicePrefixName,
77
+ unit_id: 1,
78
+ unit: {
79
+ id: 1,
80
+ },
81
+ },
82
+ };
83
+ mock.onPost(API.UNIT.CHIP_SCAN(1)).reply(200);
84
+ await act(async () => {
85
+ tree = await renderer.create(wrapComponent(route));
86
+ });
87
+ const instance = tree.root;
88
+ const safeAreaView = instance.findAllByType(SafeAreaView);
89
+ expect(safeAreaView).toHaveLength(1);
90
+ });
91
+
92
+ test('create ConnectingProcess with devicePrefixName = ROBOT call api fail', async () => {
93
+ const scan_sensor_data = { imei: 'SENSOR-afasdfas' };
94
+ const devicePrefixName = 'ROBOT';
95
+ const gateway = { id: 1, name: 'gateway' };
96
+ const station = { id: 1, icon_kit: 'a', name: 'station' };
97
+ const route = {
98
+ params: {
99
+ scan_sensor_data,
100
+ gateway,
101
+ station,
102
+ devicePrefixName,
103
+ unit_id: 1,
104
+ unit: {
105
+ id: 1,
106
+ },
107
+ },
108
+ };
109
+ mock.onPost(API.UNIT.CHIP_SCAN(1)).reply(400);
110
+ await act(async () => {
111
+ tree = await renderer.create(wrapComponent(route));
112
+ });
113
+ const instance = tree.root;
114
+ const safeAreaView = instance.findAllByType(SafeAreaView);
115
+ expect(safeAreaView).toHaveLength(1);
116
+ });
117
+
118
+ test('create ConnectingProcess with devicePrefixName = LITE call api success', async () => {
119
+ const scan_sensor_data = { imei: 'SENSOR-afasdfas' };
120
+ const devicePrefixName = 'LITE';
121
+ const gateway = { id: 1, name: 'gateway' };
122
+ const station = { id: 1, icon_kit: 'a', name: 'station' };
123
+ const route = {
124
+ params: {
125
+ scan_sensor_data,
126
+ gateway,
127
+ station,
128
+ devicePrefixName,
129
+ unit_id: 1,
130
+ },
131
+ };
132
+ mock.onPost(API.UNIT.ADD_GATEWAY(1)).reply(200);
133
+ await act(async () => {
134
+ tree = await renderer.create(wrapComponent(route));
135
+ });
136
+ const instance = tree.root;
137
+ const safeAreaView = instance.findAllByType(SafeAreaView);
138
+ expect(safeAreaView).toHaveLength(1);
139
+ });
140
+
141
+ test('create ConnectingProcess with devicePrefixName = LITE call api fail', async () => {
142
+ const scan_sensor_data = { imei: 'SENSOR-afasdfas' };
143
+ const devicePrefixName = 'LITE';
144
+ const gateway = { id: 1, name: 'gateway' };
145
+ const station = { id: 1, icon_kit: 'a', name: 'station' };
146
+ const route = {
147
+ params: {
148
+ scan_sensor_data,
149
+ gateway,
150
+ station,
151
+ devicePrefixName,
152
+ unit_id: 1,
153
+ },
154
+ };
155
+ mock.onPost(API.UNIT.ADD_GATEWAY(1)).reply(400);
156
+ await act(async () => {
157
+ tree = await renderer.create(wrapComponent(route));
25
158
  });
26
159
  const instance = tree.root;
27
160
  const safeAreaView = instance.findAllByType(SafeAreaView);
@@ -2,7 +2,8 @@ import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
3
  import DeviceItem from '../DeviceItem/DeviceItem';
4
4
  import FImage from '../../FImage';
5
- import Text from '../../Text';
5
+ import _TextInput from '../../Form/TextInput';
6
+
6
7
  describe('Test DeviceItem button', () => {
7
8
  let tree;
8
9
  test('create DeviceItem button', () => {
@@ -11,7 +12,7 @@ describe('Test DeviceItem button', () => {
11
12
  });
12
13
  const instance = tree.root;
13
14
  const image = instance.findAllByType(FImage);
14
- const text = instance.findAllByType(Text);
15
+ const text = instance.findAllByType(_TextInput);
15
16
  expect(image).toHaveLength(0);
16
17
  expect(text).toHaveLength(1);
17
18
  });
@@ -6,12 +6,13 @@ import { useNavigation } from '@react-navigation/native';
6
6
  import ImageSuccessfully from '../../Images/Common/SuccessfullyConnected.svg';
7
7
 
8
8
  import Text from '../Text';
9
- import { axiosPost } from '../../utils/Apis/axios';
9
+ import { axiosPatch, axiosPost } from '../../utils/Apis/axios';
10
10
  import { API, Colors } from '../../configs';
11
11
  import styles from './styles';
12
12
  import DeviceItem from './DeviceItem/DeviceItem';
13
13
  import Connecting from '../Connecting';
14
14
  import { useSCContextSelector } from '../../context';
15
+ import { ToastBottomHelper } from '../../utils/Utils';
15
16
 
16
17
  const ConnectingProcess = ({ route }) => {
17
18
  const { navigate, goBack } = useNavigation();
@@ -27,29 +28,30 @@ const ConnectingProcess = ({ route }) => {
27
28
  devicePrefixName,
28
29
  wifi_ssid,
29
30
  wifi_pass,
30
- chip_id,
31
- } = route.params;
31
+ } = route.params || {};
32
32
  const [isLoading, setIsLoading] = useState(true);
33
33
  const [sensor, setSensor] = useState(null);
34
34
  const user = useSCContextSelector((state) => state?.auth?.account?.user);
35
+ const [newName, setNewName] = useState('');
35
36
 
36
37
  const ConnectingDevice = useCallback(async () => {
37
38
  setIsLoading(true);
38
39
  switch (devicePrefixName) {
39
- case 'SENSOR':
40
- {
41
- const body = { imei: scan_sensor_data?.imei, chip: gateway?.id };
42
- const { success, data } = await axiosPost(
43
- API.SUB_UNIT.SENSOR_SCAN(station.id),
44
- body
45
- );
46
- if (success) {
47
- setSensor(data);
48
- } else {
49
- goBack();
50
- }
40
+ case 'SENSOR': {
41
+ const body = { imei: scan_sensor_data?.imei, chip: gateway?.id };
42
+ const { success, data } = await axiosPost(
43
+ API.SUB_UNIT.SENSOR_SCAN(station.id),
44
+ body
45
+ );
46
+ if (success) {
47
+ setSensor(data);
48
+ } else {
49
+ ToastBottomHelper.error(JSON.stringify(data));
50
+ goBack();
51
51
  }
52
+
52
53
  break;
54
+ }
53
55
  case 'ROBOT': {
54
56
  const { success, data } = await axiosPost(API.UNIT.CHIP_SCAN(unit.id), {
55
57
  imei: gateway?.imei,
@@ -63,19 +65,23 @@ const ConnectingProcess = ({ route }) => {
63
65
  if (success) {
64
66
  setSensor(data);
65
67
  } else {
68
+ ToastBottomHelper.error(JSON.stringify(data));
66
69
  goBack();
67
70
  }
68
71
  break;
69
72
  }
70
73
  case 'LITE': {
71
- const { success } = await axiosPost(API.UNIT.ADD_GATEWAY(unit_id), {
72
- chip: chip_id,
73
- imei: gateway?.imei,
74
- chip_name: gateway?.model,
75
- });
74
+ const { success, data } = await axiosPost(
75
+ API.UNIT.ADD_GATEWAY(unit_id),
76
+ {
77
+ imei: gateway?.imei,
78
+ chip_name: gateway?.model,
79
+ }
80
+ );
76
81
  if (success) {
77
82
  setSensor({ name: gateway?.model });
78
83
  } else {
84
+ ToastBottomHelper.error(JSON.stringify(data));
79
85
  goBack();
80
86
  }
81
87
  break;
@@ -95,7 +101,6 @@ const ConnectingProcess = ({ route }) => {
95
101
  wifi_pass,
96
102
  user?.phone_number,
97
103
  unit_id,
98
- chip_id,
99
104
  ]);
100
105
 
101
106
  const ConnectingSuccess = useCallback(() => {
@@ -110,12 +115,46 @@ const ConnectingProcess = ({ route }) => {
110
115
  station?.name !== undefined ? '- ' + station?.name : ''
111
116
  }`}
112
117
  </Text>
113
- <DeviceItem icon={sensor?.icon_kit} name={sensor?.name} />
118
+ <DeviceItem
119
+ icon={sensor?.icon_kit}
120
+ name={newName}
121
+ setNewName={setNewName}
122
+ />
114
123
  </View>
115
124
  );
116
- }, [sensor?.icon_kit, sensor?.name, station?.name, t, unit?.name, unit_name]);
125
+ }, [newName, sensor?.icon_kit, station?.name, t, unit?.name, unit_name]);
126
+
127
+ const handleDone = useCallback(async () => {
128
+ let result, message;
129
+ switch (devicePrefixName) {
130
+ case 'SENSOR': {
131
+ const { success, data } = await axiosPatch(
132
+ API.SENSOR.SENSOR_DETAIL(sensor?.id),
133
+ {
134
+ name: newName,
135
+ }
136
+ );
137
+ result = success;
138
+ message = data;
139
+ break;
140
+ }
141
+ case 'ROBOT':
142
+ case 'LITE': {
143
+ const { success, data } = await axiosPatch(
144
+ API.CHIP.CHIP_DETAIL(sensor?.id),
145
+ {
146
+ name: newName,
147
+ }
148
+ );
149
+ result = success;
150
+ message = data;
151
+ break;
152
+ }
153
+ }
117
154
 
118
- const handleDone = useCallback(() => {
155
+ if (!result) {
156
+ ToastBottomHelper.error(JSON.stringify(message));
157
+ }
119
158
  navigate(Routes.UnitStack, {
120
159
  screen: Routes.UnitDetail,
121
160
  params: {
@@ -125,7 +164,15 @@ const ConnectingProcess = ({ route }) => {
125
164
  stationId: station?.id,
126
165
  },
127
166
  });
128
- }, [navigate, station?.id, unit, unit_id]);
167
+ }, [
168
+ devicePrefixName,
169
+ navigate,
170
+ newName,
171
+ sensor?.id,
172
+ station?.id,
173
+ unit,
174
+ unit_id,
175
+ ]);
129
176
 
130
177
  useEffect(() => {
131
178
  ConnectingDevice();
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
+ import MockAdapter from 'axios-mock-adapter';
3
4
 
4
5
  import MyPinnedSharedUnit from '../index';
5
6
  import { Text } from 'react-native';
@@ -9,9 +10,9 @@ import { mockSCStore } from '../../../../context/mockStore';
9
10
  import { TESTID } from '../../../../configs/Constants';
10
11
  import { API } from '../../../../configs';
11
12
  import { TouchableOpacity } from 'react-native';
12
- import axios from 'axios';
13
+ import api from '../../../../utils/Apis/axios';
13
14
 
14
- jest.mock('axios');
15
+ const mock = new MockAdapter(api.axiosInstance);
15
16
 
16
17
  const mockedNavigate = jest.fn();
17
18
  jest.mock('@react-navigation/native', () => {
@@ -32,21 +33,14 @@ const wrapComponent = (route) => (
32
33
 
33
34
  describe('Test MyPinnedSharedUnit', () => {
34
35
  let tree;
35
- afterEach(() => {
36
- axios.get.mockClear();
37
- });
38
36
 
39
37
  test('create', async () => {
40
- const response = {
41
- status: 200,
42
- data: [{ id: 1 }],
43
- };
44
- axios.get.mockImplementation(async () => {
45
- return response;
46
- });
38
+ mock.onGet(API.UNIT.SHARED_UNITS()).reply(200, [{ id: 1 }]);
39
+
47
40
  await act(async () => {
48
41
  tree = await create(wrapComponent());
49
42
  });
43
+
50
44
  const instance = tree.root;
51
45
  const texts = instance.findAllByType(Text);
52
46
  expect(texts).toHaveLength(4);
@@ -65,6 +59,15 @@ describe('Test MyPinnedSharedUnit', () => {
65
59
  goToAllSharedUnits.props.onPress();
66
60
  });
67
61
  expect(mockedNavigate).toHaveBeenCalled();
68
- expect(axios.get).toHaveBeenCalledWith(API.UNIT.SHARED_UNITS(), {});
62
+ });
63
+
64
+ test('render without item', async () => {
65
+ mock.onGet(API.UNIT.SHARED_UNITS()).reply(400, []);
66
+ await act(async () => {
67
+ tree = await create(wrapComponent());
68
+ });
69
+ const instance = tree.root;
70
+ const texts = instance.findAllByType(Text);
71
+ expect(texts).toHaveLength(4);
69
72
  });
70
73
  });
@@ -60,7 +60,7 @@ const MyPinnedSharedUnit = () => {
60
60
  {sharedUnits &&
61
61
  Boolean(sharedUnits.length) &&
62
62
  sharedUnits
63
- .filter((sharedUnit) => sharedUnit.is_pin)
63
+ .filter((sharedUnit) => sharedUnit?.is_pin)
64
64
  .map((item, index) => (
65
65
  <View key={item.id}>
66
66
  <SharedUnit
@@ -4,9 +4,7 @@ import MyUnit from '..';
4
4
  import { TESTID } from '../../../../configs/Constants';
5
5
  import { SCProvider } from '../../../../context';
6
6
  import { mockSCStore } from '../../../../context/mockStore';
7
- import axios from 'axios';
8
7
 
9
- jest.mock('axios');
10
8
  const mockedNavigate = jest.fn();
11
9
  const mockUseIsFocused = jest.fn();
12
10
  const mockedDispatch = jest.fn();
@@ -36,9 +34,6 @@ const wrapComponent = () => (
36
34
 
37
35
  describe('Test MyUnit', () => {
38
36
  let tree;
39
- beforeEach(() => {
40
- axios.get.mockClear();
41
- });
42
37
  const getElement = (instance) => {
43
38
  const goToDetail = instance.findAll(
44
39
  (item) => item.props.testID === TESTID.MY_UNIT_GO_TO_DETAIL
@@ -29,7 +29,7 @@ const ConnectedViewHeader = memo(
29
29
  const t = useTranslations();
30
30
  const lastUpdatedStr = lastUpdated
31
31
  ? timeDifference(new Date(), lastUpdated)
32
- : null;
32
+ : `5 ${t('seconds_ago')}`;
33
33
  return (
34
34
  <View style={styles.statusContainer}>
35
35
  <View style={styles.connectStatus}>
@@ -0,0 +1,58 @@
1
+ import React from 'react';
2
+ import { TouchableWithoutFeedback } from 'react-native';
3
+ import renderer, { act } from 'react-test-renderer';
4
+ import ItemHanetDevice from './ItemHanetDevice';
5
+ import { SCProvider } from '../../../context';
6
+ import { mockSCStore } from '../../../context/mockStore';
7
+
8
+ const wrapComponent = (props) => (
9
+ <SCProvider initState={mockSCStore({})}>
10
+ <ItemHanetDevice {...props} />
11
+ </SCProvider>
12
+ );
13
+
14
+ const mockNavigate = jest.fn();
15
+ jest.mock('@react-navigation/native', () => {
16
+ return {
17
+ ...jest.requireActual('@react-navigation/native'),
18
+ useNavigation: () => ({
19
+ navigate: mockNavigate,
20
+ }),
21
+ };
22
+ });
23
+
24
+ describe('Test ItemHanetDevice', () => {
25
+ let tree, props;
26
+
27
+ beforeEach(() => {
28
+ props = {
29
+ svgMain: 'icon',
30
+ title: 'title',
31
+ sensor: {},
32
+ unit: {},
33
+ station: {},
34
+ };
35
+ });
36
+
37
+ test('render ItemHanetDevice', () => {
38
+ act(() => {
39
+ tree = renderer.create(wrapComponent(props));
40
+ });
41
+ const instance = tree.root;
42
+ const touches = instance.findAllByType(TouchableWithoutFeedback);
43
+ act(() => {
44
+ tree = touches[0].props.onPress();
45
+ });
46
+ expect(mockNavigate).toBeCalled();
47
+ });
48
+
49
+ test('render ItemHanetDevice sensor has icon', () => {
50
+ props.sensor.icon_kit = 'icon';
51
+ act(() => {
52
+ tree = renderer.create(wrapComponent(props));
53
+ });
54
+ const instance = tree.root;
55
+ const touches = instance.findAllByType(TouchableWithoutFeedback);
56
+ expect(touches.length).toBeGreaterThan(0);
57
+ });
58
+ });
@@ -151,12 +151,12 @@ const HistoryChart = memo(
151
151
  if (configuration.config !== 'power_consumption') {
152
152
  return null;
153
153
  }
154
- const { price } = chartConfig;
155
- if (price === '' || isNaN(price)) {
154
+ const { price: chartPrice } = chartConfig;
155
+ if (chartPrice === '' || isNaN(chartPrice)) {
156
156
  return null;
157
157
  }
158
158
  const sum = datas[0].data.reduce((a, b) => a + b.y, 0);
159
- const roundedSum = sum * price;
159
+ const roundedSum = sum * chartPrice;
160
160
  return roundedSum.toFixed();
161
161
  }, [configuration, datas, chartConfig]);
162
162
 
@@ -11,8 +11,9 @@ import { useNavigation } from '@react-navigation/native';
11
11
  import { useTranslations } from '../../hooks/Common/useTranslations';
12
12
  import ItemQuickAction from '../../commons/Action/ItemQuickAction';
13
13
  import Text from '../../commons/Text';
14
- import { isDeviceConnected } from '../../iot/RemoteControl/Bluetooth';
14
+ import { isDeviceConnected as isBluetoothDeviceConnected } from '../../iot/RemoteControl/Bluetooth';
15
15
  import { useSCContextSelector } from '../../context';
16
+ import { useGGHomeDeviceConnected } from '../../hooks/Common';
16
17
 
17
18
  import { Colors } from '../../configs';
18
19
  import { TESTID, DEVICE_TYPE, DEVICE_SIZE } from '../../configs/Constants';
@@ -26,7 +27,6 @@ const ItemDevice = memo(
26
27
  sensor,
27
28
  unit,
28
29
  station,
29
- isGGHomeConnected,
30
30
  serverDown,
31
31
  status,
32
32
  wrapStyle,
@@ -39,6 +39,7 @@ const ItemDevice = memo(
39
39
  const isNetworkConnected = useSCContextSelector(
40
40
  (state) => state.app.isNetworkConnected
41
41
  );
42
+ const { isConnected: isGGHomeConnected } = useGGHomeDeviceConnected(sensor);
42
43
 
43
44
  const goToSensorDisplay = useCallback(() => {
44
45
  navigation.navigate(Routes.DeviceDetail, {
@@ -46,24 +47,27 @@ const ItemDevice = memo(
46
47
  station,
47
48
  sensorData: sensor,
48
49
  title,
49
- isGGHomeConnected,
50
50
  });
51
- }, [navigation, sensor, station, title, unit, isGGHomeConnected]);
51
+ }, [navigation, sensor, station, title, unit]);
52
52
 
53
53
  const isConnectedViaInternet =
54
54
  status === undefined
55
55
  ? !serverDown && isNetworkConnected && sensor.is_connected
56
56
  : !serverDown && isNetworkConnected && status.is_connected;
57
+
57
58
  const isConnectedViaBLE =
58
59
  isBluetoothEnabled &&
59
- isDeviceConnected(sensor?.remote_control_options?.bluetooth?.address);
60
- const isConnectedViaGGHome =
61
- !!sensor &&
62
- sensor?.is_other_device &&
63
- !sensor?.device_type !== DEVICE_TYPE.LG_THINQ &&
64
- isGGHomeConnected;
60
+ isBluetoothDeviceConnected(
61
+ sensor?.remote_control_options?.bluetooth?.address
62
+ );
63
+
65
64
  const isConnected =
66
- isConnectedViaInternet || isConnectedViaGGHome || isConnectedViaBLE;
65
+ !!sensor && sensor?.is_other_device
66
+ ? sensor?.device_type === DEVICE_TYPE.LG_THINQ
67
+ ? true
68
+ : isGGHomeConnected
69
+ : isConnectedViaInternet || isConnectedViaBLE;
70
+
67
71
  const borderColor = isConnected ? Colors.Gray4 : Colors.Red6;
68
72
  const textConnected = isConnected ? t('connected') : t('disconnected');
69
73