@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,180 @@
1
+ import React, { memo, useCallback, useMemo } from 'react';
2
+ import { View } from 'react-native';
3
+
4
+ import styles from './styles';
5
+ import DetailConfigAction from '../components/DetailConfigAction';
6
+ import { useRoute, useNavigation } from '@react-navigation/native';
7
+ import { calculateLength, calculateStartAddress } from '../utils';
8
+ import DetailActionModbus from '../components/DetailActionModbus';
9
+ import Routes from '../../../utils/Route';
10
+
11
+ const DetailConfigActionModbus = () => {
12
+ const { params = {} } = useRoute();
13
+ const { navigate } = useNavigation();
14
+ const {
15
+ itemActionConfig,
16
+ isConfigRead,
17
+ isConfigWrite,
18
+ isAction,
19
+ isChildAction,
20
+ } = params;
21
+
22
+ const sa = useMemo(() => {
23
+ if (itemActionConfig?.sa1 && itemActionConfig?.sa2) {
24
+ return calculateStartAddress(
25
+ itemActionConfig?.sa1,
26
+ itemActionConfig?.sa2
27
+ );
28
+ }
29
+ return '--';
30
+ }, [itemActionConfig?.sa1, itemActionConfig?.sa2]);
31
+
32
+ const len = useMemo(() => {
33
+ if (itemActionConfig?.len1 && itemActionConfig?.len2) {
34
+ return calculateLength(itemActionConfig?.len1, itemActionConfig?.len2);
35
+ }
36
+ return '--';
37
+ }, [itemActionConfig?.len1, itemActionConfig?.len2]);
38
+
39
+ const listConfigRead = useMemo(
40
+ () => [
41
+ {
42
+ id: 1,
43
+ title: 'Function',
44
+ data: itemActionConfig?.func || '--',
45
+ },
46
+ {
47
+ id: 2,
48
+ title: 'Sa',
49
+ data: sa,
50
+ },
51
+ {
52
+ id: 3,
53
+ title: 'Len',
54
+ data: len,
55
+ },
56
+ ],
57
+ [itemActionConfig?.func, len, sa]
58
+ );
59
+
60
+ const listConfigWrite = useMemo(
61
+ () => [
62
+ {
63
+ id: 1,
64
+ title: 'Function',
65
+ data: itemActionConfig?.func || '--',
66
+ },
67
+ {
68
+ id: 2,
69
+ title: 'Sa',
70
+ data: sa,
71
+ },
72
+ {
73
+ id: 3,
74
+ title: 'Len',
75
+ data: len,
76
+ },
77
+ {
78
+ id: 4,
79
+ title: 'Ex',
80
+ data: itemActionConfig?.ex || '--',
81
+ },
82
+ ],
83
+ [itemActionConfig?.ex, itemActionConfig?.func, len, sa]
84
+ );
85
+
86
+ const listAction = useMemo(
87
+ () => [...(itemActionConfig?.items || [])],
88
+ [itemActionConfig?.items]
89
+ );
90
+
91
+ const listActionChild = useMemo(
92
+ () => [
93
+ {
94
+ id: 1,
95
+ title: 'config_write',
96
+ data: '--',
97
+ },
98
+ {
99
+ id: 2,
100
+ title: 'Len',
101
+ data: len,
102
+ },
103
+ {
104
+ id: 3,
105
+ title: 'Delay',
106
+ data: itemActionConfig?.delay,
107
+ },
108
+ {
109
+ id: 4,
110
+ title: 'Index',
111
+ data: itemActionConfig?.index,
112
+ },
113
+ {
114
+ id: 5,
115
+ title: 'Ex',
116
+ data: itemActionConfig?.ex || '--',
117
+ },
118
+ ],
119
+ [
120
+ itemActionConfig?.delay,
121
+ itemActionConfig?.ex,
122
+ itemActionConfig?.index,
123
+ len,
124
+ ]
125
+ );
126
+
127
+ const title = useMemo(
128
+ () =>
129
+ (isChildAction && itemActionConfig?.actionName) ||
130
+ ((isConfigRead || isConfigWrite) && itemActionConfig?.config?.name) ||
131
+ (isAction && itemActionConfig?.name) ||
132
+ '',
133
+ [
134
+ isAction,
135
+ isChildAction,
136
+ isConfigRead,
137
+ isConfigWrite,
138
+ itemActionConfig?.actionName,
139
+ itemActionConfig?.config?.name,
140
+ itemActionConfig?.name,
141
+ ]
142
+ );
143
+
144
+ const onPressRow = useCallback(
145
+ (item) => () => {
146
+ navigate(Routes.DetailChildConfigActionModbus, {
147
+ isChildAction: true,
148
+ itemActionConfig: item,
149
+ });
150
+ },
151
+ [navigate]
152
+ );
153
+ return (
154
+ <View style={styles.wrap}>
155
+ {isChildAction || isConfigRead || isConfigWrite ? (
156
+ <DetailConfigAction
157
+ title={title}
158
+ listData={
159
+ (isChildAction && listActionChild) ||
160
+ (isConfigRead && listConfigRead) ||
161
+ (isConfigWrite && listConfigWrite)
162
+ }
163
+ isDetailConfigModbus
164
+ onRowOne
165
+ />
166
+ ) : (
167
+ isAction && (
168
+ <DetailActionModbus
169
+ title={title}
170
+ listData={listAction}
171
+ itemAction={itemActionConfig}
172
+ onPressRow={onPressRow}
173
+ />
174
+ )
175
+ )}
176
+ </View>
177
+ );
178
+ };
179
+
180
+ export default memo(DetailConfigActionModbus);
@@ -0,0 +1,9 @@
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
+ });
@@ -0,0 +1,73 @@
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 DetailConfigActionZigbee from '..';
6
+ import { useRoute } from '@react-navigation/native';
7
+ import DetailConfigAction from '../../components/DetailConfigAction';
8
+
9
+ const wrapComponent = () => (
10
+ <SCProvider initState={mockSCStore({})}>
11
+ <DetailConfigActionZigbee />
12
+ </SCProvider>
13
+ );
14
+ jest.mock('@react-navigation/native', () => {
15
+ return {
16
+ ...jest.requireActual('@react-navigation/native'),
17
+ useRoute: jest.fn(),
18
+ };
19
+ });
20
+
21
+ jest.mock('@react-navigation/native', () => {
22
+ return {
23
+ ...jest.requireActual('@react-navigation/native'),
24
+ useNavigation: () => ({
25
+ navigate: jest.fn(),
26
+ pop: jest.fn(),
27
+ }),
28
+ useRoute: jest.fn(),
29
+ useIsFocused: () => true,
30
+ };
31
+ });
32
+
33
+ describe('Test DetailConfigActionZigbee', () => {
34
+ let tree;
35
+ it('test render DetailConfigActionZigbee isConfig', async () => {
36
+ useRoute.mockReturnValue({
37
+ params: {
38
+ device: {
39
+ id: 1,
40
+ sensor: { id: 1, name: 'sensor', connection_time: 30 },
41
+ },
42
+ isConfig: true,
43
+ isAction: false,
44
+ itemActionConfig: { config: { id: 1, name: 'config1' } },
45
+ },
46
+ });
47
+ await act(async () => {
48
+ tree = await create(wrapComponent());
49
+ });
50
+ const instance = tree.root;
51
+ const detailConfigAction = instance?.findAllByType(DetailConfigAction);
52
+ expect(detailConfigAction).toHaveLength(1);
53
+ });
54
+ it('test render DetailConfigActionZigbee isAction', async () => {
55
+ useRoute.mockReturnValue({
56
+ params: {
57
+ device: {
58
+ id: 1,
59
+ sensor: { id: 1, name: 'sensor', connection_time: 30 },
60
+ },
61
+ isConfig: false,
62
+ isAction: true,
63
+ itemActionConfig: { config: { id: 1, name: 'action' } },
64
+ },
65
+ });
66
+ await act(async () => {
67
+ tree = await create(wrapComponent());
68
+ });
69
+ const instance = tree.root;
70
+ const detailConfigAction = instance?.findAllByType(DetailConfigAction);
71
+ expect(detailConfigAction).toHaveLength(1);
72
+ });
73
+ });
@@ -0,0 +1,62 @@
1
+ import React, { memo, useMemo } from 'react';
2
+ import { View } from 'react-native';
3
+
4
+ import styles from './styles';
5
+ import DetailConfigAction from '../components/DetailConfigAction';
6
+ import { useRoute } from '@react-navigation/native';
7
+
8
+ const DetailConfigActionZigbee = () => {
9
+ const { params = {} } = useRoute();
10
+ const { device = {}, itemActionConfig, isConfig, isAction } = params;
11
+
12
+ const listData = useMemo(
13
+ () => [
14
+ {
15
+ id: 1,
16
+ title: (isConfig && 'config_name') || (isAction && 'action_name') || '',
17
+ data:
18
+ (isConfig && itemActionConfig?.config?.name) ||
19
+ (isAction && itemActionConfig?.action?.name) ||
20
+ '--',
21
+ },
22
+ {
23
+ id: 2,
24
+ title: (isConfig && 'key') || (isAction && 'control_payload') || '',
25
+ data: '--',
26
+ },
27
+ ],
28
+ [
29
+ isAction,
30
+ isConfig,
31
+ itemActionConfig?.action?.name,
32
+ itemActionConfig?.config?.name,
33
+ ]
34
+ );
35
+
36
+ const title = useMemo(
37
+ () =>
38
+ (isConfig && itemActionConfig?.config?.name) ||
39
+ (isAction && itemActionConfig?.action?.name) ||
40
+ '',
41
+ [
42
+ isAction,
43
+ isConfig,
44
+ itemActionConfig?.action?.name,
45
+ itemActionConfig?.config?.name,
46
+ ]
47
+ );
48
+
49
+ const subTitle = useMemo(() => device?.sensor?.name || '--', [device]);
50
+
51
+ return (
52
+ <View style={styles.wrap}>
53
+ <DetailConfigAction
54
+ title={title}
55
+ subTitle={subTitle}
56
+ listData={listData}
57
+ />
58
+ </View>
59
+ );
60
+ };
61
+
62
+ export default memo(DetailConfigActionZigbee);
@@ -0,0 +1,9 @@
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
+ });
@@ -0,0 +1,73 @@
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 DeviceGatewayInfo from '..';
6
+ import { useRoute } from '@react-navigation/native';
7
+ import Information from '../../components/Information';
8
+
9
+ const wrapComponent = () => (
10
+ <SCProvider initState={mockSCStore({})}>
11
+ <DeviceGatewayInfo />
12
+ </SCProvider>
13
+ );
14
+ jest.mock('@react-navigation/native', () => {
15
+ return {
16
+ ...jest.requireActual('@react-navigation/native'),
17
+ useRoute: jest.fn(),
18
+ };
19
+ });
20
+
21
+ jest.mock('@react-navigation/native', () => {
22
+ return {
23
+ ...jest.requireActual('@react-navigation/native'),
24
+ useNavigation: () => ({
25
+ goBack: jest.fn(),
26
+ }),
27
+ useRoute: jest.fn(),
28
+ useIsFocused: () => true,
29
+ };
30
+ });
31
+
32
+ describe('Test DeviceGatewayInfo', () => {
33
+ let tree;
34
+ it('test render DeviceGatewayInfo zigbee', async () => {
35
+ useRoute.mockReturnValue({
36
+ params: {
37
+ device: {
38
+ ieee_address: '1111',
39
+ model_name: '1111',
40
+ sensor: { name: 'sensor', connection_time: 30 },
41
+ },
42
+ isZigbee: true,
43
+ isModbus: false,
44
+ },
45
+ });
46
+ await act(async () => {
47
+ tree = await create(wrapComponent());
48
+ });
49
+ const instance = tree.root;
50
+ const information = instance?.findAllByType(Information);
51
+ expect(information).toHaveLength(1);
52
+ });
53
+ it('test render DeviceGatewayInfo modbus', async () => {
54
+ useRoute.mockReturnValue({
55
+ params: {
56
+ device: {
57
+ address: 'aaa',
58
+ delay: 0,
59
+ index: '1',
60
+ sensor: { name: 'sensor', connection_time: 30 },
61
+ },
62
+ isZigbee: false,
63
+ isModbus: true,
64
+ },
65
+ });
66
+ await act(async () => {
67
+ tree = await create(wrapComponent());
68
+ });
69
+ const instance = tree.root;
70
+ const information = instance?.findAllByType(Information);
71
+ expect(information).toHaveLength(1);
72
+ });
73
+ });
@@ -0,0 +1,96 @@
1
+ import React, { memo, useMemo } from 'react';
2
+ import { View } from 'react-native';
3
+ import t from '../../../hooks/Common/useTranslations';
4
+ import { useRoute } from '@react-navigation/native';
5
+ import styles from './styles';
6
+ import Information from '../components/Information';
7
+
8
+ const DeviceGatewayInfo = () => {
9
+ const { params = {} } = useRoute();
10
+ const { device = {}, isZigbee = false, isModbus = false } = params;
11
+ const {
12
+ ieee_address = '',
13
+ model_name = '',
14
+ address = '',
15
+ delay = '',
16
+ index = '',
17
+ sensor = {},
18
+ } = device;
19
+ const { name = '', connection_time = '' } = sensor;
20
+
21
+ const deviceInformationZigbee = useMemo(
22
+ () => [
23
+ {
24
+ id: 1,
25
+ title: 'device_name',
26
+ data: name,
27
+ },
28
+ {
29
+ id: 2,
30
+ title: 'connection_time',
31
+ data: connection_time,
32
+ },
33
+ {
34
+ id: 3,
35
+ title: 'ieee_address',
36
+ data: ieee_address,
37
+ },
38
+ {
39
+ id: 4,
40
+ title: 'model',
41
+ data: model_name,
42
+ },
43
+ ],
44
+ [ieee_address, model_name, connection_time, name]
45
+ );
46
+
47
+ const deviceInformationModbus = useMemo(
48
+ () => [
49
+ {
50
+ id: 1,
51
+ title: 'device_name',
52
+ data: name,
53
+ },
54
+ {
55
+ id: 2,
56
+ title: 'connection_time',
57
+ data: connection_time,
58
+ },
59
+ {
60
+ id: 3,
61
+ title: 'address',
62
+ data: address,
63
+ },
64
+ {
65
+ id: 4,
66
+ title: 'delay',
67
+ data: delay,
68
+ },
69
+ {
70
+ id: 5,
71
+ title: 'index',
72
+ data: index,
73
+ },
74
+ ],
75
+ [name, connection_time, address, delay, index]
76
+ );
77
+
78
+ return (
79
+ <View style={styles.wrap}>
80
+ <Information
81
+ listInformation={
82
+ isZigbee
83
+ ? deviceInformationZigbee
84
+ : isModbus
85
+ ? deviceInformationModbus
86
+ : []
87
+ }
88
+ isModbus={isModbus}
89
+ isDevice
90
+ title={t('device_information')}
91
+ />
92
+ </View>
93
+ );
94
+ };
95
+
96
+ export default memo(DeviceGatewayInfo);
@@ -0,0 +1,9 @@
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
+ });