From 3a5d768a63dfeb760b52d7f54aa6464d7b980a95 Mon Sep 17 00:00:00 2001 From: fyodorklimenko Date: Wed, 11 Jul 2018 17:56:13 +0300 Subject: [PATCH] added more details to ModelvalidationError's message --- app/flowchart/modelvalidation-service.js | 26 ++++----- app/flowchart/modelvalidation-service_test.js | 56 ++++++++++--------- dist/ngFlowchart.js | 14 ++--- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/app/flowchart/modelvalidation-service.js b/app/flowchart/modelvalidation-service.js index 58e15ed..f15f11d 100644 --- a/app/flowchart/modelvalidation-service.js +++ b/app/flowchart/modelvalidation-service.js @@ -26,7 +26,7 @@ angular.forEach(nodes, function(node) { that.validateNode(node); if (ids.indexOf(node.id) !== -1) { - throw new ModelvalidationError('Id not unique.'); + throw new ModelvalidationError('Node\'s id = "' + node.id + '" is not unique.'); } ids.push(node.id); }); @@ -35,7 +35,7 @@ angular.forEach(nodes, function(node) { angular.forEach(node.connectors, function(connector) { if (connectorIds.indexOf(connector.id) !== -1) { - throw new ModelvalidationError('Id not unique.'); + throw new ModelvalidationError('Connector with id = "' + connector.id + '" is not unique.'); } connectorIds.push(connector.id); }); @@ -46,19 +46,19 @@ this.validateNode = function(node) { var that = this; if (node.id === undefined) { - throw new ModelvalidationError('Id not valid.'); + throw new ModelvalidationError('Node\'s id is not valid.'); } if (typeof node.name !== 'string') { - throw new ModelvalidationError('Name not valid.'); + throw new ModelvalidationError('Node\'s (id = "' + node.id + '") name is not string.'); } if (typeof node.x !== 'number' || node.x < 0 || Math.round(node.x) !== node.x) { - throw new ModelvalidationError('Coordinates not valid.') + throw new ModelvalidationError('Node\'s (id = "' + node.id + '") horizontal coordinate is not valid.') } if (typeof node.y !== 'number' || node.y < 0 || Math.round(node.y) !== node.y) { - throw new ModelvalidationError('Coordinates not valid.') + throw new ModelvalidationError('Node\'s (id = "' + node.id + '") vertical coordinate is not valid.') } if (!Array.isArray(node.connectors)) { - throw new ModelvalidationError('Connectors not valid.'); + throw new ModelvalidationError('Node\'s (id = "' + node.id + '") connectors property is not valid.'); } angular.forEach(node.connectors, function(connector) { that.validateConnector(connector); @@ -96,10 +96,10 @@ this._validateEdge = function(edge, nodes) { if (edge.source === undefined) { - throw new ModelvalidationError('Source not valid.'); + throw new ModelvalidationError('Source is not valid.'); } if (edge.destination === undefined) { - throw new ModelvalidationError('Destination not valid.'); + throw new ModelvalidationError('Destination is not valid.'); } if (edge.source === edge.destination) { @@ -107,11 +107,11 @@ } var sourceNode = nodes.filter(function(node) {return node.connectors.some(function(connector) {return connector.id === edge.source})})[0]; if (sourceNode === undefined) { - throw new ModelvalidationError('Source not valid.'); + throw new ModelvalidationError('Source is not valid.'); } var destinationNode = nodes.filter(function(node) {return node.connectors.some(function(connector) {return connector.id === edge.destination})})[0]; if (destinationNode === undefined) { - throw new ModelvalidationError('Destination not valid.'); + throw new ModelvalidationError('Destination is not valid.'); } if (sourceNode === destinationNode) { throw new ModelvalidationError('Edge with same source and destination nodes.'); @@ -126,10 +126,10 @@ this.validateConnector = function(connector) { if (connector.id === undefined) { - throw new ModelvalidationError('Id not valid.'); + throw new ModelvalidationError('Connector\'s id is not valid.'); } if (connector.type === undefined || connector.type === null || typeof connector.type !== 'string') { - throw new ModelvalidationError('Type not valid.'); + throw new ModelvalidationError('Connector\'s (id = "' + connector.id + '") type is not valid.'); } return connector; }; diff --git a/app/flowchart/modelvalidation-service_test.js b/app/flowchart/modelvalidation-service_test.js index d9932b1..3de1b72 100644 --- a/app/flowchart/modelvalidation-service_test.js +++ b/app/flowchart/modelvalidation-service_test.js @@ -61,10 +61,11 @@ describe('The modelvalidation', function() { var that = this; var nodes = angular.copy(this.validNodes); - nodes[0].id = nodes[1].id; + var id = nodes[1].id; + nodes[0].id = id; expect(function() { that.Modelvalidation.validateNodes(nodes) - }).toThrowError('Id not unique.'); + }).toThrowError('Node\'s id = "' + id + '" is not unique.'); nodes = angular.copy(this.validNodes); expect(this.Modelvalidation.validateNodes(angular.copy(nodes))).toEqual(nodes); @@ -74,10 +75,11 @@ describe('The modelvalidation', function() { var that = this; var nodes = angular.copy(this.validNodes); - nodes[1].connectors[0].id = nodes[2].connectors[0].id; + var id = nodes[2].connectors[0].id; + nodes[1].connectors[0].id = id; expect(function() { that.Modelvalidation.validateNodes(nodes) - }).toThrowError('Id not unique.'); + }).toThrowError('Connector with id = "' + id + '" is not unique.'); nodes = angular.copy(this.validNodes); angular.forEach(nodes, function(node) { @@ -97,13 +99,13 @@ describe('The modelvalidation', function() { delete nodes[0].name; expect(function() { that.Modelvalidation.validateNodes(nodes) - }).toThrowError('Name not valid.'); + }).toThrowError('Node\'s (id = "' + nodes[0].id + '") name is not string.'); nodes = angular.copy(this.validNodes); delete nodes[1].connectors[0].id; expect(function() { that.Modelvalidation.validateNodes(nodes) - }).toThrowError('Id not valid.'); + }).toThrowError('Connector\'s id is not valid.'); }); }); @@ -120,31 +122,31 @@ describe('The modelvalidation', function() { delete node.connectors; expect(function() { that.Modelvalidation.validateNode(node) - }).toThrow(new Error('Connectors not valid.')); + }).toThrow(new Error('Node\'s (id = "' + node.id + '") connectors property is not valid.')); node = angular.copy(this.validNode); delete node.y; expect(function() { that.Modelvalidation.validateNode(node) - }).toThrow(new Error('Coordinates not valid.')); + }).toThrow(new Error('Node\'s (id = "' + node.id + '") vertical coordinate is not valid.')); node = angular.copy(this.validNode); delete node.x; expect(function() { that.Modelvalidation.validateNode(node) - }).toThrow(new Error('Coordinates not valid.')); + }).toThrow(new Error('Node\'s (id = "' + node.id + '") horizontal coordinate is not valid.')); node = angular.copy(this.validNode); delete node.id; expect(function() { that.Modelvalidation.validateNode(node) - }).toThrow(new Error('Id not valid.')); + }).toThrow(new Error('Node\'s id is not valid.')); node = angular.copy(this.validNode); delete node.name; expect(function() { that.Modelvalidation.validateNode(node) - }).toThrow(new Error('Name not valid.')); + }).toThrow(new Error('Node\'s (id = "' + node.id + '") name is not string.')); }); it('should detect if x, y are natural numbers', function() { @@ -154,26 +156,26 @@ describe('The modelvalidation', function() { node.x = -1; expect(function() { that.Modelvalidation.validateNode(node) - }).toThrow(new Error('Coordinates not valid.')); + }).toThrow(new Error('Node\'s (id = "' + node.id + '") horizontal coordinate is not valid.')); node = angular.copy(this.validNode); node.x = '1'; expect(function() { that.Modelvalidation.validateNode(node) - }).toThrow(new Error('Coordinates not valid.')); + }).toThrow(new Error('Node\'s (id = "' + node.id + '") horizontal coordinate is not valid.')); node = angular.copy(this.validNode); node.x = true; expect(function() { that.Modelvalidation.validateNode(node) - }).toThrow(new Error('Coordinates not valid.')); + }).toThrow(new Error('Node\'s (id = "' + node.id + '") horizontal coordinate is not valid.')); node = angular.copy(this.validNode); node.x = 1.1; node = {id: 1, name: '', x: 1.1, y: 1, connectors: []}; expect(function() { that.Modelvalidation.validateNode(node) - }).toThrow(new Error('Coordinates not valid.')); + }).toThrow(new Error('Node\'s (id = "' + node.id + '") horizontal coordinate is not valid.')); node = angular.copy(this.validNode); node.x = 10000; @@ -192,7 +194,7 @@ describe('The modelvalidation', function() { node.name = true; expect(function() { that.Modelvalidation.validateNode(node) - }).toThrow(new Error('Name not valid.')); + }).toThrow(new Error('Node\'s (id = "' + node.id + '") name is not string.')); node = angular.copy(this.validNode); node.name = ''; @@ -210,7 +212,7 @@ describe('The modelvalidation', function() { node.connectors = ''; expect(function() { that.Modelvalidation.validateNode(angular.copy(node)) - }).toThrow(new Error('Connectors not valid.')); + }).toThrow(new Error('Node\'s (id = \"' + node.id + '") connectors property is not valid.')); node = angular.copy(this.validNode); node.connectors = []; @@ -230,13 +232,13 @@ describe('The modelvalidation', function() { delete connector.id; expect(function() { that.Modelvalidation.validateConnector(connector) - }).toThrowError('Id not valid.'); + }).toThrowError('Connector\'s id is not valid.'); connector = angular.copy(this.validConnector); delete connector.type; expect(function() { that.Modelvalidation.validateConnector(connector) - }).toThrowError('Type not valid.'); + }).toThrowError('Connector\'s (id = "' + connector.id + '") type is not valid.'); connector = angular.copy(this.validConnector); expect(that.Modelvalidation.validateConnector(connector)).toEqual(this.validConnector); @@ -249,19 +251,19 @@ describe('The modelvalidation', function() { connector.type = null; expect(function() { that.Modelvalidation.validateConnector(connector) - }).toThrowError('Type not valid.'); + }).toThrowError('Connector\'s (id = "' + connector.id + '") type is not valid.'); connector = angular.copy(this.validConnector); connector.type = 1; expect(function() { that.Modelvalidation.validateConnector(connector) - }).toThrowError('Type not valid.'); + }).toThrowError('Connector\'s (id = "' + connector.id + '") type is not valid.'); connector = angular.copy(this.validConnector); connector.type = true; expect(function() { that.Modelvalidation.validateConnector(connector) - }).toThrowError('Type not valid.'); + }).toThrowError('Connector\'s (id = "' + connector.id + '") type is not valid.'); connector = angular.copy(this.validConnector); connector.type = ''; @@ -305,13 +307,13 @@ describe('The modelvalidation', function() { delete edge.source; expect(function() { that.Modelvalidation.validateEdge(edge, angular.copy(that.validModel.nodes)) - }).toThrowError('Source not valid.'); + }).toThrowError('Source is not valid.'); edge = angular.copy(this.validEdge); delete edge.destination; expect(function() { that.Modelvalidation.validateEdge(edge, angular.copy(that.validModel.nodes)) - }).toThrowError('Destination not valid.'); + }).toThrowError('Destination is not valid.'); }); it('should guarantee that source and destination are valid connector ids', function() { @@ -321,13 +323,13 @@ describe('The modelvalidation', function() { model.edges.push({source: -1000, destination: model.nodes[1].connectors[0].id}); expect(function() { that.Modelvalidation.validateEdge(model.edges[model.edges.length - 1], model.nodes) - }).toThrowError('Source not valid.'); + }).toThrowError('Source is not valid.'); model = angular.copy(this.validModel); model.edges.push({source: model.nodes[1].connectors[0].id, destination: -1000}); expect(function() { that.Modelvalidation.validateEdge(model.edges[model.edges.length - 1], model.nodes) - }).toThrowError('Destination not valid.'); + }).toThrowError('Destination is not valid.'); model = angular.copy(this.validModel); expect(this.Modelvalidation.validateEdge(model.edges[0], model.nodes)).toEqual(this.validModel.edges[0]); @@ -356,7 +358,7 @@ describe('The modelvalidation', function() { delete model.nodes[0].id; expect(function() { that.Modelvalidation.validateEdge(model.edges[0], model.nodes) - }).toThrowError('Id not valid.'); + }).toThrowError('Node\'s id is not valid.'); }); }); diff --git a/dist/ngFlowchart.js b/dist/ngFlowchart.js index e1bf0b9..04a3a09 100644 --- a/dist/ngFlowchart.js +++ b/dist/ngFlowchart.js @@ -419,7 +419,7 @@ if (!Function.prototype.bind) { angular.forEach(nodes, function(node) { that.validateNode(node); if (ids.indexOf(node.id) !== -1) { - throw new ModelvalidationError('Id not unique.'); + throw new ModelvalidationError('Node\'s id = "' + node.id + '" is not unique.'); } ids.push(node.id); }); @@ -428,7 +428,7 @@ if (!Function.prototype.bind) { angular.forEach(nodes, function(node) { angular.forEach(node.connectors, function(connector) { if (connectorIds.indexOf(connector.id) !== -1) { - throw new ModelvalidationError('Id not unique.'); + throw new ModelvalidationError('Connector\'s id = "' + connector.id + '" is not unique.'); } connectorIds.push(connector.id); }); @@ -439,19 +439,19 @@ if (!Function.prototype.bind) { this.validateNode = function(node) { var that = this; if (node.id === undefined) { - throw new ModelvalidationError('Id not valid.'); + throw new ModelvalidationError('Node\'s id is not valid.'); } if (typeof node.name !== 'string') { - throw new ModelvalidationError('Name not valid.'); + throw new ModelvalidationError('Node\'s (id = "' + node.id + '") name is not string.'); } if (typeof node.x !== 'number' || node.x < 0 || Math.round(node.x) !== node.x) { - throw new ModelvalidationError('Coordinates not valid.') + throw new ModelvalidationError('Node\'s (id = "' + node.id + '") horizontal coordinate is not valid.') } if (typeof node.y !== 'number' || node.y < 0 || Math.round(node.y) !== node.y) { - throw new ModelvalidationError('Coordinates not valid.') + throw new ModelvalidationError('Node\'s (id = "' + node.id + '") vertical coordinate is not valid.') } if (!Array.isArray(node.connectors)) { - throw new ModelvalidationError('Connectors not valid.'); + throw new ModelvalidationError('Node\'s (id = "' + node.id + '") connectors property is not valid.'); } angular.forEach(node.connectors, function(connector) { that.validateConnector(connector);