-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Vis: Default editor] Unit test cases for controls (#41244)
* Add unit tests * Enable collecting test coverage * Use brace expansion * Fix types
- Loading branch information
Showing
16 changed files
with
424 additions
and
21 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
33 changes: 33 additions & 0 deletions
33
src/legacy/ui/public/agg_types/controls/__snapshots__/size.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
src/legacy/ui/public/agg_types/controls/__snapshots__/top_aggregate.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,94 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { mountWithIntl, shallowWithIntl } from 'test_utils/enzyme_helpers'; | ||
import { EuiIconTip } from '@elastic/eui'; | ||
import { SizeParamEditor, SizeParamEditorProps } from './size'; | ||
import { aggParamCommonPropsMock } from './test_utils'; | ||
|
||
describe('SizeParamEditor', () => { | ||
let defaultProps: SizeParamEditorProps; | ||
|
||
beforeEach(() => { | ||
defaultProps = { | ||
...aggParamCommonPropsMock, | ||
value: '', | ||
setValue: jest.fn(), | ||
setValidity: jest.fn(), | ||
setTouched: jest.fn(), | ||
}; | ||
}); | ||
|
||
it('should init with the default set of props', () => { | ||
const comp = shallowWithIntl(<SizeParamEditor {...defaultProps} />); | ||
|
||
expect(comp).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render an iconTip in the label if it was passed', () => { | ||
const iconTip = <EuiIconTip position="right" content={'test'} type="questionInCircle" />; | ||
const comp = shallowWithIntl(<SizeParamEditor {...defaultProps} iconTip={iconTip} />); | ||
|
||
expect(comp.props().label.props.children[1]).toEqual(iconTip); | ||
}); | ||
|
||
it('should change its validity due to passed props', () => { | ||
const comp = mountWithIntl(<SizeParamEditor {...defaultProps} />); | ||
|
||
expect(defaultProps.setValidity).toHaveBeenCalledWith(false); | ||
expect(comp.children().props()).toHaveProperty('isInvalid', false); | ||
|
||
comp.setProps({ disabled: true, showValidation: true }); | ||
|
||
expect(defaultProps.setValidity).toHaveBeenCalledWith(true); | ||
expect(comp.children().props()).toHaveProperty('isInvalid', false); | ||
|
||
comp.setProps({ disabled: false, showValidation: true }); | ||
|
||
expect(defaultProps.setValidity).toHaveBeenCalledWith(false); | ||
expect(comp.children().props()).toHaveProperty('isInvalid', true); | ||
|
||
comp.setProps({ value: 2, showValidation: true }); | ||
|
||
expect(defaultProps.setValidity).toHaveBeenCalledWith(true); | ||
expect(comp.children().props()).toHaveProperty('isInvalid', false); | ||
expect(defaultProps.setValidity).toHaveBeenCalledTimes(4); | ||
}); | ||
|
||
it('should set new parsed value', () => { | ||
const comp = mountWithIntl(<SizeParamEditor {...defaultProps} />); | ||
const input = comp.find('[type="number"]'); | ||
input.simulate('change', { target: { value: '3' } }); | ||
|
||
expect(defaultProps.setValue).toBeCalledWith(3); | ||
|
||
input.simulate('change', { target: { value: '' } }); | ||
|
||
expect(defaultProps.setValue).toBeCalledWith(''); | ||
expect(defaultProps.setValue).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
it('should call setTouched on blur', () => { | ||
const comp = mountWithIntl(<SizeParamEditor {...defaultProps} />); | ||
comp.find('[type="number"]').simulate('blur'); | ||
|
||
expect(defaultProps.setTouched).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { AggConfig, VisState } from 'ui/vis'; | ||
import { EditorConfig } from 'ui/vis/editors/config/types'; | ||
import { SubAggParamsProp } from 'ui/vis/editors/default/components/default_editor_agg_params'; | ||
import { AggParam } from '..'; | ||
|
||
export const aggParamCommonPropsMock = { | ||
agg: {} as AggConfig, | ||
aggParam: {} as AggParam, | ||
editorConfig: {} as EditorConfig, | ||
metricAggs: [] as AggConfig[], | ||
subAggParams: {} as SubAggParamsProp, | ||
state: {} as VisState, | ||
showValidation: false, | ||
}; |
Oops, something went wrong.