mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-24 00:54:03 +02:00
Graph#revert accept id instead of entity ref
trivial test cases (revert across create/update/delete) all pass
This commit is contained in:
@@ -1,11 +1,27 @@
|
||||
describe('iD.actions.Revert', function() {
|
||||
it('reverts an entity', function() {
|
||||
var n1 = iD.Node({id: 'n' }),
|
||||
it('deletes a new entity', function() {
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
graph = iD.Graph().replace(n1);
|
||||
|
||||
graph = iD.actions.Revert('n')(graph);
|
||||
expect(graph.hasEntity('n')).to.be.undefined;
|
||||
});
|
||||
|
||||
it('reverts an updated entity', function() {
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
n2 = n1.update({}),
|
||||
graph = iD.Graph([n1]).replace(n2);
|
||||
|
||||
expect(graph.entity('n')).to.equal(n2);
|
||||
graph = iD.actions.Revert(n2)(graph)
|
||||
expect(graph.entity('n')).to.equal(n1);
|
||||
graph = iD.actions.Revert('n')(graph);
|
||||
expect(graph.hasEntity('n')).to.equal(n1);
|
||||
});
|
||||
|
||||
it('restores a deleted entity', function() {
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
graph = iD.Graph([n1]).remove(n1);
|
||||
|
||||
graph = iD.actions.Revert('n')(graph);
|
||||
expect(graph.hasEntity('n')).to.equal(n1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
+69
-43
@@ -357,86 +357,112 @@ describe('iD.Graph', function() {
|
||||
});
|
||||
|
||||
describe("#revert", function () {
|
||||
it("is a no-op if the entity is identical to the base entity", function () {
|
||||
var n1 = iD.Node({id: 'n' }),
|
||||
it("is a no-op if the head entity is identical to the base entity", function () {
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
graph = iD.Graph([n1]);
|
||||
expect(graph.revert(n1)).to.equal(graph);
|
||||
expect(graph.revert('n')).to.equal(graph);
|
||||
});
|
||||
|
||||
it("returns a new graph", function () {
|
||||
var n1 = iD.Node({id: 'n' }),
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
n2 = n1.update({}),
|
||||
graph = iD.Graph([n1]).replace(n2);
|
||||
expect(graph.revert(n2)).not.to.equal(graph);
|
||||
expect(graph.revert('n')).not.to.equal(graph);
|
||||
});
|
||||
|
||||
it("doesn't modify the receiver", function () {
|
||||
var n1 = iD.Node({id: 'n' }),
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
n2 = n1.update({}),
|
||||
graph = iD.Graph([n1]).replace(n2);
|
||||
graph.revert(n2);
|
||||
expect(graph.entity(n2.id)).to.equal(n2);
|
||||
});
|
||||
|
||||
it("reverts an updated entity to the base version", function () {
|
||||
var n1 = iD.Node({id: 'n' }),
|
||||
n2 = n1.update({}),
|
||||
graph = iD.Graph([n1]).replace(n2);
|
||||
|
||||
expect(graph.entity('n')).to.equal(n2);
|
||||
graph = graph.revert(n2);
|
||||
expect(graph.entity('n')).to.equal(n1);
|
||||
graph.revert('n');
|
||||
expect(graph.hasEntity('n')).to.equal(n2);
|
||||
});
|
||||
|
||||
it("removes a new entity", function () {
|
||||
var n1 = iD.Node({id: 'n' }),
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
graph = iD.Graph().replace(n1);
|
||||
|
||||
expect(graph.entity('n')).to.equal(n1);
|
||||
graph = graph.revert(n1);
|
||||
graph = graph.revert('n');
|
||||
expect(graph.hasEntity('n')).to.be.undefined;
|
||||
});
|
||||
|
||||
it("reverts updated parentWays", function () {
|
||||
var n1 = iD.Node({id: 'n' }),
|
||||
it("reverts an updated entity to the base version", function () {
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
n2 = n1.update({}),
|
||||
graph = iD.Graph([n1]).replace(n2);
|
||||
|
||||
graph = graph.revert('n');
|
||||
expect(graph.hasEntity('n')).to.equal(n1);
|
||||
});
|
||||
|
||||
it("restores a deleted entity", function () {
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
graph = iD.Graph([n1]).remove(n1);
|
||||
|
||||
graph = graph.revert('n');
|
||||
expect(graph.hasEntity('n')).to.equal(n1);
|
||||
});
|
||||
|
||||
it("removes new parentWays", function () {
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
w1 = iD.Way({id: 'w', nodes: ['n']}),
|
||||
graph = iD.Graph().replace(n1).replace(w1);
|
||||
|
||||
graph = graph.revert('w');
|
||||
expect(graph.hasEntity('n')).to.equal(n1);
|
||||
expect(graph.parentWays(n1)).to.eql([]);
|
||||
});
|
||||
|
||||
it("removes new parentRelations", function () {
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
r1 = iD.Relation({id: 'r', members: [{id: 'n'}]}),
|
||||
graph = iD.Graph().replace(n1).replace(r1);
|
||||
|
||||
graph = graph.revert('r');
|
||||
expect(graph.hasEntity('n')).to.equal(n1);
|
||||
expect(graph.parentRelations(n1)).to.eql([]);
|
||||
});
|
||||
|
||||
it("reverts updated parentWays", function () {
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
w1 = iD.Way({id: 'w', nodes: ['n']}),
|
||||
w2 = w1.removeNode('n'),
|
||||
graph = iD.Graph([n1, w1]).replace(w2);
|
||||
|
||||
expect(graph.parentWays(graph.entity('n'))).to.eql([]);
|
||||
graph = graph.revert(w2);
|
||||
expect(graph.parentWays(graph.entity('n'))).to.eql([w1]);
|
||||
graph = graph.revert('w');
|
||||
expect(graph.hasEntity('n')).to.equal(n1);
|
||||
expect(graph.parentWays(n1)).to.eql([w1]);
|
||||
});
|
||||
|
||||
it("reverts updated parentRelations", function () {
|
||||
var n1 = iD.Node({id: 'n' }),
|
||||
it("reverts updated parentRelations", function () {
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
r1 = iD.Relation({id: 'r', members: [{id: 'n'}]}),
|
||||
r2 = r1.removeMembersWithID('n'),
|
||||
graph = iD.Graph([n1, r1]).replace(r2);
|
||||
|
||||
expect(graph.parentRelations(graph.entity('n'))).to.eql([]);
|
||||
graph = graph.revert(r2);
|
||||
expect(graph.parentRelations(graph.entity('n'))).to.eql([r1]);
|
||||
graph = graph.revert('r');
|
||||
expect(graph.hasEntity('n')).to.equal(n1);
|
||||
expect(graph.parentRelations(n1)).to.eql([r1]);
|
||||
});
|
||||
|
||||
it("removes new parentWays", function () {
|
||||
var n1 = iD.Node({id: 'n' }),
|
||||
it("restores deleted parentWays", function () {
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
w1 = iD.Way({id: 'w', nodes: ['n']}),
|
||||
graph = iD.Graph().replace(n1).replace(w1);
|
||||
graph = iD.Graph([n1, w1]).remove(w1);
|
||||
|
||||
expect(graph.parentWays(graph.entity('n'))).to.eql([w1]);
|
||||
graph = graph.revert(w1);
|
||||
expect(graph.parentWays(graph.entity('n'))).to.eql([]);
|
||||
graph = graph.revert('w');
|
||||
expect(graph.hasEntity('n')).to.equal(n1);
|
||||
expect(graph.parentWays(n1)).to.eql([w1]);
|
||||
});
|
||||
|
||||
it("removes new parentRelations", function () {
|
||||
var n1 = iD.Node({id: 'n' }),
|
||||
it("restores deleted parentRelations", function () {
|
||||
var n1 = iD.Node({id: 'n'}),
|
||||
r1 = iD.Relation({id: 'r', members: [{id: 'n'}]}),
|
||||
graph = iD.Graph().replace(n1).replace(r1);
|
||||
graph = iD.Graph([n1, r1]).remove(r1);
|
||||
|
||||
expect(graph.parentRelations(graph.entity('n'))).to.eql([r1]);
|
||||
graph = graph.revert(r1);
|
||||
expect(graph.parentRelations(graph.entity('n'))).to.eql([]);
|
||||
graph = graph.revert('r');
|
||||
expect(graph.hasEntity('n')).to.equal(n1);
|
||||
expect(graph.parentRelations(n1)).to.eql([r1]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user