Permalink
Browse files

more grid tests around how the feature __id__ is handled

  • Loading branch information...
1 parent cb5b0f1 commit e88ed41bef6eb086611529d709d2fbd44b3dbc9a @springmeyer springmeyer committed Jul 12, 2012
Showing with 54 additions and 0 deletions.
  1. +54 −0 test/render_grid.test.js
View
54 test/render_grid.test.js
@@ -5,6 +5,9 @@ var fs = require('fs');
var stylesheet = './examples/stylesheet.xml';
var reference = fs.readFileSync('./test/support/grid2.json', 'utf8');
var reference_view = fs.readFileSync('./test/support/grid_view.json', 'utf8');
+var reference__id__ = fs.readFileSync('./test/support/grid__id__.json', 'utf8');
+var reference__id__2 = fs.readFileSync('./test/support/grid__id__2.json', 'utf8');
+var reference__id__3 = fs.readFileSync('./test/support/grid__id__3.json', 'utf8');
describe('mapnik grid rendering ', function() {
@@ -101,4 +104,55 @@ describe('mapnik grid rendering ', function() {
});
});
+ it('should match expected output if __id__ is not the grid key', function(done) {
+ var map = new mapnik.Map(256, 256);
+ map.loadSync(stylesheet, {strict: true});
+ map.zoomAll();
+ var grid = new mapnik.Grid(map.width, map.height, {key: 'NAME'});
+ var options = {'layer': 0,
+ 'fields': ['FIPS','__id__']
+ };
+ map.render(grid, options, function(err, grid) {
+ if (err) throw err;
+ var grid_utf = grid.encodeSync('utf', {resolution: 4});
+ //fs.writeFileSync('./ref.json',JSON.stringify(grid_utf))
+ assert.equal(JSON.stringify(grid_utf), reference__id__);
+ done();
+ });
+ });
+
+ it('should match expected output if __id__ both the grid key and in the attributes with others', function(done) {
+ var map = new mapnik.Map(256, 256);
+ map.loadSync(stylesheet, {strict: true});
+ map.zoomAll();
+ var grid = new mapnik.Grid(map.width, map.height, {key: '__id__'});
+ var options = {'layer': 0,
+ 'fields': ['__id__','NAME']
+ };
+ map.render(grid, options, function(err, grid) {
+ if (err) throw err;
+ var grid_utf = grid.encodeSync('utf', {resolution: 4});
+ //fs.writeFileSync('./ref.json',JSON.stringify(grid_utf))
+ assert.equal(JSON.stringify(grid_utf), reference__id__2);
+ done();
+ });
+ });
+
+ it('should match expected output if __id__ the grid key and the only attributes', function(done) {
+ var map = new mapnik.Map(256, 256);
+ map.loadSync(stylesheet, {strict: true});
+ map.zoomAll();
+ var grid = new mapnik.Grid(map.width, map.height, {key: '__id__'});
+ var options = {'layer': 0,
+ 'fields': ['__id__']
+ };
+ map.render(grid, options, function(err, grid) {
+ if (err) throw err;
+ var grid_utf = grid.encodeSync('utf', {resolution: 4});
+ //fs.writeFileSync('./ref.json',JSON.stringify(grid_utf))
+ assert.equal(JSON.stringify(grid_utf), reference__id__3);
+ done();
+ });
+ });
+
});

0 comments on commit e88ed41

Please sign in to comment.