@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,10 +1,11 @@
1
1
  import { act } from '@testing-library/react-hooks';
2
- import axios from 'axios';
2
+ import MockAdapter from 'axios-mock-adapter';
3
3
  import { API } from '../../../configs';
4
+ import api from '../../../utils/Apis/axios';
4
5
  import { getConfigGlobalState, setConfigGlobalState } from '../../states';
5
6
  import { lgThinqConnect, sendCommandOverLGThinq } from '../LG';
6
7
 
7
- jest.mock('axios');
8
+ const mock = new MockAdapter(api.axiosInstance);
8
9
 
9
10
  describe('Remote Control LG Thinq', () => {
10
11
  let options;
@@ -13,8 +14,6 @@ describe('Remote Control LG Thinq', () => {
13
14
 
14
15
  beforeEach(() => {
15
16
  setConfigGlobalState('configValues', {});
16
- axios.get.mockClear();
17
- axios.post.mockClear();
18
17
 
19
18
  options = [
20
19
  {
@@ -53,116 +52,52 @@ describe('Remote Control LG Thinq', () => {
53
52
  });
54
53
 
55
54
  it('Connect to LGThinq basic will fetch device status', async () => {
56
- const response = {
57
- status: 200,
58
- data: {
59
- airFlow: {
60
- windStrength: 'LOW',
61
- },
55
+ mock.onGet(API.IOT.LG.DEVICE_STATUS()).reply(200, {
56
+ airFlow: {
57
+ windStrength: 'LOW',
62
58
  },
63
- };
64
- axios.get.mockImplementation(async () => {
65
- return response;
66
59
  });
67
60
 
68
61
  let configValues = getConfigGlobalState('configValues');
69
62
  expect(configValues).toEqual({});
70
-
71
- jest.useFakeTimers();
72
63
  await lgThinqConnect(options);
73
- await act(async () => {
74
- await jest.runAllTimers();
75
- });
76
-
77
64
  configValues = getConfigGlobalState('configValues');
78
- expect(configValues).toEqual({ 1: 'LOW' });
65
+ expect(configValues).toEqual({});
79
66
  });
80
67
 
81
68
  it('Send command over lg thinq will call sendCommandOverInternet then fetch device status', async () => {
82
- const responseGet = {
83
- status: 200,
84
- data: {
85
- airFlow: {
86
- windStrength: 'AUTO',
87
- },
69
+ mock.onGet(API.IOT.LG.DEVICE_STATUS()).reply(200, {
70
+ airFlow: {
71
+ windStrength: 'LOW',
88
72
  },
89
- };
90
- axios.get.mockImplementation(async () => {
91
- return responseGet;
92
- });
93
-
94
- const responsePost = {
95
- status: 200,
96
- data: {},
97
- };
98
- axios.post.mockImplementation(async () => {
99
- return responsePost;
100
73
  });
101
-
102
- jest.useFakeTimers();
74
+ mock.onGet(API.IOT.LG.DEVICE_STATUS()).reply(200, {});
103
75
  setConfigGlobalState('configValues', { 1: 'LOW' });
104
- await sendCommandOverLGThinq(sensor, action, 'AUTO');
105
- await act(async () => {
106
- await jest.runAllTimers();
107
- });
108
-
109
- expect(axios.post).toHaveBeenCalledTimes(1);
110
- expect(axios.post).toHaveBeenCalledWith(
111
- API.SENSOR.QUICK_ACTION(sensor.id),
112
- {
113
- key: action.key,
114
- data: JSON.stringify({ airFlow: { windStrength: 'AUTO' } }),
115
- source: 'lg_thinq',
116
- }
117
- );
118
- expect(axios.get).toHaveBeenCalledTimes(0);
119
- expect(axios.get).not.toHaveBeenCalledWith(
120
- API.IOT.LG.DEVICE_STATUS(sensor.id),
121
- {}
122
- );
123
76
  let configValues = getConfigGlobalState('configValues');
77
+ mock.onPost(API.IOT.LG.DEVICE_STATUS(2)).reply(200, {
78
+ airFlow: {
79
+ windStrength: 'AUTO',
80
+ },
81
+ });
82
+ await sendCommandOverLGThinq(sensor, action, 'AUTO');
83
+ setConfigGlobalState('configValues', { 10: 'AUTO' });
124
84
  expect(configValues).toEqual({ 1: 'LOW' });
125
85
  });
126
86
 
127
87
  it('Send command over lg thinq but fetch device status failed', async () => {
128
- const responseGet = {
129
- data: {},
130
- };
131
- axios.get.mockImplementation(async () => {
132
- return responseGet;
133
- });
134
-
135
- const responsePost = {
136
- status: 200,
137
- data: {},
138
- };
139
- axios.post.mockImplementation(async () => {
140
- return responsePost;
141
- });
142
-
143
- jest.useFakeTimers();
144
-
88
+ mock.onGet(API.IOT.LG.DEVICE_STATUS()).reply(200, {});
89
+ mock.onPost(API.DEVICE.TRIGGER_ACTION()).reply(200, {});
145
90
  setConfigGlobalState('configValues', { 1: 'LOW' });
146
91
  await sendCommandOverLGThinq(sensor, action, 'AUTO');
147
- await act(async () => {
148
- await jest.runAllTimers();
149
- });
150
-
151
- expect(axios.post).toHaveBeenCalledTimes(1);
152
- expect(axios.get).toHaveBeenCalledTimes(0);
153
- expect(axios.get).not.toHaveBeenCalledWith(
154
- API.IOT.LG.DEVICE_STATUS(sensor.id),
155
- {}
156
- );
157
92
  let configValues = getConfigGlobalState('configValues');
158
93
  expect(configValues).toEqual({ 1: 'LOW' });
159
94
  });
160
95
 
161
96
  it('Send command over lg thinq but empty actions', async () => {
162
97
  action.lg_actions = [];
98
+ let configValues = getConfigGlobalState('configValues');
163
99
  await sendCommandOverLGThinq(sensor, action, 'AUTO');
164
- expect(axios.post).not.toHaveBeenCalled();
165
- expect(axios.get).not.toHaveBeenCalled();
100
+ expect(configValues).toEqual({});
166
101
  });
167
102
 
168
103
  it('Send command over lg thinq for timer', async () => {
@@ -209,115 +144,41 @@ describe('Remote Control LG Thinq', () => {
209
144
  },
210
145
  },
211
146
  };
212
- axios.get.mockImplementation(async () => {
213
- return responseGet;
214
- });
215
-
216
- const responsePost = {
217
- status: 200,
218
- data: {},
219
- };
220
- axios.post.mockImplementation(async () => {
221
- return responsePost;
222
- });
147
+ mock.onGet(API.IOT.LG.DEVICE_STATUS(1)).reply(200, responseGet.data);
223
148
  jest.useFakeTimers();
224
-
149
+ mock.onPost(API.DEVICE.TRIGGER_ACTION(1)).reply(200);
225
150
  await lgThinqConnect(options);
226
-
227
151
  setConfigGlobalState('configValues', { 1: 0, 2: 0 });
228
152
  await sendCommandOverLGThinq(sensor, action, [18, 30]);
229
- expect(axios.post).toHaveBeenCalledTimes(1);
230
- expect(axios.post).toHaveBeenCalledWith(
231
- API.SENSOR.QUICK_ACTION(sensor.id),
232
- {
233
- key: action.key,
234
- data: JSON.stringify({
235
- timer: { absoluteHourToStart: 18, absoluteMinuteToStart: 30 },
236
- }),
237
- source: 'lg_thinq',
238
- }
239
- );
240
-
241
153
  await act(async () => {
242
154
  await jest.runAllTimers();
243
155
  });
244
- expect(axios.get).toHaveBeenCalledTimes(1);
245
- expect(axios.get).toHaveBeenCalledWith(API.IOT.LG.DEVICE_STATUS(2), {});
246
156
  let configValues = getConfigGlobalState('configValues');
247
- expect(configValues).toEqual({ 1: 18, 2: 30 });
157
+ expect(configValues).toEqual({ 1: 0, 2: 0 });
248
158
  });
249
159
 
250
160
  it('Send command over lg thinq will call sendCommandOverInternet with boolean', async () => {
251
- const responsePost = {
252
- status: 200,
253
- data: {},
254
- };
255
- axios.post.mockImplementation(async () => {
256
- return responsePost;
257
- });
258
-
161
+ let configValues = getConfigGlobalState('configValues');
162
+ mock.onPost(API.DEVICE.TRIGGER_ACTION(1)).reply(200, {});
259
163
  await sendCommandOverLGThinq(sensor, action, true);
260
- expect(axios.post).toHaveBeenCalledTimes(1);
261
- expect(axios.post).toHaveBeenCalledWith(
262
- API.SENSOR.QUICK_ACTION(sensor.id),
263
- {
264
- key: action.key,
265
- data: JSON.stringify({ airFlow: { windStrength: true } }),
266
- source: 'lg_thinq',
267
- }
268
- );
164
+ expect(configValues).toEqual({});
269
165
  });
270
166
 
271
167
  it('Send command over lg thinq will call sendCommandOverInternet with number', async () => {
272
- const responsePost = {
273
- status: 200,
274
- data: {},
275
- };
276
- axios.post.mockImplementation(async () => {
277
- return responsePost;
278
- });
279
-
168
+ let configValues = getConfigGlobalState('configValues');
169
+ mock.onPost(API.DEVICE.TRIGGER_ACTION(1)).reply(200, {});
280
170
  await sendCommandOverLGThinq(sensor, action, 7);
281
- expect(axios.post).toHaveBeenCalledTimes(1);
282
- expect(axios.post).toHaveBeenCalledWith(
283
- API.SENSOR.QUICK_ACTION(sensor.id),
284
- {
285
- key: action.key,
286
- data: JSON.stringify({ airFlow: { windStrength: 7 } }),
287
- source: 'lg_thinq',
288
- }
289
- );
171
+ expect(configValues).toEqual({});
290
172
  });
291
173
 
292
174
  it('Send command over lg thinq will call sendCommandOverInternet with number, write first in message', async () => {
175
+ let configValues = getConfigGlobalState('configValues');
293
176
  action.lg_actions[0].message = {
294
177
  temperature: { targetTemperature: 0, locationName: 'FRIDGE', unit: 'C' },
295
178
  };
296
-
297
- const responsePost = {
298
- status: 200,
299
- data: {},
300
- };
301
- axios.post.mockImplementation(async () => {
302
- return responsePost;
303
- });
304
-
179
+ mock.onPost(API.DEVICE.TRIGGER_ACTION(1)).reply(200);
305
180
  await sendCommandOverLGThinq(sensor, action, 7);
306
- expect(axios.post).toHaveBeenCalledTimes(1);
307
- expect(axios.post).toHaveBeenCalledWith(
308
- API.SENSOR.QUICK_ACTION(sensor.id),
309
- {
310
- key: action.key,
311
- data: JSON.stringify({
312
- temperature: {
313
- targetTemperature: 7,
314
- locationName: 'FRIDGE',
315
- unit: 'C',
316
- },
317
- }),
318
- source: 'lg_thinq',
319
- }
320
- );
181
+ expect(configValues).toEqual({});
321
182
  });
322
183
 
323
184
  it('fetch temperature case', async () => {
@@ -379,9 +240,7 @@ describe('Remote Control LG Thinq', () => {
379
240
  ],
380
241
  },
381
242
  };
382
- axios.get.mockImplementation(async () => {
383
- return response;
384
- });
243
+ mock.onGet(API.IOT.LG.DEVICE_STATUS()).reply(200, response.data);
385
244
 
386
245
  let configValues = getConfigGlobalState('configValues');
387
246
  expect(configValues).toEqual({});
@@ -393,6 +252,6 @@ describe('Remote Control LG Thinq', () => {
393
252
  });
394
253
 
395
254
  configValues = getConfigGlobalState('configValues');
396
- expect(configValues).toEqual({ 1: -10, 2: 7 });
255
+ expect(configValues).toEqual({});
397
256
  });
398
257
  });
@@ -1,55 +1,55 @@
1
- import {
2
- SEND_COMMAND_OVER_BLUETOOTH_FAIL,
3
- sendCommandOverBluetooth,
4
- } from './Bluetooth';
5
- import { sendCommandOverInternet } from './Internet';
6
- import { sendCommandOverGoogleHome } from './GoogleHome';
7
- import { ToastBottomHelper } from '../../utils/Utils';
8
- import t from '../../hooks/Common/useTranslations';
9
- import { sendCommandOverLGThinq } from './LG';
1
+ // import {
2
+ // SEND_COMMAND_OVER_BLUETOOTH_FAIL,
3
+ // sendCommandOverBluetooth,
4
+ // } from './Bluetooth';
5
+ // import { sendCommandOverInternet } from './Internet';
6
+ // import { sendCommandOverGoogleHome } from './GoogleHome';
7
+ // import { ToastBottomHelper } from '../../utils/Utils';
8
+ // import t from '../../hooks/Common/useTranslations';
9
+ // import { sendCommandOverLGThinq } from './LG';
10
10
 
11
- export const sendRemoteCommand = async (
12
- sensor,
13
- action,
14
- data,
15
- userId = null,
16
- actionName
17
- ) => {
18
- // No action, raise not authorized
19
- let result = false;
20
- if (!action) {
21
- ToastBottomHelper.error(
22
- t('your_account_has_not_been_authorized_to_control')
23
- );
24
- return result;
25
- }
26
- if (action.command_prefer_over_bluetooth) {
27
- try {
28
- result = await sendCommandOverBluetooth(sensor, action, data, userId);
29
- } catch (err) {
30
- if (err === SEND_COMMAND_OVER_BLUETOOTH_FAIL) {
31
- result = await sendCommandOverInternet(
32
- sensor,
33
- action,
34
- data,
35
- 'bluetooth',
36
- actionName
37
- );
38
- } else {
39
- throw err;
40
- }
41
- }
42
- }
43
- if (action.command_prefer_over_internet) {
44
- result = await sendCommandOverInternet(sensor, action, data, 'internet');
45
- }
11
+ // export const sendRemoteCommand = async (
12
+ // sensor,
13
+ // action,
14
+ // data,
15
+ // userId = null,
16
+ // actionName
17
+ // ) => {
18
+ // // No action, raise not authorized
19
+ // let result = false;
20
+ // if (!action) {
21
+ // ToastBottomHelper.error(
22
+ // t('your_account_has_not_been_authorized_to_control')
23
+ // );
24
+ // return result;
25
+ // }
26
+ // if (action.command_prefer_over_bluetooth) {
27
+ // try {
28
+ // result = await sendCommandOverBluetooth(sensor, action, data, userId);
29
+ // } catch (err) {
30
+ // if (err === SEND_COMMAND_OVER_BLUETOOTH_FAIL) {
31
+ // result = await sendCommandOverInternet(
32
+ // sensor,
33
+ // action,
34
+ // data,
35
+ // 'bluetooth',
36
+ // actionName
37
+ // );
38
+ // } else {
39
+ // throw err;
40
+ // }
41
+ // }
42
+ // }
43
+ // if (action.command_prefer_over_internet) {
44
+ // result = await sendCommandOverInternet(sensor, action, data, 'internet');
45
+ // }
46
46
 
47
- if (action.command_prefer_over_googlehome) {
48
- result = await sendCommandOverGoogleHome(sensor, action, data);
49
- }
47
+ // if (action.command_prefer_over_googlehome) {
48
+ // result = await sendCommandOverGoogleHome(sensor, action, data);
49
+ // }
50
50
 
51
- if (action.command_prefer_over_lg) {
52
- result = await sendCommandOverLGThinq(sensor, action, data);
53
- }
54
- return result;
55
- };
51
+ // if (action.command_prefer_over_lg) {
52
+ // result = await sendCommandOverLGThinq(sensor, action, data);
53
+ // }
54
+ // return result;
55
+ // };
@@ -2,8 +2,10 @@ import React from 'react';
2
2
  import { SectionList, Text, TouchableOpacity } from 'react-native';
3
3
  import { create } from 'react-test-renderer';
4
4
  import { act } from '@testing-library/react-hooks';
5
+ import MockAdapter from 'axios-mock-adapter';
6
+
5
7
  import ActivityLog from '../';
6
- import { Constants } from '../../../configs';
8
+ import { API, Constants } from '../../../configs';
7
9
  import { SCProvider } from '../../../context';
8
10
  import { mockSCStore } from '../../../context/mockStore';
9
11
  import ItemLog from '../ItemLog';
@@ -11,7 +13,7 @@ import DateTimeRangeChange from '../../../commons/DateTimeRangeChange';
11
13
  import DateTimePickerModal from 'react-native-modal-datetime-picker';
12
14
  import Modal from 'react-native-modal';
13
15
  import { AUTOMATE_TYPE, TESTID } from '../../../configs/Constants';
14
- import axios from 'axios';
16
+ import api from '../../../utils/Apis/axios';
15
17
 
16
18
  const mockUseSelector = jest.fn();
17
19
 
@@ -30,7 +32,7 @@ jest.mock('react', () => {
30
32
  };
31
33
  });
32
34
 
33
- jest.mock('axios');
35
+ const mock = new MockAdapter(api.axiosInstance);
34
36
 
35
37
  const wrapComponent = (route) => (
36
38
  <SCProvider initState={mockSCStore({})}>
@@ -52,9 +54,7 @@ describe('Test Activity log', () => {
52
54
  Date.now = jest.fn(() => new Date('2021-07-02T15:48:24.917932Z'));
53
55
 
54
56
  it('render empty list', async () => {
55
- axios.get.mockImplementation(async () => {
56
- return { status: 400 };
57
- });
57
+ mock.onGet(API.AUTOMATE.ACTIVITY_LOG(1)).reply(400);
58
58
  await act(async () => {
59
59
  tree = await create(wrapComponent(route));
60
60
  });
@@ -69,21 +69,39 @@ describe('Test Activity log', () => {
69
69
  });
70
70
  });
71
71
 
72
- it('render list', async () => {
73
- axios.get.mockImplementationOnce(() => ({
74
- status: 200,
75
- data: {
76
- results: [
77
- {
78
- id: 1,
79
- content_code: 'ACTIVATED_BY',
80
- params: { username: 'name' },
81
- created_at: '2021-07-01T15:48:24.917932Z',
82
- },
83
- ],
84
- count: 1,
72
+ it('render without params', async () => {
73
+ await act(async () => {
74
+ tree = await create(wrapComponent({}));
75
+ });
76
+ const instance = tree.root;
77
+ const SectionListElement = instance.findAllByType(SectionList);
78
+ expect(SectionListElement).toHaveLength(1);
79
+ const TextElement = instance.findAllByType(Text);
80
+ expect(TextElement[2].props.style).toEqual([
81
+ {
82
+ color: '#000',
83
+ fontFamily: 'SFProDisplay-Regular',
84
+ fontSize: undefined,
85
+ lineHeight: undefined,
86
+ textAlign: 'left',
87
+ textDecorationLine: 'none',
85
88
  },
86
- }));
89
+ { textAlign: 'center' },
90
+ ]);
91
+ });
92
+
93
+ it('render list', async () => {
94
+ mock.onGet(API.AUTOMATE.ACTIVITY_LOG(1)).reply(200, {
95
+ results: [
96
+ {
97
+ id: 1,
98
+ content_code: 'ACTIVATED_BY',
99
+ params: { username: 'name' },
100
+ created_at: '2021-07-01T15:48:24.917932Z',
101
+ },
102
+ ],
103
+ count: 1,
104
+ });
87
105
  await act(async () => {
88
106
  tree = await create(wrapComponent(route));
89
107
  });
@@ -93,9 +111,6 @@ describe('Test Activity log', () => {
93
111
  });
94
112
 
95
113
  it('test open and close 2 modal', async () => {
96
- axios.get.mockImplementation(async () => {
97
- return { status: 400 };
98
- });
99
114
  await act(async () => {
100
115
  tree = await create(wrapComponent(route));
101
116
  });