Add filtered field tests
This commit is contained in:
parent
66cc146a02
commit
a3538d9007
84
test/filtered.test.js
Normal file
84
test/filtered.test.js
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/**
|
||||||
|
* Test the filtered field.
|
||||||
|
*
|
||||||
|
* When compiled, a rule provides metainformation fields like index, constant...etc
|
||||||
|
* one of this fields is the "filtered field".
|
||||||
|
*
|
||||||
|
* This field gives information about whether a property is filtered or not.
|
||||||
|
*
|
||||||
|
* A property is filtered if it was activated inside a filter. In the following cartocss
|
||||||
|
* code marker-color.filtered will be true because is inside a population filter.
|
||||||
|
*
|
||||||
|
* #layer {
|
||||||
|
* maker-width: 20;
|
||||||
|
* [population > 100] {
|
||||||
|
* marker-color: red; //
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
var assert = require('assert');
|
||||||
|
var Carto = require('../lib/carto/index.js');
|
||||||
|
var renderer = new Carto.RendererJS({strict: true});
|
||||||
|
|
||||||
|
|
||||||
|
describe('Field:filtered propery', function () {
|
||||||
|
it('should be false when the property is not filtered', function () {
|
||||||
|
var style = `
|
||||||
|
#layer {
|
||||||
|
marker-fill: red;
|
||||||
|
}`;
|
||||||
|
var layers = renderer.render(style).layers[0].shader;
|
||||||
|
assert(!layers['marker-fill'].filtered);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be true when the property is filtered', function () {
|
||||||
|
style = `
|
||||||
|
#layer {
|
||||||
|
[foo > 30]{
|
||||||
|
marker-fill: red;
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
|
||||||
|
var layers = renderer.render(style).layers[0].shader;
|
||||||
|
assert(layers['marker-fill'].filtered);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be true when the property is filtered at first level', function () {
|
||||||
|
style = `
|
||||||
|
#layer [foo > 30]{
|
||||||
|
marker-fill: red;
|
||||||
|
}`;
|
||||||
|
|
||||||
|
var layers = renderer.render(style).layers[0].shader;
|
||||||
|
assert(layers['marker-fill'].filtered);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be false when the property is not filterd but there is another filtered properties', function () {
|
||||||
|
style = `
|
||||||
|
#layer {
|
||||||
|
marker-fill: red;
|
||||||
|
[bar < 200]{
|
||||||
|
marker-allow-overlap: false;
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
|
||||||
|
var layers = renderer.render(style).layers[0].shader;
|
||||||
|
|
||||||
|
assert(!layers['marker-fill'].filtered);
|
||||||
|
assert(layers['marker-allow-overlap'].filtered);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be true when the property is filtered and have a default value', function () {
|
||||||
|
style = `
|
||||||
|
#layer {
|
||||||
|
marker-fill: red;
|
||||||
|
[bar < 200]{
|
||||||
|
marker-fill: blue;
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
|
||||||
|
var layers = renderer.render(style).layers[0].shader;
|
||||||
|
|
||||||
|
assert(layers['marker-fill'].filtered);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user