mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-18 14:45:12 +02:00
Modify Graph so it can track deleted ids
This commit is contained in:
+66
-40
@@ -21,35 +21,46 @@ describe('iD.Graph', function() {
|
||||
});
|
||||
}
|
||||
|
||||
describe('operations', function() {
|
||||
it('#remove', function() {
|
||||
var entities = { 'n-1': {
|
||||
type: 'node',
|
||||
loc: [-80, 30],
|
||||
id: 'n-1'
|
||||
}
|
||||
};
|
||||
var graph = iD.Graph(entities, 'first graph');
|
||||
var g2 = graph.remove(entities['n-1'], 'Removed node');
|
||||
expect(graph.entity('n-1')).to.equal(entities['n-1']);
|
||||
expect(g2.entity('n-1')).to.equal(undefined);
|
||||
describe("#remove", function () {
|
||||
it("returns a new graph", function () {
|
||||
var node = iD.Node(),
|
||||
graph = iD.Graph([node]);
|
||||
expect(graph.remove(node)).not.to.equal(graph);
|
||||
});
|
||||
it('#replace', function() {
|
||||
var entities = { 'n-1': {
|
||||
type: 'node',
|
||||
loc: [-80, 30],
|
||||
id: 'n-1'
|
||||
}
|
||||
};
|
||||
var replacement = {
|
||||
type: 'node',
|
||||
loc: [-80, 40],
|
||||
id: 'n-1'
|
||||
};
|
||||
var graph = iD.Graph(entities, 'first graph');
|
||||
var g2 = graph.replace(replacement, 'Removed node');
|
||||
expect(graph.entity('n-1').loc[1]).to.equal(30);
|
||||
expect(g2.entity('n-1').loc[1]).to.equal(40);
|
||||
|
||||
it("doesn't modify the receiver", function () {
|
||||
var node = iD.Node(),
|
||||
graph = iD.Graph([node]);
|
||||
graph.remove(node);
|
||||
expect(graph.entity(node.id)).to.equal(node);
|
||||
});
|
||||
|
||||
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;
|
||||
});
|
||||
});
|
||||
|
||||
describe("#replace", function () {
|
||||
it("returns a new graph", function () {
|
||||
var node = iD.Node(),
|
||||
graph = iD.Graph([node]);
|
||||
expect(graph.replace(node)).not.to.equal(graph);
|
||||
});
|
||||
|
||||
it("doesn't modify the receiver", function () {
|
||||
var node = iD.Node(),
|
||||
graph = iD.Graph([node]);
|
||||
graph.replace(node);
|
||||
expect(graph.entity(node.id)).to.equal(node);
|
||||
});
|
||||
|
||||
it("replaces the entity in the result", function () {
|
||||
var node1 = iD.Node(),
|
||||
node2 = node1.update({}),
|
||||
graph = iD.Graph([node1]);
|
||||
expect(graph.replace(node2).entity(node2.id)).to.equal(node2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -82,21 +93,36 @@ describe('iD.Graph', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#modifications", function () {
|
||||
it("filters entities by modified", function () {
|
||||
var a = {id: 'a', modified: function () { return true; }},
|
||||
b = {id: 'b', modified: function () { return false; }},
|
||||
graph = iD.Graph({ 'a': a, 'b': b });
|
||||
expect(graph.modifications()).to.eql([graph.fetch('a')]);
|
||||
describe("#modified", function () {
|
||||
it("returns an Array of ids of modified entities", function () {
|
||||
var node1 = iD.Node({id: 'n1', _updated: true}),
|
||||
node2 = iD.Node({id: 'n2'}),
|
||||
graph = iD.Graph([node1, node2]);
|
||||
expect(graph.modified()).to.eql([node1.id]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#creations", function () {
|
||||
it("filters entities by created", function () {
|
||||
var a = {id: 'a', created: function () { return true; }},
|
||||
b = {id: 'b', created: function () { return false; }},
|
||||
graph = iD.Graph({ 'a': a, 'b': b });
|
||||
expect(graph.creations()).to.eql([graph.fetch('a')]);
|
||||
describe("#created", function () {
|
||||
it("returns an Array of ids of created entities", function () {
|
||||
var node1 = iD.Node({id: 'n-1', _updated: true}),
|
||||
node2 = iD.Node({id: 'n2'}),
|
||||
graph = iD.Graph([node1, node2]);
|
||||
expect(graph.created()).to.eql([node1.id]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#deleted", function () {
|
||||
it("returns an Array of ids of deleted entities", function () {
|
||||
var node1 = iD.Node({id: "n1"}),
|
||||
node2 = iD.Node(),
|
||||
graph = iD.Graph([node1, node2]).remove(node1);
|
||||
expect(graph.deleted()).to.eql([node1.id]);
|
||||
});
|
||||
|
||||
it("doesn't include created entities that were subsequently deleted", function () {
|
||||
var node = iD.Node(),
|
||||
graph = iD.Graph([node]).remove(node);
|
||||
expect(graph.deleted()).to.eql([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -101,6 +101,31 @@ describe("iD.History", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#changes", function () {
|
||||
it("includes created entities", function () {
|
||||
var node = iD.Node();
|
||||
history.perform(function (graph) { return graph.replace(node); });
|
||||
expect(history.changes().created).to.eql([node]);
|
||||
});
|
||||
|
||||
it("includes modified entities", function () {
|
||||
var node1 = iD.Node({id: "n1"}),
|
||||
node2 = node1.update({}),
|
||||
graph = iD.Graph([node1]);
|
||||
history.merge(graph);
|
||||
history.perform(function (graph) { return graph.replace(node2); });
|
||||
expect(history.changes().modified).to.eql([node2]);
|
||||
});
|
||||
|
||||
it("includes deleted entities", function () {
|
||||
var node = iD.Node({id: "n1"}),
|
||||
graph = iD.Graph([node]);
|
||||
history.merge(graph);
|
||||
history.perform(function (graph) { return graph.remove(node); });
|
||||
expect(history.changes().deleted).to.eql([node]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#reset", function () {
|
||||
it("clears the version stack", function () {
|
||||
history.perform(action, "annotation");
|
||||
|
||||
Reference in New Issue
Block a user