@perses-dev/dashboards 0.23.1 → 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.
Files changed (46) hide show
  1. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +7 -3
  2. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +2 -1
  3. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  4. package/dist/components/TimeRangeControls/TimeRangeControls.js +8 -4
  5. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  6. package/package.json +6 -5
  7. package/dist/cjs/components/Panel/Panel.test.js +0 -137
  8. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +0 -131
  9. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +0 -87
  10. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +0 -95
  11. package/dist/cjs/components/Variables/variable-model.test.js +0 -106
  12. package/dist/cjs/context/TemplateVariableProvider/query-params.test.js +0 -82
  13. package/dist/cjs/utils/panelUtils.test.js +0 -195
  14. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +0 -110
  15. package/dist/components/Panel/Panel.test.d.ts +0 -2
  16. package/dist/components/Panel/Panel.test.d.ts.map +0 -1
  17. package/dist/components/Panel/Panel.test.js +0 -130
  18. package/dist/components/Panel/Panel.test.js.map +0 -1
  19. package/dist/components/PanelDrawer/PanelDrawer.test.d.ts +0 -2
  20. package/dist/components/PanelDrawer/PanelDrawer.test.d.ts.map +0 -1
  21. package/dist/components/PanelDrawer/PanelDrawer.test.js +0 -124
  22. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +0 -1
  23. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts +0 -2
  24. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts.map +0 -1
  25. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +0 -80
  26. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +0 -1
  27. package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts +0 -2
  28. package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts.map +0 -1
  29. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +0 -88
  30. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +0 -1
  31. package/dist/components/Variables/variable-model.test.d.ts +0 -2
  32. package/dist/components/Variables/variable-model.test.d.ts.map +0 -1
  33. package/dist/components/Variables/variable-model.test.js +0 -104
  34. package/dist/components/Variables/variable-model.test.js.map +0 -1
  35. package/dist/context/TemplateVariableProvider/query-params.test.d.ts +0 -2
  36. package/dist/context/TemplateVariableProvider/query-params.test.d.ts.map +0 -1
  37. package/dist/context/TemplateVariableProvider/query-params.test.js +0 -80
  38. package/dist/context/TemplateVariableProvider/query-params.test.js.map +0 -1
  39. package/dist/utils/panelUtils.test.d.ts +0 -2
  40. package/dist/utils/panelUtils.test.d.ts.map +0 -1
  41. package/dist/utils/panelUtils.test.js +0 -193
  42. package/dist/utils/panelUtils.test.js.map +0 -1
  43. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts +0 -2
  44. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts.map +0 -1
  45. package/dist/views/ViewDashboard/tests/panelGroups.test.js +0 -103
  46. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +0 -1
@@ -1,106 +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 _variableModel = require("./variable-model");
18
- describe('filterVariableList', ()=>{
19
- const testSuite = [
20
- {
21
- title: 'basic case',
22
- capturing_regexp: /([^-]*)-host-([^-]*)/g,
23
- originalValues: [
24
- {
25
- label: 'l1',
26
- value: 'us1-host-ahdix'
27
- },
28
- {
29
- label: 'l2',
30
- value: 'us1-host-diua'
31
- },
32
- {
33
- label: 'l3',
34
- value: 'eu1-host-adf'
35
- },
36
- {
37
- label: 'l4',
38
- value: 'bar'
39
- }
40
- ],
41
- result: [
42
- {
43
- label: 'l1',
44
- value: 'us1ahdix'
45
- },
46
- {
47
- label: 'l2',
48
- value: 'us1diua'
49
- },
50
- {
51
- label: 'l3',
52
- value: 'eu1adf'
53
- }
54
- ]
55
- },
56
- {
57
- title: 'duplicate captured value',
58
- capturing_regexp: /prometheus-(.+):\d+/g,
59
- originalValues: [
60
- {
61
- label: 'l1',
62
- value: 'prometheus-app:9090'
63
- },
64
- {
65
- label: 'l2',
66
- value: 'prometheus-app:9091'
67
- },
68
- {
69
- label: 'l3',
70
- value: 'prometheus-platform:9091'
71
- },
72
- {
73
- label: 'l4',
74
- value: 'prometheus-database:9091'
75
- },
76
- {
77
- label: 'l5',
78
- value: 'prometheus-perses:9091'
79
- }
80
- ],
81
- result: [
82
- {
83
- label: 'l1',
84
- value: 'app'
85
- },
86
- {
87
- label: 'l3',
88
- value: 'platform'
89
- },
90
- {
91
- label: 'l4',
92
- value: 'database'
93
- },
94
- {
95
- label: 'l5',
96
- value: 'perses'
97
- }
98
- ]
99
- }
100
- ];
101
- testSuite.forEach(({ title , capturing_regexp , originalValues , result })=>{
102
- it(title, ()=>{
103
- expect((0, _variableModel.filterVariableList)(originalValues, capturing_regexp)).toEqual(result);
104
- });
105
- });
106
- });
@@ -1,82 +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 _queryParams = require("./query-params");
18
- describe('getInitalValuesFromQueryParameters', ()=>{
19
- test('base case', ()=>{
20
- expect((0, _queryParams.getInitalValuesFromQueryParameters)({
21
- 'var-foo': 'bar',
22
- 'var-baz': [
23
- 'qux',
24
- 'quux'
25
- ]
26
- })).toEqual({
27
- foo: 'bar',
28
- baz: [
29
- 'qux',
30
- 'quux'
31
- ]
32
- });
33
- });
34
- });
35
- describe('encodeVariableValue', ()=>{
36
- const testCases = [
37
- {
38
- input: 'foo',
39
- expected: 'foo'
40
- },
41
- {
42
- input: [
43
- 'foo',
44
- 'bar'
45
- ],
46
- expected: 'foo,bar'
47
- },
48
- {
49
- input: '$__all',
50
- expected: '$__all'
51
- }
52
- ];
53
- testCases.forEach(({ input , expected })=>{
54
- test(`encodes ${input} as ${expected}`, ()=>{
55
- expect((0, _queryParams.encodeVariableValue)(input)).toEqual(expected);
56
- });
57
- });
58
- });
59
- describe('decodeVariableValue', ()=>{
60
- const testCases = [
61
- {
62
- input: 'foo',
63
- expected: 'foo'
64
- },
65
- {
66
- input: 'foo,bar',
67
- expected: [
68
- 'foo',
69
- 'bar'
70
- ]
71
- },
72
- {
73
- input: '$__all',
74
- expected: '$__all'
75
- }
76
- ];
77
- testCases.forEach(({ input , expected })=>{
78
- test(`encodes ${input} as ${expected}`, ()=>{
79
- expect((0, _queryParams.decodeVariableValue)(input)).toEqual(expected);
80
- });
81
- });
82
- });
@@ -1,195 +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 _panelUtils = require("./panelUtils");
18
- describe('insertPanelInLayout', ()=>{
19
- describe('inserts the panel to the right when space is available', ()=>{
20
- test('with a single panel in that row', ()=>{
21
- const newLayout = {
22
- i: 'abc',
23
- w: 10,
24
- h: 8
25
- };
26
- const referenceLayout = {
27
- i: 'one',
28
- x: 0,
29
- y: 0,
30
- w: 6,
31
- h: 6
32
- };
33
- const layouts = [
34
- referenceLayout
35
- ];
36
- expect((0, _panelUtils.insertPanelInLayout)(newLayout, referenceLayout, layouts)).toEqual([
37
- referenceLayout,
38
- {
39
- x: 6,
40
- y: 0,
41
- ...newLayout
42
- }
43
- ]);
44
- });
45
- test('with multiple panels in that row with space between them', ()=>{
46
- const newLayout = {
47
- i: 'abc',
48
- w: 10,
49
- h: 8
50
- };
51
- const referenceLayout = {
52
- i: 'one',
53
- x: 0,
54
- y: 0,
55
- w: 3,
56
- h: 4
57
- };
58
- const otherPanelInRow = {
59
- i: 'two',
60
- x: 20,
61
- y: 0,
62
- w: 4,
63
- h: 4
64
- };
65
- const layouts = [
66
- referenceLayout,
67
- otherPanelInRow
68
- ];
69
- expect((0, _panelUtils.insertPanelInLayout)(newLayout, referenceLayout, layouts)).toEqual([
70
- referenceLayout,
71
- {
72
- x: 3,
73
- y: 0,
74
- ...newLayout
75
- },
76
- otherPanelInRow
77
- ]);
78
- });
79
- });
80
- describe('inserts the panel below when space is not available to the right', ()=>{
81
- test('with a single panel in the initial layout', ()=>{
82
- const newLayout = {
83
- i: 'abc',
84
- w: 10,
85
- h: 8
86
- };
87
- const referenceLayout = {
88
- i: 'one',
89
- x: 1,
90
- y: 0,
91
- w: 18,
92
- h: 4
93
- };
94
- const layouts = [
95
- referenceLayout
96
- ];
97
- expect((0, _panelUtils.insertPanelInLayout)(newLayout, referenceLayout, layouts)).toEqual([
98
- referenceLayout,
99
- {
100
- x: 1,
101
- y: 4,
102
- ...newLayout
103
- }
104
- ]);
105
- });
106
- test('with a single panel in the same row and additional panels below', ()=>{
107
- const newLayout = {
108
- i: 'abc',
109
- w: 10,
110
- h: 8
111
- };
112
- const referenceLayout = {
113
- i: 'one',
114
- x: 0,
115
- y: 0,
116
- w: 18,
117
- h: 4
118
- };
119
- const nextRowItem = {
120
- i: 'two',
121
- x: 0,
122
- y: 4,
123
- w: 6,
124
- h: 6
125
- };
126
- const layouts = [
127
- referenceLayout,
128
- nextRowItem
129
- ];
130
- expect((0, _panelUtils.insertPanelInLayout)(newLayout, referenceLayout, layouts)).toEqual([
131
- referenceLayout,
132
- {
133
- x: 0,
134
- y: 4,
135
- ...newLayout
136
- },
137
- {
138
- ...nextRowItem,
139
- y: nextRowItem.y + newLayout.h
140
- }
141
- ]);
142
- });
143
- });
144
- });
145
- describe('getValidPanelKey', ()=>{
146
- test('removes whitespace', ()=>{
147
- expect((0, _panelUtils.getValidPanelKey)('my panel name', {})).toBe('mypanelname');
148
- });
149
- test('does not include a counter if the key is not in use', ()=>{
150
- const mockPanelDefs = {
151
- alreadyInUse: {
152
- kind: 'Panel',
153
- spec: {}
154
- }
155
- };
156
- expect((0, _panelUtils.getValidPanelKey)('newPanelName', mockPanelDefs)).toBe('newPanelName');
157
- });
158
- test('includes a counter if the key is already in use', ()=>{
159
- const mockPanelDefs = {
160
- alreadyInUse: {
161
- kind: 'Panel',
162
- spec: {}
163
- }
164
- };
165
- expect((0, _panelUtils.getValidPanelKey)('alreadyInUse', mockPanelDefs)).toBe('alreadyInUse-1');
166
- });
167
- test('includes an incremented counter if the key is already in use multiple times', ()=>{
168
- const mockPanelDefs = {
169
- popularKey: {
170
- kind: 'Panel',
171
- spec: {}
172
- },
173
- 'popularKey-1': {
174
- kind: 'Panel',
175
- spec: {}
176
- }
177
- };
178
- expect((0, _panelUtils.getValidPanelKey)('popularKey', mockPanelDefs)).toBe('popularKey-2');
179
- expect((0, _panelUtils.getValidPanelKey)('popularKey-1', mockPanelDefs)).toBe('popularKey-2');
180
- });
181
- test('does not duplicate counters when they are out of order', ()=>{
182
- const mockPanelDefs = {
183
- outoforder: {
184
- kind: 'Panel',
185
- spec: {}
186
- },
187
- 'outoforder-2': {
188
- kind: 'Panel',
189
- spec: {}
190
- }
191
- };
192
- expect((0, _panelUtils.getValidPanelKey)('outoforder', mockPanelDefs)).toBe('outoforder-3');
193
- expect((0, _panelUtils.getValidPanelKey)('outoforder-2', mockPanelDefs)).toBe('outoforder-3');
194
- });
195
- });
@@ -1,110 +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 _pluginSystem = require("@perses-dev/plugin-system");
21
- const _context = require("../../../context");
22
- const _test = require("../../../test");
23
- const _dashboardApp = require("../DashboardApp");
24
- function _interopRequireDefault(obj) {
25
- return obj && obj.__esModule ? obj : {
26
- default: obj
27
- };
28
- }
29
- describe('Panel Groups', ()=>{
30
- const renderDashboard = ()=>{
31
- (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.TimeRangeProvider, {
32
- initialTimeRange: {
33
- pastDuration: '30m'
34
- },
35
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.TemplateVariableProvider, {
36
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.DashboardProvider, {
37
- initialState: {
38
- dashboardResource: (0, _test.getTestDashboard)(),
39
- isEditMode: true
40
- },
41
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_dashboardApp.DashboardApp, {
42
- dashboardResource: (0, _test.getTestDashboard)(),
43
- isReadonly: false
44
- })
45
- })
46
- })
47
- }));
48
- };
49
- it('should delete panel', ()=>{
50
- renderDashboard();
51
- const panelTitle = 'CPU';
52
- const deletePanelButton = _react.screen.getByLabelText(`delete panel ${panelTitle}`);
53
- _userEvent.default.click(deletePanelButton);
54
- _react.screen.getByText('Delete Panel');
55
- const deleteButton = _react.screen.getByText('Delete');
56
- _userEvent.default.click(deleteButton);
57
- // The panel should disappear
58
- const deletedPanel = _react.screen.queryByText(panelTitle);
59
- expect(deletedPanel).not.toBeInTheDocument();
60
- });
61
- it('should only delete panel from panel group if panel is not referenced more than once', ()=>{
62
- renderDashboard();
63
- const panelTitle = 'Disk I/O Utilization';
64
- const panels = _react.screen.getAllByText(panelTitle);
65
- expect(panels).toHaveLength(2);
66
- const deletePanelButton = _react.screen.getAllByLabelText(`delete panel ${panelTitle}`)[0];
67
- if (deletePanelButton === undefined) throw new Error('Missing delete button');
68
- _userEvent.default.click(deletePanelButton);
69
- _react.screen.getByText('Delete Panel');
70
- const deleteButton = _react.screen.getByText('Delete');
71
- _userEvent.default.click(deleteButton);
72
- // The deleted panel should still be on screen in the other group
73
- const deletedPanel = _react.screen.queryByText(panelTitle);
74
- expect(deletedPanel).toBeInTheDocument();
75
- });
76
- it('should swap panels', ()=>{
77
- renderDashboard();
78
- // should move panel down
79
- const groupTitle1 = 'CPU Stats';
80
- const moveGroupDownBtn = _react.screen.getByLabelText(`move group ${groupTitle1} down`);
81
- _userEvent.default.click(moveGroupDownBtn);
82
- // should move panel up
83
- const groupTitle2 = 'Disk Stats';
84
- const moveGroupUpBtn = _react.screen.getByLabelText(`move group ${groupTitle2} up`);
85
- _userEvent.default.click(moveGroupUpBtn);
86
- /* TODO: Figure out how to test this visually without coupling to the store
87
- const layouts = storeApi.getState().layouts;
88
- expect(layouts[0]?.title).toBe(undefined);
89
- expect(layouts[1]?.title).toBe('Disk Stats');
90
- expect(layouts[2]?.title).toBe('CPU Stats');
91
- */ });
92
- it('should delete a panel group', ()=>{
93
- renderDashboard();
94
- const groupTitle = 'CPU Stats';
95
- const deleteGroupIcon = _react.screen.getByLabelText(`delete group ${groupTitle}`);
96
- _userEvent.default.click(deleteGroupIcon);
97
- _react.screen.getByText('Delete Panel Group');
98
- const deleteButton = _react.screen.getByText('Delete');
99
- _userEvent.default.click(deleteButton);
100
- // should remove group
101
- const deletedGroup = _react.screen.queryByText(groupTitle);
102
- expect(deletedGroup).not.toBeInTheDocument();
103
- // CPU panel should be completely gone since it wasn't in any other group
104
- let panel = _react.screen.queryByText('CPU');
105
- expect(panel).not.toBeInTheDocument();
106
- // A DiskIO panel should still be present in the other group that wasn't deleted
107
- panel = _react.screen.queryByText('Disk I/O Utilization');
108
- expect(panel).toBeInTheDocument();
109
- });
110
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Panel.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Panel.test.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.test.tsx"],"names":[],"mappings":""}
@@ -1,130 +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
- import { jsx as _jsx } from "react/jsx-runtime";
14
- import { screen, waitFor } from '@testing-library/react';
15
- import userEvent from '@testing-library/user-event';
16
- import { renderWithContext } from '../../test';
17
- import { Panel } from './Panel';
18
- describe('Panel', ()=>{
19
- const createTestPanel = ()=>({
20
- kind: 'Panel',
21
- spec: {
22
- display: {
23
- name: 'Fake Panel Title',
24
- description: 'This is a fake panel'
25
- },
26
- plugin: {
27
- kind: 'TimeSeriesChart',
28
- spec: {}
29
- }
30
- }
31
- });
32
- // Helper to render the panel with some context set
33
- const renderPanel = (definition, editHandlers)=>{
34
- definition !== null && definition !== void 0 ? definition : definition = createTestPanel();
35
- renderWithContext(/*#__PURE__*/ _jsx(Panel, {
36
- definition: definition,
37
- editHandlers: editHandlers
38
- }));
39
- };
40
- // Helper to get the panel once rendered
41
- const getPanel = ()=>screen.getByRole('region', {
42
- name: 'Fake Panel Title'
43
- });
44
- it('should render panel', async ()=>{
45
- renderPanel();
46
- const panel = getPanel();
47
- expect(panel).toBeInTheDocument();
48
- // Should diplay header with panel's title
49
- const header = screen.getByRole('banner');
50
- expect(header).toHaveTextContent('Fake Panel Title');
51
- // Should display chart's content from the fake panel plugin
52
- const content = screen.getByRole('figure');
53
- await waitFor(()=>{
54
- expect(content).toHaveTextContent('TimeSeriesChart panel');
55
- });
56
- expect(content);
57
- });
58
- it('shows panel description', async ()=>{
59
- renderPanel();
60
- const panel = getPanel();
61
- // Description button should not be visible until hover on panel
62
- const missingButton = screen.queryByRole('button', {
63
- name: /description/i
64
- });
65
- expect(missingButton).not.toBeInTheDocument();
66
- userEvent.hover(panel);
67
- const descriptionButton = screen.getByRole('button', {
68
- name: /description/i
69
- });
70
- expect(descriptionButton).toBeInTheDocument();
71
- // Can hover to see panel description in tooltip
72
- userEvent.hover(descriptionButton);
73
- const tooltip = await screen.findByRole('tooltip');
74
- expect(tooltip).toHaveTextContent('This is a fake panel');
75
- });
76
- it('does not show description when panel does not have one', ()=>{
77
- // Render a panel without a description set
78
- const withoutDescription = createTestPanel();
79
- withoutDescription.spec.display.description = undefined;
80
- renderPanel(withoutDescription);
81
- const panel = getPanel();
82
- userEvent.hover(panel);
83
- const descriptionButton = screen.queryByRole('button', {
84
- name: /description/i
85
- });
86
- expect(descriptionButton).not.toBeInTheDocument();
87
- });
88
- it('does not show description in edit mode', ()=>{
89
- renderPanel(undefined, {
90
- onEditPanelClick: jest.fn(),
91
- onDeletePanelClick: jest.fn(),
92
- onDuplicatePanelClick: jest.fn()
93
- });
94
- const panel = getPanel();
95
- userEvent.hover(panel);
96
- const descriptionButton = screen.queryByRole('button', {
97
- name: /description/i
98
- });
99
- expect(descriptionButton).not.toBeInTheDocument();
100
- });
101
- it('can trigger panel actions in edit mode', ()=>{
102
- const onEditPanelClick = jest.fn();
103
- const onDeletePanelClick = jest.fn();
104
- const onDuplicatePanelClick = jest.fn();
105
- renderPanel(undefined, {
106
- onEditPanelClick,
107
- onDeletePanelClick,
108
- onDuplicatePanelClick
109
- });
110
- const panel = getPanel();
111
- userEvent.hover(panel);
112
- const editButton = screen.getByRole('button', {
113
- name: /edit/i
114
- });
115
- userEvent.click(editButton);
116
- const deleteButton = screen.getByRole('button', {
117
- name: /delete/i
118
- });
119
- userEvent.click(deleteButton);
120
- const duplicateButton = screen.getByRole('button', {
121
- name: /duplicate/i
122
- });
123
- userEvent.click(duplicateButton);
124
- expect(onEditPanelClick).toHaveBeenCalledTimes(1);
125
- expect(onDeletePanelClick).toHaveBeenCalledTimes(1);
126
- expect(onDuplicatePanelClick).toHaveBeenCalledTimes(1);
127
- });
128
- });
129
-
130
- //# sourceMappingURL=Panel.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/components/Panel/Panel.test.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { screen, waitFor } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { PanelDefinition } from '@perses-dev/core';\nimport { renderWithContext } from '../../test';\nimport { Panel, PanelProps } from './Panel';\n\ndescribe('Panel', () => {\n const createTestPanel = (): PanelDefinition => ({\n kind: 'Panel',\n spec: {\n display: {\n name: 'Fake Panel Title',\n description: 'This is a fake panel',\n },\n plugin: {\n kind: 'TimeSeriesChart',\n spec: {},\n },\n },\n });\n\n // Helper to render the panel with some context set\n const renderPanel = (definition?: PanelDefinition, editHandlers?: PanelProps['editHandlers']) => {\n definition ??= createTestPanel();\n\n renderWithContext(<Panel definition={definition} editHandlers={editHandlers} />);\n };\n\n // Helper to get the panel once rendered\n const getPanel = () => screen.getByRole('region', { name: 'Fake Panel Title' });\n\n it('should render panel', async () => {\n renderPanel();\n\n const panel = getPanel();\n expect(panel).toBeInTheDocument();\n\n // Should diplay header with panel's title\n const header = screen.getByRole('banner');\n expect(header).toHaveTextContent('Fake Panel Title');\n\n // Should display chart's content from the fake panel plugin\n const content = screen.getByRole('figure');\n await waitFor(() => {\n expect(content).toHaveTextContent('TimeSeriesChart panel');\n });\n expect(content);\n });\n\n it('shows panel description', async () => {\n renderPanel();\n\n const panel = getPanel();\n\n // Description button should not be visible until hover on panel\n const missingButton = screen.queryByRole('button', { name: /description/i });\n expect(missingButton).not.toBeInTheDocument();\n userEvent.hover(panel);\n const descriptionButton = screen.getByRole('button', { name: /description/i });\n expect(descriptionButton).toBeInTheDocument();\n\n // Can hover to see panel description in tooltip\n userEvent.hover(descriptionButton);\n const tooltip = await screen.findByRole('tooltip');\n expect(tooltip).toHaveTextContent('This is a fake panel');\n });\n\n it('does not show description when panel does not have one', () => {\n // Render a panel without a description set\n const withoutDescription = createTestPanel();\n withoutDescription.spec.display.description = undefined;\n renderPanel(withoutDescription);\n\n const panel = getPanel();\n userEvent.hover(panel);\n const descriptionButton = screen.queryByRole('button', { name: /description/i });\n expect(descriptionButton).not.toBeInTheDocument();\n });\n\n it('does not show description in edit mode', () => {\n renderPanel(undefined, {\n onEditPanelClick: jest.fn(),\n onDeletePanelClick: jest.fn(),\n onDuplicatePanelClick: jest.fn(),\n });\n\n const panel = getPanel();\n userEvent.hover(panel);\n const descriptionButton = screen.queryByRole('button', { name: /description/i });\n expect(descriptionButton).not.toBeInTheDocument();\n });\n\n it('can trigger panel actions in edit mode', () => {\n const onEditPanelClick = jest.fn();\n const onDeletePanelClick = jest.fn();\n const onDuplicatePanelClick = jest.fn();\n renderPanel(undefined, { onEditPanelClick, onDeletePanelClick, onDuplicatePanelClick });\n\n const panel = getPanel();\n userEvent.hover(panel);\n\n const editButton = screen.getByRole('button', { name: /edit/i });\n userEvent.click(editButton);\n\n const deleteButton = screen.getByRole('button', { name: /delete/i });\n userEvent.click(deleteButton);\n\n const duplicateButton = screen.getByRole('button', { name: /duplicate/i });\n userEvent.click(duplicateButton);\n\n expect(onEditPanelClick).toHaveBeenCalledTimes(1);\n expect(onDeletePanelClick).toHaveBeenCalledTimes(1);\n expect(onDuplicatePanelClick).toHaveBeenCalledTimes(1);\n });\n});\n"],"names":["screen","waitFor","userEvent","renderWithContext","Panel","describe","createTestPanel","kind","spec","display","name","description","plugin","renderPanel","definition","editHandlers","getPanel","getByRole","it","panel","expect","toBeInTheDocument","header","toHaveTextContent","content","missingButton","queryByRole","not","hover","descriptionButton","tooltip","findByRole","withoutDescription","undefined","onEditPanelClick","jest","fn","onDeletePanelClick","onDuplicatePanelClick","editButton","click","deleteButton","duplicateButton","toHaveBeenCalledTimes"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2E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AAC,CAAC;QAExF,MAAMnB,KAAK,GAAGH,QAAQ,EAAE,AAAC;QACzBd,SAAS,CAAC0B,KAAK,CAACT,KAAK,CAAC,CAAC;QAEvB,MAAMoB,UAAU,GAAGvC,MAAM,CAACiB,SAAS,CAAC,QAAQ,EAAE;YAAEP,IAAI,SAAS;SAAE,CAAC,AAAC;QACjER,SAAS,CAACsC,KAAK,CAACD,UAAU,CAAC,CAAC;QAE5B,MAAME,YAAY,GAAGzC,MAAM,CAACiB,SAAS,CAAC,QAAQ,EAAE;YAAEP,IAAI,WAAW;SAAE,CAAC,AAAC;QACrER,SAAS,CAACsC,KAAK,CAACC,YAAY,CAAC,CAAC;QAE9B,MAAMC,eAAe,GAAG1C,MAAM,CAACiB,SAAS,CAAC,QAAQ,EAAE;YAAEP,IAAI,cAAc;SAAE,CAAC,AAAC;QAC3ER,SAAS,CAACsC,KAAK,CAACE,eAAe,CAAC,CAAC;QAEjCtB,MAAM,CAACc,gBAAgB,CAAC,CAACS,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAClDvB,MAAM,CAACiB,kBAAkB,CAAC,CAACM,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACpDvB,MAAM,CAACkB,qBAAqB,CAAC,CAACK,qBAAqB,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=PanelDrawer.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PanelDrawer.test.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelDrawer.test.tsx"],"names":[],"mappings":""}