@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,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
- import axios from 'axios';
3
+ import MockAdapter from 'axios-mock-adapter';
4
4
  import { Animated, RefreshControl } from 'react-native';
5
5
 
6
6
  import { SCProvider } from '../../../context';
@@ -8,6 +8,7 @@ import { mockSCStore } from '../../../context/mockStore';
8
8
  import Notification from '../index';
9
9
  import NotificationItem from '../components/NotificationItem';
10
10
  import { API } from '../../../configs';
11
+ import api from '../../../utils/Apis/axios';
11
12
 
12
13
  const wrapComponent = () => (
13
14
  <SCProvider initState={mockSCStore({})}>
@@ -15,7 +16,7 @@ const wrapComponent = () => (
15
16
  </SCProvider>
16
17
  );
17
18
 
18
- jest.mock('axios');
19
+ const mock = new MockAdapter(api.axiosInstance);
19
20
 
20
21
  jest.mock('react', () => {
21
22
  return {
@@ -53,9 +54,9 @@ describe('test Notification', () => {
53
54
  ],
54
55
  },
55
56
  };
56
- axios.get.mockImplementation(async () => {
57
- return response;
58
- });
57
+ mock
58
+ .onGet(API.NOTIFICATION.LIST_EOH_NOTIFICATIONS(1, ''))
59
+ .reply(200, response.data);
59
60
  await act(async () => {
60
61
  tree = await create(wrapComponent());
61
62
  });
@@ -63,10 +64,6 @@ describe('test Notification', () => {
63
64
  const notificationItem = instance.findAllByType(NotificationItem);
64
65
 
65
66
  expect(notificationItem).toHaveLength(2);
66
- expect(axios.get).toHaveBeenCalledWith(
67
- API.NOTIFICATION.LIST_EOH_NOTIFICATIONS(1, ''),
68
- {}
69
- );
70
67
  });
71
68
 
72
69
  test('test handleOnLoadMore', async () => {
@@ -95,22 +92,18 @@ describe('test Notification', () => {
95
92
  ],
96
93
  },
97
94
  };
98
- axios.get.mockImplementation(async () => {
99
- return response;
100
- });
95
+ mock
96
+ .onGet(API.NOTIFICATION.LIST_EOH_NOTIFICATIONS(1, ''))
97
+ .reply(200, response.data);
101
98
  await act(async () => {
102
99
  tree = await create(wrapComponent());
103
100
  });
104
101
  const instance = tree.root;
105
102
  const scrollView = instance.findByType(Animated.ScrollView);
106
-
107
103
  act(() => {
108
104
  scrollView.props.onMomentumScrollEnd();
109
105
  });
110
- expect(axios.get).toHaveBeenCalledWith(
111
- API.NOTIFICATION.LIST_EOH_NOTIFICATIONS(1, ''),
112
- {}
113
- );
106
+ expect(scrollView).toBeDefined();
114
107
  });
115
108
 
116
109
  test('test onRefresh', async () => {
@@ -139,21 +132,17 @@ describe('test Notification', () => {
139
132
  ],
140
133
  },
141
134
  };
142
- axios.get.mockImplementation(async () => {
143
- return response;
144
- });
135
+ mock
136
+ .onGet(API.NOTIFICATION.LIST_EOH_NOTIFICATIONS(1, ''))
137
+ .reply(200, response.data);
145
138
  await act(async () => {
146
139
  tree = await create(wrapComponent());
147
140
  });
148
141
  const instance = tree.root;
149
142
  const refreshControl = instance.findByType(RefreshControl);
150
-
151
143
  act(() => {
152
144
  refreshControl.props.onRefresh();
153
145
  });
154
- expect(axios.get).toHaveBeenCalledWith(
155
- API.NOTIFICATION.LIST_EOH_NOTIFICATIONS(1, ''),
156
- {}
157
- );
146
+ expect(refreshControl).toBeDefined();
158
147
  });
159
148
  });
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
3
  import { TouchableOpacity } from 'react-native';
4
- import axios from 'axios';
4
+ import MockAdapter from 'axios-mock-adapter';
5
5
 
6
6
  import { SCProvider } from '../../../context';
7
7
  import { mockSCStore } from '../../../context/mockStore';
@@ -9,6 +9,7 @@ import NotificationItem from '../components/NotificationItem';
9
9
  import { NOTIFICATION_TYPES, SENSOR_TYPE } from '../../../configs/Constants';
10
10
  import Routes from '../../../utils/Route';
11
11
  import { API } from '../../../configs';
12
+ import api from '../../../utils/Apis/axios';
12
13
 
13
14
  const wrapComponent = (item) => (
14
15
  <SCProvider initState={mockSCStore({})}>
@@ -16,7 +17,7 @@ const wrapComponent = (item) => (
16
17
  </SCProvider>
17
18
  );
18
19
 
19
- jest.mock('axios');
20
+ const mock = new MockAdapter(api.axiosInstance);
20
21
 
21
22
  const mockNavigate = jest.fn();
22
23
  jest.mock('@react-navigation/native', () => {
@@ -238,10 +239,10 @@ describe('test NotificationItem', () => {
238
239
  });
239
240
  const instance = tree.root;
240
241
  const button = instance.findByType(TouchableOpacity);
242
+ mock.onPost(API.NOTIFICATION.SET_READ(1)).reply(200);
241
243
  act(() => {
242
244
  button.props.onPress();
243
245
  });
244
- expect(axios.post).toHaveBeenCalledWith(API.NOTIFICATION.SET_READ(1));
245
246
  expect(mockNavigate).toHaveBeenCalledWith(Routes.UnitStack, {
246
247
  screen: Routes.UnitSummary,
247
248
  params: {
@@ -253,10 +254,10 @@ describe('test NotificationItem', () => {
253
254
 
254
255
  test('test render Notify not in any case', () => {
255
256
  item.content_code = 'NEW CASE';
256
- (item.params = "{ 'unit_id': 1 }"),
257
- act(() => {
258
- tree = create(wrapComponent(item));
259
- });
257
+ item.params = "{ 'unit_id': 1 }";
258
+ act(() => {
259
+ tree = create(wrapComponent(item));
260
+ });
260
261
  const instance = tree.root;
261
262
  const button = instance.findByType(TouchableOpacity);
262
263
  act(() => {
@@ -41,7 +41,7 @@ const NotificationItem = memo(({ item }) => {
41
41
  return values;
42
42
  }, [paramsJSON]);
43
43
 
44
- const customColorText = (text, params) => {
44
+ const customColorText = (text, colorParams) => {
45
45
  return text.split('**').map((str, i) =>
46
46
  i % 2 === 0 ? (
47
47
  <Text type="Body" key={i} style={styles.textNotification}>
@@ -49,7 +49,7 @@ const NotificationItem = memo(({ item }) => {
49
49
  </Text>
50
50
  ) : (
51
51
  <Text type="Body" bold key={i} style={styles.textNotification}>
52
- {params[(i - 1) / 2]}
52
+ {colorParams[(i - 1) / 2]}
53
53
  </Text>
54
54
  )
55
55
  );
@@ -167,7 +167,6 @@ const NotificationItem = memo(({ item }) => {
167
167
  }),
168
168
  };
169
169
  case NOTIFICATION_TYPES.BOOKING_EXPIRED_AND_VIOLATION_CREATED:
170
- const violated_booking_id = paramsJSON.violated_booking_id;
171
170
  return {
172
171
  content: customColorText(
173
172
  t(
@@ -178,7 +177,7 @@ const NotificationItem = memo(({ item }) => {
178
177
  redirect: () =>
179
178
  navigation.navigate(Routes.SmartParkingStack, {
180
179
  screen: Routes.SmartParkingBookingDetails,
181
- params: { id: violated_booking_id || booking_id },
180
+ params: { id: paramsJSON.violated_booking_id || booking_id },
182
181
  }),
183
182
  };
184
183
  case NOTIFICATION_TYPES.MOVE_CAR_WITHOUT_PAY_VIOLATION:
@@ -206,7 +205,6 @@ const NotificationItem = memo(({ item }) => {
206
205
  }),
207
206
  };
208
207
  case NOTIFICATION_TYPES.PAY_FINE_AND_EXTEND_SUCCESSFULLY:
209
- const new_booking_id = paramsJSON.booking_id_new;
210
208
  return {
211
209
  content: customColorText(
212
210
  t('text_notification_content_pay_fine_and_extend_successfully'),
@@ -215,7 +213,7 @@ const NotificationItem = memo(({ item }) => {
215
213
  redirect: () =>
216
214
  navigation.navigate(Routes.SmartParkingStack, {
217
215
  screen: Routes.SmartParkingBookingDetails,
218
- params: { id: new_booking_id },
216
+ params: { id: paramsJSON.booking_id_new },
219
217
  }),
220
218
  };
221
219
  case NOTIFICATION_TYPES.STOP_VIOLATION_FREE_PARKING_ZONE:
@@ -231,8 +229,7 @@ const NotificationItem = memo(({ item }) => {
231
229
  }),
232
230
  };
233
231
  case NOTIFICATION_TYPES.NOTIFY_INDICATOR:
234
- const { sensor_type, summary_id } = paramsJSON;
235
- switch (sensor_type) {
232
+ switch (paramsJSON.sensor_type) {
236
233
  case SENSOR_TYPE.AIR_QUALITY:
237
234
  return {
238
235
  content: customColorText(
@@ -243,7 +240,7 @@ const NotificationItem = memo(({ item }) => {
243
240
  navigation.navigate(Routes.UnitStack, {
244
241
  screen: Routes.UnitSummary,
245
242
  params: {
246
- summaryId: summary_id,
243
+ summaryId: paramsJSON.summary_id,
247
244
  unitId,
248
245
  },
249
246
  }),
@@ -259,7 +256,7 @@ const NotificationItem = memo(({ item }) => {
259
256
  navigation.navigate(Routes.UnitStack, {
260
257
  screen: Routes.UnitSummary,
261
258
  params: {
262
- summaryId: summary_id,
259
+ summaryId: paramsJSON.summary_id,
263
260
  unitId,
264
261
  },
265
262
  }),
@@ -275,7 +272,7 @@ const NotificationItem = memo(({ item }) => {
275
272
  navigation.navigate(Routes.UnitStack, {
276
273
  screen: Routes.UnitSummary,
277
274
  params: {
278
- summaryId: summary_id,
275
+ summaryId: paramsJSON.summary_id,
279
276
  unitId,
280
277
  },
281
278
  }),
@@ -291,7 +288,7 @@ const NotificationItem = memo(({ item }) => {
291
288
  navigation.navigate(Routes.UnitStack, {
292
289
  screen: Routes.UnitSummary,
293
290
  params: {
294
- summaryId: summary_id,
291
+ summaryId: paramsJSON.summary_id,
295
292
  unitId,
296
293
  },
297
294
  }),
@@ -307,7 +304,7 @@ const NotificationItem = memo(({ item }) => {
307
304
  navigation.navigate(Routes.UnitStack, {
308
305
  screen: Routes.UnitSummary,
309
306
  params: {
310
- summaryId: summary_id,
307
+ summaryId: paramsJSON.summary_id,
311
308
  unitId,
312
309
  },
313
310
  }),
@@ -388,12 +385,13 @@ const NotificationItem = memo(({ item }) => {
388
385
  }
389
386
 
390
387
  case NOTIFICATION_TYPES.NOTIFY_REMOVE_UNIT:
391
- const unitOwerName = paramsJSON?.unit_owner_name;
392
- const textNotify = unitOwerName
393
- ? t('text_notification_content_remove_unit_to_member')
394
- : t('text_notification_content_remove_unit_to_owner');
395
388
  return {
396
- content: customColorText(textNotify, arrParams),
389
+ content: customColorText(
390
+ paramsJSON?.unit_owner_name
391
+ ? t('text_notification_content_remove_unit_to_member')
392
+ : t('text_notification_content_remove_unit_to_owner'),
393
+ arrParams
394
+ ),
397
395
  redirect: () => null,
398
396
  iconContent: (
399
397
  <IconComponent icon={'home'} style={styles.backgroundSummer} />
@@ -474,7 +472,6 @@ const NotificationItem = memo(({ item }) => {
474
472
  ),
475
473
  };
476
474
  case NOTIFICATION_TYPES.NOTIFY_RENAME_SUB_UNIT:
477
- const stationId = paramsJSON?.sub_unit_id;
478
475
  return {
479
476
  content: customColorText(
480
477
  t('text_notification_content_rename_sub_unit'),
@@ -485,7 +482,7 @@ const NotificationItem = memo(({ item }) => {
485
482
  screen: Routes.UnitDetail,
486
483
  params: {
487
484
  unitId,
488
- stationId,
485
+ stationId: paramsJSON?.sub_unit_id,
489
486
  },
490
487
  });
491
488
  },
@@ -13,6 +13,7 @@ import {
13
13
  unwatchNotificationData,
14
14
  } from '../../utils/Monitor';
15
15
  import { useSCContextSelector } from '../../context';
16
+ import { notImplemented } from '../../utils/Utils';
16
17
 
17
18
  let page = 1;
18
19
 
@@ -26,12 +27,18 @@ const Notification = memo(() => {
26
27
  <View style={styles.rightComponent}>
27
28
  <TouchableOpacity
28
29
  style={styles.iconPlus}
29
- onPress={() => alert(t('feature_under_development'))}
30
+ onPress={() => {
31
+ notImplemented(t);
32
+ }}
30
33
  >
31
34
  <Icon name={'plus'} size={27} color={Colors.Black} />
32
35
  </TouchableOpacity>
33
36
 
34
- <TouchableOpacity onPress={() => alert(t('feature_under_development'))}>
37
+ <TouchableOpacity
38
+ onPress={() => {
39
+ notImplemented(t);
40
+ }}
41
+ >
35
42
  <Icon name={'search'} size={27} color={Colors.Black} />
36
43
  </TouchableOpacity>
37
44
  </View>
@@ -70,8 +70,8 @@ const Timer = ({
70
70
  }, []);
71
71
 
72
72
  useEffect(() => {
73
- const scrollListener = scrollX.addListener(({ value }) => {
74
- !isFirstTime && onChangeValue && onChangeValue(value, selected);
73
+ const scrollListener = scrollX.addListener(({ value: timeValue }) => {
74
+ !isFirstTime && onChangeValue && onChangeValue(timeValue, selected);
75
75
  });
76
76
  return () => scrollX.removeListener(scrollListener);
77
77
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1,7 +1,11 @@
1
+ import moment from 'moment';
1
2
  import React from 'react';
3
+ import { Animated, TouchableOpacity } from 'react-native';
2
4
  import { act, create } from 'react-test-renderer';
3
5
  import PlayBackCamera from '..';
4
6
  import { ModalCustom } from '../../../commons/Modal';
7
+ import Text from '../../../commons/Text';
8
+ import { TESTID } from '../../../configs/Constants';
5
9
  import { SCProvider } from '../../../context';
6
10
  import { mockSCStore } from '../../../context/mockStore';
7
11
 
@@ -26,14 +30,95 @@ const wrapComponent = () => (
26
30
  </SCProvider>
27
31
  );
28
32
 
33
+ const mockSetState = jest.fn();
34
+ jest.mock('react', () => {
35
+ return {
36
+ ...jest.requireActual('react'),
37
+ useState: jest.fn((init) => [init, mockSetState]),
38
+ memo: (x) => x,
39
+ };
40
+ });
41
+
42
+ let dateTemp = moment().format('YYYY-MM-DD');
43
+
29
44
  describe('Test PlayBackCamera', () => {
30
45
  let tree;
46
+ jest.useFakeTimers();
47
+
31
48
  it('Test render', async () => {
32
- await act(() => {
33
- tree = create(wrapComponent());
49
+ await act(async () => {
50
+ tree = await create(wrapComponent());
34
51
  });
35
52
  const instance = tree.root;
36
53
  const HeaderCustoms = instance.findAllByType(ModalCustom);
37
54
  expect(HeaderCustoms).toHaveLength(2);
55
+ const textOpenModal = instance.findAll(
56
+ (el) => el.props.testID === TESTID.OPEN_DATE_MODAL && el.type === Text
57
+ );
58
+ await textOpenModal[0].props.onPress();
59
+ expect(mockSetState).toBeCalledWith(true);
60
+
61
+ mockSetState.mockClear();
62
+ const buttonCancel = instance.findAll(
63
+ (el) =>
64
+ el.props.testID === TESTID.ON_PRESS_CANCEL &&
65
+ el.type === TouchableOpacity
66
+ );
67
+ await buttonCancel[0].props.onPress();
68
+ expect(mockSetState).toBeCalledWith(false);
69
+ expect(mockSetState).toBeCalledWith(dateTemp);
70
+
71
+ mockSetState.mockClear();
72
+ const buttonOK = instance.findAll(
73
+ (el) =>
74
+ el.props.testID === TESTID.ON_PRESS_OK && el.type === TouchableOpacity
75
+ );
76
+ await buttonOK[0].props.onPress();
77
+ expect(mockSetState).toBeCalledWith(false);
78
+
79
+ mockSetState.mockClear();
80
+ const buttonAddDate = instance.findAll(
81
+ (el) =>
82
+ el.props.testID === TESTID.ON_PRESS_ADD_DATE &&
83
+ el.type === TouchableOpacity
84
+ );
85
+ await buttonAddDate[0].props.onPress();
86
+ expect(mockSetState).not.toBeCalled();
87
+
88
+ mockSetState.mockClear();
89
+ const buttonSubDate = instance.findAll(
90
+ (el) =>
91
+ el.props.testID === TESTID.ON_PRESS_SUB_DATE &&
92
+ el.type === TouchableOpacity
93
+ );
94
+ await buttonSubDate[0].props.onPress();
95
+ expect(mockSetState).toBeCalledWith(
96
+ moment(dateTemp).subtract(1, 'days').format('YYYY-MM-DD')
97
+ );
98
+
99
+ mockSetState.mockClear();
100
+ const timer = instance.findAllByType(Animated.ScrollView);
101
+ //NOTE: isFirstTime = true
102
+ timer[0].props.onScroll({
103
+ nativeEvent: {
104
+ contentInset: { bottom: 10, left: 10, right: 10, top: 10 },
105
+ contentOffset: { x: 10, y: 0 },
106
+ contentSize: { height: 10, width: 10 },
107
+ layoutMeasurement: { height: 10, width: 10 },
108
+ zoomScale: 1,
109
+ },
110
+ });
111
+ jest.runAllTimers();
112
+ //NOTE: isFirstTime = false
113
+ timer[0].props.onScroll({
114
+ nativeEvent: {
115
+ contentInset: { bottom: 10, left: 10, right: 10, top: 10 },
116
+ contentOffset: { x: 60, y: 0 },
117
+ contentSize: { height: 10, width: 10 },
118
+ layoutMeasurement: { height: 10, width: 10 },
119
+ zoomScale: 1,
120
+ },
121
+ });
122
+ expect(mockSetState).toBeCalledWith({ h: '00', m: '37', s: 30 });
38
123
  });
39
124
  });
@@ -13,6 +13,7 @@ import Text from '../../commons/Text';
13
13
  import Timer from './Timer';
14
14
  import { useStatusBarPreview } from '../../hooks/Common/useStatusBar';
15
15
  import MediaPlayerFull from '../../commons/MediaPlayerDetail/MediaPlayerFull';
16
+ import { TESTID } from '../../configs/Constants';
16
17
 
17
18
  let dateTemp = moment().format('YYYY-MM-DD');
18
19
  let isFirstTime = true;
@@ -61,7 +62,7 @@ const PlayBackCamera = () => {
61
62
  dateTemp = date;
62
63
  }, [selected]);
63
64
 
64
- const onChangeValue = (value, selected) => {
65
+ const onChangeValue = (value, selectedTime) => {
65
66
  if (!isFirstTime) {
66
67
  const currentTime =
67
68
  parseFloat(arrHourTemp[0]) +
@@ -77,11 +78,11 @@ const PlayBackCamera = () => {
77
78
  const m = t4[0] < 10 ? '0' + t4[0] : t4[0];
78
79
  const s = t5 < 10 ? '0' + t5 : t5;
79
80
  setHour({ h, m, s });
80
- if (value + 0.5 > currentTime * 96 && selected === now) {
81
+ if (value + 0.5 > currentTime * 96 && selectedTime === now) {
81
82
  setUri(item?.configuration?.uri);
82
83
  } else {
83
84
  const playback = item?.configuration?.playback || '';
84
- const date = selected.split('-');
85
+ const date = selectedTime.split('-');
85
86
  setUri(
86
87
  `${playback.split('=')[0]}=${date[0]}${date[1]}${
87
88
  date[2]
@@ -151,12 +152,18 @@ const PlayBackCamera = () => {
151
152
  <View style={styles.container}>
152
153
  <View style={styles.row}>
153
154
  <TouchableOpacity
155
+ testID={TESTID.ON_PRESS_SUB_DATE}
154
156
  onPress={onSubtractDate}
155
157
  style={styles.commomButton}
156
158
  >
157
159
  <Image source={Images.arrowLeft} />
158
160
  </TouchableOpacity>
159
- <Text onPress={onOpenDateModal} style={styles.textDate} type="h4">
161
+ <Text
162
+ testID={TESTID.OPEN_DATE_MODAL}
163
+ onPress={onOpenDateModal}
164
+ style={styles.textDate}
165
+ type="h4"
166
+ >
160
167
  {moment(selected).format('DD/MM/YYYY')}
161
168
  </Text>
162
169
  <TouchableOpacity
@@ -165,7 +172,11 @@ const PlayBackCamera = () => {
165
172
  >
166
173
  <Image source={Images.file} style={styles.iconDate} />
167
174
  </TouchableOpacity>
168
- <TouchableOpacity onPress={onAddDate} style={styles.commomButton}>
175
+ <TouchableOpacity
176
+ testID={TESTID.ON_PRESS_ADD_DATE}
177
+ onPress={onAddDate}
178
+ style={styles.commomButton}
179
+ >
169
180
  <Image source={Images.arrowLeft} style={styles.arrowRight} />
170
181
  </TouchableOpacity>
171
182
  </View>
@@ -231,12 +242,17 @@ const PlayBackCamera = () => {
231
242
  <TouchableOpacity
232
243
  onPress={onPressCancel}
233
244
  style={styles.commomButton}
245
+ testID={TESTID.ON_PRESS_CANCEL}
234
246
  >
235
247
  <Text type="h4" semibold hilight>
236
248
  {t('cancel')}
237
249
  </Text>
238
250
  </TouchableOpacity>
239
- <TouchableOpacity onPress={onPressOk} style={styles.commomButton}>
251
+ <TouchableOpacity
252
+ testID={TESTID.ON_PRESS_OK}
253
+ onPress={onPressOk}
254
+ style={styles.commomButton}
255
+ >
240
256
  <Text type="h4" semibold hilight>
241
257
  {t('done')}
242
258
  </Text>
@@ -1,12 +1,14 @@
1
1
  import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
- import axios from 'axios';
3
+ import MockAdapter from 'axios-mock-adapter';
4
4
 
5
5
  import { SCProvider } from '../../../context';
6
6
  import { mockSCStore } from '../../../context/mockStore';
7
7
  import ScanChipQR from '..';
8
8
  import QRScan from '../components/QRScan';
9
9
  import Routes from '../../../utils/Route';
10
+ import api from '../../../utils/Apis/axios';
11
+ import { API } from '../../../configs';
10
12
 
11
13
  const wrapComponent = (route) => (
12
14
  <SCProvider initState={mockSCStore({})}>
@@ -17,7 +19,7 @@ const wrapComponent = (route) => (
17
19
  const mockedNavigate = jest.fn();
18
20
  const mockedGoBack = jest.fn();
19
21
 
20
- jest.mock('axios');
22
+ const mock = new MockAdapter(api.axiosInstance);
21
23
 
22
24
  jest.mock('react', () => {
23
25
  return { ...jest.requireActual('react'), memo: (x) => x };
@@ -48,10 +50,6 @@ describe('test ScanChipQR', () => {
48
50
  };
49
51
  });
50
52
 
51
- afterEach(() => {
52
- axios.get.mockClear();
53
- });
54
-
55
53
  test('create ScanChipQR', async () => {
56
54
  let tree;
57
55
  await act(async () => {
@@ -68,13 +66,8 @@ describe('test ScanChipQR', () => {
68
66
  id: 1,
69
67
  name: 'ABC',
70
68
  };
71
- const response = {
72
- status: 200,
73
- data: new_chip,
74
- };
75
- axios.post.mockImplementation(async () => {
76
- return response;
77
- });
69
+
70
+ mock.onPost(API.UNIT.CHIP_SCAN_GET_WIFI_INFO()).reply(200, new_chip);
78
71
 
79
72
  let tree;
80
73
  const body = { id: 1, imei: 'SENSOR-X341241', name: 'New Chip' };
@@ -104,13 +97,7 @@ describe('test ScanChipQR', () => {
104
97
  id: 1,
105
98
  name: 'ABC',
106
99
  };
107
- const response = {
108
- data: new_chip,
109
- };
110
- axios.post.mockImplementation(async () => {
111
- return response;
112
- });
113
-
100
+ mock.onPost(API.UNIT.CHIP_SCAN_GET_WIFI_INFO()).reply(200, new_chip);
114
101
  let tree;
115
102
  const body = { id: 1, imei: 'IMEI_X', name: 'New Chip' };
116
103
  await act(async () => {
@@ -3,6 +3,7 @@ import API from '../../../configs/API';
3
3
  import { useCallback, useState } from 'react';
4
4
  import { axiosPost } from '../../../utils/Apis/axios';
5
5
  import Routes from '../../../utils/Route';
6
+ import { ToastBottomHelper } from '../../../utils/Utils';
6
7
 
7
8
  const useChipScan = (route) => {
8
9
  const {
@@ -48,28 +49,26 @@ const useChipScan = (route) => {
48
49
  }
49
50
  );
50
51
  if (success) {
51
- if (new_chip.is_wifi) {
52
- navigation.navigate(Routes.ConnectWifiWarning, {
53
- wifi_ssid: new_chip.wifi_ssid,
54
- wifi_pass: new_chip.wifi_pass,
55
- chip_id: new_chip.id,
56
- unit_id: unit_id,
57
- unit_name: unit_name,
58
- devicePrefixName,
59
- body,
60
- });
61
- } else {
62
- navigation.navigate(Routes.ConnectingGateway, {
63
- new_chip,
64
- ...route.params,
65
- });
66
- }
52
+ navigation.navigate(Routes.ConnectWifiWarning, {
53
+ wifi_ssid: new_chip.wifi_ssid,
54
+ wifi_pass: new_chip.wifi_pass,
55
+ chip_id: new_chip.id,
56
+ unit_id: unit_id,
57
+ unit_name: unit_name,
58
+ devicePrefixName,
59
+ body,
60
+ });
67
61
  } else {
62
+ ToastBottomHelper.error(
63
+ 'Fail to fetch wifi info',
64
+ devicePrefixName
65
+ );
68
66
  navigation.goBack();
69
67
  }
70
68
  }
71
69
  break;
72
70
  default:
71
+ ToastBottomHelper.error('Invalid QR prefix', devicePrefixName);
73
72
  navigation.goBack();
74
73
  break;
75
74
  }