From eff18cb2572a91e4746ccf3195a9419e3457cb25 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 9 Dec 2014 00:59:25 -0500 Subject: [PATCH] add tests for iD.actions.MergeRemoteChanges --- test/index.html | 4 +- test/index_packaged.html | 9 +- test/spec/actions/merge_remote_changes.js | 157 +++++++++++++++++++++- 3 files changed, 165 insertions(+), 5 deletions(-) diff --git a/test/index.html b/test/index.html index 63dc14ded..5126e198f 100644 --- a/test/index.html +++ b/test/index.html @@ -117,9 +117,9 @@ + - @@ -137,8 +137,8 @@ - + diff --git a/test/index_packaged.html b/test/index_packaged.html index 9df77e3cc..ce200c76c 100644 --- a/test/index_packaged.html +++ b/test/index_packaged.html @@ -27,9 +27,9 @@ + - @@ -44,11 +44,16 @@ - + + + + + + diff --git a/test/spec/actions/merge_remote_changes.js b/test/spec/actions/merge_remote_changes.js index a09b4f6e9..7345254f2 100644 --- a/test/spec/actions/merge_remote_changes.js +++ b/test/spec/actions/merge_remote_changes.js @@ -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'}); + }); + }); + });