@eohjsc/react-native-smart-city 0.4.57 → 0.4.58
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.
package/package.json
CHANGED
|
@@ -16,6 +16,12 @@ import Compass from '../../../commons/Device/WindDirection/Compass';
|
|
|
16
16
|
import DeviceAlertStatus from '../../../commons/Device/DeviceAlertStatus';
|
|
17
17
|
import MockAdapter from 'axios-mock-adapter';
|
|
18
18
|
import api from '../../../utils/Apis/axios';
|
|
19
|
+
import CurrentRainSensor from '../../../commons/Device/RainningSensor/CurrentRainSensor';
|
|
20
|
+
|
|
21
|
+
jest.mock('../../../iot/states', () => ({
|
|
22
|
+
useConfigGlobalState: () => [{}, null],
|
|
23
|
+
getConfigGlobalState: () => 'en',
|
|
24
|
+
}));
|
|
19
25
|
|
|
20
26
|
new MockAdapter(api.axiosInstance);
|
|
21
27
|
|
|
@@ -102,6 +108,7 @@ describe('Test SensorDisplayItem', () => {
|
|
|
102
108
|
const actionGroup = instance.findAllByType(ActionGroup);
|
|
103
109
|
expect(actionGroup).toHaveLength(1);
|
|
104
110
|
});
|
|
111
|
+
|
|
105
112
|
it('render camera', async () => {
|
|
106
113
|
const item = {
|
|
107
114
|
id: 10452,
|
|
@@ -304,4 +311,106 @@ describe('Test SensorDisplayItem', () => {
|
|
|
304
311
|
const flatListItems = instance.findAllByType(DeviceAlertStatus);
|
|
305
312
|
expect(flatListItems).toHaveLength(1);
|
|
306
313
|
});
|
|
314
|
+
|
|
315
|
+
const _testCircleMini = async (item, expectProps) => {
|
|
316
|
+
const sensor = {
|
|
317
|
+
name: 'Sensor name',
|
|
318
|
+
is_managed_by_backend: false,
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
await act(async () => {
|
|
322
|
+
tree = await renderer.create(wrapComponent({ item, sensor }));
|
|
323
|
+
});
|
|
324
|
+
const instance = tree.root;
|
|
325
|
+
|
|
326
|
+
const currentRainSensor = instance.findByType(CurrentRainSensor);
|
|
327
|
+
expect(currentRainSensor.props).toEqual(expectProps);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
it('render circle_mini', async () => {
|
|
331
|
+
const globalStates = require('../../../iot/states');
|
|
332
|
+
globalStates.useConfigGlobalState = () => [{ 99: { value: 1 } }, null];
|
|
333
|
+
|
|
334
|
+
const item = {
|
|
335
|
+
id: 10452,
|
|
336
|
+
order: 0,
|
|
337
|
+
template: 'circle_mini',
|
|
338
|
+
type: 'circle_mini',
|
|
339
|
+
configuration: {
|
|
340
|
+
config: {
|
|
341
|
+
id: 99,
|
|
342
|
+
title: '1',
|
|
343
|
+
color: 'blue',
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
is_configuration_ready: true,
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
await _testCircleMini(item, {
|
|
350
|
+
data: [
|
|
351
|
+
{
|
|
352
|
+
id: 99,
|
|
353
|
+
title: '1',
|
|
354
|
+
color: 'blue',
|
|
355
|
+
value: 1,
|
|
356
|
+
evaluate: {
|
|
357
|
+
color: null,
|
|
358
|
+
text: '--',
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
],
|
|
362
|
+
isWidgetOrder: undefined,
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it('render circle_mini without config value', async () => {
|
|
367
|
+
const globalStates = require('../../../iot/states');
|
|
368
|
+
globalStates.useConfigGlobalState = () => [{ 2: { value: 1 } }, null];
|
|
369
|
+
|
|
370
|
+
const item = {
|
|
371
|
+
id: 10452,
|
|
372
|
+
order: 0,
|
|
373
|
+
template: 'circle_mini',
|
|
374
|
+
type: 'circle_mini',
|
|
375
|
+
configuration: {
|
|
376
|
+
config: {
|
|
377
|
+
id: 99,
|
|
378
|
+
title: '1',
|
|
379
|
+
color: 'blue',
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
is_configuration_ready: true,
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
await _testCircleMini(item, {
|
|
386
|
+
data: [
|
|
387
|
+
{
|
|
388
|
+
id: 99,
|
|
389
|
+
title: '1',
|
|
390
|
+
color: 'blue',
|
|
391
|
+
value: null,
|
|
392
|
+
evaluate: null,
|
|
393
|
+
},
|
|
394
|
+
],
|
|
395
|
+
isWidgetOrder: undefined,
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it('render circle_mini without config id', async () => {
|
|
400
|
+
const item = {
|
|
401
|
+
id: 10452,
|
|
402
|
+
order: 0,
|
|
403
|
+
template: 'circle_mini',
|
|
404
|
+
type: 'circle_mini',
|
|
405
|
+
configuration: {
|
|
406
|
+
config: null,
|
|
407
|
+
},
|
|
408
|
+
is_configuration_ready: true,
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
await _testCircleMini(item, {
|
|
412
|
+
data: undefined,
|
|
413
|
+
isWidgetOrder: undefined,
|
|
414
|
+
});
|
|
415
|
+
});
|
|
307
416
|
});
|
|
@@ -46,6 +46,13 @@ export const SensorDisplayItem = ({
|
|
|
46
46
|
|
|
47
47
|
const evaluateValue = useEvaluateValue();
|
|
48
48
|
|
|
49
|
+
const checkConfigValue = (configValue) => {
|
|
50
|
+
if (configValue === null || configValue === undefined) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
|
|
49
56
|
const getData = useCallback(() => {
|
|
50
57
|
if (!item.configuration) {
|
|
51
58
|
return;
|
|
@@ -83,6 +90,34 @@ export const SensorDisplayItem = ({
|
|
|
83
90
|
value_evaluation,
|
|
84
91
|
]);
|
|
85
92
|
|
|
93
|
+
const getDataCircleMini = useCallback(() => {
|
|
94
|
+
if (!item?.configuration?.config?.id) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const config = item.configuration.config;
|
|
99
|
+
const configValue = configValues[config.id]?.value;
|
|
100
|
+
const configEvaluate = evaluate[config.id] || {};
|
|
101
|
+
|
|
102
|
+
const hasConfigValue = checkConfigValue(configValue);
|
|
103
|
+
|
|
104
|
+
let value = {
|
|
105
|
+
id: config.id,
|
|
106
|
+
value: hasConfigValue ? configValue : null,
|
|
107
|
+
evaluate: hasConfigValue
|
|
108
|
+
? evaluateValue(configValue, value_evaluation) || configEvaluate
|
|
109
|
+
: null,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return [{ ...config, ...value }].filter(Boolean);
|
|
113
|
+
}, [
|
|
114
|
+
configValues,
|
|
115
|
+
evaluate,
|
|
116
|
+
evaluateValue,
|
|
117
|
+
item.configuration,
|
|
118
|
+
value_evaluation,
|
|
119
|
+
]);
|
|
120
|
+
|
|
86
121
|
const doAction = useCallback(
|
|
87
122
|
async (action, data) => {
|
|
88
123
|
if (processing) {
|
|
@@ -156,6 +191,13 @@ export const SensorDisplayItem = ({
|
|
|
156
191
|
isWidgetOrder={isWidgetOrder}
|
|
157
192
|
/>
|
|
158
193
|
);
|
|
194
|
+
case 'circle_mini':
|
|
195
|
+
return (
|
|
196
|
+
<CurrentRainSensor
|
|
197
|
+
data={getDataCircleMini(item)}
|
|
198
|
+
isWidgetOrder={isWidgetOrder}
|
|
199
|
+
/>
|
|
200
|
+
);
|
|
159
201
|
case 'value':
|
|
160
202
|
switch (type || template) {
|
|
161
203
|
case 'circle':
|