From 6a9cbf11f3e4c2f746a3a74af595874817f0d1e7 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Fri, 3 Feb 2017 17:30:59 +0100 Subject: [PATCH] Add tests --- test/spec/ol/interaction/modify.test.js | 75 ++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/test/spec/ol/interaction/modify.test.js b/test/spec/ol/interaction/modify.test.js index 61d6935c8f..349c731ac9 100644 --- a/test/spec/ol/interaction/modify.test.js +++ b/test/spec/ol/interaction/modify.test.js @@ -370,6 +370,39 @@ describe('ol.interaction.Modify', function() { }); + describe('circle modification', function() { + it('changes the circle radius and center', function() { + var circleFeature = new ol.Feature(new ol.geom.Circle([10, 10], 20)); + features.length = 0; + features.push(circleFeature); + + var modify = new ol.interaction.Modify({ + features: new ol.Collection(features) + }); + map.addInteraction(modify); + + // Change center + simulateEvent('pointermove', 10, -10, false, 0); + simulateEvent('pointerdown', 10, -10, false, 0); + simulateEvent('pointermove', 5, -5, false, 0); + simulateEvent('pointerdrag', 5, -5, false, 0); + simulateEvent('pointerup', 5, -5, false, 0); + + expect(circleFeature.getGeometry().getRadius()).to.equal(20); + expect(circleFeature.getGeometry().getCenter()).to.eql([5, 5]); + + // Increase radius + simulateEvent('pointermove', 25, -5, false, 0); + simulateEvent('pointerdown', 25, -5, false, 0); + simulateEvent('pointermove', 30, -5, false, 0); + simulateEvent('pointerdrag', 30, -5, false, 0); + simulateEvent('pointerup', 30, -5, false, 0); + + expect(circleFeature.getGeometry().getRadius()).to.equal(25); + expect(circleFeature.getGeometry().getCenter()).to.eql([5, 5]); + }); + }); + describe('boundary modification', function() { var modify, feature, events; @@ -539,7 +572,47 @@ describe('ol.interaction.Modify', function() { }; }); - it('updates the segment data', function() { + it('updates circle segment data', function() { + var feature = new ol.Feature(new ol.geom.Circle([10, 10], 20)); + features.length = 0; + features.push(feature); + + var modify = new ol.interaction.Modify({ + features: new ol.Collection(features) + }); + map.addInteraction(modify); + + var listeners; + + listeners = getListeners(feature, modify); + expect(listeners).to.have.length(1); + + var firstSegmentData; + + firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5], + function(node) { + return node; + }); + expect(firstSegmentData.segment[0]).to.eql([10, 10]); + expect(firstSegmentData.segment[1]).to.eql([10, 10]); + + var center = feature.getGeometry().getCenter(); + center[0] = 1; + center[1] = 1; + feature.getGeometry().setCenter(center); + + firstSegmentData = modify.rBush_.forEachInExtent([0, 0, 5, 5], + function(node) { + return node; + }); + expect(firstSegmentData.segment[0]).to.eql([1, 1]); + expect(firstSegmentData.segment[1]).to.eql([1, 1]); + + listeners = getListeners(feature, modify); + expect(listeners).to.have.length(1); + }); + + it('updates polygon segment data', function() { var modify = new ol.interaction.Modify({ features: new ol.Collection(features) });