diff --git a/changelog.md b/changelog.md index be49578f2..f6e7d1e17 100644 --- a/changelog.md +++ b/changelog.md @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fix bug on models default folder opening, see [this issue](https://github.com/ditrit/leto-modelizer/issues/303). * Fix Sonar new bugs/code smell due to quality profil change, see [this issue](https://github.com/ditrit/leto-modelizer/issues/322). * Fix bug on using default file name from plugin instead of the file name specified by the user, when adding a component after creating a diagram from scratch. +* Fix Array attributes to allow missing definition, see [this issue](https://github.com/ditrit/leto-modelizer/issues/344). ### Removed diff --git a/src/components/inputs/ArrayInput.vue b/src/components/inputs/ArrayInput.vue index 32e1c9190..49b0c367d 100644 --- a/src/components/inputs/ArrayInput.vue +++ b/src/components/inputs/ArrayInput.vue @@ -27,7 +27,7 @@ const props = defineProps({ }); const arrayInput = ref(null); -const options = ref(props.attribute.definition.rules.values); +const options = ref(props.attribute.definition?.rules.values || null); const localValue = ref(props.attribute.value); watch(() => arrayInput.value, () => { diff --git a/tests/unit/components/inputs/ArrayInput.spec.js b/tests/unit/components/inputs/ArrayInput.spec.js index 281260205..a4b81e277 100644 --- a/tests/unit/components/inputs/ArrayInput.spec.js +++ b/tests/unit/components/inputs/ArrayInput.spec.js @@ -8,45 +8,108 @@ import { ComponentAttributeDefinition } from 'leto-modelizer-plugin-core'; installQuasarPlugin(); describe('Test component: ArrayInput', () => { - let wrapper; - - beforeEach(() => { - wrapper = shallowMount(ArrayInput, { - props: { - attribute: { - value: ['test'], - definition: new ComponentAttributeDefinition(), - }, - }, - global: { - stubs: { - qSelect: true, - }, - plugins: [ - createI18n({ - locale: 'en-US', - allowComposition: true, - messages: i18nConfiguration, - }), - ], - }, - }); - wrapper.vm.arrayInput = { - validate: jest.fn(() => Promise.resolve(true)), - }; - }); + const global = { + stubs: { + qSelect: true, + }, + plugins: [ + createI18n({ + locale: 'en-US', + allowComposition: true, + messages: i18nConfiguration, + }), + ], + }; describe('Test variables initialization', () => { describe('Test prop: attribute', () => { it('should be an object containing value', () => { + const wrapper = shallowMount(ArrayInput, { + props: { + attribute: { + value: ['test'], + definition: new ComponentAttributeDefinition(), + }, + }, + global, + }); + wrapper.vm.arrayInput = { + validate: jest.fn(() => Promise.resolve(true)), + }; expect(wrapper.vm.attribute.value).toEqual(['test']); }); }); describe('Test variable: localValue', () => { it('should match attribute.value', () => { + const wrapper = shallowMount(ArrayInput, { + props: { + attribute: { + value: ['test'], + definition: new ComponentAttributeDefinition(), + }, + }, + global, + }); + wrapper.vm.arrayInput = { + validate: jest.fn(() => Promise.resolve(true)), + }; expect(wrapper.vm.localValue).toEqual(['test']); }); }); + + describe('Test variable: options', () => { + it('should not be null when the attribute has a definition and rules with values', () => { + const wrapper = shallowMount(ArrayInput, { + props: { + attribute: { + value: ['test'], + definition: new ComponentAttributeDefinition({ + rules: { + values: ['value1', 'value2', 'value3'], + }, + }), + }, + }, + global, + }); + wrapper.vm.arrayInput = { + validate: jest.fn(() => Promise.resolve(true)), + }; + expect(wrapper.vm.options).toEqual(['value1', 'value2', 'value3']); + }); + + it('should be null when the attribute has a definition with no rules', () => { + const wrapper = shallowMount(ArrayInput, { + props: { + attribute: { + value: ['test'], + definition: new ComponentAttributeDefinition(), + }, + }, + global, + }); + wrapper.vm.arrayInput = { + validate: jest.fn(() => Promise.resolve(true)), + }; + expect(wrapper.vm.options).toBeNull(); + }); + + it('should be null and not raise an error when the attribute has no definition', () => { + const wrapper = shallowMount(ArrayInput, { + props: { + attribute: { + value: ['test'], + definition: null, + }, + }, + global, + }); + wrapper.vm.arrayInput = { + validate: jest.fn(() => Promise.resolve(true)), + }; + expect(wrapper.vm.options).toBeNull(); + }); + }); }); });