@eohjsc/react-native-smart-city 0.3.86 → 0.3.87

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 (42) hide show
  1. package/package.json +1 -1
  2. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +30 -0
  3. package/src/commons/{FourButtonFilterHistory → ChartAggregationOption}/__test__/FourButtonFilterHistory.test.js +2 -2
  4. package/src/commons/ChartAggregationOption/index.js +72 -0
  5. package/src/commons/{FourButtonFilterHistory → ChartAggregationOption}/styles.js +0 -0
  6. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +19 -0
  7. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +30 -9
  8. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +13 -1
  9. package/src/commons/Dashboard/MyUnit/index.js +20 -10
  10. package/src/commons/DateTimeRangeChange/DateTimeButton.js +3 -12
  11. package/src/commons/DateTimeRangeChange/index.js +113 -19
  12. package/src/commons/Device/HistoryChart.js +2 -2
  13. package/src/commons/Device/LinearChart.js +2 -2
  14. package/src/commons/Device/WindSpeed/Anemometer/index.js +23 -18
  15. package/src/commons/Device/WindSpeed/__test__/Anemometer.test.js +1 -1
  16. package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +7 -7
  17. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +40 -13
  18. package/src/configs/API.js +1 -1
  19. package/src/configs/AccessibilityLabel.js +4 -0
  20. package/src/context/actionType.ts +2 -0
  21. package/src/context/reducer.ts +10 -0
  22. package/src/hooks/Common/useTranslations.ts +1 -1
  23. package/src/hooks/IoT/useRemoteControl.js +0 -1
  24. package/src/screens/ActivityLog/__test__/FilterPopup.test.js +1 -1
  25. package/src/screens/ActivityLog/__test__/index.test.js +1 -1
  26. package/src/screens/AddNewGateway/__test__/ScanModbusQR.test.js +15 -0
  27. package/src/screens/Device/__test__/DetailHistoryChart.test.js +1 -0
  28. package/src/screens/Device/__test__/sensorDisplayItem.test.js +150 -2
  29. package/src/screens/Device/components/ChartWrapper.js +39 -0
  30. package/src/screens/Device/components/ChartWrapperStyles.js +42 -0
  31. package/src/screens/Device/components/SensorDisplayItem.js +6 -2
  32. package/src/screens/Device/components/VisualChart.js +255 -0
  33. package/src/screens/Device/components/__test__/VisualChart.test.js +440 -0
  34. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +7 -6
  35. package/src/screens/SmartAccount/SuccessfullyConnected/__test__/SuccessfullyConnected.test.js +3 -0
  36. package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +47 -0
  37. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +15 -2
  38. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +52 -0
  39. package/src/screens/Unit/components/__test__/Header.test.js +9 -0
  40. package/src/utils/I18n/translations/en.json +1 -1
  41. package/src/utils/I18n/translations/vi.json +1 -1
  42. package/src/commons/FourButtonFilterHistory/index.js +0 -72
@@ -0,0 +1,255 @@
1
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
2
+ import moment from 'moment/moment';
3
+ import _ from 'lodash';
4
+ import HighchartsReactNative from '@eohjsc/highcharts';
5
+
6
+ import ChartWrapper from './ChartWrapper';
7
+ import { useFetchConfigHistory } from '../../../commons/UnitSummary/ConfigHistoryChart';
8
+ import { StyleSheet, View } from 'react-native';
9
+ import { Colors } from '../../../configs';
10
+ import ChartAggregationOption from '../../../commons/ChartAggregationOption';
11
+ import Text from '../../../commons/Text';
12
+
13
+ const groupByTime = (format) => (x) => x[0].format(format);
14
+
15
+ const groupByDay = groupByTime('YYYY-MM-DD');
16
+ const groupByMonth = groupByTime('YYYY-MM');
17
+ const groupByYear = groupByTime('YYYY');
18
+ const groupByWeek = groupByTime('YYYY-WW');
19
+ const groupByHour = groupByTime('YYYY-MM-DD HH');
20
+
21
+ const groupByFunc = {
22
+ day: groupByDay,
23
+ month: groupByMonth,
24
+ week: groupByWeek,
25
+ year: groupByYear,
26
+ hour: groupByHour,
27
+ };
28
+
29
+ export const convertLineChartData = (data = [], valueType = 'raw', groupBy) => {
30
+ let arr = [];
31
+ for (let i = 0; i < data.length; i++) {
32
+ arr.push([moment(data[i].x), data[i].y]);
33
+ }
34
+ if (valueType === 'raw') {
35
+ return arr;
36
+ }
37
+ if (groupBy) {
38
+ arr = _.groupBy(arr, groupByFunc[groupBy]);
39
+ arr = Object.entries(arr).map((x) => {
40
+ if (valueType === 'sum') {
41
+ return [moment(x[0]).valueOf(), _.sum(x[1].map((i) => i[1]))];
42
+ }
43
+ if (valueType === 'avg') {
44
+ return [
45
+ moment(x[0]).valueOf(),
46
+ _.sum(x[1].map((i) => i[1])) / x[1].length,
47
+ ];
48
+ }
49
+ /* istanbul ignore next */
50
+ return null;
51
+ });
52
+ }
53
+
54
+ return arr;
55
+ };
56
+
57
+ export const CHART_TYPE_ENUM = {
58
+ line_chart: 'line_chart',
59
+ bar_chart: 'bar_chart',
60
+ horizontal_bar_chart: 'horizontal_bar_chart',
61
+ stacked_bar_chart: 'stacked_bar_chart',
62
+ area_chart: 'area_chart',
63
+ scatter_chart: 'scatter_chart',
64
+ };
65
+
66
+ const styles = StyleSheet.create({
67
+ chartStyle: {
68
+ backgroundColor: Colors.White,
69
+ flex: 1,
70
+ },
71
+ titleHistory: {
72
+ flexDirection: 'row',
73
+ alignItems: 'center',
74
+ justifyContent: 'space-between',
75
+ paddingHorizontal: 16,
76
+ },
77
+ webviewStyle: {
78
+ flex: 1,
79
+ minHeight: 200,
80
+ height: 300,
81
+ opacity: 0.99,
82
+ },
83
+ });
84
+
85
+ const chartOptions = {
86
+ colors: ['#00979D', '#F10303', '#FFF7E6'],
87
+ credits: {
88
+ enabled: false,
89
+ },
90
+ title: {
91
+ text: '',
92
+ },
93
+ time: {
94
+ // NOTE: default is 0 for the same with server timezone
95
+ timezoneOffset: -7 * 60,
96
+ },
97
+ xAxis: {
98
+ type: 'datetime',
99
+ title: {
100
+ text: '',
101
+ },
102
+ },
103
+ plotOptions: {},
104
+ series: [],
105
+ };
106
+
107
+ const groupByOptions = [
108
+ { title: 'H', data: 'hour' },
109
+ { title: 'D', data: 'day' },
110
+ { title: 'W', data: 'week' },
111
+ { title: 'M', data: 'month' },
112
+ { title: 'Y', data: 'year' },
113
+ ];
114
+
115
+ const VisualChart = ({ item, isDemo = false, isTemplate }) => {
116
+ const { configuration = {} } = item;
117
+ const {
118
+ configs = [],
119
+ value_type = 'raw',
120
+ aggregation_period,
121
+ date_format,
122
+ show_time,
123
+ } = configuration;
124
+ const canChooseGroup = value_type !== 'raw';
125
+ const [chartData, setChartData] = useState(configs);
126
+ const [options, setOption] = useState(chartOptions);
127
+ const [groupBy, setGroupBy] = useState(
128
+ canChooseGroup ? aggregation_period : null
129
+ );
130
+ const chartRef = useRef();
131
+
132
+ const fetchDataDisplayHistory = useFetchConfigHistory(configs, setChartData);
133
+
134
+ const getSeries = useCallback(() => {
135
+ let series = [];
136
+ for (let i = 0; i < chartData.length; i++) {
137
+ const arr = convertLineChartData(chartData[i].data, value_type, groupBy);
138
+
139
+ series.push({
140
+ name: chartData[i].title,
141
+ data: arr,
142
+ color: chartData[i].color,
143
+ states: {
144
+ inactive: {
145
+ opacity: 1,
146
+ },
147
+ },
148
+ });
149
+ }
150
+ return series;
151
+ }, [chartData, groupBy, value_type]);
152
+
153
+ const updateChart = useCallback(() => {
154
+ setOption((prev) => ({
155
+ ...prev,
156
+ series: getSeries(),
157
+ }));
158
+ }, [getSeries]);
159
+
160
+ useEffect(() => {
161
+ setOption((prev) => {
162
+ const newOption = {
163
+ ...prev,
164
+ chart: { ...prev.chart },
165
+ plotOptions: { ...prev.plotOptions },
166
+ };
167
+ switch (configuration?.type) {
168
+ case CHART_TYPE_ENUM.bar_chart:
169
+ newOption.chart.type = 'column';
170
+ newOption.plotOptions.column = {
171
+ ...chartOptions.plotOptions.column,
172
+ stacking: undefined,
173
+ };
174
+ break;
175
+ case CHART_TYPE_ENUM.horizontal_bar_chart:
176
+ newOption.chart.type = 'bar';
177
+ break;
178
+ case CHART_TYPE_ENUM.area_chart:
179
+ newOption.chart.type = 'area';
180
+ break;
181
+ case CHART_TYPE_ENUM.stacked_bar_chart:
182
+ newOption.chart.type = 'column';
183
+ newOption.plotOptions.column = {
184
+ ...chartOptions.plotOptions.column,
185
+ stacking: 'normal',
186
+ dataLabels: {
187
+ enabled: true,
188
+ },
189
+ };
190
+ break;
191
+ case CHART_TYPE_ENUM.scatter_chart:
192
+ newOption.chart.type = 'scatter';
193
+ newOption.plotOptions.scatter = {
194
+ ...newOption.plotOptions.scatter,
195
+ showInLegend: false,
196
+ jitter: {
197
+ x: 0.24,
198
+ y: 0,
199
+ },
200
+ marker: {
201
+ radius: 2,
202
+ symbol: 'circle',
203
+ },
204
+ tooltip: {
205
+ pointFormat: 'Measurement: {point.y:.3f}',
206
+ },
207
+ };
208
+ break;
209
+ default:
210
+ newOption.chart.type = 'line';
211
+ break;
212
+ }
213
+ return newOption;
214
+ });
215
+
216
+ chartRef.current?.chart?.redraw();
217
+ }, [configuration?.type]);
218
+
219
+ useEffect(() => {
220
+ if (!isDemo) {
221
+ updateChart();
222
+ }
223
+ }, [updateChart, chartData, item?.configuration?.configs?.length, isDemo]);
224
+
225
+ return (
226
+ <View style={styles.container}>
227
+ <View style={styles.titleHistory}>
228
+ <Text size={20} semibold color={Colors.Gray9}>
229
+ {item.label}
230
+ </Text>
231
+ {canChooseGroup && (
232
+ <ChartAggregationOption
233
+ groupBy={groupBy}
234
+ setGroupBy={setGroupBy}
235
+ options={groupByOptions}
236
+ />
237
+ )}
238
+ </View>
239
+ <ChartWrapper
240
+ onChangeDate={fetchDataDisplayHistory}
241
+ dateFormat={date_format}
242
+ showTime={show_time}
243
+ isTemplate={isTemplate}
244
+ >
245
+ <HighchartsReactNative
246
+ options={options}
247
+ styles={styles.chartStyle}
248
+ webviewStyles={styles.webviewStyle}
249
+ />
250
+ </ChartWrapper>
251
+ </View>
252
+ );
253
+ };
254
+
255
+ export default VisualChart;
@@ -0,0 +1,440 @@
1
+ import React from 'react';
2
+ import MockAdapter from 'axios-mock-adapter';
3
+ import moment from 'moment';
4
+ import HighchartsReactNative from '@eohjsc/highcharts';
5
+ import { act, create } from 'react-test-renderer';
6
+
7
+ import VisualChart from '../VisualChart';
8
+ import { API } from '../../../../configs';
9
+ import { getPusher } from '../../../../utils/Pusher';
10
+ import { flushPromises } from '../../../AllGateway/test-utils';
11
+ import api from '../../../../utils/Apis/axios';
12
+ import ChartAggregationOption from '../../../../commons/ChartAggregationOption';
13
+ import DateTimeRangeChange from '../../../../commons/DateTimeRangeChange';
14
+
15
+ const render = async (component) => {
16
+ let tree;
17
+ await act(async () => {
18
+ tree = await create(component);
19
+ });
20
+ return tree;
21
+ };
22
+
23
+ jest.mock('react-redux', () => {
24
+ return {
25
+ ...jest.requireActual('react-redux'),
26
+ useSelector: jest.fn(),
27
+ };
28
+ });
29
+
30
+ const mockAxios = new MockAdapter(api.axiosInstance);
31
+
32
+ describe('Test LinearChartWidget', () => {
33
+ let tree;
34
+ beforeEach(() => {
35
+ mockAxios.reset();
36
+ });
37
+
38
+ const assertChartData = (data, expected) => {
39
+ const expected2 = expected.map((item) => [
40
+ moment(item[0]).valueOf(),
41
+ item[1],
42
+ ]);
43
+ expect([expected.toString(), expected2.toString()]).toContain(
44
+ data.toString()
45
+ );
46
+ };
47
+
48
+ it('Test render fetch data from api', async () => {
49
+ mockAxios.onGet(API.CONFIG.DISPLAY_HISTORY_V3()).reply(200, {
50
+ configs: [
51
+ {
52
+ id: 1,
53
+ head: [],
54
+ tail: [{ x: 1000, y: 100 }],
55
+ middle: { ready: [], not_ready: [] },
56
+ },
57
+ ],
58
+ });
59
+ tree = await render(
60
+ <VisualChart
61
+ item={{
62
+ is_configuration_ready: true,
63
+ configuration: {
64
+ type: 'line_chart',
65
+ configs: [
66
+ {
67
+ id: 1,
68
+ },
69
+ ],
70
+ },
71
+ id: 1,
72
+ template: 'history',
73
+ }}
74
+ />
75
+ );
76
+ const instance = tree.root;
77
+ const chart = instance.findByType(HighchartsReactNative);
78
+ assertChartData(chart.props.options.series[0].data, [[moment(1000), 100]]);
79
+ });
80
+
81
+ it('Test render fetch data from api and cache', async () => {
82
+ const cacheUrl1 = 'https://s3.eoh.io/xxx1.json';
83
+ const cacheUrl2 = 'https://s3.eoh.io/xxx2.json';
84
+ const cacheUrl3 = 'https://s3.eoh.io/xxx3.json';
85
+ const cacheUrl4 = 'https://s3.eoh.io/xxx4.json';
86
+ const responseData = {
87
+ configs: [
88
+ {
89
+ id: 1,
90
+ head: [{ x: 1, y: 2 }],
91
+ tail: [{ x: 2, y: 3 }],
92
+ middle: {
93
+ ready: [
94
+ { date: '2022-03-02', url: cacheUrl1 },
95
+ { date: '2022-03-04', url: cacheUrl3 },
96
+ ],
97
+ not_ready: [
98
+ { date: '2022-03-03', url: cacheUrl2 },
99
+ { date: '2022-03-05', url: cacheUrl4 },
100
+ ],
101
+ channel: 'cache-xxx',
102
+ },
103
+ },
104
+ ],
105
+ };
106
+ mockAxios.onGet(cacheUrl1).reply(200, [{ x: 3, y: 4 }]);
107
+ mockAxios.onGet(cacheUrl2).reply(200, [{ x: 4, y: 5 }]);
108
+ mockAxios.onGet(cacheUrl3).reply(200, [{ x: 5, y: 6 }]);
109
+ mockAxios.onGet(cacheUrl4).reply(200, [{ x: 7, y: 8 }]);
110
+
111
+ mockAxios.onGet(API.CONFIG.DISPLAY_HISTORY_V3()).reply(200, responseData);
112
+ tree = await render(
113
+ <VisualChart
114
+ item={{
115
+ is_configuration_ready: true,
116
+ configuration: {
117
+ type: 'line_chart',
118
+ configs: [
119
+ {
120
+ id: 1,
121
+ },
122
+ ],
123
+ },
124
+ id: 1,
125
+ template: 'history',
126
+ }}
127
+ />
128
+ );
129
+ const instance = tree.root;
130
+ const chart = instance.findByType(HighchartsReactNative);
131
+ assertChartData(chart.props.options.series[0].data, [
132
+ [moment(1), 2],
133
+ [moment(3), 4],
134
+ [moment(5), 6],
135
+ [moment(2), 3],
136
+ ]);
137
+
138
+ await act(async () => {
139
+ await getPusher()
140
+ .subscribe('cache-xxx')
141
+ .trigger('caching-value-log-process', {
142
+ success: true,
143
+ });
144
+ });
145
+
146
+ await flushPromises();
147
+
148
+ assertChartData(chart.props.options.series[0].data, [
149
+ [moment(1), 2],
150
+ [moment(3), 4],
151
+ [moment(4), 5],
152
+ [moment(5), 6],
153
+ [moment(7), 8],
154
+ [moment(2), 3],
155
+ ]);
156
+ });
157
+
158
+ it('Test render aggregation sum', async () => {
159
+ mockAxios.onGet(API.CONFIG.DISPLAY_HISTORY_V3()).reply(200, {
160
+ configs: [
161
+ {
162
+ id: 1,
163
+ head: [],
164
+ tail: [
165
+ { x: 1000, y: 100 },
166
+ { x: 1000 + 86400000, y: 100 },
167
+ ],
168
+ middle: { ready: [], not_ready: [] },
169
+ },
170
+ ],
171
+ });
172
+ tree = await render(
173
+ <VisualChart
174
+ item={{
175
+ is_configuration_ready: true,
176
+ configuration: {
177
+ type: 'line_chart',
178
+ value_type: 'sum',
179
+ aggregation_period: 'day',
180
+ configs: [
181
+ {
182
+ id: 1,
183
+ },
184
+ ],
185
+ },
186
+ id: 1,
187
+ template: 'history',
188
+ }}
189
+ />
190
+ );
191
+ const instance = tree.root;
192
+ const chart = instance.findByType(HighchartsReactNative);
193
+ assertChartData(chart.props.options.series[0].data, [
194
+ ['1970-01-01', 100],
195
+ ['1970-01-02', 100],
196
+ ]);
197
+
198
+ const groupByOption = instance.findByType(ChartAggregationOption);
199
+
200
+ await act(async () => {
201
+ groupByOption.props.setGroupBy('month');
202
+ });
203
+ assertChartData(chart.props.options.series[0].data, [['1970-01', 200]]);
204
+ });
205
+
206
+ it('Test render aggregation sum', async () => {
207
+ mockAxios.onGet(API.CONFIG.DISPLAY_HISTORY_V3()).reply(200, {
208
+ configs: [
209
+ {
210
+ id: 1,
211
+ head: [],
212
+ tail: [
213
+ { x: 1000, y: 100 },
214
+ { x: 1000, y: 100 },
215
+ ],
216
+ middle: { ready: [], not_ready: [] },
217
+ },
218
+ ],
219
+ });
220
+ tree = await render(
221
+ <VisualChart
222
+ item={{
223
+ is_configuration_ready: true,
224
+ configuration: {
225
+ type: 'line_chart',
226
+ value_type: 'sum',
227
+ aggregation_period: 'day',
228
+ configs: [
229
+ {
230
+ id: 1,
231
+ },
232
+ ],
233
+ },
234
+ id: 1,
235
+ template: 'history',
236
+ }}
237
+ />
238
+ );
239
+ const instance = tree.root;
240
+ const chart = instance.findByType(HighchartsReactNative);
241
+ assertChartData(chart.props.options.series[0].data, [['1970-01-01', 200]]);
242
+ });
243
+
244
+ it('Test render aggregation average', async () => {
245
+ mockAxios.onGet(API.CONFIG.DISPLAY_HISTORY_V3()).reply(200, {
246
+ configs: [
247
+ {
248
+ id: 1,
249
+ head: [],
250
+ tail: [
251
+ { x: 1000, y: 100 },
252
+ { x: 1000, y: 200 },
253
+ ],
254
+ middle: { ready: [], not_ready: [] },
255
+ },
256
+ ],
257
+ });
258
+ tree = await render(
259
+ <VisualChart
260
+ item={{
261
+ is_configuration_ready: true,
262
+ configuration: {
263
+ type: 'line_chart',
264
+ value_type: 'avg',
265
+ aggregation_period: 'day',
266
+ configs: [
267
+ {
268
+ id: 1,
269
+ },
270
+ ],
271
+ },
272
+ id: 1,
273
+ template: 'history',
274
+ }}
275
+ />
276
+ );
277
+ const instance = tree.root;
278
+ const chart = instance.findByType(HighchartsReactNative);
279
+ assertChartData(chart.props.options.series[0].data, [['1970-01-01', 150]]);
280
+ });
281
+
282
+ it('Test render not demo', async () => {
283
+ mockAxios.onGet(API.CONFIG.DISPLAY_HISTORY_V3()).reply(400);
284
+ tree = await render(
285
+ <VisualChart
286
+ item={{
287
+ configuration: {
288
+ type: 'line_chart',
289
+ configs: [
290
+ {
291
+ data: [{ x: 1000, y: 100 }],
292
+ title: 'xxx',
293
+ },
294
+ ],
295
+ },
296
+ id: 1,
297
+ template: 'history',
298
+ }}
299
+ />
300
+ );
301
+ const instance = tree.root;
302
+ const chart = instance.findByType(HighchartsReactNative);
303
+ assertChartData(chart.props.options.series[0].data, [[moment(1000), 100]]);
304
+ });
305
+
306
+ it('Test render bar chart', async () => {
307
+ tree = await render(
308
+ <VisualChart
309
+ item={{
310
+ configuration: {
311
+ type: 'bar_chart',
312
+ configs: [],
313
+ },
314
+ id: 1,
315
+ template: 'history',
316
+ }}
317
+ />
318
+ );
319
+ const instance = tree.root;
320
+ const chart = instance.findByType(HighchartsReactNative);
321
+ expect(chart.props.options.chart.type).toEqual('column');
322
+ });
323
+
324
+ it('Test render horizontal_bar_chart', async () => {
325
+ tree = await render(
326
+ <VisualChart
327
+ item={{
328
+ configuration: {
329
+ type: 'horizontal_bar_chart',
330
+ configs: [],
331
+ },
332
+ id: 1,
333
+ template: 'history',
334
+ }}
335
+ />
336
+ );
337
+ const instance = tree.root;
338
+ const chart = instance.findByType(HighchartsReactNative);
339
+ expect(chart.props.options.chart.type).toEqual('bar');
340
+ });
341
+
342
+ it('Test render area_chart', async () => {
343
+ tree = await render(
344
+ <VisualChart
345
+ item={{
346
+ configuration: {
347
+ type: 'area_chart',
348
+ configs: [],
349
+ },
350
+ id: 1,
351
+ template: 'history',
352
+ }}
353
+ />
354
+ );
355
+ const instance = tree.root;
356
+ const chart = instance.findByType(HighchartsReactNative);
357
+ expect(chart.props.options.chart.type).toEqual('area');
358
+ });
359
+
360
+ it('Test render stacked_bar_chart', async () => {
361
+ tree = await render(
362
+ <VisualChart
363
+ item={{
364
+ configuration: {
365
+ type: 'stacked_bar_chart',
366
+ configs: [],
367
+ },
368
+ id: 1,
369
+ template: 'history',
370
+ }}
371
+ />
372
+ );
373
+ const instance = tree.root;
374
+ const chart = instance.findByType(HighchartsReactNative);
375
+ expect(chart.props.options.chart.type).toEqual('column');
376
+ expect(chart.props.options.plotOptions.column.stacking).toEqual('normal');
377
+ });
378
+
379
+ it('Test render scatter_chart', async () => {
380
+ tree = await render(
381
+ <VisualChart
382
+ item={{
383
+ configuration: {
384
+ type: 'scatter_chart',
385
+ configs: [],
386
+ },
387
+ id: 1,
388
+ template: 'history',
389
+ }}
390
+ />
391
+ );
392
+ const instance = tree.root;
393
+ const chart = instance.findByType(HighchartsReactNative);
394
+ expect(chart.props.options.chart.type).toEqual('scatter');
395
+ });
396
+
397
+ it('not fetch data if empty config', async () => {
398
+ tree = await render(
399
+ <VisualChart
400
+ item={{
401
+ configuration: {
402
+ type: 'line_chart',
403
+ configs: [{}],
404
+ },
405
+ id: 1,
406
+ template: 'history',
407
+ }}
408
+ />
409
+ );
410
+ expect(mockAxios.history.get).toHaveLength(0);
411
+ });
412
+
413
+ it('not fetch data when change date', async () => {
414
+ tree = await render(
415
+ <VisualChart
416
+ item={{
417
+ configuration: {
418
+ type: 'line_chart',
419
+ configs: [{ id: 1 }],
420
+ },
421
+ id: 1,
422
+ template: 'history',
423
+ }}
424
+ />
425
+ );
426
+ expect(mockAxios.history.get).toHaveLength(1);
427
+
428
+ const instance = tree.root;
429
+ const dateRange = instance.findByType(DateTimeRangeChange);
430
+ await act(async () => {
431
+ dateRange.props.selectStart(moment().subtract(5, 'days'));
432
+ });
433
+ expect(mockAxios.history.get).toHaveLength(2);
434
+
435
+ await act(async () => {
436
+ dateRange.props.selectEnd(moment().subtract(1, 'days'));
437
+ });
438
+ expect(mockAxios.history.get).toHaveLength(3);
439
+ });
440
+ });
@@ -70,12 +70,13 @@ describe('test EmergencyContactsSelectContacts', () => {
70
70
  tree = await create(wrapComponent(route));
71
71
  });
72
72
  const instance = tree.root;
73
- const rowUser = instance.findAllByProps(
74
- (item) =>
75
- item.props.accessibilityLabel ===
76
- AccessibilityLabel.EMERGENCY_SELECT_CONTACT + 0
77
- );
78
- expect(rowUser[0]).toBeDefined();
73
+ const rowUser = instance.findByProps({
74
+ accessibilityLabel: AccessibilityLabel.EMERGENCY_SELECT_CONTACT + 0,
75
+ });
76
+ await act(async () => {
77
+ rowUser.props.onPress();
78
+ });
79
+ expect(rowUser.props.text).toEqual('test');
79
80
  });
80
81
 
81
82
  it('test onSave emergencyContactsSelectContacts', async () => {