add tests for iD.actions.MergeRemoteChanges

This commit is contained in:
Bryan Housel
2014-12-09 00:59:25 -05:00
parent 5aa95d4dd4
commit eff18cb257
3 changed files with 165 additions and 5 deletions
+2 -2
View File
@@ -117,9 +117,9 @@
<script src='../js/id/ui/preset/wikipedia.js'></script>
<script src='../js/id/actions.js'></script>
<script src='../js/id/actions/add_entity.js'></script>
<script src='../js/id/actions/add_member.js'></script>
<script src="../js/id/actions/add_midpoint.js"></script>
<script src='../js/id/actions/add_entity.js'></script>
<script src='../js/id/actions/add_vertex.js'></script>
<script src='../js/id/actions/change_member.js'></script>
<script src='../js/id/actions/change_preset.js'></script>
@@ -137,8 +137,8 @@
<script src='../js/id/actions/merge.js'></script>
<script src='../js/id/actions/merge_polygon.js'></script>
<script src='../js/id/actions/merge_remote_changes.js'></script>
<script src='../js/id/actions/move_node.js'></script>
<script src='../js/id/actions/move.js'></script>
<script src='../js/id/actions/move_node.js'></script>
<script src='../js/id/actions/noop.js'></script>
<script src='../js/id/actions/orthogonalize.js'></script>
<script src='../js/id/actions/restrict_turn.js'></script>
+7 -2
View File
@@ -27,9 +27,9 @@
<script src="spec/lib/d3.keybinding.js"></script>
<script src="spec/lib/locale.js"></script>
<script src="spec/actions/add_entity.js"></script>
<script src="spec/actions/add_member.js"></script>
<script src="spec/actions/add_midpoint.js"></script>
<script src="spec/actions/add_entity.js"></script>
<script src="spec/actions/change_member.js"></script>
<script src="spec/actions/change_preset.js"></script>
<script src="spec/actions/change_tags.js"></script>
@@ -44,11 +44,16 @@
<script src='spec/actions/disconnect.js'></script>
<script src="spec/actions/join.js"></script>
<script src='spec/actions/merge.js'></script>
<script src="spec/actions/move_node.js"></script>
<script src='spec/actions/merge_polygon.js'></script>
<script src='spec/actions/merge_remote_changes.js'></script>
<script src="spec/actions/move.js"></script>
<script src="spec/actions/move_node.js"></script>
<script src="spec/actions/noop.js"></script>
<script src="spec/actions/orthogonalize.js"></script>
<script src="spec/actions/restrict_turn.js"></script>
<script src="spec/actions/reverse.js"></script>
<script src="spec/actions/split.js"></script>
<script src="spec/actions/straighten.js"></script>
<script src="spec/actions/unrestrict_turn.js"></script>
<script src="spec/geo/extent.js"></script>
+156 -1
View File
@@ -1,3 +1,158 @@
describe("iD.actions.MergeRemoteChanges", function () {
// TODO
describe("non-destuctive merging", function () {
it("doesn't merge nodes if location is different", function () {
var base = iD.Node({id: 'a', loc: [1, 1], version: '1', tags: {foo: 'foo'}}),
local = iD.Node({id: 'a', loc: [1, 1], version: '1', v: 2, tags: {foo: 'foo_v2'}}),
remote = iD.Node({id: 'a', loc: [3, 3], version: '2', tags: {bar: 'bar'}}),
graph = iD.Graph([local]),
action = iD.actions.MergeRemoteChanges(base, local, remote);
graph = action(graph);
expect(graph.entity('a').loc).to.eql([1, 1]);
expect(graph.entity('a').version).to.eql('1');
expect(graph.entity('a').tags).to.eql({foo: 'foo_v2'});
});
it("doesn't merge nodes if changed tags conflict", function () {
var base = iD.Node({id: 'a', loc: [1, 1], version: '1', tags: {foo: 'foo'}}),
local = iD.Node({id: 'a', loc: [1, 1], version: '1', v: 2, tags: {foo: 'foo_v2'}}),
remote = iD.Node({id: 'a', loc: [1, 1], version: '2', tags: {foo: 'bar'}}),
graph = iD.Graph([local]),
action = iD.actions.MergeRemoteChanges(base, local, remote);
graph = action(graph);
expect(graph.entity('a').loc).to.eql([1, 1]);
expect(graph.entity('a').version).to.eql('1');
expect(graph.entity('a').tags).to.eql({foo: 'foo_v2'});
});
it("does merge nodes if location is same and changed tags don't conflict", function () {
var base = iD.Node({id: 'a', loc: [1, 1], version: '1', tags: {foo: 'foo'}}),
local = iD.Node({id: 'a', loc: [1, 1], version: '1', v: 2, tags: {foo: 'foo_v2'}}),
remote = iD.Node({id: 'a', loc: [1, 1], version: '2', tags: {foo: 'foo', bar: 'bar'}}),
graph = iD.Graph([local]),
action = iD.actions.MergeRemoteChanges(base, local, remote);
graph = action(graph);
expect(graph.entity('a').loc).to.eql([1, 1]);
expect(graph.entity('a').version).to.eql('2');
expect(graph.entity('a').tags).to.eql({foo: 'foo_v2', bar: 'bar'});
});
// test merging ways
// test merging relations
});
describe("destuctive merging", function () {
it("merges nodes with 'force_local' option", function () {
var base = iD.Node({id: 'a', loc: [1, 1], version: '1', tags: {foo: 'foo'}}),
local = iD.Node({id: 'a', loc: [2, 2], version: '1', v: 2, tags: {foo: 'foo_v2'}}),
remote = iD.Node({id: 'a', loc: [3, 3], version: '2', tags: {foo: 'bar'}}),
graph = iD.Graph([local]),
action = iD.actions.MergeRemoteChanges(base, local, remote).withOption('force_local');
graph = action(graph);
expect(graph.entity('a').loc).to.eql([2, 2]);
expect(graph.entity('a').version).to.eql('2');
expect(graph.entity('a').tags).to.eql({foo: 'foo_v2'});
});
it("merges nodes with 'force_remote' option", function () {
var base = iD.Node({id: 'a', loc: [1, 1], version: '1', tags: {foo: 'foo'}}),
local = iD.Node({id: 'a', loc: [2, 2], version: '1', v: 2, tags: {foo: 'foo_v2'}}),
remote = iD.Node({id: 'a', loc: [3, 3], version: '2', tags: {foo: 'bar'}}),
graph = iD.Graph([local]),
action = iD.actions.MergeRemoteChanges(base, local, remote).withOption('force_remote');
graph = action(graph);
expect(graph.entity('a').loc).to.eql([3, 3]);
expect(graph.entity('a').version).to.eql('2');
expect(graph.entity('a').tags).to.eql({foo: 'bar'});
});
it("merges ways with 'force_local' option", function () {
var a = iD.Node({id: 'a'}),
b = iD.Node({id: 'b'}),
c = iD.Node({id: 'c'}),
d = iD.Node({id: 'd'}),
e = iD.Node({id: 'e'}),
f = iD.Node({id: 'f'}),
base = iD.Way({id: 'w', nodes: ['a', 'b'], version: '1', tags: {foo: 'foo'}}),
local = iD.Way({id: 'w', nodes: ['c', 'd'], version: '1', v: 2, tags: {foo: 'foo_v2'}}),
remote = iD.Way({id: 'w', nodes: ['e', 'f'], version: '2', tags: {foo: 'bar'}}),
graph = iD.Graph([c, d, local]),
action = iD.actions.MergeRemoteChanges(base, local, remote).withOption('force_local');
graph = action(graph);
expect(graph.entity('w').nodes).to.eql(['c', 'd']);
expect(graph.entity('w').version).to.eql('2');
expect(graph.entity('w').tags).to.eql({foo: 'foo_v2'});
});
it("merges ways with 'force_remote' option", function () {
var a = iD.Node({id: 'a'}),
b = iD.Node({id: 'b'}),
c = iD.Node({id: 'c'}),
d = iD.Node({id: 'd'}),
e = iD.Node({id: 'e'}),
f = iD.Node({id: 'f'}),
base = iD.Way({id: 'w', nodes: ['a', 'b'], version: '1', tags: {foo: 'foo'}}),
local = iD.Way({id: 'w', nodes: ['c', 'd'], version: '1', v: 2, tags: {foo: 'foo_v2'}}),
remote = iD.Way({id: 'w', nodes: ['e', 'f'], version: '2', tags: {foo: 'bar'}}),
graph = iD.Graph([c, d, local]),
action = iD.actions.MergeRemoteChanges(base, local, remote).withOption('force_remote');
graph = action(graph);
// expect(graph.hasEntity('e')).to.be.true;
// expect(graph.hasEntity('f')).to.be.true;
expect(graph.entity('w').nodes).to.eql(['e', 'f']);
expect(graph.entity('w').version).to.eql('2');
expect(graph.entity('w').tags).to.eql({foo: 'bar'});
});
it("merges relations with 'force_local' option", function () {
var a = iD.Node({id: 'a'}),
b = iD.Node({id: 'b'}),
c = iD.Node({id: 'c'}),
base = iD.Relation({id: 'r', members: [{id: 'a', type: 'node'}], version: '1', tags: {foo: 'foo'}}),
local = iD.Relation({id: 'r', members: [{id: 'b', type: 'node'}], version: '1', v: 2, tags: {foo: 'foo_v2'}}),
remote = iD.Relation({id: 'r', members: [{id: 'c', type: 'node'}], version: '2', tags: {foo: 'bar'}}),
graph = iD.Graph([b, local]),
action = iD.actions.MergeRemoteChanges(base, local, remote).withOption('force_local');
graph = action(graph);
expect(graph.entity('r').members).to.eql([{id: 'b', type: 'node'}]);
expect(graph.entity('r').version).to.eql('2');
expect(graph.entity('r').tags).to.eql({foo: 'foo_v2'});
});
it("merges relations with 'force_remote' option", function () {
var a = iD.Node({id: 'a'}),
b = iD.Node({id: 'b'}),
c = iD.Node({id: 'c'}),
base = iD.Relation({id: 'r', members: [{id: 'a', type: 'node'}], version: '1', tags: {foo: 'foo'}}),
local = iD.Relation({id: 'r', members: [{id: 'b', type: 'node'}], version: '1', v: 2, tags: {foo: 'foo_v2'}}),
remote = iD.Relation({id: 'r', members: [{id: 'c', type: 'node'}], version: '2', tags: {foo: 'bar'}}),
graph = iD.Graph([b, local]),
action = iD.actions.MergeRemoteChanges(base, local, remote).withOption('force_remote');
graph = action(graph);
// expect(graph.hasEntity('c')).to.be.true;
expect(graph.entity('r').members).to.eql([{id: 'c', type: 'node'}]);
expect(graph.entity('r').version).to.eql('2');
expect(graph.entity('r').tags).to.eql({foo: 'bar'});
});
});
});