1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

update selected to value in AnsibleSelect

This commit is contained in:
John Mitchell 2019-02-13 14:52:11 -05:00
parent de658939c5
commit 35c94e9cd8
No known key found for this signature in database
GPG Key ID: FE6A9B5BD4EB5C94
2 changed files with 12 additions and 6 deletions

View File

@ -8,18 +8,21 @@ describe('<AnsibleSelect />', () => {
test('initially renders succesfully', async () => {
mount(
<AnsibleSelect
selected="foo"
value="foo"
name="bar"
onChange={() => { }}
labelName={label}
data={mockData}
/>
);
});
test('calls "onSelectChange" on dropdown select change', () => {
const spy = jest.spyOn(AnsibleSelect.prototype, 'onSelectChange');
const wrapper = mount(
<AnsibleSelect
selected="foo"
value="foo"
name="bar"
onChange={() => { }}
labelName={label}
data={mockData}
@ -29,10 +32,12 @@ describe('<AnsibleSelect />', () => {
wrapper.find('select').simulate('change');
expect(spy).toHaveBeenCalled();
});
test('content not rendered when data property is falsey', () => {
const wrapper = mount(
<AnsibleSelect
selected="foo"
value="foo"
name="bar"
onChange={() => { }}
labelName={label}
data={null}

View File

@ -26,18 +26,19 @@ class AnsibleSelect extends React.Component {
}
onSelectChange (val, event) {
const { onChange } = this.props;
const { onChange, name } = this.props;
event.target.name = name;
onChange(val, event);
}
render () {
const { count } = this.state;
const { labelName, selected, data, fieldId } = this.props;
const { labelName, value, data, fieldId } = this.props;
let elem;
if (count > 1) {
elem = (
<FormGroup label={labelName} fieldId={fieldId || 'ansible-select'}>
<Select value={selected} id={`select-${fieldId}` || 'ansible-select-element'} onChange={this.onSelectChange} aria-label="Select Input">
<Select value={value} id={`select-${fieldId}` || 'ansible-select-element'} onChange={this.onSelectChange} aria-label="Select Input">
{data.map((datum) => (
<SelectOption isDisabled={datum.disabled} key={datum} value={datum} label={datum} />
))}