From b10b28b49cfb33d5ba94da0a3f8ca3e1fc49562f Mon Sep 17 00:00:00 2001 From: X221782 Date: Thu, 20 Jul 2023 10:19:35 +0200 Subject: [PATCH 1/2] Fix bug in ArrayInput when the attribute's definition is null --- src/components/inputs/ArrayInput.vue | 2 +- .../unit/components/inputs/ArrayInput.spec.js | 117 ++++++++++++++---- 2 files changed, 91 insertions(+), 28 deletions(-) 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(); + }); + }); }); }); From 5c1d8d068d0d0c552702be5882a2dfb68f0b9e98 Mon Sep 17 00:00:00 2001 From: X221782 Date: Thu, 20 Jul 2023 10:38:41 +0200 Subject: [PATCH 2/2] Update changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) 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