Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions app/flowchart/modelvalidation-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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);
Expand Down Expand Up @@ -96,22 +96,22 @@

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) {
throw new ModelvalidationError('Edge with same source and destination connectors.');
}
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.');
Expand All @@ -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;
};
Expand Down
56 changes: 29 additions & 27 deletions app/flowchart/modelvalidation-service_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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.');
});
});

Expand All @@ -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() {
Expand All @@ -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;
Expand All @@ -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 = '';
Expand All @@ -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 = [];
Expand All @@ -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);
Expand All @@ -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 = '';
Expand Down Expand Up @@ -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() {
Expand All @@ -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]);
Expand Down Expand Up @@ -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.');
});
});

Expand Down
14 changes: 7 additions & 7 deletions dist/ngFlowchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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);
Expand Down