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:
parent
de658939c5
commit
35c94e9cd8
@ -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}
|
||||
|
@ -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} />
|
||||
))}
|
||||
|
Loading…
Reference in New Issue
Block a user