From 3733b02a375ff6a977db9738e4ab8d42183ed4af Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sun, 9 Feb 2014 18:45:47 -0800 Subject: [PATCH] Expand tests --- test/spec/actions/merge_polygon.js | 48 +++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/test/spec/actions/merge_polygon.js b/test/spec/actions/merge_polygon.js index 85ac68f8e..da0d742cb 100644 --- a/test/spec/actions/merge_polygon.js +++ b/test/spec/actions/merge_polygon.js @@ -85,20 +85,46 @@ describe("iD.actions.MergePolygon", function () { expect(find(r, 'w5').role).to.equal('outer'); }); - it("moves tags to the relation", function() { + it("merges multipolygon tags", function() { + var graph = iD.Graph([ + iD.Relation({id: 'r1', tags: {type: 'multipolygon', a: 'a'}}), + iD.Relation({id: 'r2', tags: {type: 'multipolygon', b: 'b'}}) + ]); + + graph = iD.actions.MergePolygon(['r1', 'r2'])(graph); + + expect(graph.entity('r1').tags.a).to.equal('a'); + expect(graph.entity('r1').tags.b).to.equal('b'); + }); + + it("merges tags from closed outer ways", function() { graph = graph.replace(graph.entity('w0').update({ tags: { 'building': 'yes' }})); - // this is a new inner member whose tags should not be moved to the relation - graph = graph.replace(graph.entity('w1').update({ tags: { 'natural': 'water' }})); - // this is a new outer member whose tags should be moved to the relation - graph = graph.replace(graph.entity('w5').update({ tags: { 'amenity': 'school' }})); - graph = iD.actions.MergePolygon(['w0', 'w1','w5'], 'r')(graph); - var r = graph.entity('r'); + graph = iD.actions.MergePolygon(['w0', 'w5'], 'r')(graph); expect(graph.entity('w0').tags.building).to.equal(undefined); + expect(graph.entity('r').tags.building).to.equal('yes'); + }); + + it("merges no tags from unclosed outer ways", function() { + graph = graph.replace(graph.entity('w3').update({ tags: { 'natural': 'water' }})); + + var r1 = iD.Relation({id: 'r1', tags: {type: 'multipolygon'}}); + var r2 = iD.Relation({id: 'r2', tags: {type: 'multipolygon'}, + members: [ + { type: 'way', role: 'outer', id: 'w3' }, + { type: 'way', role: 'outer', id: 'w4' } + ]}); + + graph = graph.replace(r1).replace(r2); + graph = iD.actions.MergePolygon(['r1', 'r2'])(graph); + expect(graph.entity('w3').tags.natural).to.equal('water'); + expect(graph.entity('r1').tags.natural).to.equal(undefined); + }); + + it("merges no tags from inner ways", function() { + graph = graph.replace(graph.entity('w1').update({ tags: { 'natural': 'water' }})); + graph = iD.actions.MergePolygon(['w0', 'w1'], 'r')(graph); expect(graph.entity('w1').tags.natural).to.equal('water'); - expect(graph.entity('w5').tags.amenity).to.equal(undefined); - expect(r.tags.building).to.equal('yes'); - expect(r.tags.natural).to.equal(undefined); - expect(r.tags.amenity).to.equal('school'); + expect(graph.entity('r').tags.natural).to.equal(undefined); }); it("doesn't copy area tags from ways", function() {