Skip to content

Commit

Permalink
[WIP] Increasing code-coverage for choropleth feature
Browse files Browse the repository at this point in the history
  • Loading branch information
aashish24 committed Mar 11, 2017
1 parent e8370cf commit e1bc72c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/choroplethFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ var choroplethFeature = function (arg) {
],
scale: d3.scale.quantize(),
accessors: {
//accessor for ID on geodata feature
//accessor for ID on geodata feature
geoId: function (geoFeature) {
return geoFeature.properties.GEO_ID;
},
//accessor for ID on scalar element
//accessor for ID on scalar element
scalarId: function (scalarElement) {
return scalarElement.id;
},
//accessor for value on scalar element
//accessor for value on scalar element
scalarValue: function (scalarElement) {
return scalarElement.value;
}
Expand Down
68 changes: 68 additions & 0 deletions tests/cases/choroplethFeature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Test geo.choroplethFeature and geo.gl.choroplethFeature

var geo = require('../test-utils').geo;
var $ = require('jquery');
var mockVGLRenderer = require('../test-utils').mockVGLRenderer;
var restoreVGLRenderer = require('../test-utils').restoreVGLRenderer;

describe('geo.choroplethFeature', function () {
'use strict';

function create_map(opts) {
var node = $('<div id="map"/>').css({width: '640px', height: '360px'});
$('#map').remove();
$('body').append(node);
opts = $.extend({}, opts);
opts.node = node;
return geo.map(opts);
}

var mpdata = [{
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': [
[
[
[101.2, 1.2], [101.8, 1.2], [101.8, 1.8], [101.2, 1.8], [101.2, 1.2]
],
],
[
[
[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]
],
]
]
},
'properties': {
'GEO_ID': 0
}
}];

describe('create', function () {
it('create function', function () {
mockVGLRenderer();
var map, layer, choropleth;
map = create_map();
layer = map.createLayer('feature', {renderer: 'vgl'});
choropleth = layer.createFeature('choropleth');
expect(choropleth instanceof geo.choroplethFeature).toBe(true);
restoreVGLRenderer();
});

it('multipolygon', function () {
mockVGLRenderer();
var map, layer, choropleth,
scalarValues = [{'id': 0, 'value': 10}];

map = create_map();
layer = map.createLayer('feature', {renderer: 'vgl'});
choropleth = layer.createFeature('choropleth')
.data(mpdata)
.scalar(scalarValues)
.choropleth({});
expect(choropleth instanceof geo.choroplethFeature).toBe(true);
restoreVGLRenderer();
});
});
});

0 comments on commit e1bc72c

Please sign in to comment.