@eohjsc/react-native-smart-city 0.2.97 → 0.3.0

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 (197) hide show
  1. package/README.md +35 -14
  2. package/package.json +4 -2
  3. package/src/commons/Action/ItemQuickAction.js +5 -2
  4. package/src/commons/ActionGroup/ColorPickerTemplate.js +1 -1
  5. package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
  6. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +12 -4
  7. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
  8. package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLock.js +7 -4
  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/OnOffSmartLock/SetupGeneratePasscode/index.js +1 -0
  13. package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplate.js +10 -10
  14. package/src/commons/ActionGroup/OnOffTemplate/index.js +18 -15
  15. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +9 -3
  16. package/src/commons/ActionGroup/SliderRangeTemplate.js +1 -1
  17. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +4 -1
  18. package/src/commons/ActionGroup/StatesGridActionTemplate.js +22 -8
  19. package/src/commons/ActionGroup/TimerActionTemplate.js +11 -3
  20. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +13 -9
  21. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
  22. package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +14 -14
  23. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +53 -78
  24. package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +36 -20
  25. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
  26. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
  27. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
  28. package/src/commons/ActionGroup/__test__/index.test.js +135 -0
  29. package/src/commons/Auth/AccountList.js +1 -1
  30. package/src/commons/Automate/ItemAutomate.js +1 -3
  31. package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
  32. package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
  33. package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
  34. package/src/commons/ConnectingProcess/index.js +1 -1
  35. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
  36. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
  37. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
  38. package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
  39. package/src/commons/Device/HistoryChart.js +4 -0
  40. package/src/commons/Device/LinearChart.js +15 -0
  41. package/src/commons/Device/PMSensor/PMSensorIndicatior.js +16 -12
  42. package/src/commons/Device/PMSensor/PMSensorIndicatorStyles.js +3 -0
  43. package/src/commons/Device/WaterQualitySensor/ListQualityIndicator.js +1 -0
  44. package/src/commons/Explore/__test__/CityItem.test.js +33 -54
  45. package/src/commons/FieldTemplate/ChooseUserField/ChooseFieldStyles.js +25 -0
  46. package/src/commons/FieldTemplate/ChooseUserField/ChoosePopup.js +96 -0
  47. package/src/commons/FieldTemplate/ChooseUserField/ChoosePopupStyles.js +39 -0
  48. package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +118 -0
  49. package/src/commons/FieldTemplate/ChooseUserField/index.js +62 -0
  50. package/src/commons/FieldTemplate/PasscodeField/PasscodeFieldStyles.js +30 -0
  51. package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +90 -0
  52. package/src/commons/FieldTemplate/PasscodeField/index.js +43 -0
  53. package/src/commons/FieldTemplate/ScheduleField/ScheduleFieldStyles.js +13 -0
  54. package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +179 -0
  55. package/src/commons/FieldTemplate/ScheduleField/index.js +176 -0
  56. package/src/commons/FullLoading/index.js +2 -1
  57. package/src/commons/MenuActionAddnew/index.js +1 -0
  58. package/src/commons/MenuActionList/index.js +1 -0
  59. package/src/commons/MenuActionMore/index.js +1 -1
  60. package/src/commons/PreventAccess/__test__/PreventAccess.test.js +62 -0
  61. package/src/commons/PreventAccess/index.js +9 -1
  62. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
  63. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
  64. package/src/commons/SubUnit/OneTap/index.js +1 -2
  65. package/src/commons/Unit/SharedUnit.js +1 -0
  66. package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
  67. package/src/commons/WheelDateTimePicker/index.js +2 -1
  68. package/src/configs/API.js +87 -138
  69. package/src/configs/Constants.js +27 -1
  70. package/src/configs/SCConfig.js +2 -0
  71. package/src/iot/RemoteControl/__test__/GoogleHome.test.js +8 -30
  72. package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
  73. package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
  74. package/src/navigations/UnitStack.js +8 -0
  75. package/src/screens/AQIGuide/index.js +1 -1
  76. package/src/screens/ActivityLog/FilterPopup.js +2 -0
  77. package/src/screens/ActivityLog/__test__/index.test.js +38 -23
  78. package/src/screens/ActivityLog/hooks/__test__/index.test.js +51 -90
  79. package/src/screens/ActivityLog/index.js +2 -2
  80. package/src/screens/AddCommon/SelectSubUnit.js +1 -0
  81. package/src/screens/AddCommon/SelectUnit.js +1 -0
  82. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
  83. package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
  84. package/src/screens/AddLocationMaps/index.js +4 -1
  85. package/src/screens/AddNewAction/SelectSensorDevices.js +8 -2
  86. package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
  87. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
  88. package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +3 -1
  89. package/src/screens/AddNewAutoSmart/index.js +5 -2
  90. package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
  91. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -33
  92. package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
  93. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +21 -21
  94. package/src/screens/AddNewDevice/index.js +1 -0
  95. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +4 -1
  96. package/src/screens/AddNewGateway/SelectGateway.js +1 -0
  97. package/src/screens/AddNewGateway/SetupGatewayWifi.js +1 -0
  98. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
  99. package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
  100. package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
  101. package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
  102. package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
  103. package/src/screens/AddNewGateway/index.js +1 -0
  104. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +10 -24
  105. package/src/screens/AddNewOneTap/index.js +3 -2
  106. package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
  107. package/src/screens/Automate/__test__/index.test.js +7 -12
  108. package/src/screens/Automate/index.js +2 -0
  109. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
  110. package/src/screens/ConfirmUnitDeletion/index.js +7 -1
  111. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
  112. package/src/screens/Device/__test__/detail.test.js +23 -84
  113. package/src/screens/Device/detail.js +31 -8
  114. package/src/screens/Device/hooks/useFavoriteDevice.js +5 -9
  115. package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
  116. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +6 -3
  117. package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
  118. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +20 -2
  119. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +40 -23
  120. package/src/screens/EmergencySetting/index.js +4 -1
  121. package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
  122. package/src/screens/Explore/index.js +2 -0
  123. package/src/screens/GuestInfo/__test__/index.test.js +14 -41
  124. package/src/screens/GuestInfo/components/RecurringDetail.js +1 -0
  125. package/src/screens/GuestInfo/components/TemporaryDetail.js +2 -2
  126. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +8 -12
  127. package/src/screens/HanetCamera/__test__/Detail.test.js +27 -42
  128. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +8 -5
  129. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -32
  130. package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +43 -35
  131. package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
  132. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +33 -22
  133. package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +44 -45
  134. package/src/screens/ManageAccess/index.js +2 -1
  135. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
  136. package/src/screens/MoveToAnotherSubUnit/index.js +5 -5
  137. package/src/screens/Notification/__test__/Notification.test.js +14 -25
  138. package/src/screens/Notification/__test__/NotificationItem.test.js +4 -3
  139. package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
  140. package/src/screens/PlayBackCamera/index.js +19 -3
  141. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
  142. package/src/screens/ScanChipQR/components/QRScan/index.js +1 -0
  143. package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +8 -24
  144. package/src/screens/ScriptDetail/__test__/index.test.js +17 -86
  145. package/src/screens/ScriptDetail/index.js +5 -4
  146. package/src/screens/SelectUnit/__test__/index.test.js +12 -55
  147. package/src/screens/SelectUnit/index.js +5 -2
  148. package/src/screens/SetSchedule/index.js +6 -2
  149. package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
  150. package/src/screens/SharedUnit/index.js +2 -0
  151. package/src/screens/Sharing/InfoMemberUnit.js +1 -1
  152. package/src/screens/Sharing/MemberList.js +12 -11
  153. package/src/screens/Sharing/SelectPermission.js +107 -70
  154. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
  155. package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
  156. package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
  157. package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
  158. package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
  159. package/src/screens/Sharing/hooks/index.js +3 -0
  160. package/src/screens/SideMenuDetail/SideMenuDetailStyles.js +28 -0
  161. package/src/screens/SideMenuDetail/__test__/index.test.js +154 -0
  162. package/src/screens/SideMenuDetail/index.js +149 -0
  163. package/src/screens/SmartIr/components/SelectBrand.js +1 -1
  164. package/src/screens/SubUnit/ManageSubUnit.js +1 -0
  165. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +21 -67
  166. package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
  167. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
  168. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +47 -44
  169. package/src/screens/SyncLGDevice/AddLGDevice.js +1 -0
  170. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +14 -90
  171. package/src/screens/TDSGuide/index.js +4 -1
  172. package/src/screens/UVIndexGuide/index.js +1 -1
  173. package/src/screens/Unit/ChooseLocation.js +1 -1
  174. package/src/screens/Unit/ManageUnit.js +1 -0
  175. package/src/screens/Unit/SelectAddress.js +4 -1
  176. package/src/screens/Unit/Station/index.js +1 -0
  177. package/src/screens/Unit/Summaries.js +1 -1
  178. package/src/screens/Unit/__test__/CheckSendEmail.test.js +15 -28
  179. package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
  180. package/src/screens/Unit/__test__/Detail.test.js +83 -185
  181. package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
  182. package/src/screens/Unit/__test__/SelectAddress.test.js +13 -39
  183. package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
  184. package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
  185. package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
  186. package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
  187. package/src/screens/Unit/components/SharedUnit/index.js +1 -0
  188. package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
  189. package/src/screens/UnitSummary/__test__/index.test.js +38 -31
  190. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
  191. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
  192. package/src/screens/WaterQualityGuide/index.js +1 -1
  193. package/src/utils/Apis/axios.js +37 -13
  194. package/src/utils/I18n/translations/en.json +1 -0
  195. package/src/utils/I18n/translations/vi.json +1 -0
  196. package/src/utils/Route/index.js +1 -0
  197. package/src/utils/Utils.js +6 -6
@@ -1,14 +1,18 @@
1
1
  import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
+ import MockAdapter from 'axios-mock-adapter';
3
4
 
4
5
  import ManageAccessScreen from '../index';
5
6
  import { HeaderCustom } from '../../../commons/Header';
6
- import axios from 'axios';
7
7
  import { SCProvider } from '../../../context';
8
8
  import { mockSCStore } from '../../../context/mockStore';
9
9
  import { ScrollView } from 'react-native';
10
10
  import { RowItem } from '../../../commons/RowItem';
11
11
  import Routes from '../../../utils/Route';
12
+ import api from '../../../utils/Apis/axios';
13
+ import { API } from '../../../configs';
14
+
15
+ const mock = new MockAdapter(api.axiosInstance);
12
16
 
13
17
  const mockUseIsFocused = jest.fn();
14
18
  const mockedNavigate = jest.fn();
@@ -31,8 +35,6 @@ jest.mock('@react-navigation/native', () => {
31
35
  };
32
36
  });
33
37
 
34
- jest.mock('axios');
35
-
36
38
  const wrapComponent = (route) => (
37
39
  <SCProvider initState={mockSCStore({})}>
38
40
  <ManageAccessScreen route={route} />
@@ -44,7 +46,6 @@ describe('Test Manage Access', () => {
44
46
  let route;
45
47
 
46
48
  beforeEach(() => {
47
- axios.get.mockClear();
48
49
  mockedNavigate.mockClear();
49
50
  route = {
50
51
  params: {
@@ -59,27 +60,25 @@ describe('Test Manage Access', () => {
59
60
  },
60
61
  };
61
62
  });
63
+
62
64
  it('render Manage Access', async () => {
63
65
  mockUseIsFocused.mockImplementation(() => true);
64
- const response = {
65
- status: 200,
66
- data: [
67
- {
66
+ mock.onGet(API.UNIT.MANAGE_ACCESS(1)).reply(200, [
67
+ {
68
+ id: 1,
69
+ user: {
68
70
  id: 1,
69
- user: {
70
- id: 1,
71
- name: 'jason',
72
- phone_number: '0984524544',
73
- email: '123@gmail.com',
74
- },
75
- access_schedule: 'always',
76
- schedule: 'Always',
71
+ name: 'jason',
72
+ phone_number: '0984524544',
73
+ email: '123@gmail.com',
77
74
  },
78
- ],
79
- };
80
- axios.get.mockImplementation(async () => {
81
- return response;
82
- });
75
+ access_schedule: 'always',
76
+ schedule: 'Always',
77
+ },
78
+ {
79
+ id: 2,
80
+ },
81
+ ]);
83
82
  await act(async () => {
84
83
  tree = await create(wrapComponent(route));
85
84
  });
@@ -89,7 +88,7 @@ describe('Test Manage Access', () => {
89
88
  expect(header).toHaveLength(1);
90
89
  expect(scrollView).toHaveLength(1);
91
90
  const memberButton = instance.findAllByType(RowItem);
92
- expect(memberButton).toHaveLength(1);
91
+ expect(memberButton).toHaveLength(2);
93
92
  await act(async () => {
94
93
  await memberButton[0].props.onPress();
95
94
  });
@@ -97,4 +96,16 @@ describe('Test Manage Access', () => {
97
96
  id: 1,
98
97
  });
99
98
  });
99
+
100
+ it('render Manage Access without params', async () => {
101
+ mockUseIsFocused.mockImplementation(() => false);
102
+ await act(async () => {
103
+ tree = await create(wrapComponent({}));
104
+ });
105
+ const instance = tree.root;
106
+ const header = instance.findAllByType(HeaderCustom);
107
+ const scrollView = instance.findAllByType(ScrollView);
108
+ expect(header).toHaveLength(1);
109
+ expect(scrollView).toHaveLength(1);
110
+ });
100
111
  });
@@ -1,7 +1,10 @@
1
1
  import { act, renderHook } from '@testing-library/react-hooks';
2
+ import MockAdapter from 'axios-mock-adapter';
2
3
  import useManageAccess from '../index';
3
- import axios from 'axios';
4
4
  import API from '../../../../configs/API';
5
+ import api from '../../../../utils/Apis/axios';
6
+
7
+ const mock = new MockAdapter(api.axiosInstance);
5
8
 
6
9
  jest.mock('react', () => {
7
10
  return {
@@ -10,15 +13,7 @@ jest.mock('react', () => {
10
13
  };
11
14
  });
12
15
 
13
- jest.mock('axios');
14
-
15
16
  describe('Test Use Manage Access', () => {
16
- beforeEach(() => {
17
- axios.get.mockClear();
18
- });
19
- afterEach(() => {
20
- axios.get.mockClear();
21
- });
22
17
  const unit = { id: 1, name: 'unit name' };
23
18
  const sensor = {
24
19
  id: 1,
@@ -30,49 +25,53 @@ describe('Test Use Manage Access', () => {
30
25
 
31
26
  it('Test fetch data', () => {
32
27
  const { result } = renderHook(() => useManageAccess(unit, sensor));
33
- axios.get.mockImplementation(() => ({
34
- status: 200,
35
- data: [
36
- {
28
+ mock.onGet(API.UNIT.MANAGE_ACCESS(unit.id)).reply(200, [
29
+ {
30
+ id: 1,
31
+ user: {
37
32
  id: 1,
38
- user: {
39
- id: 1,
40
- name: 'jason',
41
- phone_number: '0984524544',
42
- email: '123@gmail.com',
43
- },
44
- access_schedule: 'always',
45
- schedule: 'Always',
33
+ name: 'jason',
34
+ phone_number: '0984524544',
35
+ email: '123@gmail.com',
46
36
  },
47
- {
48
- id: 2,
49
- user: {
50
- id: 1,
51
- name: 'mike',
52
- phone_number: '0984524144',
53
- email: '1235@gmail.com',
54
- },
55
- access_schedule: 'recurring',
56
- schedule: 'M/T 02:40 - 08:40 AM',
37
+ access_schedule: 'always',
38
+ schedule: 'Always',
39
+ },
40
+ {
41
+ id: 2,
42
+ user: {
43
+ id: 1,
44
+ name: 'mike',
45
+ phone_number: '0984524144',
46
+ email: '1235@gmail.com',
57
47
  },
58
- {
59
- id: 3,
60
- user: {
61
- id: 1,
62
- name: 'david',
63
- phone_number: '0984524541',
64
- email: '1234@gmail.com',
65
- },
66
- access_schedule: 'temporary',
67
- schedule: '02:40 09/08/2020 - 08:40 09/10/2020',
48
+ access_schedule: 'recurring',
49
+ schedule: 'M/T 02:40 - 08:40 AM',
50
+ },
51
+ {
52
+ id: 3,
53
+ user: {
54
+ id: 1,
55
+ name: 'david',
56
+ phone_number: '0984524541',
57
+ email: '1234@gmail.com',
68
58
  },
69
- ],
70
- }));
59
+ access_schedule: 'temporary',
60
+ schedule: '02:40 09/08/2020 - 08:40 09/10/2020',
61
+ },
62
+ ]);
71
63
  act(() => {
72
64
  result.current.onRefresh();
73
65
  });
74
- expect(axios.get).toHaveBeenCalledWith(API.UNIT.MANAGE_ACCESS(unit.id), {
75
- params: { sensor_id: sensor.id },
66
+ expect(result.current.isLoading).toBe(true);
67
+ });
68
+
69
+ it('Test get manage access failure', () => {
70
+ const { result } = renderHook(() => useManageAccess(unit, sensor));
71
+ mock.onGet(API.UNIT.MANAGE_ACCESS(unit.id)).reply(400, []);
72
+ act(() => {
73
+ result.current.onRefresh();
76
74
  });
75
+ expect(result.current.data).toEqual([]);
77
76
  });
78
77
  });
@@ -19,7 +19,7 @@ import { RowItem } from '../../commons/RowItem';
19
19
  const ManageAccessScreen = memo(({ route }) => {
20
20
  const t = useTranslations();
21
21
  const { params = {} } = route;
22
- const { unit, sensor } = params;
22
+ const { unit = {}, sensor = {} } = params;
23
23
  const { navigate } = useNavigation();
24
24
  const isFocused = useIsFocused();
25
25
  const { data, isRefresh, isLoading, onRefresh } = useManageAccess(
@@ -46,6 +46,7 @@ const ManageAccessScreen = memo(({ route }) => {
46
46
  refreshControl={
47
47
  <RefreshControl refreshing={false} onRefresh={onRefresh} />
48
48
  }
49
+ scrollIndicatorInsets={{ right: 1 }}
49
50
  >
50
51
  <View style={styles.container}>
51
52
  <Text semibold style={styles.titleGuest}>
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
- import axios from 'axios';
2
+ import MockAdapter from 'axios-mock-adapter';
3
3
  import { create } from 'react-test-renderer';
4
4
  import { act } from '@testing-library/react-hooks';
5
+ import { TouchableOpacity } from 'react-native';
5
6
 
6
7
  import { TESTID } from '../../../configs/Constants';
7
8
  import { API } from '../../../configs';
@@ -9,8 +10,20 @@ import MoveToAnotherSubUnit from '../';
9
10
  import { SCProvider } from '../../../context';
10
11
  import { mockSCStore } from '../../../context/mockStore';
11
12
  import BottomButtonView from '../../../commons/BottomButtonView';
13
+ import api from '../../../utils/Apis/axios';
14
+
15
+ const mock = new MockAdapter(api.axiosInstance);
16
+
17
+ const mockNavigate = jest.fn();
18
+ jest.mock('@react-navigation/native', () => {
19
+ return {
20
+ ...jest.requireActual('@react-navigation/native'),
21
+ useNavigation: () => ({
22
+ navigate: mockNavigate,
23
+ }),
24
+ };
25
+ });
12
26
 
13
- jest.mock('axios');
14
27
  jest.mock('react', () => {
15
28
  return {
16
29
  ...jest.requireActual('react'),
@@ -85,6 +98,17 @@ describe('Test Render ListSubUnit', () => {
85
98
  },
86
99
  };
87
100
 
101
+ it('render ListSubUnit with out params', async () => {
102
+ await act(async () => {
103
+ tree = await create(wrapComponent({}));
104
+ });
105
+ const instance = tree.root;
106
+ const rowSubUnit = instance.findAll(
107
+ (el) => el.props.testID === TESTID.ROW_SUB_UNIT
108
+ );
109
+ expect(rowSubUnit).toHaveLength(0);
110
+ });
111
+
88
112
  it('render ListSubUnit', async () => {
89
113
  await act(async () => {
90
114
  tree = await create(wrapComponent(route));
@@ -112,15 +136,14 @@ describe('Test Render ListSubUnit', () => {
112
136
  sensors: [],
113
137
  });
114
138
  });
115
- act(() => {
116
- bottomButtonView.props.onPressMain();
117
- });
118
-
119
- expect(axios.patch).toHaveBeenCalledWith(
120
- API.SENSOR.CHANGE_SUB_UNIT(200, 3, 73),
121
- {
122
- station_id: 4,
123
- }
124
- );
139
+ mock.onPatch(API.SENSOR.CHANGE_SUB_UNIT(200, 3, 73)).reply(200);
140
+ await bottomButtonView.props.onPressMain();
141
+ expect(mockNavigate).toBeCalled();
142
+ const TouchableOpacities = instance.findAllByType(TouchableOpacity);
143
+ await TouchableOpacities[2].props.onPress();
144
+ mockNavigate.mockClear();
145
+ mock.onPatch(API.SENSOR.CHANGE_SUB_UNIT(200, 3, 73)).reply(400);
146
+ await bottomButtonView.props.onPressMain();
147
+ expect(mockNavigate).not.toBeCalled();
125
148
  });
126
149
  });
@@ -36,12 +36,12 @@ const MoveToAnotherSubUnit = memo(({ route }) => {
36
36
  const { unit, sensor, station } = params;
37
37
  const { navigate } = useNavigation();
38
38
  const [selectedSubUnit, setSelectedSubUnit] = useState(
39
- unit.stations?.find((subUnit) => subUnit.id === station.id)
39
+ unit?.stations?.find((subUnit) => subUnit.id === station.id)
40
40
  );
41
41
 
42
42
  const listStationUnit = useMemo(() => {
43
- return unit.stations.slice(2);
44
- }, [unit.stations]);
43
+ return unit?.stations.slice(2) || [];
44
+ }, [unit?.stations]);
45
45
 
46
46
  const handleOnSelect = useCallback((item) => {
47
47
  setSelectedSubUnit(item);
@@ -57,12 +57,12 @@ const MoveToAnotherSubUnit = memo(({ route }) => {
57
57
  if (success) {
58
58
  navigate(Routes.UnitDetail);
59
59
  }
60
- }, [navigate, selectedSubUnit.id, sensor.id, station.id, unit.id]);
60
+ }, [navigate, selectedSubUnit?.id, sensor?.id, station?.id, unit?.id]);
61
61
 
62
62
  return (
63
63
  <View style={styles.wrap}>
64
64
  <HeaderCustom title={t('move_to_another_sub_unit')} isShowSeparator />
65
- <ScrollView>
65
+ <ScrollView scrollIndicatorInsets={{ right: 1 }}>
66
66
  <View style={styles.container}>
67
67
  <View>
68
68
  {listStationUnit.map((item, index) => (
@@ -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: {
@@ -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;
@@ -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>