@centreon/ui 25.2.3 → 25.2.5

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.
@@ -1,622 +0,0 @@
1
- import { LineChartData } from '../models';
2
-
3
- type TestCase = [number | null, string, 1000 | 1024, string | null];
4
-
5
- describe('timeSeries', () => {
6
- const graphData: LineChartData = {
7
- global: {},
8
- metrics: [
9
- {
10
- average_value: 1,
11
- data: [0, 1],
12
- ds_data: {
13
- ds_color_area: 'transparent',
14
- ds_color_line: 'black',
15
- ds_filled: false,
16
- ds_invert: null,
17
- ds_legend: 'Round-Trip-Time Average',
18
- ds_order: null,
19
- ds_stack: null,
20
- ds_transparency: 80
21
- },
22
- legend: 'Round-Trip-Time Average (ms)',
23
- maximum_value: 1.5,
24
- metric: 'rta',
25
- metric_id: 1,
26
- minimum_value: 0.5,
27
- unit: 'ms'
28
- },
29
- {
30
- average_value: 1,
31
- data: [0.5, 3],
32
- ds_data: {
33
- ds_color_area: 'blue',
34
- ds_color_line: 'blue',
35
- ds_filled: true,
36
- ds_invert: null,
37
- ds_legend: 'Time',
38
- ds_order: null,
39
- ds_stack: null,
40
- ds_transparency: 80
41
- },
42
- legend: 'Time (ms)',
43
- maximum_value: 1.5,
44
- metric: 'time',
45
- metric_id: 2,
46
- minimum_value: 0.5,
47
- unit: 'ms'
48
- },
49
- {
50
- average_value: 1,
51
- data: [6, 4],
52
- ds_data: {
53
- ds_color_area: 'red',
54
- ds_color_line: 'red',
55
- ds_filled: true,
56
- ds_invert: null,
57
- ds_legend: 'Average duration',
58
- ds_order: '2',
59
- ds_stack: '1',
60
- ds_transparency: 80
61
- },
62
- legend: 'Average duration (ms)',
63
- maximum_value: 1.5,
64
- metric: 'avgDuration',
65
- metric_id: 3,
66
- minimum_value: 0.5,
67
- unit: 'ms'
68
- },
69
- {
70
- average_value: 1,
71
- data: [12, 25],
72
- ds_data: {
73
- ds_color_area: 'yellow',
74
- ds_color_line: 'yellow',
75
- ds_filled: true,
76
- ds_invert: '1',
77
- ds_legend: 'Duration',
78
- ds_order: '1',
79
- ds_stack: '1',
80
- ds_transparency: 80
81
- },
82
- legend: 'Duration (ms)',
83
- maximum_value: 1.5,
84
- metric: 'duration',
85
- metric_id: 4,
86
- minimum_value: 0.5,
87
- unit: 'ms'
88
- },
89
- {
90
- average_value: 1,
91
- data: [0, 1],
92
- ds_data: {
93
- ds_color_area: 'yellow',
94
- ds_color_line: 'yellow',
95
- ds_filled: true,
96
- ds_invert: null,
97
- ds_legend: 'Packet Loss',
98
- ds_order: null,
99
- ds_stack: null,
100
- ds_transparency: 80
101
- },
102
- legend: 'Packet Loss (%)',
103
- maximum_value: 1.5,
104
- metric: 'packet_loss',
105
- metric_id: 5,
106
- minimum_value: 0.5,
107
- unit: '%'
108
- }
109
- ],
110
- times: ['2020-11-05T10:35:00Z', '2020-11-05T10:40:00Z']
111
- };
112
-
113
- describe('getTimeSeries', () => {
114
- it('returns the time series for the given graph data', () => {
115
- expect(getTimeSeries(graphData)).toEqual([
116
- {
117
- 1: 0,
118
- 2: 0.5,
119
- 3: 6,
120
- 4: 12,
121
- 5: 0,
122
- timeTick: '2020-11-05T10:35:00Z'
123
- },
124
- {
125
- 1: 1,
126
- 2: 3,
127
- 3: 4,
128
- 4: 25,
129
- 5: 1,
130
- timeTick: '2020-11-05T10:40:00Z'
131
- }
132
- ]);
133
- });
134
-
135
- it('filters metric values below the given lower-limit value', () => {
136
- const graphDataWithLowerLimit = {
137
- ...graphData,
138
- global: {
139
- 'lower-limit': 0.4
140
- }
141
- };
142
-
143
- expect(getTimeSeries(graphDataWithLowerLimit)).toEqual([
144
- {
145
- 2: 0.5,
146
- 3: 6,
147
- 4: 12,
148
- timeTick: '2020-11-05T10:35:00Z'
149
- },
150
- {
151
- 1: 1,
152
- 2: 3,
153
- 3: 4,
154
- 4: 25,
155
- 5: 1,
156
- timeTick: '2020-11-05T10:40:00Z'
157
- }
158
- ]);
159
- });
160
- });
161
-
162
- describe('getLineData', () => {
163
- it('returns the line information for the given graph data', () => {
164
- expect(getLineData(graphData)).toEqual([
165
- {
166
- areaColor: 'transparent',
167
- average_value: 1,
168
- color: 'black',
169
- display: true,
170
- filled: false,
171
- highlight: undefined,
172
- invert: null,
173
- legend: 'Round-Trip-Time Average',
174
- lineColor: 'black',
175
- maximum_value: 1.5,
176
- metric: 'rta',
177
- metric_id: 1,
178
- minimum_value: 0.5,
179
- name: 'Round-Trip-Time Average (ms)',
180
- stackOrder: null,
181
- transparency: 80,
182
- unit: 'ms'
183
- },
184
- {
185
- areaColor: 'blue',
186
- average_value: 1,
187
- color: 'blue',
188
- display: true,
189
- filled: true,
190
- highlight: undefined,
191
- invert: null,
192
- legend: 'Time',
193
- lineColor: 'blue',
194
- maximum_value: 1.5,
195
- metric: 'time',
196
- metric_id: 2,
197
- minimum_value: 0.5,
198
- name: 'Time (ms)',
199
- stackOrder: null,
200
- transparency: 80,
201
- unit: 'ms'
202
- },
203
- {
204
- areaColor: 'red',
205
- average_value: 1,
206
- color: 'red',
207
- display: true,
208
- filled: true,
209
- highlight: undefined,
210
- invert: null,
211
- legend: 'Average duration',
212
- lineColor: 'red',
213
- maximum_value: 1.5,
214
- metric: 'avgDuration',
215
- metric_id: 3,
216
- minimum_value: 0.5,
217
- name: 'Average duration (ms)',
218
- stackOrder: 2,
219
- transparency: 80,
220
- unit: 'ms'
221
- },
222
- {
223
- areaColor: 'yellow',
224
- average_value: 1,
225
- color: 'yellow',
226
- display: true,
227
- filled: true,
228
- highlight: undefined,
229
- invert: '1',
230
- legend: 'Duration',
231
- lineColor: 'yellow',
232
- maximum_value: 1.5,
233
- metric: 'duration',
234
- metric_id: 4,
235
- minimum_value: 0.5,
236
- name: 'Duration (ms)',
237
- stackOrder: 1,
238
- transparency: 80,
239
- unit: 'ms'
240
- },
241
- {
242
- areaColor: 'yellow',
243
- average_value: 1,
244
- color: 'yellow',
245
- display: true,
246
- filled: true,
247
- highlight: undefined,
248
- invert: null,
249
- legend: 'Packet Loss',
250
- lineColor: 'yellow',
251
- maximum_value: 1.5,
252
- metric: 'packet_loss',
253
- metric_id: 5,
254
- minimum_value: 0.5,
255
- name: 'Packet Loss (%)',
256
- stackOrder: null,
257
- transparency: 80,
258
- unit: '%'
259
- }
260
- ]);
261
- });
262
- });
263
-
264
- describe('getMetrics', () => {
265
- it('returns the metrics for the given time value', () => {
266
- expect(
267
- getMetrics({
268
- rta: 1,
269
- time: 0,
270
- timeTick: '2020-11-05T10:40:00Z'
271
- })
272
- ).toEqual(['rta', 'time']);
273
- });
274
- });
275
-
276
- describe('getMetricValuesForUnit', () => {
277
- it('returns the values in the given time series corresponding to the given line unit', () => {
278
- const series = getTimeSeries(graphData);
279
- const lines = getLineData(graphData);
280
- const unit = 'ms';
281
-
282
- expect(
283
- getMetricValuesForUnit({ lines, timeSeries: series, unit })
284
- ).toEqual([0, 1, 0.5, 3, 6, 4, 12, 25]);
285
- });
286
- });
287
-
288
- describe('getUnits', () => {
289
- it('returns the units for the given lines', () => {
290
- const lines = getLineData(graphData);
291
-
292
- expect(getUnits(lines)).toEqual(['ms', '%']);
293
- });
294
- });
295
-
296
- describe('getDates', () => {
297
- it('teruns the dates for the given time series', () => {
298
- const series = getTimeSeries(graphData);
299
-
300
- expect(getDates(series)).toEqual([
301
- new Date('2020-11-05T10:35:00.000Z'),
302
- new Date('2020-11-05T10:40:00.000Z')
303
- ]);
304
- });
305
- });
306
-
307
- describe('getLineForMetric', () => {
308
- it('returns the line corresponding to the given metrics', () => {
309
- const lines = getLineData(graphData);
310
-
311
- expect(getLineForMetric({ lines, metric_id: 1 })).toEqual({
312
- areaColor: 'transparent',
313
- average_value: 1,
314
- color: 'black',
315
- display: true,
316
- filled: false,
317
- highlight: undefined,
318
- invert: null,
319
- legend: 'Round-Trip-Time Average',
320
- lineColor: 'black',
321
- maximum_value: 1.5,
322
- metric: 'rta',
323
- metric_id: 1,
324
- minimum_value: 0.5,
325
- name: 'Round-Trip-Time Average (ms)',
326
- stackOrder: null,
327
- transparency: 80,
328
- unit: 'ms'
329
- });
330
- });
331
- });
332
-
333
- describe('getMetricValuesForLines', () => {
334
- it('returns the metric values for the given lines within the given time series', () => {
335
- const lines = getLineData(graphData);
336
- const series = getTimeSeries(graphData);
337
-
338
- expect(
339
- getMetricValuesForLines({ lines, timeSeries: series })
340
- ).toEqual([0, 1, 0.5, 3, 6, 4, 12, 25, 0, 1]);
341
- });
342
- });
343
-
344
- describe(formatMetricValue, () => {
345
- const cases: Array<TestCase> = [
346
- [218857269, '', 1000, '218.86m'],
347
- [218857269, '', 1024, '208.72 M'],
348
- [0.12232323445, '', 1000, '0.12'],
349
- [1024, 'B', 1000, '1 KB'],
350
- [1024, 'B', 1024, '1 KB'],
351
- [null, 'B', 1024, null]
352
- ];
353
-
354
- it.each(cases)(
355
- 'formats the given value to a human readable form according to the given unit and base',
356
- (value, unit, base, formattedResult) => {
357
- expect(formatMetricValue({ base, unit, value })).toEqual(
358
- formattedResult
359
- );
360
- }
361
- );
362
- });
363
-
364
- describe('getSortedStackedLines', () => {
365
- it('returns stacked lines sorted by their own order for the given lines', () => {
366
- const lines = getLineData(graphData);
367
-
368
- expect(getSortedStackedLines(lines)).toEqual([
369
- {
370
- areaColor: 'yellow',
371
- average_value: 1,
372
- color: 'yellow',
373
- display: true,
374
- filled: true,
375
- highlight: undefined,
376
- invert: '1',
377
- legend: 'Duration',
378
- lineColor: 'yellow',
379
- maximum_value: 1.5,
380
- metric: 'duration',
381
- metric_id: 4,
382
- minimum_value: 0.5,
383
- name: 'Duration (ms)',
384
- stackOrder: 1,
385
- transparency: 80,
386
- unit: 'ms'
387
- },
388
- {
389
- areaColor: 'red',
390
- average_value: 1,
391
- color: 'red',
392
- display: true,
393
- filled: true,
394
- highlight: undefined,
395
- invert: null,
396
- legend: 'Average duration',
397
- lineColor: 'red',
398
- maximum_value: 1.5,
399
- metric: 'avgDuration',
400
- metric_id: 3,
401
- minimum_value: 0.5,
402
- name: 'Average duration (ms)',
403
- stackOrder: 2,
404
- transparency: 80,
405
- unit: 'ms'
406
- }
407
- ]);
408
- });
409
- });
410
-
411
- describe('getStackedMetricValues', () => {
412
- it('returns stacked metrics values for the given lines and the given time series', () => {
413
- const lines = getLineData(graphData);
414
- const series = getTimeSeries(graphData);
415
-
416
- expect(
417
- getStackedMetricValues({
418
- lines: getSortedStackedLines(lines),
419
- timeSeries: series
420
- })
421
- ).toEqual([18, 29]);
422
- });
423
- });
424
-
425
- describe('getTimeSeriesForLines', () => {
426
- it('returns the specific time series for the given lines and the fiven time series', () => {
427
- const lines = getLineData(graphData);
428
- const series = getTimeSeries(graphData);
429
-
430
- expect(
431
- getTimeSeriesForLines({
432
- lines: getSortedStackedLines(lines),
433
- timeSeries: series
434
- })
435
- ).toEqual([
436
- {
437
- 3: 6,
438
- 4: 12,
439
- timeTick: '2020-11-05T10:35:00Z'
440
- },
441
- {
442
- 3: 4,
443
- 4: 25,
444
- timeTick: '2020-11-05T10:40:00Z'
445
- }
446
- ]);
447
- });
448
- });
449
-
450
- describe('getInvertedStackedLines', () => {
451
- it('returns inverted and stacked lines for the given lines', () => {
452
- const lines = getLineData(graphData);
453
-
454
- expect(getInvertedStackedLines(lines)).toEqual([
455
- {
456
- areaColor: 'yellow',
457
- average_value: 1,
458
- color: 'yellow',
459
- display: true,
460
- filled: true,
461
- highlight: undefined,
462
- invert: '1',
463
- legend: 'Duration',
464
- lineColor: 'yellow',
465
- maximum_value: 1.5,
466
- metric: 'duration',
467
- metric_id: 4,
468
- minimum_value: 0.5,
469
- name: 'Duration (ms)',
470
- stackOrder: 1,
471
- transparency: 80,
472
- unit: 'ms'
473
- }
474
- ]);
475
- });
476
- });
477
-
478
- describe('getNotInvertedStackedLines', () => {
479
- it('returns not inverted and stacked lines for the given lines', () => {
480
- const lines = getLineData(graphData);
481
-
482
- expect(getNotInvertedStackedLines(lines)).toEqual([
483
- {
484
- areaColor: 'red',
485
- average_value: 1,
486
- color: 'red',
487
- display: true,
488
- filled: true,
489
- highlight: undefined,
490
- invert: null,
491
- legend: 'Average duration',
492
- lineColor: 'red',
493
- maximum_value: 1.5,
494
- metric: 'avgDuration',
495
- metric_id: 3,
496
- minimum_value: 0.5,
497
- name: 'Average duration (ms)',
498
- stackOrder: 2,
499
- transparency: 80,
500
- unit: 'ms'
501
- }
502
- ]);
503
- });
504
- });
505
-
506
- describe('hasUnitStackedLines', () => {
507
- it('returns true if the given unit contains stacked lines following the given lines, false otherwise', () => {
508
- const lines = getLineData(graphData);
509
-
510
- expect(hasUnitStackedLines({ lines, unit: 'ms' })).toEqual(
511
- true
512
- );
513
-
514
- expect(hasUnitStackedLines({ lines, unit: '%' })).toEqual(
515
- false
516
- );
517
- });
518
- });
519
- });
520
-
521
- describe('Format value with unit', () => {
522
- const units = [
523
- 'B',
524
- 'bytes',
525
- 'bytespersecond',
526
- 'B/s',
527
- 'B/sec',
528
- 'o',
529
- 'octets',
530
- 'b/s',
531
- 'b',
532
- 'ms',
533
- '%',
534
- ''
535
- ];
536
-
537
- const getExpectedResult = (unit): string => {
538
- if (unit === '') {
539
- return '324.23m';
540
- }
541
-
542
- return `309.21 M${unit}`;
543
- };
544
-
545
- const humanReadableTestCases = units.map((unit) => {
546
- if (unit === '%') {
547
- return {
548
- expectedResult: '45.56%',
549
- unit,
550
- value: 45.55678
551
- };
552
- }
553
-
554
- if (unit === 'ms') {
555
- return {
556
- expectedResult: '34.23 seconds',
557
- unit,
558
- value: 34232
559
- };
560
- }
561
-
562
- return {
563
- expectedResult: getExpectedResult(unit),
564
- unit,
565
- value: 324234232.34233
566
- };
567
- });
568
-
569
- const rawTestCases = units.map((unit) => {
570
- if (unit === '%') {
571
- return {
572
- expectedResult: '45.55678%',
573
- unit,
574
- value: 45.55678
575
- };
576
- }
577
-
578
- if (unit === 'ms') {
579
- return {
580
- expectedResult: '34232 ms',
581
- unit,
582
- value: 34232
583
- };
584
- }
585
-
586
- return {
587
- expectedResult:
588
- unit === '' ? '324234232.34233 ' : `324234232.34233 ${unit}`,
589
- unit,
590
- value: 324234232.34233
591
- };
592
- });
593
-
594
- describe('Format the value as human readable', () => {
595
- it.each(humanReadableTestCases)(
596
- 'formats the value with $unit',
597
- ({ value, unit, expectedResult }) => {
598
- expect(
599
- formatMetricValueWithUnit({
600
- unit,
601
- value
602
- })
603
- ).toEqual(expectedResult);
604
- }
605
- );
606
- });
607
-
608
- describe('Format the value as raw', () => {
609
- it.each(rawTestCases)(
610
- 'formats the value with $unit',
611
- ({ value, unit, expectedResult }) => {
612
- expect(
613
- timeSeries.formatMetricValueWithUnit({
614
- isRaw: true,
615
- unit,
616
- value
617
- })
618
- ).toEqual(expectedResult);
619
- }
620
- );
621
- });
622
- });