-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new codemirror-promql-based expression editor (#8634)
* Add new codemirror-promql-based expression editor This adds advanced autocompletion, syntax highlighting, and linting for PromQL. Fixes #6160 Fixes #5421 Signed-off-by: Julius Volz <julius.volz@gmail.com> * Group new editor options and float them left Signed-off-by: Julius Volz <julius.volz@gmail.com> * Improve history autocompletion handling Signed-off-by: Julius Volz <julius.volz@gmail.com> * Only show info tooltips for unabbreviated completion items Signed-off-by: Julius Volz <julius.volz@gmail.com> * Rename "new editor" to "experimental editor" Signed-off-by: Julius Volz <julius.volz@gmail.com> * Add path prefix support Signed-off-by: Julius Volz <julius.volz@gmail.com> * Revert accidental check-in of go.sum changes Signed-off-by: Julius Volz <julius.volz@gmail.com> * Remove spurious console.log Signed-off-by: Julius Volz <julius.volz@gmail.com> * Fix completion item type icon styling Signed-off-by: Julius Volz <julius.volz@gmail.com>
- Loading branch information
Showing
13 changed files
with
1,005 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
web/ui/react-app/src/pages/graph/CMExpressionInput.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as React from 'react'; | ||
import { mount, ReactWrapper } from 'enzyme'; | ||
import CMExpressionInput from './CMExpressionInput'; | ||
import { Button, InputGroup, InputGroupAddon, Input } from 'reactstrap'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faSearch, faSpinner } from '@fortawesome/free-solid-svg-icons'; | ||
|
||
describe('CMExpressionInput', () => { | ||
const expressionInputProps = { | ||
value: 'node_cpu', | ||
queryHistory: [], | ||
metricNames: [], | ||
executeQuery: (): void => { | ||
// Do nothing. | ||
}, | ||
onExpressionChange: (): void => { | ||
// Do nothing. | ||
}, | ||
loading: false, | ||
enableAutocomplete: true, | ||
enableHighlighting: true, | ||
enableLinter: true, | ||
}; | ||
|
||
let expressionInput: ReactWrapper; | ||
beforeEach(() => { | ||
expressionInput = mount(<CMExpressionInput {...expressionInputProps} />); | ||
}); | ||
|
||
it('renders an InputGroup', () => { | ||
const inputGroup = expressionInput.find(InputGroup); | ||
expect(inputGroup.prop('className')).toEqual('expression-input'); | ||
}); | ||
|
||
it('renders a search icon when it is not loading', () => { | ||
const addon = expressionInput.find(InputGroupAddon).filterWhere(addon => addon.prop('addonType') === 'prepend'); | ||
const icon = addon.find(FontAwesomeIcon); | ||
expect(icon.prop('icon')).toEqual(faSearch); | ||
}); | ||
|
||
it('renders a loading icon when it is loading', () => { | ||
const expressionInput = mount(<CMExpressionInput {...expressionInputProps} loading={true} />); | ||
const addon = expressionInput.find(InputGroupAddon).filterWhere(addon => addon.prop('addonType') === 'prepend'); | ||
const icon = addon.find(FontAwesomeIcon); | ||
expect(icon.prop('icon')).toEqual(faSpinner); | ||
expect(icon.prop('spin')).toBe(true); | ||
}); | ||
|
||
it('renders a CodeMirror expression input', () => { | ||
const input = expressionInput.find('div.cm-expression-input'); | ||
expect(input.text()).toContain('node_cpu'); | ||
}); | ||
|
||
it('renders an execute button', () => { | ||
const addon = expressionInput.find(InputGroupAddon).filterWhere(addon => addon.prop('addonType') === 'append'); | ||
const button = addon | ||
.find(Button) | ||
.find('.execute-btn') | ||
.first(); | ||
expect(button.prop('color')).toEqual('primary'); | ||
expect(button.text()).toEqual('Execute'); | ||
}); | ||
|
||
it('executes the query when clicking the execute button', () => { | ||
const spyExecuteQuery = jest.fn(); | ||
const props = { ...expressionInputProps, executeQuery: spyExecuteQuery }; | ||
const wrapper = mount(<CMExpressionInput {...props} />); | ||
const btn = wrapper.find(Button).filterWhere(btn => btn.hasClass('execute-btn')); | ||
btn.simulate('click'); | ||
expect(spyExecuteQuery).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
Oops, something went wrong.