From 1b1271c3a3dcb180dc33a6e9cc8ad830b6d70097 Mon Sep 17 00:00:00 2001 From: john gravois Date: Tue, 28 Apr 2015 12:05:41 -0700 Subject: [PATCH] added tests --- spec/Layers/FeatureLayer/FeatureLayerSpec.js | 2 +- .../Layers/FeatureLayer/FeatureManagerSpec.js | 24 +++++++++++++++ spec/Services/FeatureLayerSpec.js | 30 ++++++++++++++++++- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/spec/Layers/FeatureLayer/FeatureLayerSpec.js b/spec/Layers/FeatureLayer/FeatureLayerSpec.js index 24ea86c5e..2aa9f8ed3 100644 --- a/spec/Layers/FeatureLayer/FeatureLayerSpec.js +++ b/spec/Layers/FeatureLayer/FeatureLayerSpec.js @@ -116,7 +116,7 @@ describe('L.esri.Layers.FeatureLayer', function () { layer.addLayers([1]); }); - it('should readd features back to a map', function(){ + it('should read features back to a map', function(){ map.removeLayer(layer.getFeature(1)); layer.createLayers([{ diff --git a/spec/Layers/FeatureLayer/FeatureManagerSpec.js b/spec/Layers/FeatureLayer/FeatureManagerSpec.js index 555547cd7..1546b8c15 100644 --- a/spec/Layers/FeatureLayer/FeatureManagerSpec.js +++ b/spec/Layers/FeatureLayer/FeatureManagerSpec.js @@ -715,6 +715,30 @@ describe('L.esri.Layers.FeatureManager', function () { server.respond(); }); + it('should wrap the removeFeatures method on the underlying service', function(done){ + server.respondWith('POST', 'http://gis.example.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/deleteFeatures', JSON.stringify({ + 'deleteResults' : [{ + 'objectId' : 1, + 'success' : true + },{ + 'objectId' : 2, + 'success' : true + }] + })); + + layer.deleteFeatures([1,2], function(error, response){ + expect(layer.removeLayers).to.have.been.calledWith([1]); + expect(layer.removeLayers).to.have.been.calledWith([2]); + expect(response[1]).to.deep.equal({ + 'objectId': 2, + 'success': true + }); + done(); + }); + + server.respond(); + }); + it('should support generalizing geometries', function(){ server.respondWith('GET', 'http://gis.example.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?returnGeometry=true&where=1%3D1&outSr=4326&outFields=*&inSr=4326&geometry=%7B%22xmin%22%3A-122.6953125%2C%22ymin%22%3A45.521743896993634%2C%22xmax%22%3A-122.6513671875%2C%22ymax%22%3A45.55252525134013%2C%22spatialReference%22%3A%7B%22wkid%22%3A4326%7D%7D&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&geometryPrecision=6&maxAllowableOffset=0.00004291534423829546&f=json', JSON.stringify({ fields: fields, diff --git a/spec/Services/FeatureLayerSpec.js b/spec/Services/FeatureLayerSpec.js index f21fc8873..bed23d07d 100644 --- a/spec/Services/FeatureLayerSpec.js +++ b/spec/Services/FeatureLayerSpec.js @@ -129,7 +129,7 @@ describe('L.esri.Services.FeatureLayer', function () { })); }); - it('should be able to remove features from the layer', function(){ + it('should be able to remove a feature from the layer', function(){ var callback = sinon.spy(); service.deleteFeature(1, callback); @@ -163,4 +163,32 @@ describe('L.esri.Services.FeatureLayer', function () { }] })); }); + + it('should be able to remove features from the layer', function(){ + var callback = sinon.spy(); + + service.deleteFeatures([1,2], callback); + + requests[0].respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, JSON.stringify({ + 'deleteResults' : [{ + 'objectId' : 1, + 'success' : true + },{ + 'objectId' : 2, + 'success' : true + }] + })); + + var requestBody = window.decodeURIComponent(requests[0].requestBody); + + expect(requestBody).to.equal('objectIds=1,2&f=json'); + + callback.should.have.been.calledWith(undefined, [{ + 'objectId' : 1, + 'success' : true + },{ + 'objectId' : 2, + 'success' : true + }]); + }); }); \ No newline at end of file