diff --git a/test/spec/ol/interaction/drawinteraction.test.js b/test/spec/ol/interaction/drawinteraction.test.js index 3c379698ba..8deb91d730 100644 --- a/test/spec/ol/interaction/drawinteraction.test.js +++ b/test/spec/ol/interaction/drawinteraction.test.js @@ -470,6 +470,70 @@ describe('ol.interaction.Draw', function() { }); + describe('#setActive()', function() { + var interaction; + + beforeEach(function() { + interaction = new ol.interaction.Draw({ + type: ol.geom.GeometryType.LINE_STRING + }); + + expect(interaction.getActive()).to.be(true); + + map.addInteraction(interaction); + + // first point + simulateEvent('pointermove', 10, 20); + simulateEvent('pointerdown', 10, 20); + simulateEvent('pointerup', 10, 20); + + expect(interaction.sketchFeature_).not.to.be(null); + }); + + afterEach(function() { + map.removeInteraction(interaction); + }); + + describe('#setActive(false)', function() { + it('unsets the map from the feature overlay', function() { + interaction.setActive(false); + expect(interaction.overlay_.map_).to.be(null); + }); + it('aborts the drawing', function() { + interaction.setActive(false); + expect(interaction.sketchFeature_).to.be(null); + }); + it('fires change:active', function() { + listenerSpy = sinon.spy(function() { + // test that the interaction's change:active listener is called first + expect(interaction.overlay_.map_).to.be(null); + }); + interaction.on('change:active', listenerSpy); + interaction.setActive(false); + expect(listenerSpy.callCount).to.be(1); + }); + }); + + describe('#setActive(true)', function() { + beforeEach(function() { + interaction.setActive(false); + }); + it('sets the map into the feature overlay', function() { + interaction.setActive(true); + expect(interaction.overlay_.map_).to.be(map); + }); + it('fires change:active', function() { + listenerSpy = sinon.spy(function() { + // test that the interaction's change:active listener is called first + expect(interaction.overlay_.map_).not.to.be(null); + }); + interaction.on('change:active', listenerSpy); + interaction.setActive(true); + expect(listenerSpy.callCount).to.be(1); + }); + }); + }); + }); goog.require('goog.dispose');