From b7b14420a4d55a37dcca91a7f39522898d8e434f Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 19 Nov 2013 16:51:41 -0700 Subject: [PATCH] Test removeFeatures and featureremove event --- test/spec/ol/source/vectorsource.test.js | 54 +++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/test/spec/ol/source/vectorsource.test.js b/test/spec/ol/source/vectorsource.test.js index 5606ee2250..860543fe85 100644 --- a/test/spec/ol/source/vectorsource.test.js +++ b/test/spec/ol/source/vectorsource.test.js @@ -100,6 +100,28 @@ describe('ol.source.Vector', function() { }); + describe('#removeFeatures()', function() { + + it('removes cached features', function() { + var features = [new ol.Feature(), new ol.Feature()]; + var source = new ol.source.Vector({features: features}); + + expect(source.getFeatures()).to.have.length(2); + source.removeFeatures(features); + expect(source.getFeatures()).to.have.length(0); + }); + + it('removes cached features', function() { + var features = [new ol.Feature(), new ol.Feature()]; + var source = new ol.source.Vector({features: features}); + + expect(source.getFeatures()).to.have.length(2); + source.removeFeatures([features[0]]); + expect(source.getFeatures()).to.eql([features[1]]); + }); + + }); + describe('#forEachFeatureInExtent()', function() { var features = [ @@ -180,7 +202,7 @@ describe('ol.source.Vector', function() { describe('featureadd event', function() { - it('is dispatched after features load', function(done) { + it('is dispatched after features are added', function(done) { var source = new ol.source.Vector(); var features = [ new ol.Feature({g: new ol.geom.Point([10, 5])}), @@ -208,6 +230,36 @@ describe('ol.source.Vector', function() { }); + describe('featureremove event', function() { + + it('is dispatched after features are removed', function(done) { + var features = [ + new ol.Feature({g: new ol.geom.Point([10, 5])}), + new ol.Feature({g: new ol.geom.Point([-10, -5])}) + ]; + var source = new ol.source.Vector({features: features}); + + goog.events.listen(source, ol.source.VectorEventType.REMOVE, + function(evt) { + var features = evt.features; + expect(features).to.be.an('array'); + expect(features).to.have.length(2); + expect(features).to.contain(features[0]); + expect(features).to.contain(features[1]); + + var extents = evt.extents; + expect(extents).to.be.an('array'); + expect(extents).to.have.length(1); + expect(extents[0]).to.be.eql([-10, -5, 10, 5]); + + done(); + }); + + source.removeFeatures(features); + }); + + }); + describe('featurechange event', function() { var source, features;