From 5f44d094705395e672a5873a000dbfdd027104cd Mon Sep 17 00:00:00 2001 From: Avishkar Autar Date: Wed, 28 Dec 2022 00:58:38 -0500 Subject: [PATCH 1/3] add Entity.hasAnyConnectorAnchor() method --- spec/EntitySpec.js | 22 ++++++++++++++++++++++ src/Entity.js | 16 ++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/spec/EntitySpec.js b/spec/EntitySpec.js index ab14486..9e69ed6 100644 --- a/spec/EntitySpec.js +++ b/spec/EntitySpec.js @@ -174,6 +174,28 @@ describe("Entity.hasConnectorAnchor", function() { }); }); +describe("Entity.hasAnyConnectorAnchor", function() { + it("returns true if 1+ anchor is assigned to Entity", function() { + const o = new Entity( + "obj-123", + 100, + 200, + 10, + 20, + sheet, + window.document.createElement('div'), + [window.document.createElement('div')], + [window.document.createElement('div')] + ); + + const anchorElemA = window.document.createElement('div'); + const anchorElemB = window.document.createElement('div'); + const newAnchorA = o.addInteractableConnectorAnchor(anchorElem); + + expect(o.hasAnyConnectorAnchor([newAnchorA, anchorElemB])).toBe(true); + }); +}); + describe("Entity.translate", function() { it("translates entity", function() { const entityDomElem = window.document.createElement('div'); diff --git a/src/Entity.js b/src/Entity.js index 8a5a387..a6bac4a 100644 --- a/src/Entity.js +++ b/src/Entity.js @@ -121,6 +121,22 @@ function Entity(_id, _x, _y, _width, _height, _sheet, _domElement, _translateHan return false; }; + /** + * + * @param {ConnectorAnchor} _anchor + * @returns {Boolean} + */ + this.hasConnectorAnchor = function(_anchor) { + const anchors = self.getConnectorAnchors(); + for(let i=0; i Date: Wed, 28 Dec 2022 01:01:06 -0500 Subject: [PATCH 2/3] fix test, add method --- spec/EntitySpec.js | 6 +++--- src/Entity.js | 16 +++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/spec/EntitySpec.js b/spec/EntitySpec.js index 9e69ed6..16abb4f 100644 --- a/spec/EntitySpec.js +++ b/spec/EntitySpec.js @@ -176,7 +176,7 @@ describe("Entity.hasConnectorAnchor", function() { describe("Entity.hasAnyConnectorAnchor", function() { it("returns true if 1+ anchor is assigned to Entity", function() { - const o = new Entity( + const entity = new Entity( "obj-123", 100, 200, @@ -190,9 +190,9 @@ describe("Entity.hasAnyConnectorAnchor", function() { const anchorElemA = window.document.createElement('div'); const anchorElemB = window.document.createElement('div'); - const newAnchorA = o.addInteractableConnectorAnchor(anchorElem); + const newAnchorA = entity.addInteractableConnectorAnchor(anchorElemA); - expect(o.hasAnyConnectorAnchor([newAnchorA, anchorElemB])).toBe(true); + expect(entity.hasAnyConnectorAnchor([newAnchorA, anchorElemB])).toBe(true); }); }); diff --git a/src/Entity.js b/src/Entity.js index a6bac4a..5e11d58 100644 --- a/src/Entity.js +++ b/src/Entity.js @@ -123,19 +123,21 @@ function Entity(_id, _x, _y, _width, _height, _sheet, _domElement, _translateHan /** * - * @param {ConnectorAnchor} _anchor + * @param {ConnectorAnchor[]} _anchors * @returns {Boolean} */ - this.hasConnectorAnchor = function(_anchor) { - const anchors = self.getConnectorAnchors(); - for(let i=0; i Date: Wed, 28 Dec 2022 01:04:05 -0500 Subject: [PATCH 3/3] refactor Entity.hasConnectorAnchor() --- src/Entity.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Entity.js b/src/Entity.js index 5e11d58..e84be4f 100644 --- a/src/Entity.js +++ b/src/Entity.js @@ -111,14 +111,7 @@ function Entity(_id, _x, _y, _width, _height, _sheet, _domElement, _translateHan * @returns {Boolean} */ this.hasConnectorAnchor = function(_anchor) { - const anchors = self.getConnectorAnchors(); - for(let i=0; i