@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
@@ -52,6 +52,21 @@ const chartOptions = {
52
52
  format: '{value:%d.%m %H:%M}',
53
53
  },
54
54
  },
55
+ legend: {
56
+ useHTML: true,
57
+ labelFormatter: function () {
58
+ if (this.visible) {
59
+ return (
60
+ '<span style="color:#333333;font-weight:bold">' +
61
+ this.name +
62
+ '</span>'
63
+ );
64
+ }
65
+ return (
66
+ '<span style="color:#cccccc;font-weight:bold">' + this.name + '</span>'
67
+ );
68
+ },
69
+ },
55
70
  };
56
71
 
57
72
  function LinearChart({ datas }) {
@@ -69,7 +69,7 @@ const SonosSpeaker = memo(() => {
69
69
  <View style={styles.containerSlider}>
70
70
  <Slider
71
71
  value={value}
72
- onValueChange={(value) => setValue(value)}
72
+ onValueChange={setValue}
73
73
  step={1}
74
74
  minimumValue={0}
75
75
  maximumValue={100}
@@ -2,12 +2,15 @@ import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
3
  import CityItem from '../CityItem';
4
4
  import { TouchableOpacity } from 'react-native';
5
- import axios from 'axios';
6
5
  import { API } from '../../../configs';
7
6
  import Pin from '../../../../assets/images/Explore/Pin.svg';
8
7
  import PinOutline from '../../../../assets/images/Explore/PinOutline.svg';
9
8
  import { SCProvider } from '../../../context';
10
9
  import { mockSCStore } from '../../../context/mockStore';
10
+ import MockAdapter from 'axios-mock-adapter';
11
+ import api from '../../../utils/Apis/axios';
12
+
13
+ const mock = new MockAdapter(api.axiosInstance);
11
14
 
12
15
  const mockedDispatch = jest.fn();
13
16
 
@@ -17,7 +20,6 @@ const wrapComponent = (item, mockeSelect) => (
17
20
  </SCProvider>
18
21
  );
19
22
 
20
- jest.mock('axios');
21
23
  jest.mock('react-redux', () => ({
22
24
  ...jest.requireActual('react-redux'),
23
25
  useDispatch: () => mockedDispatch,
@@ -25,9 +27,6 @@ jest.mock('react-redux', () => ({
25
27
 
26
28
  describe('Test CityItem', () => {
27
29
  let tree;
28
- afterEach(() => {
29
- axios.post.mockClear();
30
- });
31
30
 
32
31
  test('render CityItem is_pin: true', async () => {
33
32
  const item = {
@@ -38,37 +37,23 @@ describe('Test CityItem', () => {
38
37
  count_pin: 1,
39
38
  };
40
39
  const mockeSelect = jest.fn();
41
- const response = {
42
- status: 200,
43
- };
44
-
45
- axios.post.mockImplementation(async () => {
46
- return response;
47
- });
40
+ mock.onPost(API.UNIT.PIN_UNIT()).reply(200);
48
41
  await act(async () => {
49
42
  tree = await renderer.create(wrapComponent(item, mockeSelect));
50
43
  });
51
44
  const instance = tree.root;
52
45
  const buttons = instance.findAllByType(TouchableOpacity);
53
46
  expect(buttons.length).toBe(2);
54
- await act(async () => {
55
- await buttons[0].props.onPress();
56
- });
47
+ await buttons[0].props.onPress();
57
48
  expect(mockeSelect).toHaveBeenCalledTimes(1);
58
-
59
49
  const pin = instance.findAllByType(Pin);
60
50
  expect(pin.length).toBe(2);
61
- await act(async () => {
62
- await pin[1].props.onPress();
63
- });
64
- expect(axios.post).toHaveBeenCalledWith(API.UNIT.UNPIN_UNIT(1));
65
-
51
+ mock.onPost(API.UNIT.PIN_UNIT()).reply(200);
52
+ await pin[1].props.onPress();
66
53
  const unpin = instance.findAllByType(PinOutline);
54
+ mock.onPost(API.UNIT.UNPIN_UNIT(1)).reply(200);
55
+ await unpin[1].props.onPress();
67
56
  expect(unpin.length).toBe(2);
68
- await act(async () => {
69
- await unpin[1].props.onPress();
70
- });
71
- expect(axios.post).toHaveBeenCalledWith(API.UNIT.UNPIN_UNIT(1));
72
57
  });
73
58
 
74
59
  test('render CityItem is_pin: false', async () => {
@@ -80,24 +65,33 @@ describe('Test CityItem', () => {
80
65
  count_pin: 1,
81
66
  };
82
67
  const mockeSelect = jest.fn();
83
- const response = {
84
- status: 200,
85
- };
86
-
87
- axios.post.mockImplementation(async () => {
88
- return response;
89
- });
90
68
  await act(async () => {
91
69
  tree = await renderer.create(wrapComponent(item, mockeSelect));
92
70
  });
93
71
  const instance = tree.root;
94
-
95
72
  const unpin = instance.findAllByType(PinOutline);
73
+ mock.onPost(API.UNIT.PIN_UNIT(1)).reply(200);
74
+ await unpin[1].props.onPress();
96
75
  expect(unpin.length).toBe(2);
76
+ });
77
+
78
+ test('render CityItem is_pin: false and call api false', async () => {
79
+ const item = {
80
+ id: 1,
81
+ name: 'name',
82
+ icon: 'icon',
83
+ is_pin: false,
84
+ count_pin: 1,
85
+ };
86
+ const mockeSelect = jest.fn();
97
87
  await act(async () => {
98
- await unpin[1].props.onPress();
88
+ tree = await renderer.create(wrapComponent(item, mockeSelect));
99
89
  });
100
- expect(axios.post).toHaveBeenCalledWith(API.UNIT.PIN_UNIT(1));
90
+ const instance = tree.root;
91
+ const unpin = instance.findAllByType(PinOutline);
92
+ mock.onPost(API.UNIT.PIN_UNIT(1)).reply(400);
93
+ await unpin[1].props.onPress();
94
+ expect(unpin.length).toBe(2);
101
95
  });
102
96
 
103
97
  test('render CityItem PinOutline axios.post response false', async () => {
@@ -109,22 +103,14 @@ describe('Test CityItem', () => {
109
103
  count_pin: 1,
110
104
  };
111
105
  const mockeSelect = jest.fn();
112
- const response = {};
113
-
114
- axios.post.mockImplementation(async () => {
115
- return response;
116
- });
106
+ mock.onPost(API.UNIT.PIN_UNIT()).reply(200, {});
117
107
  await act(async () => {
118
108
  tree = await renderer.create(wrapComponent(item, mockeSelect));
119
109
  });
120
110
  const instance = tree.root;
121
-
122
111
  const unpin = instance.findAllByType(PinOutline);
112
+ await unpin[1].props.onPress();
123
113
  expect(unpin.length).toBe(2);
124
- await act(async () => {
125
- await unpin[1].props.onPress();
126
- });
127
- expect(axios.post).not.toHaveBeenCalledWith(API.UNIT.UNPIN_UNIT(1));
128
114
  });
129
115
 
130
116
  test('render CityItem Pin axios.post response false', async () => {
@@ -136,21 +122,14 @@ describe('Test CityItem', () => {
136
122
  count_pin: 1,
137
123
  };
138
124
  const mockeSelect = jest.fn();
139
- const response = {};
140
-
141
- axios.post.mockImplementation(async () => {
142
- return response;
143
- });
125
+ mock.onPost(API.UNIT.UNPIN_UNIT(1)).reply(400, {});
144
126
  await act(async () => {
145
127
  tree = await renderer.create(wrapComponent(item, mockeSelect));
146
128
  });
147
129
  const instance = tree.root;
148
130
  const pin = instance.findAllByType(Pin);
131
+ await pin[1].props.onPress();
149
132
  expect(pin.length).toBe(2);
150
- await act(async () => {
151
- await pin[1].props.onPress();
152
- });
153
- expect(axios.post).toHaveBeenCalledWith(API.UNIT.UNPIN_UNIT(1));
154
133
  });
155
134
 
156
135
  test('render CityItem icon null', async () => {
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import axios from 'axios';
2
+ import MockAdapter from 'axios-mock-adapter';
3
3
  import { act, create } from 'react-test-renderer';
4
4
  import { TESTID } from '../../../../configs/Constants';
5
5
  import { mockSCStore } from '../../../../context/mockStore';
@@ -7,8 +7,10 @@ import { SCProvider } from '../../../../context';
7
7
  import ChooseUserField from '../index';
8
8
  import { TouchableOpacity } from 'react-native';
9
9
  import { ModalCustom } from '../../../Modal';
10
+ import api from '../../../../utils/Apis/axios';
11
+ import { API } from '../../../../configs';
10
12
 
11
- jest.mock('axios');
13
+ const mock = new MockAdapter(api.axiosInstance);
12
14
 
13
15
  const wrapComponent = (
14
16
  unit = { id: 1 },
@@ -47,10 +49,6 @@ const wrapComponent = (
47
49
  describe('Test ChooseUserField', () => {
48
50
  let tree;
49
51
 
50
- afterEach(() => {
51
- axios.get.mockClear();
52
- });
53
-
54
52
  const onPressCancel = async (instance, popup) => {
55
53
  const buttonCancel = instance.find(
56
54
  (el) =>
@@ -79,14 +77,7 @@ describe('Test ChooseUserField', () => {
79
77
  };
80
78
 
81
79
  test('render ChooseUserField handleOnApply', async () => {
82
- const response_unit_members = {
83
- status: 200,
84
- data: [{ id: 1, name: 'Ken' }],
85
- };
86
-
87
- axios.get.mockImplementation(() => {
88
- return response_unit_members;
89
- });
80
+ mock.onGet(API.SHARE.UNITS_MEMBERS(1)).reply(200, [{ id: 1, name: 'Ken' }]);
90
81
  await act(async () => {
91
82
  tree = create(wrapComponent());
92
83
  });
@@ -110,4 +101,18 @@ describe('Test ChooseUserField', () => {
110
101
  await onPressCancel(instance, popup);
111
102
  await onPressApply(instance, popup);
112
103
  });
104
+
105
+ test('fetch unit_members error', async () => {
106
+ mock.onGet(API.SHARE.UNITS_MEMBERS(1)).reply(new Error('Network Error'));
107
+ await act(async () => {
108
+ tree = create(wrapComponent());
109
+ });
110
+ const instance = tree.root;
111
+ const ChooseField = instance.findAll(
112
+ (item) =>
113
+ item.props.testID === TESTID.CHOOSE_ITEM &&
114
+ item.type === TouchableOpacity
115
+ );
116
+ expect(ChooseField).toHaveLength(0);
117
+ });
113
118
  });
@@ -1,12 +1,10 @@
1
1
  import React from 'react';
2
- import axios from 'axios';
3
2
  import { act, create } from 'react-test-renderer';
4
3
  import { TESTID } from '../../../../configs/Constants';
5
4
  import { mockSCStore } from '../../../../context/mockStore';
6
5
  import { SCProvider } from '../../../../context';
7
6
  import PasscodeField from '../index';
8
7
 
9
- jest.mock('axios');
10
8
  const mockSetState = jest.fn();
11
9
 
12
10
  const wrapComponent = (
@@ -44,7 +42,6 @@ describe('Test PasscodeField', () => {
44
42
  let tree;
45
43
 
46
44
  afterEach(() => {
47
- axios.get.mockClear();
48
45
  mockSetState.mockClear();
49
46
  });
50
47
 
@@ -1,5 +1,4 @@
1
1
  import React from 'react';
2
- import axios from 'axios';
3
2
  import { act, create } from 'react-test-renderer';
4
3
  import { mockSCStore } from '../../../../context/mockStore';
5
4
  import { SCProvider } from '../../../../context';
@@ -7,7 +6,6 @@ import ScheduleField from '../index';
7
6
  import { TESTID } from '../../../../configs/Constants';
8
7
  import { TouchableOpacity } from 'react-native';
9
8
 
10
- jest.mock('axios');
11
9
  const mockSetState = jest.fn();
12
10
 
13
11
  const wrapComponent = (
@@ -55,7 +53,6 @@ describe('Test ScheduleField', () => {
55
53
  Date.now = jest.fn(() => new Date('2022-05-30T15:50:36+01:00'));
56
54
  });
57
55
  afterEach(() => {
58
- axios.get.mockClear();
59
56
  mockSetState.mockClear();
60
57
  });
61
58
 
@@ -152,9 +152,9 @@ const ScheduleField = ({ dataItem, index, setDataForm, dataForm }) => {
152
152
  <View style={styles.wrapper}>
153
153
  <Text style={styles.textHeadLine}>{t('access_schedule')}</Text>
154
154
 
155
- {listAccessSchedule.map((item, index) => (
155
+ {listAccessSchedule.map((item, i) => (
156
156
  <AccessScheduleItem
157
- key={index}
157
+ key={i}
158
158
  item={item}
159
159
  isSelected={item.value === accessSchedule}
160
160
  onSelect={setAccessSchedule}
@@ -6,6 +6,7 @@ import { Icon } from '@ant-design/react-native';
6
6
  import { useNavigation } from '@react-navigation/native';
7
7
  import styles from './Styles/HeaderCustomStyles';
8
8
  import { useTranslations } from '../../hooks/Common/useTranslations';
9
+ import { notImplemented } from '../../utils/Utils';
9
10
 
10
11
  const HeaderCustom = ({
11
12
  title = '',
@@ -33,7 +34,7 @@ const HeaderCustom = ({
33
34
  };
34
35
 
35
36
  const handleClose = useCallback(() => {
36
- onClose ? onClose() : alert(t('feature_under_development'));
37
+ onClose ? onClose() : notImplemented(t);
37
38
  // eslint-disable-next-line react-hooks/exhaustive-deps
38
39
  }, []);
39
40
 
@@ -76,8 +76,8 @@ const HorizontalPicker = ({
76
76
  }, [maximum, minimum, time]);
77
77
 
78
78
  useEffect(() => {
79
- const scrollListener = scrollX.addListener(({ value }) => {
80
- isCanChangeValue && onChangeValue && onChangeValue(value);
79
+ const scrollListener = scrollX.addListener(({ value: scrollValue }) => {
80
+ isCanChangeValue && onChangeValue && onChangeValue(scrollValue);
81
81
  });
82
82
  return () => scrollX.removeListener(scrollListener);
83
83
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -68,12 +68,6 @@ export default StyleSheet.create({
68
68
  right: 0,
69
69
  bottom: 0,
70
70
  },
71
- firstOpenCamera: {
72
- zIndex: -9999,
73
- position: 'absolute',
74
- width: 1,
75
- height: 1,
76
- },
77
71
  loading: {
78
72
  position: 'absolute',
79
73
  zIndex: 10,
@@ -6,15 +6,7 @@ import React, {
6
6
  useContext,
7
7
  useMemo,
8
8
  } from 'react';
9
- import {
10
- Image,
11
- View,
12
- StyleSheet,
13
- Text,
14
- TouchableOpacity,
15
- Platform,
16
- ActivityIndicator,
17
- } from 'react-native';
9
+ import { Image, View, StyleSheet, Text, TouchableOpacity } from 'react-native';
18
10
  import { VLCPlayer } from 'react-native-vlc-media-player';
19
11
  import { useTranslations } from '../../hooks/Common/useTranslations';
20
12
 
@@ -43,18 +35,14 @@ const MediaPlayerDetail = ({
43
35
  height,
44
36
  }) => {
45
37
  const { setAction } = useContext(SCContext);
46
- const { isFirstOpenCamera, camera_opened } = useSCContextSelector(
47
- (state) => state.app
48
- );
38
+ const { camera_opened } = useSCContextSelector((state) => state.app);
49
39
  const t = useTranslations();
50
40
  const [paused, setPaused] = useState(isPaused);
51
41
 
52
42
  const onTapPause = useCallback(() => {
53
- if (!isFirstOpenCamera) {
54
- setPaused(false);
55
- id && setAction(Action.CAMERA_STATUS_CHANGE, { id, status: true });
56
- }
57
- }, [id, isFirstOpenCamera, setAction]);
43
+ setPaused(false);
44
+ id && setAction(Action.CAMERA_STATUS_CHANGE, { id, status: true });
45
+ }, [id, setAction]);
58
46
 
59
47
  const onTapGoDetail = useCallback(() => {
60
48
  if (!paused) {
@@ -72,29 +60,29 @@ const MediaPlayerDetail = ({
72
60
  }, []);
73
61
 
74
62
  const getWidthHeight = useCallback(() => {
75
- let width = 0,
76
- height = 0;
63
+ let newWidth = 0,
64
+ newHeight = 0;
77
65
  switch (amount) {
78
66
  case 1:
79
- width = Constants.width;
80
- height = 224;
67
+ newWidth = Constants.width;
68
+ newHeight = 224;
81
69
  break;
82
70
  case 4:
83
- width = Constants.width / 2;
84
- height = 112;
71
+ newWidth = Constants.width / 1.5;
72
+ newHeight = 112;
85
73
  break;
86
74
  case 6:
87
- width = Constants.width / 3;
88
- height = 112;
75
+ newWidth = Constants.width / 3;
76
+ newHeight = 112;
89
77
  break;
90
78
  default:
91
- width = Constants.width - 28;
92
- height = 162;
79
+ newWidth = Constants.width - 28;
80
+ newHeight = 162;
93
81
  break;
94
82
  }
95
83
  return {
96
- width,
97
- height,
84
+ width: newWidth,
85
+ height: newHeight,
98
86
  };
99
87
  }, [amount]);
100
88
 
@@ -103,9 +91,9 @@ const MediaPlayerDetail = ({
103
91
  <VLCPlayer
104
92
  autoAspectRatio={true}
105
93
  videoAspectRatio={
106
- width && height
107
- ? `${width}:${height}`
108
- : `${getWidthHeight().width}:${getWidthHeight().height}`
94
+ amount
95
+ ? `${getWidthHeight().width}:${getWidthHeight().height}`
96
+ : `${width}:${height}`
109
97
  }
110
98
  source={{
111
99
  initType: 2,
@@ -126,31 +114,20 @@ const MediaPlayerDetail = ({
126
114
  styles.player,
127
115
  style,
128
116
  {
129
- width: width || getWidthHeight().width,
130
- height: height || getWidthHeight().height,
117
+ width: amount ? getWidthHeight().width : width,
118
+ height: amount ? getWidthHeight().height : height,
131
119
  },
132
- isFirstOpenCamera && styles.firstOpenCamera,
133
120
  ]}
134
121
  isLive={true}
135
122
  />
136
123
  );
137
124
  // eslint-disable-next-line react-hooks/exhaustive-deps
138
- }, [uri, isFirstOpenCamera]);
125
+ }, [uri]);
139
126
 
140
127
  useEffect(() => {
141
128
  setPaused(isPaused);
142
129
  }, [isPaused]);
143
130
 
144
- useEffect(() => {
145
- if (isFirstOpenCamera) {
146
- const to = setTimeout(() => {
147
- setAction(Action.IS_FIRST_OPEN_CAMERA, false);
148
- clearTimeout(to);
149
- }, 1000);
150
- }
151
- // eslint-disable-next-line react-hooks/exhaustive-deps
152
- }, [isFirstOpenCamera]);
153
-
154
131
  useEffect(() => {
155
132
  if (id && !(camera_opened || []).some((item) => item === id)) {
156
133
  setPaused(true);
@@ -161,14 +138,6 @@ const MediaPlayerDetail = ({
161
138
  const source = !thumbnail || !thumbnail.uri ? Images.BgDevice : thumbnail;
162
139
  return (
163
140
  <View style={[styles.wrap, wrapStyles]}>
164
- {isFirstOpenCamera && Platform.OS === 'ios' && (
165
- <>
166
- {renderCamera}
167
- <View style={styles.loading}>
168
- <ActivityIndicator size={'small'} color={Colors.Primary} />
169
- </View>
170
- </>
171
- )}
172
141
  <View style={[styles.loadingWrap]}>
173
142
  <Text style={styles.loadingText}>{t('loading')}</Text>
174
143
  </View>
@@ -194,7 +163,7 @@ const MediaPlayerDetail = ({
194
163
  />
195
164
  </View>
196
165
  ) : (
197
- !isFirstOpenCamera && renderCamera
166
+ renderCamera
198
167
  )}
199
168
 
200
169
  <View style={styles.buttonView}>
@@ -15,7 +15,6 @@ const wrapComponent = (sensor, mockFunction) => (
15
15
  </SCProvider>
16
16
  );
17
17
 
18
- jest.mock('axios');
19
18
  describe('Test DevicePermissionsCheckbox', () => {
20
19
  let tree;
21
20
  let sensor = {
@@ -8,13 +8,13 @@ import ItemDevice from '../../Device/ItemDevice';
8
8
  import ItemOneTap from '../OneTap/ItemOneTap';
9
9
  import ItemAddNew from '../../Device/ItemAddNew';
10
10
  import styles from './styles';
11
+ import { notImplemented } from '../../../utils/Utils';
11
12
 
12
13
  const SubUnitFavorites = ({
13
14
  isOwner,
14
15
  unit,
15
16
  favoriteDevices,
16
17
  favoriteAutomates,
17
- isGGHomeConnected,
18
18
  wrapItemStyle,
19
19
  }) => {
20
20
  const t = useTranslations();
@@ -22,7 +22,7 @@ const SubUnitFavorites = ({
22
22
  const { getStatus, serverDown } = useSensorsStatus(unit, favoriteDevices);
23
23
 
24
24
  const handleOnAddNew = () => {
25
- alert(t('feature_under_development'));
25
+ notImplemented(t);
26
26
  };
27
27
 
28
28
  return (
@@ -42,7 +42,6 @@ const SubUnitFavorites = ({
42
42
  sensor={sensor}
43
43
  unit={unit}
44
44
  station={sensor.station}
45
- isGGHomeConnected={isGGHomeConnected}
46
45
  serverDown={serverDown}
47
46
  status={getStatus(sensor)}
48
47
  wrapStyle={wrapItemStyle}
@@ -1,13 +1,18 @@
1
- import axios from 'axios';
2
1
  import React from 'react';
3
2
  import { TouchableOpacity } from 'react-native';
4
3
  import Toast from 'react-native-toast-message';
5
4
  import { act, create } from 'react-test-renderer';
5
+ import MockAdapter from 'axios-mock-adapter';
6
+
6
7
  import SubUnitAutomate from '..';
7
8
  import { AUTOMATE_TYPE, TESTID } from '../../../../configs/Constants';
8
9
  import { SCProvider } from '../../../../context';
9
10
  import { mockSCStore } from '../../../../context/mockStore';
10
11
  import Routes from '../../../../utils/Route';
12
+ import api from '../../../../utils/Apis/axios';
13
+ import { API } from '../../../../configs';
14
+
15
+ const mock = new MockAdapter(api.axiosInstance);
11
16
 
12
17
  const wrapComponent = (data) => (
13
18
  <SCProvider initState={mockSCStore({})}>
@@ -32,8 +37,6 @@ jest.mock('@react-navigation/native', () => {
32
37
  };
33
38
  });
34
39
 
35
- jest.mock('axios');
36
-
37
40
  let tree;
38
41
  let data = {
39
42
  isOwner: true,
@@ -60,18 +63,9 @@ let data = {
60
63
 
61
64
  describe('test Item', () => {
62
65
  beforeEach(() => {
63
- axios.post.mockClear();
64
66
  mockedNavigate.mockClear();
65
67
  });
66
68
  test('render SubUnitAutomate isOwner and handleOnAddNew', async () => {
67
- const response = {
68
- status: 200,
69
- };
70
-
71
- axios.post.mockImplementation(async () => {
72
- return response;
73
- });
74
-
75
69
  await act(async () => {
76
70
  tree = await create(wrapComponent(data));
77
71
  });
@@ -114,6 +108,7 @@ describe('test Item', () => {
114
108
  el.type === TouchableOpacity
115
109
  );
116
110
  expect(handleScriptAction).toHaveLength(1);
111
+ mock.onPost(API.AUTOMATE.ACTION_ONE_TAP(1)).reply(200);
117
112
  await act(async () => {
118
113
  await handleScriptAction[0].props.onPress();
119
114
  });
@@ -127,14 +122,6 @@ describe('test Item', () => {
127
122
 
128
123
  test('render SubUnitAutomate not is owner handleScriptAction fail', async () => {
129
124
  data.isOwner = false;
130
- const response = {
131
- status: 400,
132
- };
133
-
134
- axios.post.mockImplementation(async () => {
135
- return response;
136
- });
137
-
138
125
  await act(async () => {
139
126
  tree = await create(wrapComponent(data));
140
127
  });
@@ -145,6 +132,7 @@ describe('test Item', () => {
145
132
  el.type === TouchableOpacity
146
133
  );
147
134
  expect(handleScriptAction).toHaveLength(1);
135
+ mock.onPost(API.AUTOMATE.ACTION_ONE_TAP(1)).reply(400);
148
136
  await act(async () => {
149
137
  await handleScriptAction[0].props.onPress();
150
138
  });
@@ -181,14 +169,6 @@ describe('test Item', () => {
181
169
  ],
182
170
  },
183
171
  ];
184
- const response = {
185
- status: 200,
186
- };
187
-
188
- axios.post.mockImplementation(async () => {
189
- return response;
190
- });
191
-
192
172
  await act(async () => {
193
173
  tree = await create(wrapComponent(data));
194
174
  });
@@ -233,13 +213,6 @@ describe('test Item', () => {
233
213
  ],
234
214
  },
235
215
  ];
236
- const response = {
237
- status: 200,
238
- };
239
-
240
- await axios.post.mockImplementation(async () => {
241
- return response;
242
- });
243
216
 
244
217
  await act(async () => {
245
218
  tree = await create(wrapComponent(data));
@@ -41,10 +41,9 @@ const SubUnitAutomate = ({ isOwner, listAutomate, unit, wrapItemStyle }) => {
41
41
  setAutomates(listAutomate[indexAutomate]);
42
42
  // eslint-disable-next-line react-hooks/exhaustive-deps
43
43
  }, [listAutomate]);
44
-
45
44
  return (
46
45
  <Section style={styles.noShadow}>
47
- <View style={styles.boxScenario}>
46
+ <View style={styles.boxScenario} testID={TESTID.VIEW_SUB_UNIT_AUTOMATE}>
48
47
  {listAutomate.map((item, index) => (
49
48
  <TouchableOpacity
50
49
  style={