@eohjsc/react-native-smart-city 0.7.26 → 0.7.30

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 (74) hide show
  1. package/index.js +2 -0
  2. package/package.json +2 -1
  3. package/src/commons/Dashboard/MyDashboardDevice/__test__/index.test.js +68 -0
  4. package/src/commons/Dashboard/MyDashboardDevice/index.js +46 -11
  5. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +43 -11
  6. package/src/commons/Dashboard/MyUnit/index.js +40 -32
  7. package/src/commons/ModalAlert/index.js +51 -0
  8. package/src/commons/ModalAlert/styles.js +54 -0
  9. package/src/commons/SubUnit/ShortDetail.js +20 -4
  10. package/src/commons/SubUnit/__test__/ShortDetail.test.js +46 -1
  11. package/src/configs/API.js +6 -0
  12. package/src/configs/AccessibilityLabel.js +1 -0
  13. package/src/configs/Constants.js +7 -0
  14. package/src/configs/SCConfig.js +6 -0
  15. package/src/context/SCContext.tsx +12 -1
  16. package/src/context/SCStore.ts +14 -0
  17. package/src/context/actionType.ts +10 -0
  18. package/src/context/mockStore.ts +30 -1
  19. package/src/context/reducer.ts +35 -0
  20. package/src/hooks/IoT/useRemoteControl.js +4 -1
  21. package/src/hooks/IoT/useWatchSharedChips.js +130 -0
  22. package/src/hooks/Review/__test__/useInAppReview.test.js +99 -0
  23. package/src/hooks/Review/useInAppReview.js +70 -0
  24. package/src/hooks/useMqtt.js +78 -27
  25. package/src/iot/Monitor.js +149 -26
  26. package/src/iot/UpdateStates.js +60 -0
  27. package/src/iot/mqtt.js +177 -22
  28. package/src/navigations/UnitStack.js +16 -0
  29. package/src/screens/ActivityLog/FilterPopup.js +4 -79
  30. package/src/screens/ActivityLog/ItemLog.js +1 -0
  31. package/src/screens/ActivityLog/__test__/FilterPopup.test.js +2 -6
  32. package/src/screens/ActivityLog/__test__/index.test.js +51 -29
  33. package/src/screens/ActivityLog/index.js +0 -1
  34. package/src/screens/ActivityLog/styles/filterPopupStyles.js +5 -2
  35. package/src/screens/AddNewGateway/RenameNewDevices.js +5 -0
  36. package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +18 -0
  37. package/src/screens/Automate/AddNewAction/ReceiverSelect.js +208 -0
  38. package/src/screens/Automate/AddNewAction/SetupScriptEmail.js +1 -1
  39. package/src/screens/Automate/AddNewAction/SetupScriptNotify.js +18 -28
  40. package/src/screens/Automate/AddNewAction/SetupScriptReceiverEmail.js +22 -129
  41. package/src/screens/Automate/AddNewAction/SetupScriptReceiverNotify.js +59 -0
  42. package/src/screens/Automate/AddNewAction/SetupScriptReceiverSms.js +22 -129
  43. package/src/screens/Automate/AddNewAction/SetupScriptSms.js +1 -1
  44. package/src/screens/Automate/AddNewAction/Styles/{SetupScriptReceiverEmailStyles.js → ReceiverSelectStyles.js} +18 -1
  45. package/src/screens/Automate/AddNewAction/__test__/SetupScriptNotify.test.js +16 -33
  46. package/src/screens/Automate/AddNewAction/__test__/SetupScriptReceiverEmail.test.js +10 -8
  47. package/src/screens/Automate/AddNewAction/__test__/SetupScriptReceiverNotify.test.js +217 -0
  48. package/src/screens/Automate/AddNewAction/__test__/SetupScriptReceiverSms.test.js +10 -8
  49. package/src/screens/Automate/Components/InputName.js +5 -1
  50. package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +18 -0
  51. package/src/screens/Automate/ScriptDetail/index.js +6 -6
  52. package/src/screens/CreatePassword/__test__/index.test.js +133 -0
  53. package/src/screens/CreatePassword/index.js +134 -0
  54. package/src/screens/CreatePassword/styles.js +45 -0
  55. package/src/screens/Device/__test__/DeviceDetail-3rdparty.test.js +447 -0
  56. package/src/screens/Device/__test__/DeviceDetail-arduino.test.js +344 -0
  57. package/src/screens/Device/__test__/{mqttDetail.test.js → DeviceDetail-modbus.test.js} +287 -320
  58. package/src/screens/Device/__test__/DeviceDetail-zigbee.test.js +451 -0
  59. package/src/screens/Device/__test__/DeviceDetail.test.js +502 -0
  60. package/src/screens/Device/__test__/detail.test.js +61 -3
  61. package/src/screens/Device/__test__/sensorDisplayItem.test.js +28 -3
  62. package/src/screens/Device/components/SensorDisplayItem.js +16 -14
  63. package/src/screens/Device/detail.js +14 -6
  64. package/src/screens/Device/hooks/useDeviceWatchConfigControl.js +3 -2
  65. package/src/screens/Device/styles.js +0 -5
  66. package/src/screens/EnterPassword/__test__/EnterPassword.test.js +76 -1
  67. package/src/screens/EnterPassword/index.js +34 -4
  68. package/src/screens/EnterPassword/styles.js +1 -1
  69. package/src/utils/FactoryGateway.js +597 -0
  70. package/src/utils/I18n/translations/en.js +10 -0
  71. package/src/utils/I18n/translations/vi.js +10 -0
  72. package/src/utils/Route/index.js +3 -1
  73. package/src/utils/Validation.js +5 -0
  74. package/src/utils/store.js +5 -0
@@ -0,0 +1,344 @@
1
+ import { NavigationContext } from '@react-navigation/native';
2
+ import AsyncStorage from '@react-native-async-storage/async-storage';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+ import moment from 'moment';
5
+ import mqtt from 'precompiled-mqtt/dist/mqtt.browser';
6
+ import React from 'react';
7
+ import { Alert } from 'react-native';
8
+ import { act, create } from 'react-test-renderer';
9
+
10
+ import QualityIndicatorItem from '../../../commons/Device/WaterQualitySensor/QualityIndicatorsItem';
11
+ import { API } from '../../../configs';
12
+ import { SCProvider } from '../../../context';
13
+ import { mockSCStore } from '../../../context/mockStore';
14
+ import { mqttClientsPool } from '../../../hooks/useMqtt';
15
+ import { unwatchMultiDataChips, watchMultiConfigs } from '../../../iot/Monitor';
16
+ import { setConfigGlobalState } from '../../../iot/states';
17
+ import api from '../../../utils/Apis/axios';
18
+ import {
19
+ configDataFactory,
20
+ gatewayDataFactory,
21
+ } from '../../../utils/FactoryGateway';
22
+ import DeviceDetail from '../detail';
23
+
24
+ const mock = new MockAdapter(api.axiosInstance);
25
+
26
+ jest.mock('../../../iot/Monitor', () => {
27
+ return {
28
+ ...jest.requireActual('../../../iot/Monitor'),
29
+ watchMultiConfigs: jest.fn(),
30
+ unwatchMultiDataChips: jest.fn(),
31
+ };
32
+ });
33
+
34
+ let store = mockSCStore({});
35
+
36
+ const mockAxios = (
37
+ responseDisplay,
38
+ responseDisplayValueV2,
39
+ responseRemoteControl = {}
40
+ ) => {
41
+ mock.onGet(API.DEVICE.DISPLAY(1)).reply(200, responseDisplay);
42
+ mock
43
+ .onGet(API.DEVICE.REMOTE_CONTROL_OPTIONS(1))
44
+ .reply(200, responseRemoteControl);
45
+ mock
46
+ .onGet(API.DEVICE.DISPLAY_VALUES_V2(1))
47
+ .reply(200, responseDisplayValueV2);
48
+ };
49
+
50
+ const navContextValue = {
51
+ isFocused: () => false,
52
+ addListener: jest.fn(() => jest.fn()),
53
+ };
54
+ const wrapComponent = (state, account, route) => (
55
+ <SCProvider initState={state}>
56
+ <NavigationContext.Provider
57
+ value={{
58
+ ...navContextValue,
59
+ isFocused: () => true,
60
+ }}
61
+ >
62
+ <DeviceDetail account={account} route={route} />
63
+ </NavigationContext.Provider>
64
+ </SCProvider>
65
+ );
66
+
67
+ const mockAlertShow = jest.fn();
68
+ Alert.alert = mockAlertShow;
69
+
70
+ describe('test DeviceDetail', () => {
71
+ let tree;
72
+ let route;
73
+ let account;
74
+ let gatewayData;
75
+
76
+ beforeEach(() => {
77
+ route = {
78
+ params: {
79
+ unitData: {
80
+ id: 1,
81
+ name: 'Unit name',
82
+ address: '298 Dien Bien Phu',
83
+ remote_control_options: {
84
+ googlehome: [
85
+ {
86
+ config_maps: [],
87
+ auth: {},
88
+ chip_id: 1,
89
+ },
90
+ ],
91
+ },
92
+ },
93
+ station: {
94
+ id: 2,
95
+ name: 'Station name',
96
+ },
97
+ sensorData: {
98
+ id: 1,
99
+ is_managed_by_backend: true,
100
+ station: { id: 2, name: 'Station name' },
101
+ name: 'Sensor name',
102
+ chip_id: 7689,
103
+ },
104
+ title: 'Button',
105
+ },
106
+ };
107
+ account = {
108
+ token: 'abc',
109
+ };
110
+ jest.useFakeTimers();
111
+ mock.reset();
112
+ watchMultiConfigs.mockClear();
113
+ unwatchMultiDataChips.mockClear();
114
+ AsyncStorage.clear();
115
+ mqttClientsPool.clear();
116
+ act(() => {
117
+ setConfigGlobalState('configValues', {});
118
+ });
119
+ gatewayData = JSON.parse(JSON.stringify(gatewayDataFactory));
120
+ mock.onGet(API.CHIP.SHARED_CONFIGURATION).reply(200, []);
121
+ });
122
+
123
+ const _receiveDataOnDeviceDetail = async (widgetConfigs, topic, message) => {
124
+ mock.onGet(API.CHIP.JSON_CONFIGURATION).reply(200, [gatewayData]);
125
+
126
+ const responseDisplay = {
127
+ items: [
128
+ {
129
+ id: 1,
130
+ order: 0,
131
+ template: 'value',
132
+ type: 'value',
133
+ configuration: {
134
+ template: 'simple_list',
135
+ configs: widgetConfigs,
136
+ },
137
+ },
138
+ ],
139
+ };
140
+
141
+ const responseRemoteControl = {
142
+ bluetooth: {
143
+ address: 'JUvfa06PMDU8Cqlo',
144
+ password: 'MYcNoskxspWTPsnh',
145
+ },
146
+ internet: {},
147
+ };
148
+
149
+ const responseDisplayValueV2 = {
150
+ configs: [],
151
+ is_connected: true,
152
+ last_updated: '2021-01-24T12:00:00.000Z',
153
+ };
154
+
155
+ mockAxios(responseDisplay, responseDisplayValueV2, responseRemoteControl);
156
+
157
+ await act(async () => {
158
+ tree = await create(
159
+ wrapComponent(store, account, {
160
+ ...route,
161
+ params: { ...route.params },
162
+ })
163
+ );
164
+ });
165
+ const instance = tree.root;
166
+ const client = mqtt.connect();
167
+ await act(async () => {
168
+ await client.trigger('message', topic, JSON.stringify(message), 'packet');
169
+ });
170
+
171
+ const valueBox = instance.findAllByType(QualityIndicatorItem);
172
+ return valueBox;
173
+ };
174
+
175
+ // ARDUINO PIN
176
+ const testArduinoPin = async (url, data, expect1, expect2) => {
177
+ const valueBoxs = await _receiveDataOnDeviceDetail(
178
+ [{ id: 128282 }, { id: 128324 }],
179
+ url,
180
+ data
181
+ );
182
+ expect(valueBoxs[0].props.value).toEqual(expect1);
183
+ expect(valueBoxs[1].props.value).toEqual(expect2);
184
+ };
185
+
186
+ it('should render device detail, arduino batch call updateGlobalValue', async () => {
187
+ await testArduinoPin('config_value/', { 128282: 10 }, 10, '--');
188
+ });
189
+
190
+ it('should render device detail, arduino pin call updateGlobalValue', async () => {
191
+ await testArduinoPin('config/128282/value/', { v: 10 }, 10, '--');
192
+ });
193
+
194
+ it('should render device detail, arduino pin call updateGlobalValue with past last_updated', async () => {
195
+ act(() => {
196
+ setConfigGlobalState('configValues', {
197
+ 128282: { value: 0, last_updated: moment(1672531200000) },
198
+ });
199
+ });
200
+ await testArduinoPin(
201
+ 'config/128282/value/',
202
+ { v: 10, time: 1672531199 },
203
+ 0,
204
+ '--'
205
+ );
206
+ });
207
+
208
+ it('should render device detail, arduino pin call updateGlobalValue with future last_updated', async () => {
209
+ act(() => {
210
+ setConfigGlobalState('configValues', {
211
+ 128282: { value: 0, last_updated: moment(1672531200000) },
212
+ });
213
+ });
214
+ await testArduinoPin(
215
+ 'config/128282/value/',
216
+ { v: 10, time: 1672531201 },
217
+ 10,
218
+ '--'
219
+ );
220
+ });
221
+
222
+ it('should render device detail, arduino pin with same last_updated', async () => {
223
+ act(() => {
224
+ setConfigGlobalState('configValues', {
225
+ 128282: {
226
+ value: 0,
227
+ last_updated: moment(1672531200123),
228
+ last_updated_micro: 456,
229
+ },
230
+ });
231
+ });
232
+ await testArduinoPin(
233
+ 'config/128282/value/',
234
+ { v: 10, time: 1672531200.123456 },
235
+ 0,
236
+ '--'
237
+ );
238
+ });
239
+
240
+ it('should render device detail, arduino pin with edge past last_updated', async () => {
241
+ act(() => {
242
+ setConfigGlobalState('configValues', {
243
+ 128282: {
244
+ value: 0,
245
+ last_updated: moment(1672531200123),
246
+ last_updated_micro: 456,
247
+ },
248
+ });
249
+ });
250
+ await testArduinoPin(
251
+ 'config/128282/value/',
252
+ { v: 10, time: 1672531200.123455 },
253
+ 0,
254
+ '--'
255
+ );
256
+ });
257
+
258
+ it('should render device detail, arduino pin with edge future last_updated', async () => {
259
+ act(() => {
260
+ setConfigGlobalState('configValues', {
261
+ 128282: {
262
+ value: 0,
263
+ last_updated: moment(1672531200123),
264
+ last_updated_micro: 456,
265
+ },
266
+ });
267
+ });
268
+ await testArduinoPin(
269
+ 'config/128282/value/',
270
+ { v: 10, time: 1672531200.123457 },
271
+ 10,
272
+ '--'
273
+ );
274
+ });
275
+
276
+ it('should render device detail, arduino pin call updateGlobalValue, filter zero', async () => {
277
+ gatewayData.sensors[0].configs[0].active_filter = 'zero';
278
+ await testArduinoPin('config/128282/value/', { v: 0 }, '--', '--');
279
+ });
280
+
281
+ it('should render device detail, arduino pin call updateGlobalValue, filter in range', async () => {
282
+ gatewayData.sensors[0].configs[0].active_filter = 'range';
283
+ gatewayData.sensors[0].configs[0].high_level = 11;
284
+ await testArduinoPin('config/128282/value/', { v: 10 }, 10, '--');
285
+ });
286
+
287
+ it('should render device detail, arduino pin call updateGlobalValue, filter out range', async () => {
288
+ gatewayData.sensors[0].configs[0].active_filter = 'range';
289
+ gatewayData.sensors[0].configs[0].high_level = 10;
290
+ await testArduinoPin('config/128282/value/', { v: 11 }, '--', '--');
291
+ });
292
+
293
+ it('should render device detail, arduino pin call updateGlobalValue, with offset', async () => {
294
+ gatewayData.sensors[0].configs[0].ai_trans_offset_value = '1.000';
295
+ await testArduinoPin('config/128282/value/', { v: 10 }, 11, '--');
296
+ });
297
+
298
+ it('should render device detail, arduino pin call updateGlobalValue, with average sample first time', async () => {
299
+ const cacheKey = `last_values_${gatewayData.sensors[0].configs[0].id}`;
300
+ gatewayData.sensors[0].configs[0].decimal_behind = 2;
301
+ gatewayData.sensors[0].configs[0].ai_trans_average_sample = 2;
302
+ await testArduinoPin('config/128282/value/', { v: 10 }, 10, '--');
303
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(cacheKey, '[10]');
304
+ });
305
+
306
+ it('should render device detail, arduino pin call updateGlobalValue, with average sample', async () => {
307
+ const cacheKey = `last_values_${gatewayData.sensors[0].configs[0].id}`;
308
+ await AsyncStorage.setItem(cacheKey, '[0.2, 0.3, 0.4, 0.5]');
309
+ gatewayData.sensors[0].configs[0].decimal_behind = 2;
310
+ gatewayData.sensors[0].configs[0].ai_trans_average_sample = 2;
311
+ await testArduinoPin('config/128282/value/', { v: 10 }, 5.1, '--'); // (10 + 0.2) / 2 = 5.1
312
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(
313
+ cacheKey,
314
+ '[5.1,0.2]'
315
+ );
316
+ });
317
+
318
+ it('should render device detail, arduino pin call updateGlobalValue, with offset and average sample', async () => {
319
+ const cacheKey = `last_values_${gatewayData.sensors[0].configs[0].id}`;
320
+ await AsyncStorage.setItem(cacheKey, '[0.2, 0.3, 0.4, 0.5]');
321
+ gatewayData.sensors[0].configs[0].decimal_behind = 2;
322
+ gatewayData.sensors[0].configs[0].ai_trans_average_sample = 2;
323
+ gatewayData.sensors[0].configs[0].ai_trans_offset_value = '1.000';
324
+ await testArduinoPin('config/128282/value/', { v: 10 }, 5.6, '--'); // (10 + 1 + 0.2) / 2 = 5.6
325
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(
326
+ cacheKey,
327
+ '[5.6,0.2]'
328
+ );
329
+ });
330
+
331
+ it('arduino pin submit data type string updateGlobalValue', async () => {
332
+ await testArduinoPin('config/128282/value/', { v: 'on' }, 'on', '--');
333
+ });
334
+
335
+ it('should render device detail, arduino pin not call updateGlobalValue, configs is empty', async () => {
336
+ gatewayData.sensors = [{ id: configDataFactory.sensor, configs: [] }];
337
+ await testArduinoPin('config/128282/value/', { v: 10 }, '--', '--');
338
+ });
339
+
340
+ it('should render device detail, arduino pin not call updateGlobalValue, sensors is empty', async () => {
341
+ gatewayData.sensors = [];
342
+ await testArduinoPin('config/128282/value/', { v: 10 }, '--', '--');
343
+ });
344
+ });