mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-30 03:39:36 +02:00
Make Graph#entity strict
Use Graph#hasEntity for the previous behavior.
This commit is contained in:
@@ -40,7 +40,7 @@ describe("iD.actions.Circularize", function () {
|
||||
|
||||
graph = iD.actions.Circularize('-', projection, 3)(graph);
|
||||
|
||||
expect(graph.entity('a')).to.be.undefined;
|
||||
expect(graph.hasEntity('a')).to.be.undefined;
|
||||
});
|
||||
|
||||
it("reconnects unused nodes that are members of other ways", function () {
|
||||
@@ -56,7 +56,7 @@ describe("iD.actions.Circularize", function () {
|
||||
|
||||
graph = iD.actions.Circularize('-', projection, 3)(graph);
|
||||
|
||||
expect(graph.entity('a')).to.be.undefined;
|
||||
expect(graph.hasEntity('a')).to.be.undefined;
|
||||
expect(graph.entity('=').nodes).to.eql(['c']);
|
||||
});
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ describe("iD.actions.Connect", function() {
|
||||
|
||||
graph = iD.actions.Connect(['a', 'b', 'c'])(graph);
|
||||
|
||||
expect(graph.entity('a')).to.be.undefined;
|
||||
expect(graph.entity('b')).to.be.undefined;
|
||||
expect(graph.hasEntity('a')).to.be.undefined;
|
||||
expect(graph.hasEntity('b')).to.be.undefined;
|
||||
expect(graph.entity('c')).not.to.be.undefined;
|
||||
});
|
||||
|
||||
@@ -87,7 +87,7 @@ describe("iD.actions.Connect", function() {
|
||||
graph = iD.actions.Connect(['b', 'c'])(graph);
|
||||
|
||||
expect(graph.entity('-').nodes).to.eql(['a', 'c']);
|
||||
expect(graph.entity('b')).to.be.undefined;
|
||||
expect(graph.hasEntity('b')).to.be.undefined;
|
||||
});
|
||||
|
||||
it("merges adjacent nodes with connections", function() {
|
||||
@@ -117,7 +117,7 @@ describe("iD.actions.Connect", function() {
|
||||
|
||||
expect(graph.entity('-').nodes).to.eql(['a', 'c']);
|
||||
expect(graph.entity('|').nodes).to.eql(['c', 'd']);
|
||||
expect(graph.entity('b')).to.be.undefined;
|
||||
expect(graph.hasEntity('b')).to.be.undefined;
|
||||
});
|
||||
|
||||
it("deletes a degenerate way", function() {
|
||||
@@ -133,8 +133,8 @@ describe("iD.actions.Connect", function() {
|
||||
|
||||
graph = iD.actions.Connect(['a', 'b'])(graph);
|
||||
|
||||
expect(graph.entity('a')).to.be.undefined;
|
||||
expect(graph.entity('-')).to.be.undefined;
|
||||
expect(graph.hasEntity('a')).to.be.undefined;
|
||||
expect(graph.hasEntity('-')).to.be.undefined;
|
||||
});
|
||||
|
||||
it("merges tags to the surviving node", function() {
|
||||
|
||||
@@ -5,9 +5,9 @@ describe("iD.actions.DeleteMultiple", function () {
|
||||
r = iD.Relation(),
|
||||
action = iD.actions.DeleteMultiple([n.id, w.id, r.id]),
|
||||
graph = action(iD.Graph([n, w, r]));
|
||||
expect(graph.entity(n.id)).to.be.undefined;
|
||||
expect(graph.entity(w.id)).to.be.undefined;
|
||||
expect(graph.entity(r.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(n.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(w.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(r.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
it("deletes a way and one of its nodes", function () {
|
||||
@@ -15,7 +15,7 @@ describe("iD.actions.DeleteMultiple", function () {
|
||||
w = iD.Way({nodes: [n.id]}),
|
||||
action = iD.actions.DeleteMultiple([w.id, n.id]),
|
||||
graph = action(iD.Graph([n, w]));
|
||||
expect(graph.entity(w.id)).to.be.undefined;
|
||||
expect(graph.entity(n.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(w.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(n.id)).to.be.undefined;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ describe("iD.actions.DeleteNode", function () {
|
||||
var node = iD.Node(),
|
||||
action = iD.actions.DeleteNode(node.id),
|
||||
graph = action(iD.Graph([node]));
|
||||
expect(graph.entity(node.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(node.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
it("removes the node from parent ways", function () {
|
||||
@@ -31,7 +31,7 @@ describe("iD.actions.DeleteNode", function () {
|
||||
way = iD.Way({nodes: [node1.id, node2.id]}),
|
||||
action = iD.actions.DeleteNode(node1.id),
|
||||
graph = action(iD.Graph([node1, node2, way]));
|
||||
expect(graph.entity(way.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(way.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
it("deletes degenerate circular ways", function () {
|
||||
@@ -40,6 +40,6 @@ describe("iD.actions.DeleteNode", function () {
|
||||
way = iD.Way({nodes: [node1.id, node2.id, node1.id]}),
|
||||
action = iD.actions.DeleteNode(node2.id),
|
||||
graph = action(iD.Graph([node1, node2, way]));
|
||||
expect(graph.entity(way.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(way.id)).to.be.undefined;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ describe("iD.actions.DeleteRelation", function () {
|
||||
var relation = iD.Relation(),
|
||||
action = iD.actions.DeleteRelation(relation.id),
|
||||
graph = action(iD.Graph([relation]));
|
||||
expect(graph.entity(relation.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(relation.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
it("removes the relation from parent relations", function () {
|
||||
@@ -20,7 +20,7 @@ describe("iD.actions.DeleteRelation", function () {
|
||||
relation = iD.Relation({members: [{id: node.id}]}),
|
||||
action = iD.actions.DeleteRelation(relation.id),
|
||||
graph = action(iD.Graph([node, relation]));
|
||||
expect(graph.entity(node.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(node.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
it("does not delete member nodes referenced by another parent", function() {
|
||||
@@ -29,7 +29,7 @@ describe("iD.actions.DeleteRelation", function () {
|
||||
relation = iD.Relation({members: [{id: node.id}]}),
|
||||
action = iD.actions.DeleteRelation(relation.id),
|
||||
graph = action(iD.Graph([node, way, relation]));
|
||||
expect(graph.entity(node.id)).not.to.be.undefined;
|
||||
expect(graph.hasEntity(node.id)).not.to.be.undefined;
|
||||
});
|
||||
|
||||
it("does not delete member nodes with interesting tags", function() {
|
||||
@@ -37,7 +37,7 @@ describe("iD.actions.DeleteRelation", function () {
|
||||
relation = iD.Relation({members: [{id: node.id}]}),
|
||||
action = iD.actions.DeleteRelation(relation.id),
|
||||
graph = action(iD.Graph([node, relation]));
|
||||
expect(graph.entity(node.id)).not.to.be.undefined;
|
||||
expect(graph.hasEntity(node.id)).not.to.be.undefined;
|
||||
});
|
||||
|
||||
it("deletes member ways not referenced by another parent", function() {
|
||||
@@ -45,7 +45,7 @@ describe("iD.actions.DeleteRelation", function () {
|
||||
relation = iD.Relation({members: [{id: way.id}]}),
|
||||
action = iD.actions.DeleteRelation(relation.id),
|
||||
graph = action(iD.Graph([way, relation]));
|
||||
expect(graph.entity(way.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(way.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
it("does not delete member ways referenced by another parent", function() {
|
||||
@@ -54,7 +54,7 @@ describe("iD.actions.DeleteRelation", function () {
|
||||
relation2 = iD.Relation({members: [{id: way.id}]}),
|
||||
action = iD.actions.DeleteRelation(relation1.id),
|
||||
graph = action(iD.Graph([way, relation1, relation2]));
|
||||
expect(graph.entity(way.id)).not.to.be.undefined;
|
||||
expect(graph.hasEntity(way.id)).not.to.be.undefined;
|
||||
});
|
||||
|
||||
it("does not delete member ways with interesting tags", function() {
|
||||
@@ -62,7 +62,7 @@ describe("iD.actions.DeleteRelation", function () {
|
||||
relation = iD.Relation({members: [{id: way.id}]}),
|
||||
action = iD.actions.DeleteRelation(relation.id),
|
||||
graph = action(iD.Graph([way, relation]));
|
||||
expect(graph.entity(way.id)).not.to.be.undefined;
|
||||
expect(graph.hasEntity(way.id)).not.to.be.undefined;
|
||||
});
|
||||
|
||||
it("deletes nodes of deleted member ways", function() {
|
||||
@@ -71,6 +71,6 @@ describe("iD.actions.DeleteRelation", function () {
|
||||
relation = iD.Relation({members: [{id: way.id}]}),
|
||||
action = iD.actions.DeleteRelation(relation.id),
|
||||
graph = action(iD.Graph([node, way, relation]));
|
||||
expect(graph.entity(node.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(node.id)).to.be.undefined;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ describe("iD.actions.DeleteWay", function() {
|
||||
var way = iD.Way(),
|
||||
action = iD.actions.DeleteWay(way.id),
|
||||
graph = iD.Graph([way]).update(action);
|
||||
expect(graph.entity(way.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(way.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
it("removes a way from parent relations", function() {
|
||||
@@ -19,7 +19,7 @@ describe("iD.actions.DeleteWay", function() {
|
||||
way = iD.Way({nodes: [node.id]}),
|
||||
action = iD.actions.DeleteWay(way.id),
|
||||
graph = iD.Graph([node, way]).update(action);
|
||||
expect(graph.entity(node.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(node.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
it("does not delete member nodes referenced by another parent", function() {
|
||||
@@ -28,7 +28,7 @@ describe("iD.actions.DeleteWay", function() {
|
||||
way2 = iD.Way({nodes: [node.id]}),
|
||||
action = iD.actions.DeleteWay(way1.id),
|
||||
graph = iD.Graph([node, way1, way2]).update(action);
|
||||
expect(graph.entity(node.id)).not.to.be.undefined;
|
||||
expect(graph.hasEntity(node.id)).not.to.be.undefined;
|
||||
});
|
||||
|
||||
it("deletes multiple member nodes", function() {
|
||||
@@ -37,8 +37,8 @@ describe("iD.actions.DeleteWay", function() {
|
||||
way = iD.Way({nodes: [a.id, b.id]}),
|
||||
action = iD.actions.DeleteWay(way.id),
|
||||
graph = iD.Graph([a, b, way]).update(action);
|
||||
expect(graph.entity(a.id)).to.be.undefined;
|
||||
expect(graph.entity(b.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(a.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(b.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
it("deletes a circular way's start/end node", function() {
|
||||
@@ -48,9 +48,9 @@ describe("iD.actions.DeleteWay", function() {
|
||||
way = iD.Way({nodes: [a.id, b.id, c.id, a.id]}),
|
||||
action = iD.actions.DeleteWay(way.id),
|
||||
graph = iD.Graph([a, b, c, way]).update(action);
|
||||
expect(graph.entity(a.id)).to.be.undefined;
|
||||
expect(graph.entity(b.id)).to.be.undefined;
|
||||
expect(graph.entity(c.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(a.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(b.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(c.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
it("does not delete member nodes with interesting tags", function() {
|
||||
@@ -58,6 +58,6 @@ describe("iD.actions.DeleteWay", function() {
|
||||
way = iD.Way({nodes: [node.id]}),
|
||||
action = iD.actions.DeleteWay(way.id),
|
||||
graph = iD.Graph([node, way]).update(action);
|
||||
expect(graph.entity(node.id)).not.to.be.undefined;
|
||||
expect(graph.hasEntity(node.id)).not.to.be.undefined;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -91,7 +91,7 @@ describe("iD.actions.Join", function () {
|
||||
graph = iD.actions.Join(['-', '='])(graph);
|
||||
|
||||
expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c']);
|
||||
expect(graph.entity('=')).to.be.undefined;
|
||||
expect(graph.hasEntity('=')).to.be.undefined;
|
||||
});
|
||||
|
||||
it("joins a <-- b <== c", function () {
|
||||
@@ -108,7 +108,7 @@ describe("iD.actions.Join", function () {
|
||||
graph = iD.actions.Join(['-', '='])(graph);
|
||||
|
||||
expect(graph.entity('-').nodes).to.eql(['c', 'b', 'a']);
|
||||
expect(graph.entity('=')).to.be.undefined;
|
||||
expect(graph.hasEntity('=')).to.be.undefined;
|
||||
});
|
||||
|
||||
it("joins a <-- b ==> c", function () {
|
||||
@@ -126,7 +126,7 @@ describe("iD.actions.Join", function () {
|
||||
graph = iD.actions.Join(['-', '='])(graph);
|
||||
|
||||
expect(graph.entity('-').nodes).to.eql(['c', 'b', 'a']);
|
||||
expect(graph.entity('=')).to.be.undefined;
|
||||
expect(graph.hasEntity('=')).to.be.undefined;
|
||||
expect(graph.entity('-').tags).to.eql({'lanes:backward': 2});
|
||||
});
|
||||
|
||||
@@ -145,7 +145,7 @@ describe("iD.actions.Join", function () {
|
||||
graph = iD.actions.Join(['-', '='])(graph);
|
||||
|
||||
expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c']);
|
||||
expect(graph.entity('=')).to.be.undefined;
|
||||
expect(graph.hasEntity('=')).to.be.undefined;
|
||||
expect(graph.entity('-').tags).to.eql({'lanes:backward': 2});
|
||||
});
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ describe("iD.actions.Merge", function () {
|
||||
|
||||
graph = action(graph);
|
||||
|
||||
expect(graph.entity('a')).to.be.undefined;
|
||||
expect(graph.entity('b')).to.be.undefined;
|
||||
expect(graph.hasEntity('a')).to.be.undefined;
|
||||
expect(graph.hasEntity('b')).to.be.undefined;
|
||||
expect(graph.entity('w').tags).to.eql({a: 'a', b: 'b'});
|
||||
expect(graph.entity('r').members).to.eql([{id: 'w', role: 'r', type: 'way'}]);
|
||||
});
|
||||
@@ -31,8 +31,8 @@ describe("iD.actions.Merge", function () {
|
||||
|
||||
graph = action(graph);
|
||||
|
||||
expect(graph.entity('a')).to.be.undefined;
|
||||
expect(graph.entity('b')).to.be.undefined;
|
||||
expect(graph.hasEntity('a')).to.be.undefined;
|
||||
expect(graph.hasEntity('b')).to.be.undefined;
|
||||
expect(graph.entity('w').tags).to.eql({a: 'a', b: 'b', area: 'yes'});
|
||||
expect(graph.entity('r').members).to.eql([{id: 'w', role: 'r', type: 'way'}]);
|
||||
});
|
||||
|
||||
+27
-3
@@ -40,6 +40,30 @@ describe('iD.Graph', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#hasEntity", function () {
|
||||
it("returns the entity when present", function () {
|
||||
var node = iD.Node(),
|
||||
graph = iD.Graph([node]);
|
||||
expect(graph.hasEntity(node.id)).to.equal(node);
|
||||
});
|
||||
|
||||
it("returns undefined when the entity is not present", function () {
|
||||
expect(iD.Graph().hasEntity('1')).to.be.undefined;
|
||||
});
|
||||
});
|
||||
|
||||
describe("#entity", function () {
|
||||
it("returns the entity when present", function () {
|
||||
var node = iD.Node(),
|
||||
graph = iD.Graph([node]);
|
||||
expect(graph.entity(node.id)).to.equal(node);
|
||||
});
|
||||
|
||||
it("throws when the entity is not present", function () {
|
||||
expect(function() { iD.Graph().entity('1'); }).to.throw;
|
||||
});
|
||||
});
|
||||
|
||||
describe("#freeze", function () {
|
||||
it("sets the frozen flag", function () {
|
||||
expect(iD.Graph([], true).freeze().frozen).to.be.true;
|
||||
@@ -209,7 +233,7 @@ describe('iD.Graph', function() {
|
||||
it("removes the entity from the result", function () {
|
||||
var node = iD.Node(),
|
||||
graph = iD.Graph([node]);
|
||||
expect(graph.remove(node).entity(node.id)).to.be.undefined;
|
||||
expect(graph.remove(node).hasEntity(node.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
it("removes the entity as a parentWay", function () {
|
||||
@@ -323,7 +347,7 @@ describe('iD.Graph', function() {
|
||||
|
||||
graph.update(function (graph) { graph.remove(node); });
|
||||
|
||||
expect(graph.entity(node.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(node.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
it("executes all of the given functions", function () {
|
||||
@@ -336,7 +360,7 @@ describe('iD.Graph', function() {
|
||||
function (graph) { graph.replace(b); }
|
||||
);
|
||||
|
||||
expect(graph.entity(a.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(a.id)).to.be.undefined;
|
||||
expect(graph.entity(b.id)).to.equal(b);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -283,10 +283,10 @@ describe("iD.History", function () {
|
||||
history.perform(iD.actions.DeleteNode('n2'));
|
||||
history.save();
|
||||
history.reset();
|
||||
expect(history.graph().entity('n')).to.be.undefined
|
||||
expect(history.graph().hasEntity('n')).to.be.undefined
|
||||
history.restore();
|
||||
expect(history.graph().entity('n').id).to.equal('n');
|
||||
expect(history.graph().entity('n2')).to.be.undefined;
|
||||
expect(history.graph().hasEntity('n2')).to.be.undefined;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user