From b636a85aaac2bfc337f878266c266a3b77968130 Mon Sep 17 00:00:00 2001 From: Stefan Pfaffel Date: Fri, 21 Jun 2024 09:30:03 +0200 Subject: [PATCH] feat(input-select): also support kv pairs with {id,alias} --- src/components/form-input-select.vue | 2 +- tests/unit/form-input-select.spec.js | 47 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/components/form-input-select.vue b/src/components/form-input-select.vue index 72a45e5..9e048a8 100644 --- a/src/components/form-input-select.vue +++ b/src/components/form-input-select.vue @@ -23,7 +23,7 @@ :key="element.id" :class="optionClazz" :value="index"> - {{ element.name }} + {{ element.name || element.alias }} diff --git a/tests/unit/form-input-select.spec.js b/tests/unit/form-input-select.spec.js index b5f54ae..b061d97 100644 --- a/tests/unit/form-input-select.spec.js +++ b/tests/unit/form-input-select.spec.js @@ -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) + }) + }) })