@perses-dev/components 0.23.0 → 0.24.0
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/dist/ColorPicker/ColorPicker.d.ts +12 -0
- package/dist/ColorPicker/ColorPicker.d.ts.map +1 -0
- package/dist/ColorPicker/ColorPicker.js +78 -0
- package/dist/ColorPicker/ColorPicker.js.map +1 -0
- package/dist/ColorPicker/index.d.ts +2 -0
- package/dist/ColorPicker/index.d.ts.map +1 -0
- package/dist/ColorPicker/index.js +15 -0
- package/dist/ColorPicker/index.js.map +1 -0
- package/dist/EChart.d.ts +2 -2
- package/dist/EChart.d.ts.map +1 -1
- package/dist/EChart.js.map +1 -1
- package/dist/Legend/Legend.js +6 -9
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/LineChart/LineChart.d.ts +4 -2
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +1 -1
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts +3 -2
- package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js +17 -5
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -1
- package/dist/StatChart/StatChart.d.ts +0 -1
- package/dist/StatChart/StatChart.d.ts.map +1 -1
- package/dist/StatChart/StatChart.js +1 -3
- package/dist/StatChart/StatChart.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdColorPicker.d.ts +4 -0
- package/dist/ThresholdsEditor/ThresholdColorPicker.d.ts.map +1 -0
- package/dist/ThresholdsEditor/ThresholdColorPicker.js +76 -0
- package/dist/ThresholdsEditor/ThresholdColorPicker.js.map +1 -0
- package/dist/ThresholdsEditor/ThresholdInput.d.ts +13 -0
- package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -0
- package/dist/ThresholdsEditor/ThresholdInput.js +61 -0
- package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -0
- package/dist/ThresholdsEditor/ThresholdsEditor.d.ts +10 -0
- package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -0
- package/dist/ThresholdsEditor/ThresholdsEditor.js +215 -0
- package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -0
- package/dist/ThresholdsEditor/index.d.ts +2 -0
- package/dist/ThresholdsEditor/index.d.ts.map +1 -0
- package/dist/ThresholdsEditor/index.js +15 -0
- package/dist/ThresholdsEditor/index.js.map +1 -0
- package/dist/TimeSeriesTooltip/focused-series.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/focused-series.js +3 -3
- package/dist/TimeSeriesTooltip/focused-series.js.map +1 -1
- package/dist/cjs/ColorPicker/ColorPicker.js +128 -0
- package/dist/cjs/{model/legend.test.js → ColorPicker/index.js} +11 -12
- package/dist/cjs/Legend/Legend.js +5 -8
- package/dist/cjs/LineChart/LineChart.js +40 -1
- package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +1 -1
- package/dist/cjs/OptionsEditorLayout/OptionsEditorGroup.js +22 -5
- package/dist/cjs/StatChart/StatChart.js +1 -41
- package/dist/cjs/ThresholdsEditor/ThresholdColorPicker.js +87 -0
- package/dist/cjs/ThresholdsEditor/ThresholdInput.js +72 -0
- package/dist/cjs/ThresholdsEditor/ThresholdsEditor.js +265 -0
- package/dist/{model/legend.test.js → cjs/ThresholdsEditor/index.js} +15 -14
- package/dist/cjs/TimeSeriesTooltip/focused-series.js +3 -3
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/test-utils/theme.js +8 -0
- package/dist/cjs/theme/theme.js +5 -0
- package/dist/cjs/utils/theme-gen.js +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/model/graph.d.ts +2 -2
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/graph.js.map +1 -1
- package/dist/model/legend.d.ts +1 -1
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js.map +1 -1
- package/dist/model/theme.d.ts +5 -0
- package/dist/model/theme.d.ts.map +1 -1
- package/dist/model/theme.js.map +1 -1
- package/dist/model/units/bytes.d.ts +1 -1
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/decimal.d.ts +1 -1
- package/dist/model/units/decimal.d.ts.map +1 -1
- package/dist/model/units/decimal.js.map +1 -1
- package/dist/model/units/percent.d.ts +1 -1
- package/dist/model/units/percent.d.ts.map +1 -1
- package/dist/model/units/percent.js.map +1 -1
- package/dist/model/units/time.d.ts +1 -1
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/types.d.ts +1 -1
- package/dist/model/units/types.d.ts.map +1 -1
- package/dist/model/units/types.js.map +1 -1
- package/dist/test-utils/theme.d.ts.map +1 -1
- package/dist/test-utils/theme.js +8 -0
- package/dist/test-utils/theme.js.map +1 -1
- package/dist/theme/theme.js +5 -0
- package/dist/theme/theme.js.map +1 -1
- package/dist/utils/theme-gen.d.ts.map +1 -1
- package/dist/utils/theme-gen.js +8 -0
- package/dist/utils/theme-gen.js.map +1 -1
- package/package.json +5 -3
- package/dist/InfoTooltip/InfoTooltip.test.d.ts +0 -2
- package/dist/InfoTooltip/InfoTooltip.test.d.ts.map +0 -1
- package/dist/InfoTooltip/InfoTooltip.test.js +0 -36
- package/dist/InfoTooltip/InfoTooltip.test.js.map +0 -1
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts +0 -2
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts.map +0 -1
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js +0 -62
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js.map +0 -1
- package/dist/StatChart/StatChart.test.d.ts +0 -2
- package/dist/StatChart/StatChart.test.d.ts.map +0 -1
- package/dist/StatChart/StatChart.test.js +0 -94
- package/dist/StatChart/StatChart.test.js.map +0 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.test.d.ts +0 -2
- package/dist/TimeSeriesTooltip/SeriesInfo.test.d.ts.map +0 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.test.js +0 -52
- package/dist/TimeSeriesTooltip/SeriesInfo.test.js.map +0 -1
- package/dist/TimeSeriesTooltip/TooltipContent.test.d.ts +0 -2
- package/dist/TimeSeriesTooltip/TooltipContent.test.d.ts.map +0 -1
- package/dist/TimeSeriesTooltip/TooltipContent.test.js +0 -78
- package/dist/TimeSeriesTooltip/TooltipContent.test.js.map +0 -1
- package/dist/TimeSeriesTooltip/focused-series.test.d.ts +0 -2
- package/dist/TimeSeriesTooltip/focused-series.test.d.ts.map +0 -1
- package/dist/TimeSeriesTooltip/focused-series.test.js +0 -93
- package/dist/TimeSeriesTooltip/focused-series.test.js.map +0 -1
- package/dist/UnitSelector/UnitSelector.test.d.ts +0 -2
- package/dist/UnitSelector/UnitSelector.test.d.ts.map +0 -1
- package/dist/UnitSelector/UnitSelector.test.js +0 -204
- package/dist/UnitSelector/UnitSelector.test.js.map +0 -1
- package/dist/cjs/InfoTooltip/InfoTooltip.test.js +0 -43
- package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.test.js +0 -69
- package/dist/cjs/StatChart/StatChart.test.js +0 -96
- package/dist/cjs/TimeSeriesTooltip/SeriesInfo.test.js +0 -54
- package/dist/cjs/TimeSeriesTooltip/TooltipContent.test.js +0 -80
- package/dist/cjs/TimeSeriesTooltip/focused-series.test.js +0 -95
- package/dist/cjs/UnitSelector/UnitSelector.test.js +0 -211
- package/dist/cjs/model/units/units.test.js +0 -206
- package/dist/cjs/utils/format.test.js +0 -47
- package/dist/cjs/utils/theme-gen.test.js +0 -202
- package/dist/model/legend.test.d.ts +0 -2
- package/dist/model/legend.test.d.ts.map +0 -1
- package/dist/model/legend.test.js.map +0 -1
- package/dist/model/units/units.test.d.ts +0 -2
- package/dist/model/units/units.test.d.ts.map +0 -1
- package/dist/model/units/units.test.js +0 -204
- package/dist/model/units/units.test.js.map +0 -1
- package/dist/utils/format.test.d.ts +0 -2
- package/dist/utils/format.test.d.ts.map +0 -1
- package/dist/utils/format.test.js +0 -45
- package/dist/utils/format.test.js.map +0 -1
- package/dist/utils/theme-gen.test.d.ts +0 -2
- package/dist/utils/theme-gen.test.d.ts.map +0 -1
- package/dist/utils/theme-gen.test.js +0 -200
- package/dist/utils/theme-gen.test.js.map +0 -1
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _react = require("@testing-library/react");
|
|
19
|
-
const _chartsThemeProvider = require("../context/ChartsThemeProvider");
|
|
20
|
-
const _testUtils = require("../test-utils");
|
|
21
|
-
const _statChart = require("./StatChart");
|
|
22
|
-
describe('StatChart', ()=>{
|
|
23
|
-
const renderChart = (unit)=>{
|
|
24
|
-
const contentDimensions = {
|
|
25
|
-
width: 200,
|
|
26
|
-
height: 200
|
|
27
|
-
};
|
|
28
|
-
(0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_chartsThemeProvider.ChartsThemeProvider, {
|
|
29
|
-
chartsTheme: _testUtils.testChartsTheme,
|
|
30
|
-
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_statChart.StatChart, {
|
|
31
|
-
width: contentDimensions.width,
|
|
32
|
-
height: contentDimensions.height,
|
|
33
|
-
data: mockStatData,
|
|
34
|
-
unit: unit
|
|
35
|
-
})
|
|
36
|
-
}));
|
|
37
|
-
};
|
|
38
|
-
const mockStatData = {
|
|
39
|
-
calculatedValue: 7.72931659687181,
|
|
40
|
-
name: 'Example Stat Chart',
|
|
41
|
-
seriesData: {
|
|
42
|
-
name: '(((count(count(node_cpu_seconds_total{job="example"}) by (cpu))',
|
|
43
|
-
values: [
|
|
44
|
-
[
|
|
45
|
-
1654006170000,
|
|
46
|
-
7.736401673473903
|
|
47
|
-
],
|
|
48
|
-
[
|
|
49
|
-
1654006185000,
|
|
50
|
-
7.733891213538757
|
|
51
|
-
],
|
|
52
|
-
[
|
|
53
|
-
1654006200000,
|
|
54
|
-
7.731101813010433
|
|
55
|
-
],
|
|
56
|
-
[
|
|
57
|
-
1654006215000,
|
|
58
|
-
7.722454672079215
|
|
59
|
-
],
|
|
60
|
-
[
|
|
61
|
-
1654006230000,
|
|
62
|
-
7.722733612256738
|
|
63
|
-
]
|
|
64
|
-
]
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
it('render default options (no sparkline)', ()=>{
|
|
68
|
-
const unit = {
|
|
69
|
-
kind: 'Decimal',
|
|
70
|
-
decimal_places: 2
|
|
71
|
-
};
|
|
72
|
-
renderChart(unit);
|
|
73
|
-
expect(_react.screen.getByText('7.73')).toBeInTheDocument();
|
|
74
|
-
});
|
|
75
|
-
it('show value with bytes unit formatting', ()=>{
|
|
76
|
-
const unit = {
|
|
77
|
-
kind: 'Bytes'
|
|
78
|
-
};
|
|
79
|
-
renderChart(unit);
|
|
80
|
-
expect(_react.screen.getByText('7.73 bytes')).toBeInTheDocument();
|
|
81
|
-
});
|
|
82
|
-
it('show value with seconds time unit formatting', ()=>{
|
|
83
|
-
const unit = {
|
|
84
|
-
kind: 'Seconds'
|
|
85
|
-
};
|
|
86
|
-
renderChart(unit);
|
|
87
|
-
expect(_react.screen.getByText('7.73 seconds')).toBeInTheDocument();
|
|
88
|
-
});
|
|
89
|
-
it('show value with months time unit formatting', ()=>{
|
|
90
|
-
const unit = {
|
|
91
|
-
kind: 'Months'
|
|
92
|
-
};
|
|
93
|
-
renderChart(unit);
|
|
94
|
-
expect(_react.screen.getByText('7.73 months')).toBeInTheDocument();
|
|
95
|
-
});
|
|
96
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _react = require("@testing-library/react");
|
|
19
|
-
const _dom = require("@testing-library/dom");
|
|
20
|
-
const _seriesInfo = require("./SeriesInfo");
|
|
21
|
-
describe('SeriesInfo', ()=>{
|
|
22
|
-
const renderComponent = (props)=>{
|
|
23
|
-
(0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_seriesInfo.SeriesInfo, {
|
|
24
|
-
...props
|
|
25
|
-
}));
|
|
26
|
-
};
|
|
27
|
-
it('render metric __name__ beside formattedY value', ()=>{
|
|
28
|
-
const seriesInfo = {
|
|
29
|
-
seriesName: 'node_load1{env="demo",instance="demo.do.prometheus.io:9100",job="node"}',
|
|
30
|
-
y: 0.28,
|
|
31
|
-
formattedY: '28.0%',
|
|
32
|
-
markerColor: 'hsla(1016196180,50%,50%,0.8)',
|
|
33
|
-
totalSeries: 1,
|
|
34
|
-
wrapLabels: true
|
|
35
|
-
};
|
|
36
|
-
renderComponent(seriesInfo);
|
|
37
|
-
expect(_dom.screen.getByText('node_load1:')).toBeInTheDocument();
|
|
38
|
-
expect(_dom.screen.getByText('28.0%')).toBeInTheDocument();
|
|
39
|
-
expect(_dom.screen.getByText('demo.do.prometheus.io:9100')).toBeInTheDocument(); // TODO: remove quotes
|
|
40
|
-
});
|
|
41
|
-
it('render preformatted series name beside formattedY value', ()=>{
|
|
42
|
-
const seriesInfo = {
|
|
43
|
-
seriesName: 'Node memory total',
|
|
44
|
-
y: 552341504,
|
|
45
|
-
formattedY: '526.75 MB',
|
|
46
|
-
markerColor: 'hsla(-1756459732,50%,50%,0.8)',
|
|
47
|
-
totalSeries: 2,
|
|
48
|
-
wrapLabels: true
|
|
49
|
-
};
|
|
50
|
-
renderComponent(seriesInfo);
|
|
51
|
-
expect(_dom.screen.getByText('Node memory total')).toBeInTheDocument();
|
|
52
|
-
expect(_dom.screen.getByText('526.75 MB')).toBeInTheDocument();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _react = require("@testing-library/react");
|
|
19
|
-
const _dom = require("@testing-library/dom");
|
|
20
|
-
const _tooltipContent = require("./TooltipContent");
|
|
21
|
-
describe('TooltipContent', ()=>{
|
|
22
|
-
const renderComponent = (props)=>{
|
|
23
|
-
(0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltipContent.TooltipContent, {
|
|
24
|
-
...props
|
|
25
|
-
}));
|
|
26
|
-
};
|
|
27
|
-
it('render tooltip content with a single series name', ()=>{
|
|
28
|
-
const tooltipContent = {
|
|
29
|
-
focusedSeries: [
|
|
30
|
-
{
|
|
31
|
-
seriesIdx: 0,
|
|
32
|
-
datumIdx: 84,
|
|
33
|
-
seriesName: 'Test node demo.do.prometheus.io:9100',
|
|
34
|
-
date: 'Dec 23, 2022, 1:53:00 PM',
|
|
35
|
-
x: 1671821580000,
|
|
36
|
-
y: 0.1,
|
|
37
|
-
formattedY: '0.1',
|
|
38
|
-
markerColor: 'hsla(19838016,50%,50%,0.8)'
|
|
39
|
-
}
|
|
40
|
-
],
|
|
41
|
-
wrapLabels: true
|
|
42
|
-
};
|
|
43
|
-
renderComponent(tooltipContent);
|
|
44
|
-
expect(_dom.screen.getByText('Test node demo.do.prometheus.io:9100')).toBeInTheDocument();
|
|
45
|
-
expect(_dom.screen.getByText('Dec 23, 2022 -')).toBeInTheDocument();
|
|
46
|
-
expect(_dom.screen.getByText('13:53:00')).toBeInTheDocument();
|
|
47
|
-
expect(_dom.screen.getByText('0.1')).toBeInTheDocument();
|
|
48
|
-
});
|
|
49
|
-
it('render tooltip content with multiple series data', ()=>{
|
|
50
|
-
const tooltipContent = {
|
|
51
|
-
focusedSeries: [
|
|
52
|
-
{
|
|
53
|
-
seriesIdx: 2,
|
|
54
|
-
datumIdx: 48,
|
|
55
|
-
seriesName: 'node_memory_MemFree_bytes{env="demo",instance="demo.do.prometheus.io:9100",job="node"}',
|
|
56
|
-
date: 'Dec 23, 2022, 1:44:00 PM',
|
|
57
|
-
x: 1671821040000,
|
|
58
|
-
y: 84635648,
|
|
59
|
-
formattedY: '84.64M',
|
|
60
|
-
markerColor: 'hsla(1887856572,50%,50%,0.8)'
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
seriesIdx: 1,
|
|
64
|
-
datumIdx: 48,
|
|
65
|
-
seriesName: 'node_memory_Buffers_bytes{env="demo",instance="demo.do.prometheus.io:9100",job="node"}',
|
|
66
|
-
date: 'Dec 23, 2022, 1:44:00 PM',
|
|
67
|
-
x: 1671821040000,
|
|
68
|
-
y: 33771520,
|
|
69
|
-
formattedY: '33.77M',
|
|
70
|
-
markerColor: 'hsla(158479636,50%,50%,0.8)'
|
|
71
|
-
}
|
|
72
|
-
],
|
|
73
|
-
wrapLabels: true
|
|
74
|
-
};
|
|
75
|
-
renderComponent(tooltipContent);
|
|
76
|
-
expect(_dom.screen.getByText('84.64M')).toBeInTheDocument();
|
|
77
|
-
expect(_dom.screen.getByText('33.77M')).toBeInTheDocument();
|
|
78
|
-
expect(_dom.screen.getAllByText('env="demo", instance="demo.do.prometheus.io:9100", job="node"')).toHaveLength(2);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
const _focusedSeries = require("./focused-series");
|
|
18
|
-
describe('getNearbySeries', ()=>{
|
|
19
|
-
const chartData = {
|
|
20
|
-
timeSeries: [
|
|
21
|
-
{
|
|
22
|
-
type: 'line',
|
|
23
|
-
name: 'env="demo", instance="demo.do.prometheus", job="node", mode="test"',
|
|
24
|
-
color: 'hsla(-1365438424,50%,50%,0.8)',
|
|
25
|
-
data: [
|
|
26
|
-
0.0002315202231525094,
|
|
27
|
-
0.00022873082287300112,
|
|
28
|
-
0.00023152022315149463,
|
|
29
|
-
0.00023152022315149463,
|
|
30
|
-
0.00022873082287300112
|
|
31
|
-
],
|
|
32
|
-
symbol: 'circle'
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
type: 'line',
|
|
36
|
-
name: 'env="demo", instance="demo.do.prometheus", job="node", mode="test alt"',
|
|
37
|
-
color: 'hsla(286664040,50%,50%,0.8)',
|
|
38
|
-
data: [
|
|
39
|
-
0.05245188284519867,
|
|
40
|
-
0.0524463040446356,
|
|
41
|
-
0.0524463040446356,
|
|
42
|
-
0.05247140864723438,
|
|
43
|
-
0.052482566248230646
|
|
44
|
-
],
|
|
45
|
-
symbol: 'circle'
|
|
46
|
-
}
|
|
47
|
-
],
|
|
48
|
-
xAxis: [
|
|
49
|
-
1654007865000,
|
|
50
|
-
1654007880000,
|
|
51
|
-
1654007895000,
|
|
52
|
-
1654007910000,
|
|
53
|
-
1654007925000
|
|
54
|
-
],
|
|
55
|
-
rangeMs: 60000
|
|
56
|
-
};
|
|
57
|
-
// https://echarts.apache.org/en/api.html#echartsInstance.convertFromPixel
|
|
58
|
-
const pointInGrid = [
|
|
59
|
-
2,
|
|
60
|
-
0.0560655737704918
|
|
61
|
-
]; // converted from chart.getZr() mousemove coordinates
|
|
62
|
-
const yBuffer = 0.02; // calculated from y axis interval
|
|
63
|
-
const focusedSeriesOutput = [
|
|
64
|
-
{
|
|
65
|
-
date: 'May 31, 2022, 2:38:15 PM',
|
|
66
|
-
datumIdx: 2,
|
|
67
|
-
markerColor: 'hsla(286664040,50%,50%,0.8)',
|
|
68
|
-
seriesName: 'env="demo", instance="demo.do.prometheus", job="node", mode="test alt"',
|
|
69
|
-
seriesIdx: 1,
|
|
70
|
-
x: 1654007895000,
|
|
71
|
-
y: 0.0524463040446356,
|
|
72
|
-
formattedY: '0.05'
|
|
73
|
-
}
|
|
74
|
-
];
|
|
75
|
-
it('should return focused series data for points nearby the cursor', ()=>{
|
|
76
|
-
const decimalUnit = {
|
|
77
|
-
kind: 'Decimal',
|
|
78
|
-
decimal_places: 2
|
|
79
|
-
};
|
|
80
|
-
expect((0, _focusedSeries.getNearbySeries)(chartData, pointInGrid, yBuffer, decimalUnit)).toEqual(focusedSeriesOutput);
|
|
81
|
-
});
|
|
82
|
-
it('should return series values formatted as a percent', ()=>{
|
|
83
|
-
const percentFormattedOutput = [
|
|
84
|
-
...focusedSeriesOutput
|
|
85
|
-
];
|
|
86
|
-
if (percentFormattedOutput[0]) {
|
|
87
|
-
percentFormattedOutput[0].formattedY = '5%';
|
|
88
|
-
}
|
|
89
|
-
const percentFormattedUnit = {
|
|
90
|
-
kind: 'PercentDecimal',
|
|
91
|
-
decimal_places: 0
|
|
92
|
-
};
|
|
93
|
-
expect((0, _focusedSeries.getNearbySeries)(chartData, pointInGrid, yBuffer, percentFormattedUnit)).toEqual(percentFormattedOutput);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _react = require("@testing-library/react");
|
|
19
|
-
const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
20
|
-
const _unitSelector = require("./UnitSelector");
|
|
21
|
-
function _interopRequireDefault(obj) {
|
|
22
|
-
return obj && obj.__esModule ? obj : {
|
|
23
|
-
default: obj
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
describe('UnitSelector', ()=>{
|
|
27
|
-
const renderUnitSelector = (value, onChange = jest.fn())=>{
|
|
28
|
-
(0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
29
|
-
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_unitSelector.UnitSelector, {
|
|
30
|
-
value: value,
|
|
31
|
-
onChange: onChange
|
|
32
|
-
})
|
|
33
|
-
}));
|
|
34
|
-
};
|
|
35
|
-
const getUnitSelector = ()=>{
|
|
36
|
-
return _react.screen.getByRole('combobox', {
|
|
37
|
-
name: 'Units'
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
const getDecimalSelector = ()=>{
|
|
41
|
-
return _react.screen.getByRole('combobox', {
|
|
42
|
-
name: 'Decimal'
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
const getAbbreviateSwitch = ()=>{
|
|
46
|
-
return _react.screen.getByRole('checkbox', {
|
|
47
|
-
name: 'Abbreviate'
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
it('can change the unit kind by clicking', ()=>{
|
|
51
|
-
const onChange = jest.fn();
|
|
52
|
-
renderUnitSelector({
|
|
53
|
-
kind: 'Minutes'
|
|
54
|
-
}, onChange);
|
|
55
|
-
const unitSelector = getUnitSelector();
|
|
56
|
-
_userEvent.default.click(unitSelector);
|
|
57
|
-
const decimalOption = _react.screen.getByRole('option', {
|
|
58
|
-
name: 'Decimal'
|
|
59
|
-
});
|
|
60
|
-
_userEvent.default.click(decimalOption);
|
|
61
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
62
|
-
kind: 'Decimal'
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
it('can change the unit kind using a keyboard', ()=>{
|
|
66
|
-
const onChange = jest.fn();
|
|
67
|
-
renderUnitSelector({
|
|
68
|
-
kind: 'Bytes'
|
|
69
|
-
}, onChange);
|
|
70
|
-
const unitSelector = getUnitSelector();
|
|
71
|
-
_userEvent.default.tab();
|
|
72
|
-
_userEvent.default.tab();
|
|
73
|
-
expect(unitSelector).toHaveFocus();
|
|
74
|
-
_userEvent.default.clear(unitSelector);
|
|
75
|
-
_userEvent.default.keyboard('years');
|
|
76
|
-
_react.screen.getByRole('option', {
|
|
77
|
-
name: 'Years'
|
|
78
|
-
});
|
|
79
|
-
_userEvent.default.keyboard('{arrowup}{enter}');
|
|
80
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
81
|
-
kind: 'Years'
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
it('can change the decimal places by clicking', ()=>{
|
|
85
|
-
const onChange = jest.fn();
|
|
86
|
-
renderUnitSelector({
|
|
87
|
-
kind: 'Decimal',
|
|
88
|
-
decimal_places: 0,
|
|
89
|
-
abbreviate: true
|
|
90
|
-
}, onChange);
|
|
91
|
-
_userEvent.default.click(getDecimalSelector());
|
|
92
|
-
const decimalOption = _react.screen.getByRole('option', {
|
|
93
|
-
name: '1'
|
|
94
|
-
});
|
|
95
|
-
_userEvent.default.click(decimalOption);
|
|
96
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
97
|
-
kind: 'Decimal',
|
|
98
|
-
decimal_places: 1,
|
|
99
|
-
abbreviate: true
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
it('can change the decimal places using a keyboard', ()=>{
|
|
103
|
-
const onChange = jest.fn();
|
|
104
|
-
renderUnitSelector({
|
|
105
|
-
kind: 'Percent'
|
|
106
|
-
}, onChange);
|
|
107
|
-
const decimalSelector = getDecimalSelector();
|
|
108
|
-
_userEvent.default.tab();
|
|
109
|
-
_userEvent.default.tab();
|
|
110
|
-
expect(decimalSelector).toHaveFocus();
|
|
111
|
-
_userEvent.default.clear(decimalSelector);
|
|
112
|
-
_userEvent.default.keyboard('3');
|
|
113
|
-
_react.screen.getByRole('option', {
|
|
114
|
-
name: '3'
|
|
115
|
-
});
|
|
116
|
-
_userEvent.default.keyboard('{arrowup}{enter}');
|
|
117
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
118
|
-
kind: 'Percent',
|
|
119
|
-
decimal_places: 3
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
it('can change abbreviate by clicking', ()=>{
|
|
123
|
-
const onChange = jest.fn();
|
|
124
|
-
renderUnitSelector({
|
|
125
|
-
kind: 'Decimal',
|
|
126
|
-
decimal_places: 3,
|
|
127
|
-
abbreviate: true
|
|
128
|
-
}, onChange);
|
|
129
|
-
_userEvent.default.click(getAbbreviateSwitch());
|
|
130
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
131
|
-
kind: 'Decimal',
|
|
132
|
-
decimal_places: 3,
|
|
133
|
-
abbreviate: false
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
it('can change abbreviate using a keyboard', ()=>{
|
|
137
|
-
const onChange = jest.fn();
|
|
138
|
-
renderUnitSelector({
|
|
139
|
-
kind: 'Decimal',
|
|
140
|
-
decimal_places: 0
|
|
141
|
-
}, onChange);
|
|
142
|
-
_userEvent.default.tab();
|
|
143
|
-
_userEvent.default.keyboard('{space}');
|
|
144
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
145
|
-
kind: 'Decimal',
|
|
146
|
-
decimal_places: 0,
|
|
147
|
-
abbreviate: true
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
describe('with a time unit selected', ()=>{
|
|
151
|
-
it('does not allow the user to set abbreviate', ()=>{
|
|
152
|
-
renderUnitSelector({
|
|
153
|
-
kind: 'Minutes'
|
|
154
|
-
});
|
|
155
|
-
expect(getAbbreviateSwitch()).toBeDisabled();
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
describe('with a percent unit selected', ()=>{
|
|
159
|
-
it('allows the user to modify the decimal places', ()=>{
|
|
160
|
-
renderUnitSelector({
|
|
161
|
-
kind: 'Percent'
|
|
162
|
-
});
|
|
163
|
-
expect(getDecimalSelector()).toBeEnabled();
|
|
164
|
-
});
|
|
165
|
-
it('does not allow the user to set abbreviate', ()=>{
|
|
166
|
-
renderUnitSelector({
|
|
167
|
-
kind: 'PercentDecimal'
|
|
168
|
-
});
|
|
169
|
-
expect(getAbbreviateSwitch()).toBeDisabled();
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
describe('with a decimal unit selected', ()=>{
|
|
173
|
-
it('allows the user to modify the decimal places', ()=>{
|
|
174
|
-
renderUnitSelector({
|
|
175
|
-
kind: 'Decimal'
|
|
176
|
-
});
|
|
177
|
-
expect(getDecimalSelector()).toBeEnabled();
|
|
178
|
-
});
|
|
179
|
-
it('allows the user to set abbreviate', ()=>{
|
|
180
|
-
renderUnitSelector({
|
|
181
|
-
kind: 'Decimal'
|
|
182
|
-
});
|
|
183
|
-
expect(getAbbreviateSwitch()).toBeEnabled();
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
describe('with a bytes unit selected', ()=>{
|
|
187
|
-
it('allows the user to modify the decimal places', ()=>{
|
|
188
|
-
renderUnitSelector({
|
|
189
|
-
kind: 'Bytes'
|
|
190
|
-
});
|
|
191
|
-
expect(getDecimalSelector()).toBeEnabled();
|
|
192
|
-
});
|
|
193
|
-
it('allows the user to set abbreviate', ()=>{
|
|
194
|
-
renderUnitSelector({
|
|
195
|
-
kind: 'Bytes'
|
|
196
|
-
});
|
|
197
|
-
expect(getAbbreviateSwitch()).toBeEnabled();
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
it('should not show an option for disabled units', ()=>{
|
|
201
|
-
const onChange = jest.fn();
|
|
202
|
-
renderUnitSelector({
|
|
203
|
-
kind: 'Decimal'
|
|
204
|
-
}, onChange);
|
|
205
|
-
_userEvent.default.click(getUnitSelector());
|
|
206
|
-
const percentShorthandOption = _react.screen.queryByRole('option', {
|
|
207
|
-
name: '%'
|
|
208
|
-
});
|
|
209
|
-
expect(percentShorthandOption).not.toBeInTheDocument();
|
|
210
|
-
});
|
|
211
|
-
});
|