add tests for tooltipProximity and nearestFeature

This commit is contained in:
Joe Fleming 2015-06-24 19:51:44 -07:00
parent 4129ae8cf8
commit d7460c3536
2 changed files with 35 additions and 4 deletions

View file

@ -70,7 +70,7 @@ define(function (require) {
}
// find nearest feature to event latlng
var feature = this.nearestFeature(latlng);
var feature = this._nearestFeature(latlng);
// show tooltip if close enough to event latlng
if (this._tooltipProximity(latlng, feature)) {
@ -99,11 +99,11 @@ define(function (require) {
/**
* Finds nearest feature in mapData to event latlng
*
* @method nearestFeature
* @method _nearestFeature
* @param point {Leaflet latLng Object}
* @return nearestPoint {Leaflet Object}
*/
HeatmapMarker.prototype.nearestFeature = function (latLng) {
HeatmapMarker.prototype._nearestFeature = function (latLng) {
var self = this;
var nearest;

View file

@ -285,7 +285,7 @@ define(function (require) {
});
it('should return an array item with lat, lng, normalized metric for each feature', function () {
_.times(3, function () {
_.times(5, function () {
markerLayer._attr.heatNormalizeData = true;
var arr = markerLayer._dataToHeatArray(max);
@ -297,6 +297,37 @@ define(function (require) {
});
});
});
describe('tooltipProximity method', function () {
it('should return true if feature is close enough to event latlng', function () {
_.times(5, function () {
var feature = _.sample(mapData.features);
var point = markerLayer._getLatLng(feature);
var arr = markerLayer._tooltipProximity(point, feature);
expect(arr).to.be(true);
});
});
it('should return false if feature is not close enough to event latlng', function () {
_.times(5, function () {
var feature = _.sample(mapData.features);
var point = L.latLng(90, -180);
var arr = markerLayer._tooltipProximity(point, feature);
expect(arr).to.be(false);
});
});
});
describe('nearestFeature method', function () {
it('should return nearest geoJson feature object', function () {
_.times(5, function () {
var feature = _.sample(mapData.features);
var point = markerLayer._getLatLng(feature);
var nearestPoint = markerLayer.nearestFeature(point);
expect(nearestPoint).to.equal(feature);
});
});
});
});
});