Skip to content

Commit

Permalink
feat(input-select): also support kv pairs with {id,alias}
Browse files Browse the repository at this point in the history
  • Loading branch information
stfsy committed Jun 21, 2024
1 parent 4aceb2c commit b636a85
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/form-input-select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
:key="element.id"
:class="optionClazz"
:value="index">
{{ element.name }}
{{ element.name || element.alias }}
</option>
</select>
</FormElementContainerWithLabel>
Expand Down
47 changes: 47 additions & 0 deletions tests/unit/form-input-select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,51 @@ describe('FormInputSelect.vue', () => {
expect(wrapper.vm.$refs.select.attributes.id.value).to.equal('my-form-input-select')
})
})
describe('.elements', () => {
it('expects key value pairs with format {id, name}', () => {
const wrapper = mount(FormInputSelect, {
props: {
id: 'my-form-input-select',
elements: [
{
id: '1',
name: 'abc'
}
]
}
})
const option = wrapper.find('option')
expect(option.text()).to.equal('abc')
})
it('expects key value pairs with format {id, alias}', () => {
const wrapper = mount(FormInputSelect, {
props: {
id: 'my-form-input-select',
elements: [
{
id: '1',
alias: 'abc'
}
]
}
})
const option = wrapper.find('option')
expect(option.text()).to.equal('abc')
})
it('does not expect key value pairs with format {id, label} but renders anyways', () => {
const wrapper = mount(FormInputSelect, {
props: {
id: 'my-form-input-select',
elements: [
{
id: '1',
label: 'abc'
}
]
}
})
const option = wrapper.find('option')
expect(option.text()).to.have.length(0)
})
})
})

0 comments on commit b636a85

Please sign in to comment.