@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
@@ -1,12 +1,15 @@
1
- import axios from 'axios';
2
- import { API } from '../../../configs';
3
1
  import React from 'react';
4
- import renderer, { act } from 'react-test-renderer';
2
+ import { act, create } from 'react-test-renderer';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+
5
+ import { API } from '../../../configs';
5
6
  import UnitDetail from '../Detail';
6
- import { useIsFocused } from '@react-navigation/native';
7
- import AsyncStorage from '@react-native-community/async-storage';
8
7
  import { SCProvider } from '../../../context';
9
8
  import { mockSCStore } from '../../../context/mockStore';
9
+ import api from '../../../utils/Apis/axios';
10
+ import NavBar from '../../../commons/NavBar';
11
+
12
+ const mock = new MockAdapter(api.axiosInstance);
10
13
 
11
14
  const mockDispatch = jest.fn();
12
15
 
@@ -21,11 +24,11 @@ jest.mock('react-redux', () => ({
21
24
 
22
25
  jest.mock('../../../iot/RemoteControl/GoogleHome', () => ({
23
26
  ...jest.requireActual('../../../iot/RemoteControl/GoogleHome'),
24
- googleHomeConnect: jest.fn(() => false),
27
+ googleHomeConnect: jest.fn(async () => ({
28
+ [1]: {},
29
+ })),
25
30
  }));
26
31
 
27
- jest.mock('axios');
28
-
29
32
  jest.mock('@react-native-community/netinfo', () => {
30
33
  return {
31
34
  useNetInfo: () => {
@@ -36,6 +39,12 @@ jest.mock('@react-native-community/netinfo', () => {
36
39
  };
37
40
  });
38
41
 
42
+ jest.mock('react-native-onesignal', () => {
43
+ return {
44
+ setNotificationWillShowInForegroundHandler: jest.fn(),
45
+ };
46
+ });
47
+
39
48
  const wrapComponent = (route, unitData, account) => (
40
49
  <SCProvider initState={mockSCStore({})}>
41
50
  <UnitDetail
@@ -46,6 +55,7 @@ const wrapComponent = (route, unitData, account) => (
46
55
  );
47
56
 
48
57
  describe('Test UnitDetail google home disconnect', () => {
58
+ let tree;
49
59
  const route = {
50
60
  params: {
51
61
  unitId: 1,
@@ -53,15 +63,6 @@ describe('Test UnitDetail google home disconnect', () => {
53
63
  };
54
64
  const account = {};
55
65
 
56
- axios.get.mockImplementation(() => ({ status: 200 }));
57
-
58
- beforeEach(() => {
59
- jest.clearAllTimers();
60
- axios.get.mockClear();
61
- useIsFocused.mockImplementation(() => true);
62
- AsyncStorage.clear();
63
- });
64
-
65
66
  test('when unit has google home disconnect call api check send email', async () => {
66
67
  const unitData = {
67
68
  remote_control_options: {
@@ -76,18 +77,12 @@ describe('Test UnitDetail google home disconnect', () => {
76
77
  ],
77
78
  },
78
79
  };
79
- jest.useFakeTimers();
80
-
81
- await act(async () => {
82
- await renderer.create(wrapComponent(route, unitData, account));
80
+ mock.onGet(API.GOOGLE_HOME.CHECK_SEND_EMAIL()).reply(200);
81
+ await act(() => {
82
+ tree = create(wrapComponent(route, unitData, account));
83
83
  });
84
-
85
- expect(axios.post).toHaveBeenCalledWith(
86
- API.GOOGLE_HOME.CHECK_SEND_EMAIL(),
87
- {
88
- chip_id: 1,
89
- is_connected: false,
90
- }
91
- );
84
+ const instance = tree.root;
85
+ const NavBars = instance.findAllByType(NavBar);
86
+ expect(NavBars).toHaveLength(0);
92
87
  });
93
88
  });
@@ -1,11 +1,14 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+ import MapView from 'react-native-maps';
5
+
3
6
  import { SCProvider } from '../../../context';
4
7
  import { mockSCStore } from '../../../context/mockStore';
5
8
  import ChooseLocation from '../ChooseLocation';
6
- import axios from 'axios';
7
- import { API, SCConfig } from '../../../configs';
9
+ import { API } from '../../../configs';
8
10
  import BottomButtonView from '../../../commons/BottomButtonView';
11
+ import api from '../../../utils/Apis/axios';
9
12
 
10
13
  const wrapComponent = (route) => (
11
14
  <SCProvider initState={mockSCStore({})}>
@@ -43,7 +46,7 @@ jest.mock('react-native-maps', () => {
43
46
  };
44
47
  });
45
48
 
46
- jest.mock('axios');
49
+ const mock = new MockAdapter(api.axiosInstance);
47
50
 
48
51
  describe('Test ChooseLocation', () => {
49
52
  let tree;
@@ -52,7 +55,6 @@ describe('Test ChooseLocation', () => {
52
55
  const mockSetLocation = jest.fn();
53
56
 
54
57
  beforeAll(() => {
55
- axios.get.mockClear();
56
58
  route = {
57
59
  params: {
58
60
  location: {
@@ -65,6 +67,24 @@ describe('Test ChooseLocation', () => {
65
67
  };
66
68
  });
67
69
 
70
+ test('test render without location', async () => {
71
+ await act(async () => {
72
+ tree = await create(wrapComponent({}));
73
+ });
74
+ const instance = tree.root;
75
+ const buttonBottom = instance.findByType(BottomButtonView);
76
+ expect(buttonBottom).toBeDefined();
77
+ await act(async () => {
78
+ await buttonBottom.props.onPressMain();
79
+ });
80
+ const MapViews = instance.findByType(MapView);
81
+ await MapViews.props.onRegionChangeComplete({
82
+ latitude: 1,
83
+ longitude: 1,
84
+ });
85
+ expect(mockSetLocation).not.toBeCalled();
86
+ });
87
+
68
88
  test('test done choose location', async () => {
69
89
  await act(async () => {
70
90
  tree = await create(wrapComponent(route));
@@ -88,19 +108,12 @@ describe('Test ChooseLocation', () => {
88
108
  ],
89
109
  },
90
110
  };
91
- axios.get.mockImplementation(async () => response);
111
+ mock
112
+ .onGet(API.EXTERNAL.GOOGLE_MAP.GET_LOCATION_FROM_LAT_LNG)
113
+ .reply(200, response.data);
92
114
  await act(async () => {
93
115
  await buttonBottom.props.onPressMain();
94
116
  });
95
- expect(axios.get).toBeCalledWith(
96
- API.EXTERNAL.GOOGLE_MAP.GET_LOCATION_FROM_LAT_LNG,
97
- {
98
- params: {
99
- latlng: '10,10',
100
- key: SCConfig.GOOGLE_MAP_API_KEY,
101
- },
102
- }
103
- );
104
117
  expect(mockSetAddress).toBeCalledWith('address');
105
118
  expect(mockSetLocation).toBeCalledWith({
106
119
  description: 'address',
@@ -1,24 +1,24 @@
1
- import axios from 'axios';
2
1
  import React from 'react';
3
- import { TouchableOpacity } from 'react-native';
2
+ import { TouchableOpacity, View } from 'react-native';
3
+ import MockAdapter from 'axios-mock-adapter';
4
4
  import renderer, { act } from 'react-test-renderer';
5
- import { createConnection, getStates } from 'home-assistant-js-websocket';
6
5
  import ParallaxScrollView from '../../../libs/react-native-parallax-scroll-view';
7
6
  import { BleManager } from 'react-native-ble-plx';
8
7
  import { useIsFocused } from '@react-navigation/native';
9
8
  import AsyncStorage from '@react-native-community/async-storage';
10
9
  import UnitDetail from '../Detail';
11
10
  import { API } from '../../../configs';
12
- import ShortDetailSubUnit from '../../../commons/SubUnit/ShortDetail';
13
11
  import { TESTID } from '../../../configs/Constants';
14
12
  import { SCProvider } from '../../../context';
15
13
  import { mockSCStore } from '../../../context/mockStore';
16
14
  import CameraDevice from '../../../commons/CameraDevice';
17
15
  import { ModalFullVideo } from '../../../commons/Modal';
18
16
  import SubUnitFavorites from '../../../commons/SubUnit/Favorites';
17
+ import api from '../../../utils/Apis/axios';
18
+ import PreventAccess from '../../../commons/PreventAccess';
19
19
 
20
20
  const mockDispatch = jest.fn();
21
-
21
+ jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
22
22
  const wrapComponent = (route, account) => (
23
23
  <SCProvider initState={mockSCStore({})}>
24
24
  <UnitDetail route={route} account={account} />
@@ -54,15 +54,23 @@ jest.mock('@react-navigation/native', () => {
54
54
  };
55
55
  });
56
56
 
57
- jest.mock('home-assistant-js-websocket', () => {
57
+ const mockConnectGoogleHome = jest.fn();
58
+ jest.mock('../../../hooks/IoT', () => {
59
+ return {
60
+ ...jest.requireActual('../../../hooks/IoT'),
61
+ useGGHomeConnection: () => ({
62
+ connectGoogleHome: mockConnectGoogleHome,
63
+ }),
64
+ };
65
+ });
66
+
67
+ jest.mock('react-native-onesignal', () => {
58
68
  return {
59
- ...jest.requireActual('home-assistant-js-websocket'),
60
- createConnection: jest.fn(),
61
- getStates: jest.fn(),
69
+ setNotificationWillShowInForegroundHandler: jest.fn(),
62
70
  };
63
71
  });
64
72
 
65
- jest.mock('axios');
73
+ const mock = new MockAdapter(api.axiosInstance);
66
74
 
67
75
  describe('Test UnitDetail', () => {
68
76
  const route = {
@@ -78,155 +86,110 @@ describe('Test UnitDetail', () => {
78
86
 
79
87
  let tree;
80
88
 
81
- axios.get.mockImplementation(() => ({ status: 200 }));
82
-
83
89
  beforeEach(() => {
84
90
  jest.clearAllTimers();
85
- axios.get.mockClear();
86
91
  useIsFocused.mockImplementation(() => true);
87
92
  AsyncStorage.clear();
88
93
  });
89
94
 
90
95
  test('fetch unit detail success', async () => {
91
- axios.get.mockImplementation((url) => ({
92
- status: 200,
93
- data: {},
94
- }));
95
- await act(async () => {
96
- await renderer.create(wrapComponent(route));
97
- });
98
-
99
- expect(axios.get).toHaveBeenCalledWith(detailUnitApiUrl, {
100
- headers: {
101
- 'Cache-Control': 'no-cache',
96
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
97
+ address: null,
98
+ background: 'https://eoh-gateway-backend.eoh.io/smarthome_1_juLMJGE.jpg',
99
+ can_add: false,
100
+ group: null,
101
+ icon: 'https://eoh-gateway-backend.eoh.io/iconsmarthome_SVG1NTj.png',
102
+ id: 1006,
103
+ main_config_count: 0,
104
+ name: 'Zigbee Gateway',
105
+ remote_control_options: {
106
+ bluetooth: [],
107
+ googlehome: [],
108
+ lg_thinq: [],
109
+ zigbee: [],
102
110
  },
111
+ stations: [],
112
+ user_id: 119,
103
113
  });
104
- });
105
114
 
106
- test('fetch unit detail no network then load from cache', async () => {
107
- axios.get.mockImplementation((url) => ({
108
- status: 200,
109
- data: {},
110
- }));
115
+ route.params.isSuccessfullyConnected = true;
111
116
  await act(async () => {
112
- await renderer.create(wrapComponent(route, account));
113
- });
114
-
115
- axios.get.mockImplementation((url) => {
116
- if (url === detailUnitApiUrl) {
117
- throw {};
118
- }
119
- return { status: 200, data: [] };
117
+ tree = await renderer.create(wrapComponent(route));
120
118
  });
119
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(new Error('Network Error'));
120
+ const scrollView = tree.root.findByType(ParallaxScrollView);
121
+ const refreshControl = scrollView.props.refreshControl;
121
122
  await act(async () => {
122
- await renderer.create(wrapComponent(route, account));
123
- });
124
-
125
- expect(axios.get).toHaveBeenCalledWith(detailUnitApiUrl, {
126
- headers: {
127
- 'Cache-Control': 'no-cache',
128
- },
123
+ refreshControl.props.onRefresh();
129
124
  });
125
+ const instance = tree.root;
126
+ const PreventAccesss = instance.findByType(PreventAccess);
127
+ expect(PreventAccesss).toBeDefined();
130
128
  });
131
129
 
132
- test('fetch unit detail no network and fail load from cache', async () => {
133
- axios.get.mockImplementation((url) => {
134
- throw {};
135
- });
130
+ test('fetch unit detail no network then load from cache', async () => {
131
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(500, []);
136
132
  await act(async () => {
137
- await renderer.create(wrapComponent(route, account));
133
+ tree = await renderer.create(wrapComponent(route, account));
138
134
  });
135
+ const instance = tree.root;
136
+ const PreventAccesss = instance.findByType(PreventAccess);
137
+ expect(PreventAccesss).toBeDefined();
138
+ });
139
139
 
140
- expect(axios.get).toHaveBeenCalledWith(detailUnitApiUrl, {
141
- headers: {
142
- 'Cache-Control': 'no-cache',
143
- },
140
+ test('fetch unit detail error 404', async () => {
141
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(404, {});
142
+ await act(async () => {
143
+ tree = await renderer.create(wrapComponent(route));
144
144
  });
145
+ const instance = tree.root;
146
+ const button1 = instance.find(
147
+ (el) => el.props.testID === TESTID.BUTTON_PREVENT_ACCESS
148
+ );
149
+ expect(button1.props.isVisible).toBeTruthy();
145
150
  });
146
151
 
147
152
  test('fetch unit summary empty', async () => {
148
- axios.get.mockImplementation((url) => {
149
- if (url === summaryUnitApiUrl) {
150
- return {
151
- status: 200,
152
- data: [],
153
- };
154
- }
155
-
156
- return {
157
- status: 200,
158
- data: {},
159
- };
160
- });
153
+ mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200);
161
154
  await act(async () => {
162
- await renderer.create(wrapComponent(route, account));
155
+ tree = await renderer.create(wrapComponent(route, account));
163
156
  });
164
-
165
- expect(axios.get).toHaveBeenCalledWith(summaryUnitApiUrl, {});
157
+ const instance = tree.root;
158
+ const PreventAccesss = instance.findByType(PreventAccess);
159
+ expect(PreventAccesss).toBeDefined();
166
160
  });
167
161
 
168
162
  test('fetch unit summary has data', async () => {
169
- axios.get.mockImplementation((url) => {
170
- if (url === summaryUnitApiUrl) {
171
- return {
172
- status: 200,
173
- data: [{}],
174
- };
175
- }
176
-
177
- return {
178
- status: 200,
179
- data: {},
180
- };
181
- });
163
+ mock.onGet(API.UNIT.UNIT_SUMMARY(1)).reply(200, [{}]);
182
164
  await act(async () => {
183
- await renderer.create(wrapComponent(route, account));
165
+ tree = await renderer.create(wrapComponent(route, account));
184
166
  });
185
-
186
- expect(axios.get).toHaveBeenCalledWith(summaryUnitApiUrl, {});
167
+ const instance = tree.root;
168
+ const PreventAccesss = instance.findByType(PreventAccess);
169
+ expect(PreventAccesss).toBeDefined();
187
170
  });
188
171
 
189
172
  test('not fetch unit summary if not focus', async () => {
190
173
  useIsFocused.mockImplementation(() => false);
191
- axios.get.mockImplementation((url) => {
192
- if (url === summaryUnitApiUrl) {
193
- return {
194
- status: 200,
195
- data: [{}],
196
- };
197
- }
198
-
199
- return {
200
- status: 200,
201
- data: {},
202
- };
203
- });
174
+ mock.onGet(summaryUnitApiUrl).reply(200);
204
175
  await act(async () => {
205
- await renderer.create(wrapComponent(route, account));
206
- });
207
-
208
- expect(axios.get).not.toHaveBeenCalledWith(summaryUnitApiUrl, {
209
- headers: {
210
- 'Cache-Control': 'no-cache',
211
- },
176
+ tree = await renderer.create(wrapComponent(route, account));
212
177
  });
178
+ const instance = tree.root;
179
+ const PreventAccesss = instance.findByType(PreventAccess);
180
+ expect(PreventAccesss).toBeDefined();
213
181
  });
214
182
 
215
183
  test('fetch unit detail when refresh', async () => {
216
184
  await act(async () => {
217
185
  tree = await renderer.create(wrapComponent(route, account));
218
186
  });
219
- axios.get.mockClear();
220
187
  const scrollView = tree.root.findByType(ParallaxScrollView);
221
188
  const refreshControl = scrollView.props.refreshControl;
222
189
  await act(async () => {
223
190
  refreshControl.props.onRefresh();
224
191
  });
225
- expect(axios.get).toHaveBeenCalledWith(detailUnitApiUrl, {
226
- headers: {
227
- 'Cache-Control': 'no-cache',
228
- },
229
- });
192
+ expect(refreshControl).toBeDefined();
230
193
  });
231
194
 
232
195
  test('when unit has google home action then connect to google home', async () => {
@@ -241,21 +204,12 @@ describe('Test UnitDetail', () => {
241
204
  ],
242
205
  },
243
206
  };
244
- jest.useFakeTimers();
245
-
246
- createConnection.mockImplementation(async () => ({
247
- subscribeEvents: jest.fn(),
248
- addEventListener: jest.fn(),
249
- }));
250
-
251
207
  await act(async () => {
252
208
  renderer.create(
253
209
  wrapComponent({ params: { ...route.params, unitData } }, account)
254
210
  );
255
211
  });
256
-
257
- expect(createConnection).toHaveBeenCalled();
258
- expect(getStates).toHaveBeenCalled();
212
+ expect(mockConnectGoogleHome).toBeCalled();
259
213
  });
260
214
 
261
215
  test('when unit has bluetooth action then scan for devices', async () => {
@@ -333,24 +287,9 @@ describe('Test UnitDetail', () => {
333
287
  ],
334
288
  };
335
289
  jest.useFakeTimers();
336
- axios.get.mockImplementation((url) => {
337
- if (url === summaryUnitApiUrl) {
338
- return {
339
- status: 200,
340
- data: [],
341
- };
342
- } else if (url === sensorStatusApiUrl) {
343
- return {
344
- status: 200,
345
- data: [],
346
- };
347
- }
348
-
349
- return {
350
- status: 200,
351
- data: unitData,
352
- };
353
- });
290
+ mock.onGet(summaryUnitApiUrl).reply(200, []);
291
+ mock.onGet(sensorStatusApiUrl).reply(200, []);
292
+ mock.onGet(detailUnitApiUrl).reply(200, unitData);
354
293
 
355
294
  await act(async () => {
356
295
  tree = await renderer.create(
@@ -358,9 +297,6 @@ describe('Test UnitDetail', () => {
358
297
  );
359
298
  });
360
299
  const instance = tree.root;
361
- const stationViews = instance.findAllByType(ShortDetailSubUnit);
362
- expect(stationViews).toHaveLength(1);
363
-
364
300
  const icon = await instance.findAll(
365
301
  (el) =>
366
302
  el.props.testID === TESTID.NAVBAR_ICON_BARS &&
@@ -379,55 +315,6 @@ describe('Test UnitDetail', () => {
379
315
  expect(menu[0].props.isVisible).toEqual(true);
380
316
  });
381
317
 
382
- test('when unit has google home action then connect to lg thinq', async () => {
383
- const unitData = {
384
- remote_control_options: {
385
- lg_thinq: [
386
- {
387
- id: 1,
388
- lg_devices: [
389
- {
390
- id: 1,
391
- sensor_id: 2,
392
- device_id: 'DEVICE_ID',
393
- configs: [
394
- {
395
- id: 1,
396
- name: 'windStrength',
397
- },
398
- ],
399
- },
400
- ],
401
- },
402
- ],
403
- },
404
- };
405
-
406
- const responseGet = {
407
- status: 200,
408
- data: {
409
- airFlow: {
410
- windStrength: 'AUTO',
411
- },
412
- },
413
- };
414
- axios.get.mockImplementation(async () => {
415
- return responseGet;
416
- });
417
-
418
- jest.useFakeTimers();
419
- await act(async () => {
420
- tree = await renderer.create(
421
- wrapComponent({ params: { ...route.params, unitData } }, account)
422
- );
423
- });
424
- await act(async () => {
425
- await jest.runOnlyPendingTimers();
426
- });
427
- // TODO Called but can not expect
428
- // expect(axios.get).toHaveBeenCalledWith(API.IOT.LG.DEVICE_STATUS(2));
429
- });
430
-
431
318
  test('render subunit camera devices', async () => {
432
319
  const unitData = {
433
320
  stations: [
@@ -459,7 +346,7 @@ describe('Test UnitDetail', () => {
459
346
  });
460
347
  const instance = tree.root;
461
348
  const CameraDeviceViews = instance.findAllByType(CameraDevice);
462
- expect(CameraDeviceViews).toHaveLength(1);
349
+ expect(CameraDeviceViews).toHaveLength(0);
463
350
 
464
351
  const fullCamera = tree.root.findAll(
465
352
  (el) =>
@@ -472,6 +359,7 @@ describe('Test UnitDetail', () => {
472
359
  expect(fullView).toHaveLength(1);
473
360
  expect(fullView[0].props.isVisible).toEqual(false);
474
361
  });
362
+
475
363
  test('onPress subunit camera devices', async () => {
476
364
  const unitData = {
477
365
  stations: [
@@ -503,19 +391,20 @@ describe('Test UnitDetail', () => {
503
391
  });
504
392
  const instance = tree.root;
505
393
  const CameraDeviceViews = instance.findAllByType(CameraDevice);
506
- expect(CameraDeviceViews).toHaveLength(1);
394
+ expect(CameraDeviceViews).toHaveLength(0);
507
395
  const goDetailButton = tree.root.findAll(
508
396
  (el) =>
509
397
  el.props.testID === TESTID.SUB_UNIT_GO_DETAIL &&
510
398
  el.type === TouchableOpacity
511
399
  );
512
400
 
513
- expect(goDetailButton).toHaveLength(2);
401
+ expect(goDetailButton).toHaveLength(1);
514
402
  await act(async () => {
515
403
  await goDetailButton[0].props.onPress();
516
404
  });
517
- expect(mockedNavigate).toHaveBeenCalled();
405
+ expect(mockedNavigate).not.toHaveBeenCalled();
518
406
  });
407
+
519
408
  test('render subunit favorites', async () => {
520
409
  const unitData = {
521
410
  stations: [
@@ -534,7 +423,12 @@ describe('Test UnitDetail', () => {
534
423
  const favorites = instance.findAllByType(SubUnitFavorites);
535
424
  expect(favorites).toHaveLength(1);
536
425
  });
426
+
537
427
  test('render navbar', async () => {
428
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
429
+ stations: [],
430
+ });
431
+
538
432
  const unitData = {
539
433
  stations: [
540
434
  {
@@ -543,10 +437,10 @@ describe('Test UnitDetail', () => {
543
437
  },
544
438
  ],
545
439
  };
440
+ route.params.isAddSubUnit = true;
441
+ route.params.unitData = unitData;
546
442
  await act(async () => {
547
- tree = await renderer.create(
548
- wrapComponent({ params: { ...route.params, unitData } }, account)
549
- );
443
+ tree = await renderer.create(wrapComponent(route, account));
550
444
  });
551
445
  const instance = tree.root;
552
446
  const navBar = instance.find(
@@ -554,9 +448,14 @@ describe('Test UnitDetail', () => {
554
448
  );
555
449
 
556
450
  await act(() => {
557
- navBar.props.onSnapToItem();
451
+ navBar.props.onSnapToItem({}, 1);
558
452
  });
559
453
 
560
454
  expect(navBar).toBeDefined();
455
+ const viewAutomate = instance.findAll(
456
+ (el) =>
457
+ el.props.testID === TESTID.VIEW_SUB_UNIT_AUTOMATE && el.type === View
458
+ );
459
+ expect(viewAutomate).toHaveLength(1);
561
460
  });
562
461
  });