add some tests around marker creation

This commit is contained in:
Joe Fleming 2015-06-25 21:28:21 -07:00
parent ebeedf1a47
commit 0e770506c4
2 changed files with 43 additions and 4 deletions

View file

@ -168,14 +168,12 @@ define(function (require) {
* creates featurelayer from mapData (geoJson)
*
* @method _addMarkers
* @return {Leaflet featureLayer} marker layer
*/
Map.prototype._addMarkers = function () {
if (!this._geoJson) return;
if (this._markers) this._markers.destroy();
var MarkerType = markerTypes[this._markerType];
this._markers = new MarkerType(this.map, this._geoJson, {
this._markers = this._createMarkers({
tooltipFormatter: this._tooltipFormatter,
valueFormatter: this._valueFormatter,
attr: this._attr
@ -186,6 +184,18 @@ define(function (require) {
}
};
/**
* Create the marker instance using the given options
*
* @method _createMarkers
* @param options {Object} options to give to marker class
* @return {Object} marker layer
*/
Map.prototype._createMarkers = function (options) {
var MarkerType = markerTypes[this._markerType];
return new MarkerType(this.map, this._geoJson, options);
};
Map.prototype._attachEvents = function () {
var self = this;
var saturateTiles = self.saturateTiles.bind(self);

View file

@ -103,7 +103,7 @@ define(function (require) {
});
});
describe('attach events', function () {
describe('attachEvents', function () {
var map;
beforeEach(function () {
@ -136,5 +136,34 @@ define(function (require) {
expect(matchedEvents.maps).to.equal(expectedMapEvents.length);
});
});
describe('addMarkers', function () {
var map;
var createStub;
beforeEach(function () {
sinon.stub(Map.prototype, '_createMap');
createStub = sinon.stub(Map.prototype, '_createMarkers', _.constant({ addLegend: _.noop }));
map = new Map($mockMapEl, geoJsonData, {});
});
it('should pass the map options to the marker', function () {
map._addMarkers();
var args = createStub.firstCall.args[0];
expect(args).to.have.property('tooltipFormatter');
expect(args).to.have.property('valueFormatter');
expect(args).to.have.property('attr');
});
it('should destroy existing markers', function () {
var destroyStub = sinon.stub();
map._markers = { destroy: destroyStub };
map._addMarkers();
expect(destroyStub.callCount).to.be(1);
});
});
});
});