@perses-dev/plugin-system 0.23.1 → 0.25.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/cjs/model/calculations.js +6 -1
- package/dist/cjs/model/index.js +2 -2
- package/dist/cjs/runtime/time-series-queries.js +29 -6
- package/dist/model/calculations.d.ts +1 -1
- package/dist/model/calculations.d.ts.map +1 -1
- package/dist/model/calculations.js +7 -1
- package/dist/model/calculations.js.map +1 -1
- package/dist/model/datasource.d.ts +7 -0
- package/dist/model/datasource.d.ts.map +1 -1
- package/dist/model/datasource.js.map +1 -1
- package/dist/model/index.d.ts +2 -2
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +2 -2
- package/dist/model/index.js.map +1 -1
- package/dist/model/time-series-queries.d.ts +10 -4
- package/dist/model/time-series-queries.d.ts.map +1 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/dist/runtime/time-series-queries.d.ts +13 -2
- package/dist/runtime/time-series-queries.d.ts.map +1 -1
- package/dist/runtime/time-series-queries.js +30 -6
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/package.json +5 -4
- package/dist/cjs/components/CalculationSelector/CalculationSelector.test.js +0 -65
- package/dist/cjs/components/OptionsEditorTabs/OptionsEditorTabs.test.js +0 -107
- package/dist/cjs/components/PluginEditor/PluginEditor.test.js +0 -150
- package/dist/cjs/components/PluginKindSelect.test.js +0 -86
- package/dist/cjs/components/PluginRegistry/PluginRegistry.test.js +0 -144
- package/dist/cjs/components/PluginSpecEditor.test.js +0 -92
- package/dist/components/CalculationSelector/CalculationSelector.test.d.ts +0 -2
- package/dist/components/CalculationSelector/CalculationSelector.test.d.ts.map +0 -1
- package/dist/components/CalculationSelector/CalculationSelector.test.js +0 -58
- package/dist/components/CalculationSelector/CalculationSelector.test.js.map +0 -1
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.d.ts +0 -2
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.d.ts.map +0 -1
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.js +0 -100
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.js.map +0 -1
- package/dist/components/PluginEditor/PluginEditor.test.d.ts +0 -2
- package/dist/components/PluginEditor/PluginEditor.test.d.ts.map +0 -1
- package/dist/components/PluginEditor/PluginEditor.test.js +0 -143
- package/dist/components/PluginEditor/PluginEditor.test.js.map +0 -1
- package/dist/components/PluginKindSelect.test.d.ts +0 -2
- package/dist/components/PluginKindSelect.test.d.ts.map +0 -1
- package/dist/components/PluginKindSelect.test.js +0 -79
- package/dist/components/PluginKindSelect.test.js.map +0 -1
- package/dist/components/PluginRegistry/PluginRegistry.test.d.ts +0 -2
- package/dist/components/PluginRegistry/PluginRegistry.test.d.ts.map +0 -1
- package/dist/components/PluginRegistry/PluginRegistry.test.js +0 -137
- package/dist/components/PluginRegistry/PluginRegistry.test.js.map +0 -1
- package/dist/components/PluginSpecEditor.test.d.ts +0 -2
- package/dist/components/PluginSpecEditor.test.d.ts.map +0 -1
- package/dist/components/PluginSpecEditor.test.js +0 -85
- package/dist/components/PluginSpecEditor.test.js.map +0 -1
|
@@ -1,107 +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 _optionsEditorTabs = require("./OptionsEditorTabs");
|
|
21
|
-
function _interopRequireDefault(obj) {
|
|
22
|
-
return obj && obj.__esModule ? obj : {
|
|
23
|
-
default: obj
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
describe('OptionsEditorTabs', ()=>{
|
|
27
|
-
const mockTabs = [
|
|
28
|
-
{
|
|
29
|
-
label: 'Query',
|
|
30
|
-
content: /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
31
|
-
children: "Edit query configuration"
|
|
32
|
-
})
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
label: 'Settings',
|
|
36
|
-
content: /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
37
|
-
children: "Edit settings configuration"
|
|
38
|
-
})
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
label: 'JSON',
|
|
42
|
-
content: /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
43
|
-
children: "JSON editor"
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
];
|
|
47
|
-
const renderTabs = (otherTabs)=>{
|
|
48
|
-
const tabs = otherTabs !== null && otherTabs !== void 0 ? otherTabs : mockTabs;
|
|
49
|
-
(0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorTabs.OptionsEditorTabs, {
|
|
50
|
-
tabs: tabs
|
|
51
|
-
}));
|
|
52
|
-
};
|
|
53
|
-
it('renders all specified tabs in a tab list', ()=>{
|
|
54
|
-
renderTabs();
|
|
55
|
-
const tabList = _react.screen.getByRole('tablist');
|
|
56
|
-
const tabs = (0, _react.getAllByRole)(tabList, 'tab');
|
|
57
|
-
expect(tabs).toHaveLength(3);
|
|
58
|
-
expect(tabs[0]).toHaveTextContent('Query');
|
|
59
|
-
expect(tabs[1]).toHaveTextContent('Settings');
|
|
60
|
-
expect(tabs[2]).toHaveTextContent('JSON');
|
|
61
|
-
});
|
|
62
|
-
it('defaults to selecting the first tab', ()=>{
|
|
63
|
-
renderTabs();
|
|
64
|
-
const activeTab = _react.screen.getByRole('tab', {
|
|
65
|
-
selected: true
|
|
66
|
-
});
|
|
67
|
-
expect(activeTab).toHaveTextContent('Query');
|
|
68
|
-
const activeTabPanel = _react.screen.getByRole('tabpanel');
|
|
69
|
-
expect(activeTabPanel).toHaveTextContent('query configuration');
|
|
70
|
-
});
|
|
71
|
-
it('switches selected tab on click', ()=>{
|
|
72
|
-
renderTabs();
|
|
73
|
-
const jsonTab = _react.screen.getByRole('tab', {
|
|
74
|
-
name: 'JSON'
|
|
75
|
-
});
|
|
76
|
-
_userEvent.default.click(jsonTab);
|
|
77
|
-
const activeTab = _react.screen.getByRole('tab', {
|
|
78
|
-
selected: true
|
|
79
|
-
});
|
|
80
|
-
expect(activeTab).toBe(jsonTab);
|
|
81
|
-
const activeTabPanel = _react.screen.getByRole('tabpanel');
|
|
82
|
-
expect(activeTabPanel).toHaveTextContent('JSON editor');
|
|
83
|
-
});
|
|
84
|
-
it('switches selected tab on keyboard interactions', ()=>{
|
|
85
|
-
renderTabs();
|
|
86
|
-
const vizTab = _react.screen.getByRole('tab', {
|
|
87
|
-
name: 'Settings'
|
|
88
|
-
});
|
|
89
|
-
_userEvent.default.tab();
|
|
90
|
-
_userEvent.default.keyboard('{arrowright}{space}');
|
|
91
|
-
const activeTab = _react.screen.getByRole('tab', {
|
|
92
|
-
selected: true
|
|
93
|
-
});
|
|
94
|
-
expect(activeTab).toBe(vizTab);
|
|
95
|
-
const activeTabPanel = _react.screen.getByRole('tabpanel');
|
|
96
|
-
expect(activeTabPanel).toHaveTextContent('settings configuration');
|
|
97
|
-
});
|
|
98
|
-
it('renders tabs in correct order', ()=>{
|
|
99
|
-
renderTabs();
|
|
100
|
-
const tabList = _react.screen.getByRole('tablist');
|
|
101
|
-
const tabs = (0, _react.getAllByRole)(tabList, 'tab');
|
|
102
|
-
expect(tabs).toHaveLength(3);
|
|
103
|
-
expect(tabs[0]).toHaveTextContent('Query');
|
|
104
|
-
expect(tabs[1]).toHaveTextContent('Settings');
|
|
105
|
-
expect(tabs[2]).toHaveTextContent('JSON');
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,150 +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 _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
19
|
-
const _react = require("@testing-library/react");
|
|
20
|
-
const _react1 = require("react");
|
|
21
|
-
const _test = require("../../test");
|
|
22
|
-
const _pluginEditor = require("./PluginEditor");
|
|
23
|
-
function _interopRequireDefault(obj) {
|
|
24
|
-
return obj && obj.__esModule ? obj : {
|
|
25
|
-
default: obj
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
describe('PluginEditor', ()=>{
|
|
29
|
-
const renderComponent = ({ pluginType ='Panel' , defaultPluginKinds , value } = {})=>{
|
|
30
|
-
const testValue = value || {
|
|
31
|
-
kind: 'BertPanel1',
|
|
32
|
-
spec: {
|
|
33
|
-
option1: 'Option1Value'
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
// A test helper component that includes the state that's controlled from outside
|
|
37
|
-
let onChange = jest.fn();
|
|
38
|
-
function TestHelperForm() {
|
|
39
|
-
const [value, setValue] = (0, _react1.useState)(testValue);
|
|
40
|
-
onChange = jest.fn((v)=>setValue(v));
|
|
41
|
-
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginEditor.PluginEditor, {
|
|
42
|
-
pluginType: pluginType,
|
|
43
|
-
pluginKindLabel: "Panel Type",
|
|
44
|
-
value: value,
|
|
45
|
-
onChange: onChange
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
(0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(TestHelperForm, {}), undefined, {
|
|
49
|
-
defaultPluginKinds
|
|
50
|
-
});
|
|
51
|
-
return {
|
|
52
|
-
onChange
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
// Opens the PluginKindSelect and waits for loading to finish (i.e. options to appear)
|
|
56
|
-
const openPluginKind = async ()=>{
|
|
57
|
-
const select = _react.screen.getByRole('button', {
|
|
58
|
-
name: 'Panel Type'
|
|
59
|
-
});
|
|
60
|
-
_userEvent.default.click(select);
|
|
61
|
-
const options = await _react.screen.findAllByRole('option');
|
|
62
|
-
return options;
|
|
63
|
-
};
|
|
64
|
-
it('shows plugin kind and spec editor', async ()=>{
|
|
65
|
-
renderComponent();
|
|
66
|
-
const pluginKind = _react.screen.getByRole('button', {
|
|
67
|
-
name: 'Panel Type'
|
|
68
|
-
});
|
|
69
|
-
await (0, _react.waitFor)(()=>expect(pluginKind).toHaveTextContent('Bert Panel 1'));
|
|
70
|
-
const specEditor = await _react.screen.findByLabelText('BertPanel1 editor');
|
|
71
|
-
expect(specEditor).toHaveValue('Option1Value');
|
|
72
|
-
});
|
|
73
|
-
it('initializes kind and spec together', async ()=>{
|
|
74
|
-
const { onChange } = renderComponent();
|
|
75
|
-
// Switch to a new plugin kind
|
|
76
|
-
await openPluginKind();
|
|
77
|
-
const newPluginKind = _react.screen.getByRole('option', {
|
|
78
|
-
name: 'Bert Panel 2'
|
|
79
|
-
});
|
|
80
|
-
_userEvent.default.click(newPluginKind);
|
|
81
|
-
// Wait for the editor of the other plugin
|
|
82
|
-
const newEditor = await _react.screen.findByLabelText('BertPanel2 editor');
|
|
83
|
-
expect(newEditor).toBeInTheDocument();
|
|
84
|
-
expect(newEditor).toHaveValue('');
|
|
85
|
-
// Make sure onChange was only called once (i.e. initializes both kind and spec at the same time
|
|
86
|
-
expect(onChange).toHaveBeenCalledTimes(1);
|
|
87
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
88
|
-
kind: 'BertPanel2',
|
|
89
|
-
spec: {
|
|
90
|
-
option2: ''
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
it('remembers previous spec values', async ()=>{
|
|
95
|
-
renderComponent();
|
|
96
|
-
// Use the current editor to make a change to the spec value
|
|
97
|
-
let editor = await _react.screen.findByLabelText('BertPanel1 editor');
|
|
98
|
-
_userEvent.default.clear(editor);
|
|
99
|
-
_userEvent.default.type(editor, 'MyNewValue');
|
|
100
|
-
// Switch to a new plugin kind
|
|
101
|
-
await openPluginKind();
|
|
102
|
-
const newPluginKind = _react.screen.getByRole('option', {
|
|
103
|
-
name: 'Bert Panel 2'
|
|
104
|
-
});
|
|
105
|
-
_userEvent.default.click(newPluginKind);
|
|
106
|
-
// Wait for the other editor to appear, then switch back
|
|
107
|
-
const newEditor = await _react.screen.findByLabelText('BertPanel2 editor');
|
|
108
|
-
expect(newEditor).toHaveValue('');
|
|
109
|
-
await openPluginKind();
|
|
110
|
-
const oldPluginKind = _react.screen.getByRole('option', {
|
|
111
|
-
name: 'Bert Panel 1'
|
|
112
|
-
});
|
|
113
|
-
_userEvent.default.click(oldPluginKind);
|
|
114
|
-
// Make sure the editor from the first plugin appears and has our modified value from before the switch
|
|
115
|
-
editor = await _react.screen.findByLabelText('BertPanel1 editor');
|
|
116
|
-
expect(editor).toHaveValue('MyNewValue');
|
|
117
|
-
});
|
|
118
|
-
describe('when defaultPluginKinds specified in plugin registry', ()=>{
|
|
119
|
-
it('uses default kind when one is not provided', async ()=>{
|
|
120
|
-
renderComponent({
|
|
121
|
-
pluginType: 'Panel',
|
|
122
|
-
defaultPluginKinds: {
|
|
123
|
-
Panel: 'BertPanel2'
|
|
124
|
-
},
|
|
125
|
-
value: {
|
|
126
|
-
kind: '',
|
|
127
|
-
spec: {}
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
// Wait for default panel kind to load.
|
|
131
|
-
const pluginKind = _react.screen.getByRole('button', {
|
|
132
|
-
name: 'Panel Type'
|
|
133
|
-
});
|
|
134
|
-
await (0, _react.waitFor)(()=>expect(pluginKind).toHaveTextContent('Bert Panel 2'));
|
|
135
|
-
});
|
|
136
|
-
it('does not use default when kind is provided', async ()=>{
|
|
137
|
-
renderComponent({
|
|
138
|
-
pluginType: 'Panel',
|
|
139
|
-
defaultPluginKinds: {
|
|
140
|
-
Panel: 'BertPanel2'
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
// Wait for specified panel kind to load.
|
|
144
|
-
const pluginKind = _react.screen.getByRole('button', {
|
|
145
|
-
name: 'Panel Type'
|
|
146
|
-
});
|
|
147
|
-
await (0, _react.waitFor)(()=>expect(pluginKind).toHaveTextContent('Bert Panel 1'));
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
});
|
|
@@ -1,86 +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 _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
19
|
-
const _react = require("@testing-library/react");
|
|
20
|
-
const _test = require("../test");
|
|
21
|
-
const _pluginKindSelect = require("./PluginKindSelect");
|
|
22
|
-
function _interopRequireDefault(obj) {
|
|
23
|
-
return obj && obj.__esModule ? obj : {
|
|
24
|
-
default: obj
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
describe('PluginKindSelect', ()=>{
|
|
28
|
-
const renderComponent = (props)=>{
|
|
29
|
-
return (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginKindSelect.PluginKindSelect, {
|
|
30
|
-
...props
|
|
31
|
-
}));
|
|
32
|
-
};
|
|
33
|
-
// Opens the select and waits for loading to finish (i.e. options to appear)
|
|
34
|
-
const openSelect = async ()=>{
|
|
35
|
-
const select = _react.screen.getByRole('button');
|
|
36
|
-
_userEvent.default.click(select);
|
|
37
|
-
const options = await _react.screen.findAllByRole('option');
|
|
38
|
-
return options;
|
|
39
|
-
};
|
|
40
|
-
it('displays the list of plugins for a plugin type', async ()=>{
|
|
41
|
-
renderComponent({
|
|
42
|
-
pluginType: 'Panel',
|
|
43
|
-
value: ''
|
|
44
|
-
});
|
|
45
|
-
// Open the select and verify the list of options from the test plugin data
|
|
46
|
-
const options = await openSelect();
|
|
47
|
-
expect(options).toHaveLength(2);
|
|
48
|
-
let option = _react.screen.queryByRole('option', {
|
|
49
|
-
name: 'Bert Panel 1'
|
|
50
|
-
});
|
|
51
|
-
expect(option).toBeInTheDocument();
|
|
52
|
-
option = _react.screen.queryByRole('option', {
|
|
53
|
-
name: 'Bert Panel 2'
|
|
54
|
-
});
|
|
55
|
-
expect(option).toBeInTheDocument();
|
|
56
|
-
});
|
|
57
|
-
it('shows the correct selected value', async ()=>{
|
|
58
|
-
renderComponent({
|
|
59
|
-
pluginType: 'Variable',
|
|
60
|
-
value: 'ErnieVariable'
|
|
61
|
-
});
|
|
62
|
-
// Use findByRole to wait for loading to finish and selected value to appear
|
|
63
|
-
const select = await _react.screen.findByRole('button', {
|
|
64
|
-
name: 'Ernie Variable'
|
|
65
|
-
});
|
|
66
|
-
expect(select).toBeInTheDocument();
|
|
67
|
-
});
|
|
68
|
-
it('can select new value', async ()=>{
|
|
69
|
-
let onChangeValue = undefined;
|
|
70
|
-
const onChange = jest.fn((e)=>{
|
|
71
|
-
onChangeValue = e.target.value;
|
|
72
|
-
});
|
|
73
|
-
renderComponent({
|
|
74
|
-
pluginType: 'Variable',
|
|
75
|
-
value: 'ErnieVariable',
|
|
76
|
-
onChange
|
|
77
|
-
});
|
|
78
|
-
await openSelect();
|
|
79
|
-
const newOption = _react.screen.getByRole('option', {
|
|
80
|
-
name: 'Bert Variable'
|
|
81
|
-
});
|
|
82
|
-
_userEvent.default.click(newOption);
|
|
83
|
-
expect(onChange).toHaveBeenCalledTimes(1);
|
|
84
|
-
expect(onChangeValue).toBe('BertVariable');
|
|
85
|
-
});
|
|
86
|
-
});
|
|
@@ -1,144 +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 = /*#__PURE__*/ _interopRequireDefault(require("react"));
|
|
19
|
-
const _react1 = require("@testing-library/react");
|
|
20
|
-
const _runtime = require("../../runtime");
|
|
21
|
-
const _test = require("../../test");
|
|
22
|
-
function _interopRequireDefault(obj) {
|
|
23
|
-
return obj && obj.__esModule ? obj : {
|
|
24
|
-
default: obj
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
describe('PluginRegistry', ()=>{
|
|
28
|
-
const renderPluginRegistry = (children)=>{
|
|
29
|
-
(0, _test.renderWithContext)(children);
|
|
30
|
-
};
|
|
31
|
-
it('can load a plugin that exists', async ()=>{
|
|
32
|
-
renderPluginRegistry(/*#__PURE__*/ (0, _jsxRuntime.jsx)(PluginConsumer, {
|
|
33
|
-
pluginType: "Variable",
|
|
34
|
-
kind: "ErnieVariable"
|
|
35
|
-
}));
|
|
36
|
-
const hasPlugin = await _react1.screen.findByText('Has plugin: true', undefined, {
|
|
37
|
-
timeout: 3000
|
|
38
|
-
});
|
|
39
|
-
expect(hasPlugin).toBeInTheDocument();
|
|
40
|
-
});
|
|
41
|
-
it('errors when plugin is not installed', async ()=>{
|
|
42
|
-
// This plugin is not in the test metadata at all
|
|
43
|
-
renderPluginRegistry(/*#__PURE__*/ (0, _jsxRuntime.jsx)(PluginConsumer, {
|
|
44
|
-
pluginType: "TimeSeriesQuery",
|
|
45
|
-
kind: "NotInstalled"
|
|
46
|
-
}));
|
|
47
|
-
const error = await _react1.screen.findByText(/error:/i);
|
|
48
|
-
expect(error).toBeInTheDocument();
|
|
49
|
-
expect(error).toHaveTextContent(/not installed/i);
|
|
50
|
-
});
|
|
51
|
-
it('errors when plugin is missing from the module', async ()=>{
|
|
52
|
-
// This plugin is in the test metadata, but the code is missing from the module
|
|
53
|
-
renderPluginRegistry(/*#__PURE__*/ (0, _jsxRuntime.jsx)(PluginConsumer, {
|
|
54
|
-
pluginType: "Variable",
|
|
55
|
-
kind: "MissingErnieVariable"
|
|
56
|
-
}));
|
|
57
|
-
const error = await _react1.screen.findByText(/error:/i);
|
|
58
|
-
expect(error).toBeInTheDocument();
|
|
59
|
-
expect(error).toHaveTextContent(/missing/i);
|
|
60
|
-
});
|
|
61
|
-
it('lists metadata for plugin metadata that exists', async ()=>{
|
|
62
|
-
// There should be 3 variable plugins across both test modules
|
|
63
|
-
renderPluginRegistry(/*#__PURE__*/ (0, _jsxRuntime.jsx)(MetadataConsumer, {
|
|
64
|
-
pluginType: "Variable"
|
|
65
|
-
}));
|
|
66
|
-
const table = await _react1.screen.findByRole('table');
|
|
67
|
-
expect(table).toBeInTheDocument();
|
|
68
|
-
const rows = _react1.screen.getAllByRole('row');
|
|
69
|
-
expect(rows).toHaveLength(3);
|
|
70
|
-
});
|
|
71
|
-
it('lists metadata for plugin types with no plugins available', async ()=>{
|
|
72
|
-
// There are no TimeSeriesQuery plugins in any of the test modules
|
|
73
|
-
renderPluginRegistry(/*#__PURE__*/ (0, _jsxRuntime.jsx)(MetadataConsumer, {
|
|
74
|
-
pluginType: "TimeSeriesQuery"
|
|
75
|
-
}));
|
|
76
|
-
const table = await _react1.screen.findByRole('table');
|
|
77
|
-
expect(table).toBeInTheDocument();
|
|
78
|
-
const rows = _react1.screen.queryAllByRole('row');
|
|
79
|
-
expect(rows).toHaveLength(0);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
// A helper component for testing the PluginRegistry by calling usePlugin to load a plugin
|
|
83
|
-
const PluginConsumer = (props)=>{
|
|
84
|
-
const { data: plugin , isLoading , error } = (0, _runtime.usePlugin)(props.pluginType, props.kind);
|
|
85
|
-
if (error) {
|
|
86
|
-
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)("div", {
|
|
87
|
-
children: [
|
|
88
|
-
"Error: ",
|
|
89
|
-
error.message
|
|
90
|
-
]
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
if (isLoading) {
|
|
94
|
-
return /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
95
|
-
children: "Loading"
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)("div", {
|
|
99
|
-
children: [
|
|
100
|
-
"Has plugin: ",
|
|
101
|
-
(plugin !== undefined).toString()
|
|
102
|
-
]
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
// A helper component for testing the PluginRegistry metadata APIs by calling useListPluginMetadata
|
|
106
|
-
const MetadataConsumer = (props)=>{
|
|
107
|
-
const { data: pluginMetadata , isLoading , error } = (0, _runtime.useListPluginMetadata)(props.pluginType);
|
|
108
|
-
if (error) {
|
|
109
|
-
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)("div", {
|
|
110
|
-
children: [
|
|
111
|
-
"Error: ",
|
|
112
|
-
error.message
|
|
113
|
-
]
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
if (isLoading) {
|
|
117
|
-
return /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
118
|
-
children: "Loading"
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
if (pluginMetadata === undefined) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
return /*#__PURE__*/ (0, _jsxRuntime.jsx)("table", {
|
|
125
|
-
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)("tbody", {
|
|
126
|
-
children: pluginMetadata.map((item)=>/*#__PURE__*/ (0, _jsxRuntime.jsxs)("tr", {
|
|
127
|
-
children: [
|
|
128
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)("td", {
|
|
129
|
-
children: item.pluginType
|
|
130
|
-
}),
|
|
131
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)("td", {
|
|
132
|
-
children: item.kind
|
|
133
|
-
}),
|
|
134
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)("td", {
|
|
135
|
-
children: item.display.name
|
|
136
|
-
}),
|
|
137
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)("td", {
|
|
138
|
-
children: item.display.description
|
|
139
|
-
})
|
|
140
|
-
]
|
|
141
|
-
}, item.kind))
|
|
142
|
-
})
|
|
143
|
-
});
|
|
144
|
-
};
|
|
@@ -1,92 +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 _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
19
|
-
const _react = require("@testing-library/react");
|
|
20
|
-
const _test = require("../test");
|
|
21
|
-
const _pluginSpecEditor = require("./PluginSpecEditor");
|
|
22
|
-
function _interopRequireDefault(obj) {
|
|
23
|
-
return obj && obj.__esModule ? obj : {
|
|
24
|
-
default: obj
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
describe('PluginSpecEditor', ()=>{
|
|
28
|
-
const renderComponent = (props)=>{
|
|
29
|
-
(0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSpecEditor.PluginSpecEditor, {
|
|
30
|
-
...props
|
|
31
|
-
}));
|
|
32
|
-
};
|
|
33
|
-
describe('Panel plugin', ()=>{
|
|
34
|
-
it('should show query and json editors', async ()=>{
|
|
35
|
-
renderComponent({
|
|
36
|
-
pluginType: 'Panel',
|
|
37
|
-
pluginKind: 'BertPanel1',
|
|
38
|
-
value: {},
|
|
39
|
-
onChange: jest.fn()
|
|
40
|
-
});
|
|
41
|
-
const queryTab = await _react.screen.findByLabelText('Query');
|
|
42
|
-
expect(queryTab).toBeInTheDocument();
|
|
43
|
-
const editor = await _react.screen.findByLabelText('BertPanel1 editor');
|
|
44
|
-
expect(editor).toBeInTheDocument();
|
|
45
|
-
const jsonEditor = await _react.screen.findByLabelText('JSON');
|
|
46
|
-
expect(jsonEditor).toBeInTheDocument();
|
|
47
|
-
});
|
|
48
|
-
it('should display other options editor components', async ()=>{
|
|
49
|
-
renderComponent({
|
|
50
|
-
pluginType: 'Panel',
|
|
51
|
-
pluginKind: 'BertPanel2',
|
|
52
|
-
value: {},
|
|
53
|
-
onChange: jest.fn()
|
|
54
|
-
});
|
|
55
|
-
const settingsTab = await _react.screen.findByLabelText('Settings');
|
|
56
|
-
expect(settingsTab).toBeInTheDocument();
|
|
57
|
-
const editor = await _react.screen.findByLabelText('BertPanel2 editor');
|
|
58
|
-
expect(editor).toBeInTheDocument();
|
|
59
|
-
const customTab = await _react.screen.findByLabelText('Custom Tab');
|
|
60
|
-
expect(customTab).toBeInTheDocument();
|
|
61
|
-
const jsonEditor = await _react.screen.findByLabelText('JSON');
|
|
62
|
-
expect(jsonEditor).toBeInTheDocument();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
it('propagates value changes', async ()=>{
|
|
66
|
-
const onChange = jest.fn();
|
|
67
|
-
renderComponent({
|
|
68
|
-
pluginType: 'Panel',
|
|
69
|
-
pluginKind: 'BertPanel1',
|
|
70
|
-
value: {
|
|
71
|
-
option1: 'Option1Value'
|
|
72
|
-
},
|
|
73
|
-
onChange
|
|
74
|
-
});
|
|
75
|
-
const editor = await _react.screen.findByLabelText('BertPanel1 editor');
|
|
76
|
-
expect(editor).toHaveValue('Option1Value');
|
|
77
|
-
_userEvent.default.clear(editor);
|
|
78
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
79
|
-
option1: ''
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
it('shows an error if plugin fails to load', async ()=>{
|
|
83
|
-
renderComponent({
|
|
84
|
-
pluginType: 'Variable',
|
|
85
|
-
pluginKind: 'DoesNotExist',
|
|
86
|
-
value: {},
|
|
87
|
-
onChange: jest.fn()
|
|
88
|
-
});
|
|
89
|
-
const errorAlert = await _react.screen.findByRole('alert');
|
|
90
|
-
expect(errorAlert).toHaveTextContent(/doesnotexist/i);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CalculationSelector.test.d.ts","sourceRoot":"","sources":["../../../src/components/CalculationSelector/CalculationSelector.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,58 +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 { render, screen } from '@testing-library/react';
|
|
15
|
-
import userEvent from '@testing-library/user-event';
|
|
16
|
-
import { CalculationSelector } from './CalculationSelector';
|
|
17
|
-
describe('CalculationSelector', ()=>{
|
|
18
|
-
const renderCalculationSelector = (value, onChange = jest.fn())=>{
|
|
19
|
-
render(/*#__PURE__*/ _jsx("div", {
|
|
20
|
-
children: /*#__PURE__*/ _jsx(CalculationSelector, {
|
|
21
|
-
value: value,
|
|
22
|
-
onChange: onChange
|
|
23
|
-
})
|
|
24
|
-
}));
|
|
25
|
-
};
|
|
26
|
-
const getCalculationSelector = ()=>{
|
|
27
|
-
return screen.getByRole('combobox', {
|
|
28
|
-
name: 'Calculation'
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
it('can change the calculation by clicking', ()=>{
|
|
32
|
-
const onChange = jest.fn();
|
|
33
|
-
renderCalculationSelector('Last', onChange);
|
|
34
|
-
const calcSelector = getCalculationSelector();
|
|
35
|
-
userEvent.click(calcSelector);
|
|
36
|
-
const sumOption = screen.getByRole('option', {
|
|
37
|
-
name: 'Sum'
|
|
38
|
-
});
|
|
39
|
-
userEvent.click(sumOption);
|
|
40
|
-
expect(onChange).toHaveBeenCalledWith('Sum');
|
|
41
|
-
});
|
|
42
|
-
it('can change the calculation using a keyboard', ()=>{
|
|
43
|
-
const onChange = jest.fn();
|
|
44
|
-
renderCalculationSelector('First', onChange);
|
|
45
|
-
const calcSelector = getCalculationSelector();
|
|
46
|
-
userEvent.tab();
|
|
47
|
-
expect(calcSelector).toHaveFocus();
|
|
48
|
-
userEvent.clear(calcSelector);
|
|
49
|
-
userEvent.keyboard('first');
|
|
50
|
-
screen.getByRole('option', {
|
|
51
|
-
name: 'First'
|
|
52
|
-
});
|
|
53
|
-
userEvent.keyboard('{arrowup}{enter}');
|
|
54
|
-
expect(onChange).toHaveBeenCalledWith('First');
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
//# sourceMappingURL=CalculationSelector.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/CalculationSelector/CalculationSelector.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 { render, screen } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { CalculationType } from '../../model/calculations';\nimport { CalculationSelector } from './CalculationSelector';\n\ndescribe('CalculationSelector', () => {\n const renderCalculationSelector = (value: CalculationType, onChange = jest.fn()) => {\n render(\n <div>\n <CalculationSelector value={value} onChange={onChange} />\n </div>\n );\n };\n\n const getCalculationSelector = () => {\n return screen.getByRole('combobox', { name: 'Calculation' });\n };\n\n it('can change the calculation by clicking', () => {\n const onChange = jest.fn();\n renderCalculationSelector('Last', onChange);\n\n const calcSelector = getCalculationSelector();\n userEvent.click(calcSelector);\n const sumOption = screen.getByRole('option', {\n name: 'Sum',\n });\n userEvent.click(sumOption);\n\n expect(onChange).toHaveBeenCalledWith('Sum');\n });\n\n it('can change the calculation using a keyboard', () => {\n const onChange = jest.fn();\n renderCalculationSelector('First', onChange);\n\n const calcSelector = getCalculationSelector();\n userEvent.tab();\n expect(calcSelector).toHaveFocus();\n\n userEvent.clear(calcSelector);\n userEvent.keyboard('first');\n screen.getByRole('option', {\n name: 'First',\n });\n\n userEvent.keyboard('{arrowup}{enter}');\n\n expect(onChange).toHaveBeenCalledWith('First');\n });\n});\n"],"names":["render","screen","userEvent","CalculationSelector","describe","renderCalculationSelector","value","onChange","jest","fn","div","getCalculationSelector","getByRole","name","it","calcSelector","click","sumOption","expect","toHaveBeenCalledWith","tab","toHaveFocus","clear","keyboard"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,MAAM,EAAEC,MAAM,QAAQ,wBAAwB,CAAC;AACxD,OAAOC,SAAS,MAAM,6BAA6B,CAAC;AAEpD,SAASC,mBAAmB,QAAQ,uBAAuB,CAAC;AAE5DC,QAAQ,CAAC,qBAAqB,EAAE,IAAM;IACpC,MAAMC,yBAAyB,GAAG,CAACC,KAAsB,EAAEC,QAAQ,GAAGC,IAAI,CAACC,EAAE,EAAE,GAAK;QAClFT,MAAM,eACJ,KAACU,KAAG;sBACF,cAAA,KAACP,mBAAmB;gBAACG,KAAK,EAAEA,KAAK;gBAAEC,QAAQ,EAAEA,QAAQ;cAAI;UACrD,CACP,CAAC;IACJ,CAAC,AAAC;IAEF,MAAMI,sBAAsB,GAAG,IAAM;QACnC,OAAOV,MAAM,CAACW,SAAS,CAAC,UAAU,EAAE;YAAEC,IAAI,EAAE,aAAa;SAAE,CAAC,CAAC;IAC/D,CAAC,AAAC;IAEFC,EAAE,CAAC,wCAAwC,EAAE,IAAM;QACjD,MAAMP,QAAQ,GAAGC,IAAI,CAACC,EAAE,EAAE,AAAC;QAC3BJ,yBAAyB,CAAC,MAAM,EAAEE,QAAQ,CAAC,CAAC;QAE5C,MAAMQ,YAAY,GAAGJ,sBAAsB,EAAE,AAAC;QAC9CT,SAAS,CAACc,KAAK,CAACD,YAAY,CAAC,CAAC;QAC9B,MAAME,SAAS,GAAGhB,MAAM,CAACW,SAAS,CAAC,QAAQ,EAAE;YAC3CC,IAAI,EAAE,KAAK;SACZ,CAAC,AAAC;QACHX,SAAS,CAACc,KAAK,CAACC,SAAS,CAAC,CAAC;QAE3BC,MAAM,CAACX,QAAQ,CAAC,CAACY,oBAAoB,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEHL,EAAE,CAAC,6CAA6C,EAAE,IAAM;QACtD,MAAMP,QAAQ,GAAGC,IAAI,CAACC,EAAE,EAAE,AAAC;QAC3BJ,yBAAyB,CAAC,OAAO,EAAEE,QAAQ,CAAC,CAAC;QAE7C,MAAMQ,YAAY,GAAGJ,sBAAsB,EAAE,AAAC;QAC9CT,SAAS,CAACkB,GAAG,EAAE,CAAC;QAChBF,MAAM,CAACH,YAAY,CAAC,CAACM,WAAW,EAAE,CAAC;QAEnCnB,SAAS,CAACoB,KAAK,CAACP,YAAY,CAAC,CAAC;QAC9Bb,SAAS,CAACqB,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC5BtB,MAAM,CAACW,SAAS,CAAC,QAAQ,EAAE;YACzBC,IAAI,EAAE,OAAO;SACd,CAAC,CAAC;QAEHX,SAAS,CAACqB,QAAQ,CAAC,kBAAkB,CAAC,CAAC;QAEvCL,MAAM,CAACX,QAAQ,CAAC,CAACY,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OptionsEditorTabs.test.d.ts","sourceRoot":"","sources":["../../../src/components/OptionsEditorTabs/OptionsEditorTabs.test.tsx"],"names":[],"mappings":""}
|