@eohjsc/react-native-smart-city 0.3.48 → 0.3.49

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 (164) hide show
  1. package/package.json +4 -4
  2. package/src/Images/DevMode/file_copy.svg +3 -0
  3. package/src/Images/DevMode/inforCode.png +0 -0
  4. package/src/Images/DevMode/inforCode@2x.png +0 -0
  5. package/src/Images/DevMode/inforCode@3x.png +0 -0
  6. package/src/commons/Action/__test__/ItemQuickAction.test.js +0 -7
  7. package/src/commons/ActionGroup/__test__/ColorPickerTemplate.test.js +1 -8
  8. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +1 -1
  9. package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +1 -8
  10. package/src/commons/ActionTemplate/__test__/index.test.js +0 -7
  11. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +3 -3
  12. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +1 -1
  13. package/src/commons/Dashboard/MyUnit/index.js +30 -4
  14. package/src/commons/DevMode/Styles/ItemStyles.js +1 -1
  15. package/src/commons/Device/PMSensor/PMSensorIndicatior.js +2 -1
  16. package/src/commons/FourButtonFilterHistory/__test__/FourButtonFilterHistory.test.js +0 -7
  17. package/src/commons/Header/HeaderCustom.js +13 -6
  18. package/src/commons/MediaPlayer/__test__/index.test.js +0 -7
  19. package/src/commons/MediaPlayerDetail/__test__/MediaPlayerFull.test.js +0 -1
  20. package/src/commons/MenuActionMore/index.js +4 -1
  21. package/src/commons/NavBar/index.js +1 -1
  22. package/src/commons/OneTapTemplate/OptionsDropdownActionTemplate.js +1 -1
  23. package/src/commons/OneTapTemplate/__test__/NumberUpDownActionTemplate.test.js +0 -7
  24. package/src/commons/OneTapTemplate/__test__/OptionsDropdownActionTemplate.test.js +0 -7
  25. package/src/commons/OneTapTemplate/__test__/StatesGridActionTemplate.test.js +0 -7
  26. package/src/commons/RowItem/index.js +6 -1
  27. package/src/commons/SelectUnit/index.js +4 -1
  28. package/src/commons/StatusBox/styles.js +8 -3
  29. package/src/commons/SubUnit/__test__/Favorites.test.js +0 -7
  30. package/src/commons/SubUnit/__test__/ShortDetail.test.js +0 -7
  31. package/src/commons/Tabbar/__test__/index.test.js +0 -7
  32. package/src/commons/Unit/__test__/HeaderUnit.test.js +0 -5
  33. package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +0 -7
  34. package/src/configs/API.js +28 -0
  35. package/src/configs/AccessibilityLabel.js +13 -0
  36. package/src/configs/Colors.js +4 -0
  37. package/src/configs/Constants.js +6 -0
  38. package/src/configs/Images.js +1 -0
  39. package/src/context/actionType.ts +8 -1
  40. package/src/context/mockStore.ts +8 -2
  41. package/src/context/reducer.ts +27 -4
  42. package/src/hooks/IoT/__test__/useWatchConfigs.test.js +46 -0
  43. package/src/hooks/IoT/useBluetoothConnection.js +78 -4
  44. package/src/hooks/IoT/useBluetoothDeviceConnected.js +1 -1
  45. package/src/iot/RemoteControl/Bluetooth.js +0 -16
  46. package/src/iot/RemoteControl/__test__/Bluetooth.test.js +0 -25
  47. package/src/navigations/Main.js +39 -0
  48. package/src/navigations/UnitStack.js +18 -5
  49. package/src/screens/ActivityLog/__test__/FilterPopup.test.js +0 -7
  50. package/src/screens/ActivityLog/__test__/ItemLog.test.js +0 -7
  51. package/src/screens/ActivityLog/__test__/index.test.js +0 -7
  52. package/src/screens/AddLocationMaps/__test__/index.test.js +0 -7
  53. package/src/screens/AddNewAction/SelectAction.js +22 -18
  54. package/src/screens/AddNewAction/__test__/SelectAction.test.js +35 -16
  55. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +0 -7
  56. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +0 -4
  57. package/src/screens/AddNewGateway/ConnectingZigbeeDevice.js +17 -4
  58. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +0 -4
  59. package/src/screens/AddNewGateway/__test__/ConnectingModbusDevice.test.js +0 -4
  60. package/src/screens/AddNewGateway/__test__/ConnectingWifiDevice.test.js +0 -4
  61. package/src/screens/AddNewGateway/__test__/ConnectingZigbeeDevice.test.js +4 -7
  62. package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +0 -7
  63. package/src/screens/AddNewGateway/__test__/SelectDeviceType.test.js +0 -4
  64. package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +0 -4
  65. package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +0 -4
  66. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +0 -7
  67. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +0 -1
  68. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +0 -7
  69. package/src/screens/Device/__test__/detail.test.js +1 -1
  70. package/src/screens/Device/detail.js +11 -3
  71. package/src/screens/Device/hooks/useDisconnectedDevice.js +26 -7
  72. package/src/screens/EmergencyContacts/__test__/hooks.test.js +79 -0
  73. package/src/screens/Gateway/DetailConfigActionModbus/__test__/index.test.js +138 -0
  74. package/src/screens/Gateway/DetailConfigActionModbus/index.js +180 -0
  75. package/src/screens/Gateway/DetailConfigActionModbus/styles.js +9 -0
  76. package/src/screens/Gateway/DetailConfigActionZigbee/__test__/index.test.js +73 -0
  77. package/src/screens/Gateway/DetailConfigActionZigbee/index.js +62 -0
  78. package/src/screens/Gateway/DetailConfigActionZigbee/styles.js +9 -0
  79. package/src/screens/Gateway/DeviceGatewayInfo/__test__/index.test.js +73 -0
  80. package/src/screens/Gateway/DeviceGatewayInfo/index.js +96 -0
  81. package/src/screens/Gateway/DeviceGatewayInfo/styles.js +9 -0
  82. package/src/screens/Gateway/DeviceModbusDetail/__test__/index.test.js +393 -0
  83. package/src/screens/Gateway/DeviceModbusDetail/index.js +176 -0
  84. package/src/screens/Gateway/DeviceModbusDetail/styles.js +12 -0
  85. package/src/screens/Gateway/DeviceZigbeeDetail/__test__/index.test.js +265 -0
  86. package/src/screens/Gateway/DeviceZigbeeDetail/index.js +148 -0
  87. package/src/screens/Gateway/DeviceZigbeeDetail/styles.js +12 -0
  88. package/src/screens/Gateway/GatewayConnectionMethods/__test__/index.test.js +37 -0
  89. package/src/screens/Gateway/GatewayConnectionMethods/index.js +73 -0
  90. package/src/screens/Gateway/GatewayConnectionMethods/styles.js +45 -0
  91. package/src/screens/Gateway/GatewayDetail/__test__/index.test.js +298 -0
  92. package/src/screens/Gateway/GatewayDetail/index.js +148 -0
  93. package/src/screens/Gateway/GatewayDetail/styles.js +12 -0
  94. package/src/screens/Gateway/GatewayInfo/__test__/index.test.js +137 -0
  95. package/src/screens/Gateway/GatewayInfo/index.js +115 -0
  96. package/src/screens/Gateway/GatewayInfo/styles.js +9 -0
  97. package/src/screens/Gateway/__test__/index.test.js +58 -0
  98. package/src/screens/Gateway/components/Detail/__test__/index.test.js +46 -0
  99. package/src/screens/Gateway/components/Detail/index.js +62 -0
  100. package/src/screens/Gateway/components/Detail/styles.js +27 -0
  101. package/src/screens/Gateway/components/DetailActionModbus/__test__/index.test.js +49 -0
  102. package/src/screens/Gateway/components/DetailActionModbus/index.js +52 -0
  103. package/src/screens/Gateway/components/DetailActionModbus/styles.js +32 -0
  104. package/src/screens/Gateway/components/DetailConfigAction/__test__/index.test.js +59 -0
  105. package/src/screens/Gateway/components/DetailConfigAction/index.js +69 -0
  106. package/src/screens/Gateway/components/DetailConfigAction/styles.js +21 -0
  107. package/src/screens/Gateway/components/GatewayItem/__test__/index.test.js +1 -1
  108. package/src/screens/Gateway/components/GatewayItem/styles.js +4 -33
  109. package/src/screens/Gateway/components/Information/__test__/index.test.js +70 -0
  110. package/src/screens/Gateway/components/Information/index.js +116 -0
  111. package/src/screens/Gateway/components/Information/styles.js +59 -0
  112. package/src/screens/Gateway/components/RowItem/__test__/index.test.js +67 -0
  113. package/src/screens/Gateway/components/RowItem/index.js +65 -0
  114. package/src/screens/Gateway/components/RowItem/styles.js +25 -0
  115. package/src/screens/Gateway/components/TabPaneCT/__test__/index.test.js +98 -0
  116. package/src/screens/Gateway/components/TabPaneCT/index.js +134 -0
  117. package/src/screens/Gateway/components/TabPaneCT/styles.js +58 -0
  118. package/src/screens/Gateway/hooks/__test__/index.test.js +93 -0
  119. package/src/screens/Gateway/hooks/useGateway.js +110 -16
  120. package/src/screens/Gateway/index.js +19 -3
  121. package/src/screens/Gateway/styles.js +6 -8
  122. package/src/screens/Gateway/utils/index.js +16 -0
  123. package/src/screens/GuestInfo/__test__/index.test.js +0 -7
  124. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +0 -7
  125. package/src/screens/HanetCamera/__test__/Detail.test.js +0 -7
  126. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +0 -7
  127. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +0 -7
  128. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +0 -6
  129. package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +0 -7
  130. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +0 -7
  131. package/src/screens/Notification/__test__/Notification.test.js +0 -7
  132. package/src/screens/PlayBackCamera/__test__/index.test.js +0 -1
  133. package/src/screens/ScriptDetail/__test__/index.test.js +0 -7
  134. package/src/screens/SelectUnit/__test__/index.test.js +0 -1
  135. package/src/screens/SetSchedule/__test__/index.test.js +0 -7
  136. package/src/screens/Sharing/Components/__test__/DeviceItem.test.js +0 -7
  137. package/src/screens/Sharing/Components/__test__/ItemChangeRole.test.js +0 -7
  138. package/src/screens/Sharing/Components/__test__/TitleCheckBox.test.js +0 -7
  139. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +0 -6
  140. package/src/screens/Sharing/hooks/__test__/index.test.js +80 -0
  141. package/src/screens/SmartAccount/ListDevice/__test__/DeviceItem.test.js +0 -7
  142. package/src/screens/SmartIr/__test__/ButtonsBottom.test.js +0 -6
  143. package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +1 -6
  144. package/src/screens/SmartIr/__test__/SelectBrand.test.js +1 -6
  145. package/src/screens/SmartIr/__test__/SelectDeviceType.test.js +1 -6
  146. package/src/screens/SubUnit/AddSubUnit.js +1 -0
  147. package/src/screens/SubUnit/ManageSubUnit.js +4 -1
  148. package/src/screens/SubUnit/hooks/__test__/useEmergencyContacts.test.js +34 -0
  149. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +0 -7
  150. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +0 -7
  151. package/src/screens/Unit/__test__/AddMenu.test.js +0 -7
  152. package/src/screens/Unit/__test__/CheckSendEmail.test.js +1 -1
  153. package/src/screens/Unit/__test__/ChooseLocation.test.js +0 -7
  154. package/src/screens/Unit/__test__/Detail.test.js +1 -8
  155. package/src/screens/Unit/__test__/SelectAddToFavorites.test.js +0 -7
  156. package/src/screens/Unit/__test__/SelectAddress.test.js +0 -7
  157. package/src/screens/Unit/__test__/SmartAccount.test.js +0 -7
  158. package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -7
  159. package/src/screens/Unit/__test__/Summaries.test.js +0 -7
  160. package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +4 -3
  161. package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +2 -2
  162. package/src/utils/I18n/translations/en.json +28 -0
  163. package/src/utils/I18n/translations/vi.json +28 -0
  164. package/src/utils/Route/index.js +8 -0
@@ -0,0 +1,265 @@
1
+ import React from 'react';
2
+ import { create, act } from 'react-test-renderer';
3
+ import { SCProvider } from '../../../../context';
4
+ import { mockSCStore } from '../../../../context/mockStore';
5
+ import DeviceZigbeeDetail from '..';
6
+ import { useRoute } from '@react-navigation/native';
7
+ import { HeaderCustom } from '../../../../commons';
8
+ import { AccessibilityLabel } from '../../../../configs/Constants';
9
+ import Routes from '../../../../utils/Route';
10
+ import TabPaneCT from '../../components/TabPaneCT';
11
+ import MenuActionMore from '../../../../commons/MenuActionMore';
12
+ import { Alert } from 'react-native';
13
+ import Toast from 'react-native-toast-message';
14
+ import SegmentedControl from '@react-native-community/segmented-control';
15
+ import MockAdapter from 'axios-mock-adapter';
16
+ import api from '../../../../utils/Apis/axios';
17
+ import { API } from '../../../../configs';
18
+ import { PERMISSION_TYPE } from '../../../../configs/Constants';
19
+ import Detail from '../../components/Detail';
20
+
21
+ const mock = new MockAdapter(api.axiosInstance);
22
+
23
+ const wrapComponent = () => (
24
+ <SCProvider initState={mockSCStore({})}>
25
+ <DeviceZigbeeDetail />
26
+ </SCProvider>
27
+ );
28
+
29
+ jest.mock('react-native', () => {
30
+ const RN = jest.requireActual('react-native');
31
+ return Object.setPrototypeOf(
32
+ {
33
+ Alert: {
34
+ ...RN.Alert,
35
+ alert: jest.fn(),
36
+ },
37
+ },
38
+ RN
39
+ );
40
+ });
41
+
42
+ const mockPop = jest.fn();
43
+ const mockNavigate = jest.fn();
44
+ jest.mock('@react-navigation/native', () => {
45
+ return {
46
+ ...jest.requireActual('@react-navigation/native'),
47
+ useNavigation: () => ({
48
+ navigate: mockNavigate,
49
+ pop: mockPop,
50
+ }),
51
+ useRoute: jest.fn(),
52
+ useIsFocused: () => true,
53
+ };
54
+ });
55
+
56
+ const headerCustomOnPressMore = async (instance) => {
57
+ const headerCustom = instance?.findAllByType(HeaderCustom);
58
+ const buttonMore = headerCustom[0].findByProps({
59
+ accessibilityLabel: AccessibilityLabel.MENU_POPPER_MORE,
60
+ });
61
+ await act(async () => {
62
+ buttonMore.props.onPress();
63
+ });
64
+ };
65
+
66
+ describe('Test DeviceZigbeeDetail', () => {
67
+ let tree;
68
+ beforeEach(() => {
69
+ useRoute.mockReturnValue({
70
+ params: {
71
+ device: { id: 1, name: 'abc' },
72
+ gatewayId: 1,
73
+ isZigbee: true,
74
+ },
75
+ });
76
+ });
77
+ afterEach(() => {
78
+ mock.reset();
79
+ mock.resetHistory();
80
+ mockNavigate.mockClear();
81
+ Toast.show.mockClear();
82
+ });
83
+
84
+ it('test render DeviceZigbeeDetail', async () => {
85
+ await act(async () => {
86
+ tree = await create(wrapComponent());
87
+ });
88
+ const instance = tree.root;
89
+ const detail = instance?.findByType(Detail);
90
+ const headerCustom = detail.findAllByType(HeaderCustom);
91
+ const tabPaneCT = detail.findAllByType(TabPaneCT);
92
+ const menuActionMore = detail.findAllByType(MenuActionMore);
93
+
94
+ expect(headerCustom).toHaveLength(1);
95
+ expect(tabPaneCT).toHaveLength(1);
96
+ expect(menuActionMore).toHaveLength(1);
97
+ });
98
+
99
+ it('test render DeviceZigbeeDetail onPress more and onPress DeviceGatewayInfo', async () => {
100
+ await act(async () => {
101
+ tree = await create(wrapComponent());
102
+ });
103
+ const instance = tree.root;
104
+ const detail = instance?.findByType(Detail);
105
+ headerCustomOnPressMore(detail);
106
+ const menuActionMore = detail?.findAllByType(MenuActionMore);
107
+ expect(menuActionMore[0].props.isVisible).toEqual(true);
108
+ await act(async () => {
109
+ menuActionMore[0].props.listMenuItem[0].doAction();
110
+ });
111
+ expect(mockNavigate).toHaveBeenCalledWith(Routes.DeviceGatewayInfo, {
112
+ device: { id: 1, name: 'abc' },
113
+ isDevice: true,
114
+ isZigbee: true,
115
+ });
116
+ });
117
+
118
+ it('test render DeviceZigbeeDetail onPress more and onPress Delete zigbee', async () => {
119
+ await act(async () => {
120
+ tree = await create(wrapComponent());
121
+ });
122
+ const instance = tree.root;
123
+ const detail = instance?.findByType(Detail);
124
+ headerCustomOnPressMore(detail);
125
+ const menuActionMore = detail?.findByType(MenuActionMore);
126
+ expect(menuActionMore.props.isVisible).toEqual(true);
127
+ await act(async () => {
128
+ menuActionMore.props.listMenuItem[1].doAction();
129
+ });
130
+ expect(Alert.alert.mock.calls[0][0]).toEqual(
131
+ 'Are you sure you want to delete device "undefined" ?'
132
+ );
133
+ mock.onDelete(API.DEV_MODE.ZIGBEE.DEVICE_DETAIL(1, 1)).reply(200);
134
+ await act(async () => {
135
+ await Alert.alert.mock.calls[0][2][1].onPress();
136
+ });
137
+ expect(mockPop).toBeCalledWith(1);
138
+ expect(Toast.show).toBeCalledWith({
139
+ position: 'bottom',
140
+ text1: 'Delete successfully!',
141
+ text2: undefined,
142
+ type: 'success',
143
+ visibilityTime: 1000,
144
+ });
145
+ });
146
+
147
+ it('test render DeviceZigbeeDetail onPress TabPanel config', async () => {
148
+ mock
149
+ .onGet(API.DEV_MODE.ZIGBEE.CONFIG_MAP(1, 1))
150
+ .reply(200, [{ id: 1, name: 'config 1' }]);
151
+ await act(async () => {
152
+ tree = await create(wrapComponent());
153
+ });
154
+ const instance = tree.root;
155
+ const detail = instance?.findByType(Detail);
156
+ const tabPaneCT = detail.findByType(TabPaneCT);
157
+ const segmentedControl = tabPaneCT.findByType(SegmentedControl);
158
+ await act(async () => {
159
+ await segmentedControl.props.onChange({
160
+ nativeEvent: { selectedSegmentIndex: 0 },
161
+ });
162
+ });
163
+ expect(tabPaneCT.props.listTabs[0].data).toEqual([
164
+ { id: 1, name: 'config 1' },
165
+ ]);
166
+ expect(tabPaneCT.props.listTabs[0].title).toEqual(PERMISSION_TYPE.CONFIG);
167
+ });
168
+
169
+ it('test render GatewayDetail onPress TabPanel isAction', async () => {
170
+ mock
171
+ .onGet(API.DEV_MODE.ZIGBEE.ACTION(1, 1))
172
+ .reply(200, [{ id: 1, name: 'action 1' }]);
173
+ await act(async () => {
174
+ tree = await create(wrapComponent());
175
+ });
176
+ const instance = tree.root;
177
+ const detail = instance?.findByType(Detail);
178
+ const tabPaneCT = detail.findByType(TabPaneCT);
179
+ const segmentedControl = tabPaneCT.findByType(SegmentedControl);
180
+ await act(async () => {
181
+ await segmentedControl.props.onChange({
182
+ nativeEvent: { selectedSegmentIndex: 1 },
183
+ });
184
+ });
185
+ expect(tabPaneCT.props.listTabs[1].data).toEqual([
186
+ { id: 1, name: 'action 1' },
187
+ ]);
188
+ expect(tabPaneCT.props.listTabs[1].title).toEqual(PERMISSION_TYPE.ACTION);
189
+ });
190
+
191
+ it('test render GatewayDetail onPress TabPanel config onPressRow', async () => {
192
+ mock
193
+ .onGet(API.DEV_MODE.ZIGBEE.CONFIG_MAP(1, 1))
194
+ .reply(200, [{ id: 1, name: 'config 1' }]);
195
+ await act(async () => {
196
+ tree = await create(wrapComponent());
197
+ });
198
+ const instance = tree.root;
199
+ const detail = instance?.findByType(Detail);
200
+ await act(async () => {
201
+ await detail.props.onPressRow(1);
202
+ });
203
+ expect(mockNavigate).toBeCalledWith(Routes.DetailConfigActionZigbee, {
204
+ gatewayId: 1,
205
+ device: {
206
+ id: 1,
207
+ name: 'abc',
208
+ },
209
+ isAction: false,
210
+ isConfig: true,
211
+ itemActionConfig: 1,
212
+ });
213
+ });
214
+
215
+ it('test render GatewayDetail onPress TabPanel action onPressRow', async () => {
216
+ mock
217
+ .onGet(API.DEV_MODE.ZIGBEE.ACTION(1, 1))
218
+ .reply(200, [{ id: 1, name: 'action 1 1' }]);
219
+ await act(async () => {
220
+ tree = await create(wrapComponent());
221
+ });
222
+ const instance = tree.root;
223
+ const detail = instance?.findByType(Detail);
224
+ const tabPaneCT = detail.findByType(TabPaneCT);
225
+ const segmentedControl = tabPaneCT.findByType(SegmentedControl);
226
+ await act(async () => {
227
+ await segmentedControl.props.onChange({
228
+ nativeEvent: { selectedSegmentIndex: 1 },
229
+ });
230
+ });
231
+ await act(async () => {
232
+ await detail.props.onPressRow(1);
233
+ });
234
+ expect(mockNavigate).toBeCalledWith(Routes.DetailConfigActionZigbee, {
235
+ gatewayId: 1,
236
+ device: {
237
+ id: 1,
238
+ name: 'abc',
239
+ },
240
+ isAction: true,
241
+ isConfig: false,
242
+ itemActionConfig: 1,
243
+ });
244
+ });
245
+
246
+ it('test render GatewayDetail onPress TabPanel zigbee config onRefresh', async () => {
247
+ mock
248
+ .onGet(API.DEV_MODE.ZIGBEE.CONFIG_MAP(1, 1))
249
+ .reply(200, [{ id: 1, name: 'config 1' }]);
250
+
251
+ await act(async () => {
252
+ tree = await create(wrapComponent());
253
+ });
254
+ const instance = tree.root;
255
+ const detail = instance?.findByType(Detail);
256
+ const tabPaneCT = detail.findByType(TabPaneCT);
257
+ await act(async () => {
258
+ await detail.props.onRefresh();
259
+ });
260
+ expect(tabPaneCT.props.listTabs[0].data).toEqual([
261
+ { id: 1, name: 'config 1' },
262
+ ]);
263
+ expect(tabPaneCT.props.listTabs[0].title).toEqual(PERMISSION_TYPE.CONFIG);
264
+ });
265
+ });
@@ -0,0 +1,148 @@
1
+ import React, { memo, useMemo, useEffect, useCallback } from 'react';
2
+ import { View, Alert } from 'react-native';
3
+ import {
4
+ useRoute,
5
+ useNavigation,
6
+ useIsFocused,
7
+ } from '@react-navigation/native';
8
+
9
+ import { PERMISSION_TYPE } from '../../../configs/Constants';
10
+ import { useGateway } from '../hooks/useGateway';
11
+ import t from '../../../hooks/Common/useTranslations';
12
+ import Routes from '../../../utils/Route';
13
+ import Detail from '../components/Detail';
14
+ import styles from './styles';
15
+
16
+ const DeviceZigbeeDetail = () => {
17
+ const { params = {} } = useRoute();
18
+ const { device = {}, gatewayId = '', isZigbee } = params;
19
+ const { navigate } = useNavigation();
20
+ const isFocused = useIsFocused();
21
+
22
+ const {
23
+ selectedIndex,
24
+ setSelectedIndex,
25
+ fetchActionConfigDevice,
26
+ deleteDeviceDetail,
27
+ detailDeviceZigbee,
28
+ setRefresh,
29
+ refresh,
30
+ } = useGateway();
31
+
32
+ const listTabs = useMemo(
33
+ () => [
34
+ {
35
+ id: 1,
36
+ title: PERMISSION_TYPE.CONFIG,
37
+ data: detailDeviceZigbee?.configs,
38
+ },
39
+ {
40
+ id: 2,
41
+ title: PERMISSION_TYPE.ACTION,
42
+ data: detailDeviceZigbee?.actions,
43
+ },
44
+ ],
45
+ [detailDeviceZigbee?.actions, detailDeviceZigbee?.configs]
46
+ );
47
+
48
+ const listMenuItem = useMemo(() => {
49
+ const RouteGatewayInformation = {
50
+ id: 1,
51
+ text: t('device_information'),
52
+ doAction: () =>
53
+ navigate(Routes.DeviceGatewayInfo, {
54
+ device,
55
+ isDevice: true,
56
+ isZigbee,
57
+ }),
58
+ };
59
+
60
+ const ListDeleteGateway = {
61
+ id: 2,
62
+ text: t('delete_device'),
63
+ textStyle: styles.textColorRed,
64
+ doAction: () =>
65
+ Alert.alert(
66
+ t('message_delete_device', { name: device?.sensor?.name }),
67
+ '',
68
+ [
69
+ {
70
+ text: t('cancel'),
71
+ },
72
+ {
73
+ text: t('ok'),
74
+ onPress: () =>
75
+ deleteDeviceDetail(gatewayId, device?.id, isZigbee, false),
76
+ style: 'destructive',
77
+ },
78
+ ]
79
+ ),
80
+ };
81
+ return [RouteGatewayInformation, ListDeleteGateway];
82
+ }, [deleteDeviceDetail, gatewayId, isZigbee, device, navigate]);
83
+
84
+ const isConfig = useMemo(() => {
85
+ return listTabs[selectedIndex]?.title === PERMISSION_TYPE.CONFIG;
86
+ }, [listTabs, selectedIndex]);
87
+
88
+ const isAction = useMemo(() => {
89
+ return listTabs[selectedIndex]?.title === PERMISSION_TYPE.ACTION;
90
+ }, [listTabs, selectedIndex]);
91
+
92
+ useEffect(() => {
93
+ if (isFocused) {
94
+ fetchActionConfigDevice(gatewayId, device?.id, isConfig, isAction);
95
+ }
96
+ }, [
97
+ fetchActionConfigDevice,
98
+ gatewayId,
99
+ isAction,
100
+ isConfig,
101
+ isFocused,
102
+ device?.id,
103
+ ]);
104
+
105
+ const onPressRow = useCallback(
106
+ (item) => {
107
+ navigate(Routes.DetailConfigActionZigbee, {
108
+ itemActionConfig: item,
109
+ gatewayId: gatewayId,
110
+ device,
111
+ isConfig,
112
+ isAction,
113
+ });
114
+ },
115
+ [device, gatewayId, isAction, isConfig, navigate]
116
+ );
117
+
118
+ const onRefresh = useCallback(() => {
119
+ setRefresh(true);
120
+ fetchActionConfigDevice(gatewayId, device?.id, isConfig, isAction);
121
+ setRefresh(false);
122
+ }, [
123
+ device?.id,
124
+ fetchActionConfigDevice,
125
+ gatewayId,
126
+ isAction,
127
+ isConfig,
128
+ setRefresh,
129
+ ]);
130
+
131
+ return (
132
+ <View style={styles.wrap}>
133
+ <Detail
134
+ title={device?.sensor?.name || ''}
135
+ listMenuItem={listMenuItem}
136
+ listTabs={listTabs}
137
+ selectedIndex={selectedIndex}
138
+ setSelectedIndex={setSelectedIndex}
139
+ isDevice
140
+ onPressRow={onPressRow}
141
+ refresh={refresh}
142
+ onRefresh={onRefresh}
143
+ />
144
+ </View>
145
+ );
146
+ };
147
+
148
+ export default memo(DeviceZigbeeDetail);
@@ -0,0 +1,12 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { Colors } from '../../../configs';
3
+
4
+ export default StyleSheet.create({
5
+ wrap: {
6
+ flex: 1,
7
+ backgroundColor: Colors.White,
8
+ },
9
+ textColorRed: {
10
+ color: Colors.Red,
11
+ },
12
+ });
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { create, act } from 'react-test-renderer';
3
+ import { SCProvider } from '../../../../context';
4
+ import { mockSCStore } from '../../../../context/mockStore';
5
+ import GatewayConnectionMethods from '..';
6
+ import { HeaderCustom } from '../../../../commons';
7
+ import { FlatList } from 'react-native';
8
+ import { AccessibilityLabel } from '../../../../configs/Constants';
9
+
10
+ const wrapComponent = () => (
11
+ <SCProvider initState={mockSCStore({})}>
12
+ <GatewayConnectionMethods />
13
+ </SCProvider>
14
+ );
15
+
16
+ describe('Test GatewayConnectionMethods', () => {
17
+ let tree;
18
+
19
+ it('test render GatewayConnectionMethods', async () => {
20
+ await act(async () => {
21
+ tree = await create(wrapComponent());
22
+ });
23
+ const instance = tree.root;
24
+
25
+ const headerCustom = instance.findAllByType(HeaderCustom);
26
+ const text = instance.findByProps({
27
+ accessibilityLabel: AccessibilityLabel.GATEWAY_CONNECTION_METHODS_TEXT,
28
+ });
29
+ const flatList = instance.findAllByType(FlatList);
30
+
31
+ expect(headerCustom).toHaveLength(1);
32
+ expect(text.props.children).toEqual(
33
+ 'Visit EoH Web to set up other connection options.'
34
+ );
35
+ expect(flatList).toHaveLength(1);
36
+ });
37
+ });
@@ -0,0 +1,73 @@
1
+ import React, { useCallback, memo, useMemo } from 'react';
2
+ import { View, FlatList } from 'react-native';
3
+ import { Colors } from '../../../configs';
4
+ import t from '../../../hooks/Common/useTranslations';
5
+ import { Text, HeaderCustom } from '../../../commons';
6
+ import styles from './styles';
7
+ import { AccessibilityLabel } from '../../../configs/Constants';
8
+
9
+ const GatewayConnectionMethods = () => {
10
+ const RowConnection = ({ item }) => {
11
+ return (
12
+ <View style={styles.wrapRow}>
13
+ <View style={[styles.rowTitle, item?.baud && styles.noneBorderBottom]}>
14
+ <Text type="H4">{t(item?.title)}</Text>
15
+ </View>
16
+ {item?.baud && (
17
+ <View style={styles.rowBaud}>
18
+ <Text type="H4">{t('baud_speed')}</Text>
19
+ <Text color={Colors.Gray20}>{item?.baud}</Text>
20
+ </View>
21
+ )}
22
+ </View>
23
+ );
24
+ };
25
+
26
+ const gatewayInformation = useMemo(
27
+ () => [
28
+ {
29
+ id: 1,
30
+ title: 'zigbee_method',
31
+ },
32
+ {
33
+ id: 2,
34
+ title: 'modbus_method',
35
+ baud: '9600',
36
+ },
37
+ ],
38
+ []
39
+ );
40
+
41
+ const renderItem = useCallback(({ item, index }) => {
42
+ return <RowConnection item={item} key={index} />;
43
+ }, []);
44
+
45
+ return (
46
+ <View style={styles.wrap}>
47
+ <HeaderCustom
48
+ title={t('connection_methods')}
49
+ titleStyles={styles.title}
50
+ />
51
+ <View style={styles.bodyInfo}>
52
+ <Text
53
+ color={Colors.Gray20}
54
+ accessibilityLabel={
55
+ AccessibilityLabel.GATEWAY_CONNECTION_METHODS_TEXT
56
+ }
57
+ >
58
+ {t('visit_eoh_web_to_set_up_other_connection')}
59
+ </Text>
60
+ <FlatList
61
+ contentContainerStyle={styles.contentContainerStyle}
62
+ keyExtractor={(item) => item?.id}
63
+ data={gatewayInformation}
64
+ renderItem={renderItem}
65
+ extraData={gatewayInformation}
66
+ numColumns={1}
67
+ />
68
+ </View>
69
+ </View>
70
+ );
71
+ };
72
+
73
+ export default memo(GatewayConnectionMethods);
@@ -0,0 +1,45 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { Colors } from '../../../configs';
3
+
4
+ export default StyleSheet.create({
5
+ wrap: {
6
+ flex: 1,
7
+ backgroundColor: Colors.White,
8
+ },
9
+ title: {
10
+ textAlign: 'left',
11
+ paddingLeft: 16,
12
+ fontSize: 16,
13
+ lineHeight: 24,
14
+ fontWeight: 'bold',
15
+ color: Colors.Black,
16
+ },
17
+ contentContainerStyle: {
18
+ paddingVertical: 8,
19
+ },
20
+ bodyInfo: { paddingHorizontal: 16, flex: 1 },
21
+ wrapRow: {
22
+ marginVertical: 8,
23
+ },
24
+ rowTitle: {
25
+ backgroundColor: Colors.Gray21,
26
+ borderRadius: 8,
27
+ paddingHorizontal: 16,
28
+ paddingVertical: 12,
29
+ },
30
+ rowBaud: {
31
+ padding: 16,
32
+ borderBottomLeftRadius: 8,
33
+ borderBottomRightRadius: 8,
34
+ borderBottomWidth: 1,
35
+ borderLeftWidth: 1,
36
+ borderRightWidth: 1,
37
+ borderColor: Colors.Gray19,
38
+ backgroundColor: Colors.White,
39
+ overflow: 'hidden',
40
+ },
41
+ noneBorderBottom: {
42
+ borderBottomLeftRadius: 0,
43
+ borderBottomRightRadius: 0,
44
+ },
45
+ });