Skip to content

Commit 333b9b6

Browse files
committed
Added tests for pf3 select option
1 parent 256df80 commit 333b9b6

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

packages/pf3-component-mapper/src/form-fields/select/option.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,20 @@ import { components } from 'react-select';
33
import PropTypes from 'prop-types';
44
import clsx from 'clsx';
55

6-
const Option = props => {
7-
return (
8-
<div className={ clsx('ddorg__pf3-component-mapper__select__option', {
9-
'ddorg__pf3-component-mapper__select__option--is-focused': props.isFocused,
10-
'ddorg__pf3-component-mapper__select__option--is-selected': props.isSelected,
11-
}) }>
12-
<components.Option { ...props } />
13-
{ props.isSelected && (props.selectProps && !props.selectProps.isCheckbox) && <i className="selected-indicator fa fa-check"></i> }
14-
</div>
15-
);
16-
};
6+
const Option = props => (
7+
<div className={ clsx('ddorg__pf3-component-mapper__select__option', {
8+
'ddorg__pf3-component-mapper__select__option--is-focused': props.isFocused,
9+
'ddorg__pf3-component-mapper__select__option--is-selected': props.isSelected,
10+
}) }>
11+
<components.Option { ...props } />
12+
{ props.isSelected && (props.selectProps && !props.selectProps.isCheckbox) && <i className="selected-indicator fa fa-check"></i> }
13+
</div>
14+
);
1715

1816
Option.propTypes = {
1917
isFocused: PropTypes.bool,
2018
isSelected: PropTypes.bool,
2119
getStyles: PropTypes.func.isRequired,
22-
selectOption: PropTypes.func,
2320
cx: PropTypes.func.isRequired,
2421
data: PropTypes.shape({
2522
selected: PropTypes.bool,
@@ -35,7 +32,6 @@ Option.propTypes = {
3532
Option.defaultProps = {
3633
isFocused: false,
3734
isSelected: false,
38-
selectOption: () => undefined,
3935
selectProps: {
4036
isCheckbox: false,
4137
},
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import { mount } from 'enzyme';
3+
import Option from '../../../form-fields/select/option';
4+
5+
describe('<Option />', () => {
6+
const optionProps = {
7+
getStyles: jest.fn(),
8+
cx: jest.fn(),
9+
selectProps: {},
10+
};
11+
it('should render in selected variant', () => {
12+
const wrapper = mount(<Option { ...optionProps }/>);
13+
expect(wrapper.find('i.selected-indicator.fa.fa-check')).toHaveLength(0);
14+
wrapper.setProps({ isSelected: true });
15+
wrapper.update();
16+
expect(wrapper.find('i.selected-indicator.fa.fa-check')).toHaveLength(1);
17+
});
18+
});

0 commit comments

Comments
 (0)