From 461b29d1fd9e84b7361f01404f5410fc0b209c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Moitti=C3=A9?= Date: Fri, 19 Aug 2022 16:27:18 +0200 Subject: [PATCH 1/5] Add definition for ComponentLink --- src/models/ComponentLinkDefinition.js | 40 +++++++++++++++++++ .../models/ComponentLinkDefinition.spec.js | 33 +++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/models/ComponentLinkDefinition.js create mode 100644 tests/unit/models/ComponentLinkDefinition.spec.js diff --git a/src/models/ComponentLinkDefinition.js b/src/models/ComponentLinkDefinition.js new file mode 100644 index 00000000..39c2fc82 --- /dev/null +++ b/src/models/ComponentLinkDefinition.js @@ -0,0 +1,40 @@ +/** + * Definition of the link between components. + */ +class ComponentLinkDefinition { + /** + * Default constructor. + * + * @param {String} [props.sourceRef] - Reference of component can be the source in a link. + * @param {String} [props.targetRef] - Reference of component can be the target of the link. + * @param {String} [props.type] - Representation of the link. + */ + constructor(props = { + sourceRef: null, + targetRef: null, + type: null, + }) { + const { + sourceRef, + targetRef, + type, + } = props; + /** + * Reference of component can be the source in a link. + * @type {String} + */ + this.sourceRef = sourceRef || null; + /** + * Reference of component can be the target of the link. + * @type {String} + */ + this.targetRef = targetRef || null; + /** + * Representation of the link. + * @type {String} + */ + this.type = type || null; + } +} + +export default ComponentLinkDefinition; diff --git a/tests/unit/models/ComponentLinkDefinition.spec.js b/tests/unit/models/ComponentLinkDefinition.spec.js new file mode 100644 index 00000000..1210593a --- /dev/null +++ b/tests/unit/models/ComponentLinkDefinition.spec.js @@ -0,0 +1,33 @@ +import ComponentLinkDefinition from 'src/models/ComponentLinkDefinition'; + +describe('Test class: ComponentLinkDefinition', () => { + describe('Test constructor', () => { + it('Check variable instantiation', () => { + const link = new ComponentLinkDefinition(); + + expect(link.sourceRef).toBeNull(); + expect(link.targetRef).toBeNull(); + expect(link.type).toBeNull(); + }); + + it('Check passing undefined variables to constructor', () => { + const link = new ComponentLinkDefinition({}); + + expect(link.sourceRef).toBeNull(); + expect(link.targetRef).toBeNull(); + expect(link.type).toBeNull(); + }); + + it('Check passing variable to constructor', () => { + const link = new ComponentLinkDefinition({ + sourceRef: 'id1', + targetRef: 'id2', + type: 'type', + }); + + expect(link.sourceRef).toEqual('id1'); + expect(link.targetRef).toEqual('id2'); + expect(link.type).toEqual('type'); + }); + }); +}); From f15302f34c6d2582052b5b430370dfd5d16f3d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Moitti=C3=A9?= Date: Fri, 19 Aug 2022 16:28:32 +0200 Subject: [PATCH 2/5] Remove required and displayable from ComponentDefinition --- src/models/ComponentDefinition.js | 16 ---------------- tests/unit/models/ComponentDefinition.spec.js | 8 -------- 2 files changed, 24 deletions(-) diff --git a/src/models/ComponentDefinition.js b/src/models/ComponentDefinition.js index c2560d40..16e46034 100644 --- a/src/models/ComponentDefinition.js +++ b/src/models/ComponentDefinition.js @@ -12,8 +12,6 @@ class ComponentDefinition { * @param {ComponentAttributeDefinition[]} [props.definedAttributes=[]] - Defined attributes for * this type. * @param {Boolean} [props.isContainer=false] - Boolean means if this type can be a parent. - * @param {Boolean} [props.displayable=true] - Boolean means if this type can be drawn. - * @param {Boolean} [props.required=false] - Boolean means if this need to exist in all * instantiated components. */ constructor(props = { @@ -23,8 +21,6 @@ class ComponentDefinition { parentTypes: [], definedAttributes: [], isContainer: false, - displayable: true, - required: false, }) { const { type, @@ -33,8 +29,6 @@ class ComponentDefinition { parentTypes, definedAttributes, isContainer, - displayable, - required, } = props; /** * The type of the associated component. @@ -66,16 +60,6 @@ class ComponentDefinition { * @type {Boolean} */ this.isContainer = isContainer === undefined ? false : isContainer; - /** - * Boolean means if this type can be a draw. - * @type {Boolean} - */ - this.displayable = displayable === undefined ? true : displayable; - /** - * Boolean means if this need to exist in all instantiated components. - * @type {Boolean} - */ - this.required = required === undefined ? false : required; } } diff --git a/tests/unit/models/ComponentDefinition.spec.js b/tests/unit/models/ComponentDefinition.spec.js index adda848c..e6458944 100644 --- a/tests/unit/models/ComponentDefinition.spec.js +++ b/tests/unit/models/ComponentDefinition.spec.js @@ -11,8 +11,6 @@ describe('Test class: ComponentDefinition', () => { expect(componentDefinition.parentTypes).toEqual([]); expect(componentDefinition.definedAttributes).toEqual([]); expect(componentDefinition.isContainer).toBeFalsy(); - expect(componentDefinition.displayable).toBeTruthy(); - expect(componentDefinition.required).toBeFalsy(); }); it('Check passing undefined variables to constructor', () => { @@ -24,8 +22,6 @@ describe('Test class: ComponentDefinition', () => { expect(componentDefinition.parentTypes).toEqual([]); expect(componentDefinition.definedAttributes).toEqual([]); expect(componentDefinition.isContainer).toBeFalsy(); - expect(componentDefinition.displayable).toBeTruthy(); - expect(componentDefinition.required).toBeFalsy(); }); it('Check passing variable to constructor', () => { @@ -36,8 +32,6 @@ describe('Test class: ComponentDefinition', () => { parentTypes: ['type'], definedAttributes: ['attribute'], isContainer: true, - displayable: false, - required: true, }); expect(componentDefinition.type).toEqual('type'); @@ -48,8 +42,6 @@ describe('Test class: ComponentDefinition', () => { expect(componentDefinition.definedAttributes.length).toEqual(1); expect(componentDefinition.definedAttributes[0]).toEqual('attribute'); expect(componentDefinition.isContainer).toBeTruthy(); - expect(componentDefinition.displayable).toBeFalsy(); - expect(componentDefinition.required).toBeTruthy(); }); }); }); From 305468432bccc1366a0e3e0f66dd1651e06b9e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Moitti=C3=A9?= Date: Fri, 19 Aug 2022 16:41:00 +0200 Subject: [PATCH 3/5] Improve ComponentAttributeDefinition --- src/models/ComponentAttributeDefinition.js | 37 ++++++++++++++++--- .../ComponentAttributeDefinition.spec.js | 29 ++++++++++++--- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/models/ComponentAttributeDefinition.js b/src/models/ComponentAttributeDefinition.js index 5151b0d3..8e795f1a 100644 --- a/src/models/ComponentAttributeDefinition.js +++ b/src/models/ComponentAttributeDefinition.js @@ -7,9 +7,13 @@ class ComponentAttributeDefinition { * * @param {String} [props.name] - Attribute name. * @param {String} [props.type] - Attribute type, - * valid types are String/Boolean/Number/Array/Object/Link. - * @param {String[]} [props.linkTypes=[]] - Define list of Component that can be linked with this. + * valid types are String/Boolean/Number/Array/Object/Link/Reference. + * @param {String} [props.linkType] - Type of link, valid types are Default/Reverse. + * @param {String[]} [props.linkRef=[]] - Reference of accepted component for link. + * @param {String[]} [props.containerRef=[]] - Reference of accepted component for container. * @param {Boolean} [props.required=false] - Attribute is required. + * @param {ComponentAttributeDefinition[]} [props.definedAttributes=[]] - Defined attributes for + * this type. * @param {Object} [props.rules={}] - Rules of this type of Attribute. * @param {Array} [props.rules.values] - Default values of attribute. * @param {Number} [props.rules.min] - Minimum value of Attribute. @@ -19,8 +23,11 @@ class ComponentAttributeDefinition { constructor(props = { name: null, type: null, - linkTypes: [], + linkType: null, + linkRef: [], + containerRef: [], required: false, + definedAttributes: [], rules: { values: null, min: null, @@ -31,7 +38,10 @@ class ComponentAttributeDefinition { const { name, type, - linkTypes, + linkType, + linkRef, + containerRef, + definedAttributes, required, rules, } = props; @@ -41,15 +51,30 @@ class ComponentAttributeDefinition { */ this.name = name || null; /** - * Attribute type, valid types are String/Boolean/Number/Array/Object/Link. + * Attribute type, valid types are String/Boolean/Number/Array/Object/Link/Reference. * @type {String} */ this.type = type || null; + /** + * Type of link, valid types are Default/Reverse. + * @type {String} + */ + this.linkType = linkType || null; /** * Define list of Component that can be linked with this. * @type {String[]} */ - this.linkTypes = linkTypes || []; + this.linkRef = linkRef || []; + /** + * Define list of Component that can be the container of this component. + * @type {String[]} + */ + this.containerRef = containerRef || []; + /** + * Defined attributes for this type. + * @type {ComponentAttributeDefinition[]} + */ + this.definedAttributes = definedAttributes || []; /** * Attribute is required. * @type {Boolean} diff --git a/tests/unit/models/ComponentAttributeDefinition.spec.js b/tests/unit/models/ComponentAttributeDefinition.spec.js index 8c286590..18f75a32 100644 --- a/tests/unit/models/ComponentAttributeDefinition.spec.js +++ b/tests/unit/models/ComponentAttributeDefinition.spec.js @@ -7,7 +7,10 @@ describe('Test class: ComponentAttributeDefinition', () => { expect(definedAttribute.name).toBeNull(); expect(definedAttribute.type).toBeNull(); - expect(definedAttribute.linkTypes).toEqual([]); + expect(definedAttribute.linkType).toBeNull(); + expect(definedAttribute.linkRef).toEqual([]); + expect(definedAttribute.containerRef).toEqual([]); + expect(definedAttribute.definedAttributes).toEqual([]); expect(definedAttribute.required).toEqual(false); expect(definedAttribute.rules.values).toBeNull(); expect(definedAttribute.rules.min).toBeNull(); @@ -20,7 +23,10 @@ describe('Test class: ComponentAttributeDefinition', () => { expect(definedAttribute.name).toBeNull(); expect(definedAttribute.type).toBeNull(); - expect(definedAttribute.linkTypes).toEqual([]); + expect(definedAttribute.linkType).toBeNull(); + expect(definedAttribute.linkRef).toEqual([]); + expect(definedAttribute.containerRef).toEqual([]); + expect(definedAttribute.definedAttributes).toEqual([]); expect(definedAttribute.required).toEqual(false); expect(definedAttribute.rules.values).toBeNull(); expect(definedAttribute.rules.min).toBeNull(); @@ -33,7 +39,10 @@ describe('Test class: ComponentAttributeDefinition', () => { expect(definedAttribute.name).toBeNull(); expect(definedAttribute.type).toBeNull(); - expect(definedAttribute.linkTypes).toEqual([]); + expect(definedAttribute.linkType).toBeNull(); + expect(definedAttribute.linkRef).toEqual([]); + expect(definedAttribute.containerRef).toEqual([]); + expect(definedAttribute.definedAttributes).toEqual([]); expect(definedAttribute.required).toEqual(false); expect(definedAttribute.rules.values).toBeNull(); expect(definedAttribute.rules.min).toBeNull(); @@ -45,7 +54,10 @@ describe('Test class: ComponentAttributeDefinition', () => { const definedAttribute = new ComponentAttributeDefinition({ name: 'name', type: 'type', - linkTypes: ['linkTypes'], + linkType: 'Default', + linkRef: ['linkRef'], + containerRef: ['containerRef'], + definedAttributes: [new ComponentAttributeDefinition()], required: true, rules: { values: ['value'], @@ -57,8 +69,13 @@ describe('Test class: ComponentAttributeDefinition', () => { expect(definedAttribute.name).toEqual('name'); expect(definedAttribute.type).toEqual('type'); - expect(definedAttribute.linkTypes.length).toEqual(1); - expect(definedAttribute.linkTypes[0]).toEqual('linkTypes'); + expect(definedAttribute.linkType).toEqual('Default'); + expect(definedAttribute.linkRef.length).toEqual(1); + expect(definedAttribute.linkRef[0]).toEqual('linkRef'); + expect(definedAttribute.containerRef.length).toEqual(1); + expect(definedAttribute.containerRef[0]).toEqual('containerRef'); + expect(definedAttribute.definedAttributes.length).toEqual(1); + expect(definedAttribute.definedAttributes[0]).not.toBeNull(); expect(definedAttribute.required).toEqual(true); expect(definedAttribute.rules.values).toEqual(['value']); expect(definedAttribute.rules.min).toEqual(1); From dadc576dc8cd4905a64ed0b6da8d5647ae8059eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Moitti=C3=A9?= Date: Fri, 19 Aug 2022 16:42:32 +0200 Subject: [PATCH 4/5] Improve get definitions in DefaultMetadata --- src/metadata/DefaultMetadata.js | 21 ++++++++++++--------- tests/unit/metadata/DefaultMetadata.spec.js | 9 ++++++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/metadata/DefaultMetadata.js b/src/metadata/DefaultMetadata.js index d65636fc..01f81ac5 100644 --- a/src/metadata/DefaultMetadata.js +++ b/src/metadata/DefaultMetadata.js @@ -5,14 +5,14 @@ class DefaultMetadata { /** * Default constructor. - * @param {Object} metadata - Metadata provide by leto-modelizer. + * @param {Array} resources - Resources object that contains all Metadata object. */ - constructor(metadata) { + constructor(resources) { /** - * Metadata object. - * @type {Object} + * Resources object that contains all Metadata object. + * @type {Array} */ - this.metadata = metadata; + this.resources = resources; } /** @@ -24,11 +24,14 @@ class DefaultMetadata { } /** - * Get all component definitions from metadata. - * @return {ComponentDefinition[]} - Array of component definitions. + * Get all component/link definitions from metadata. + * @return {Object} - Object that contains component/link definitions. */ - getComponentDefinitions() { - return []; + getDefinitions() { + return { + components: [], + links: [], + }; } } diff --git a/tests/unit/metadata/DefaultMetadata.spec.js b/tests/unit/metadata/DefaultMetadata.spec.js index dd8f15bf..c19ca1c9 100644 --- a/tests/unit/metadata/DefaultMetadata.spec.js +++ b/tests/unit/metadata/DefaultMetadata.spec.js @@ -9,10 +9,13 @@ describe('Test Class: DefaultMetadata()', () => { }); }); - describe('Test method: getComponentDefinitions', () => { - it('Should return empty array', () => { + describe('Test method: getDefinitions', () => { + it('Should return object with component and link definitions', () => { const defaultMetadata = new DefaultMetadata(); - expect(defaultMetadata.getComponentDefinitions()).toEqual([]); + expect(defaultMetadata.getDefinitions()).toEqual({ + components: [], + links: [], + }); }); }); }); From 3b27fe7b232b183f8b55cb15d9fca0e8287ef77c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Moitti=C3=A9?= Date: Fri, 19 Aug 2022 16:50:53 +0200 Subject: [PATCH 5/5] Update changelog --- changelog.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/changelog.md b/changelog.md index 8049debb..bc327ce5 100644 --- a/changelog.md +++ b/changelog.md @@ -10,10 +10,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Install `bin-pack` library. +- Add definition model for ComponentLink +- Add properties in ComponentAttributeDefiniton: + - `linkType` used for specify the type of link (`Default` or `Reverse`) + - `ContainerRef` used for specify the reference of valid container type + - `definedAttributes` used to specify definition of subattribute in case of `Object` type ### Changed - Improve `setComponentPosition` method with `bin-pack` library. +- Rename `linkTypes` to `linkRef` in ComponentAttributeDefinition +- Rename method `getComponentDefinitions` to `getDefinitions` in DefaultMetadata. +- Method `getDefinition` will return an object with component and link definitions. + +### Removed + +- Remove attributes `required` and `displayable` in ComponentDefinition ### Fixed