diff --git a/src/models/Component.js b/src/models/Component.js index 48be3fd1..90bb065f 100644 --- a/src/models/Component.js +++ b/src/models/Component.js @@ -241,10 +241,12 @@ class Component extends FileInformation { .some((defAttribute) => { const attribute = this.getAttributeByName(defAttribute.name); - return !attribute || attribute.value === null || ( - attribute.type === 'Object' || attribute.type === 'Array' - ? attribute.value.length === 0 - : attribute.value.trim() === ''); + return !attribute + || attribute.value === null + || attribute.value === undefined + || (attribute.type === 'Array' && attribute.value.length === 0) + || (attribute.type === 'Object' && Object.keys(attribute.value).length === 0) + || (attribute.type === 'String' && attribute.value.trim() === ''); }); } diff --git a/tests/unit/models/Component.spec.js b/tests/unit/models/Component.spec.js index bc13b199..d1b1a9f6 100644 --- a/tests/unit/models/Component.spec.js +++ b/tests/unit/models/Component.spec.js @@ -632,7 +632,7 @@ describe('Test class: Component', () => { it('Should not fail on Object type attribute', () => { const attribute = new ComponentAttribute({ name: 'attribute-object', - value: [], + value: {}, type: 'Object', }); @@ -680,6 +680,84 @@ describe('Test class: Component', () => { } expect(error).toBeNull(); }); + + it('Should not fail on Number type attribute', () => { + const attribute = new ComponentAttribute({ + name: 'attribute-number', + value: 1, + type: 'Number', + }); + + let error = null; + + try { + new Component({ + attributes: [attribute], + definition: { + definedAttributes: [new ComponentAttributeDefinition({ + name: 'attribute-number', + type: 'Number', + required: true, + })], + }, + }).hasError(); + } catch (e) { + error = e; + } + expect(error).toBeNull(); + }); + + it('Should not fail on Boolean type attribute', () => { + const attribute = new ComponentAttribute({ + name: 'attribute-boolean', + value: true, + type: 'Boolean', + }); + + let error = null; + + try { + new Component({ + attributes: [attribute], + definition: { + definedAttributes: [new ComponentAttributeDefinition({ + name: 'attribute-boolean', + type: 'Boolean', + required: true, + })], + }, + }).hasError(); + } catch (e) { + error = e; + } + expect(error).toBeNull(); + }); + + it('Should not fail on String type attribute', () => { + const attribute = new ComponentAttribute({ + name: 'attribute-string', + value: '', + type: 'String', + }); + + let error = null; + + try { + new Component({ + attributes: [attribute], + definition: { + definedAttributes: [new ComponentAttributeDefinition({ + name: 'attribute-string', + type: 'String', + required: true, + })], + }, + }).hasError(); + } catch (e) { + error = e; + } + expect(error).toBeNull(); + }); }); describe('Test String attribute', () => {