Adding unit tests for rule based styling
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
goog.provide('ol.test.style.Style');
|
||||
|
||||
describe('ol.style.Style', function() {
|
||||
|
||||
describe('#apply()', function() {
|
||||
|
||||
it('applies a style to a feature', function() {
|
||||
var style = new ol.style.Style({
|
||||
rules: [
|
||||
new ol.style.Rule({
|
||||
filter: new ol.filter.Filter(function(feature) {
|
||||
return feature.get('foo') == 'bar';
|
||||
}),
|
||||
symbolizers: [
|
||||
new ol.style.Shape({
|
||||
size: 4,
|
||||
fillStyle: '#BADA55'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
});
|
||||
var feature = new ol.Feature();
|
||||
feature.set('foo', 'bar');
|
||||
expect(style.apply(feature).length).toBe(1);
|
||||
expect(style.apply(feature)[0].fillStyle).toBe('#BADA55');
|
||||
feature.set('foo', 'baz');
|
||||
expect(style.apply(feature).length).toBe(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.style.Style.applyDefaultStyle()', function() {
|
||||
var feature = new ol.Feature();
|
||||
|
||||
it('returns an empty array for features without geometry', function() {
|
||||
expect(ol.style.Style.applyDefaultStyle(feature).length).toBe(0);
|
||||
});
|
||||
|
||||
it('returns an array with the Shape default for points', function() {
|
||||
feature.setGeometry(new ol.geom.Point([0, 0]));
|
||||
expect(ol.style.Style.applyDefaultStyle(feature)[0]
|
||||
.equals(ol.style.ShapeDefaults)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns an array with the Line default for lines', function() {
|
||||
feature.setGeometry(new ol.geom.LineString([[0, 0], [1, 1]]));
|
||||
expect(ol.style.Style.applyDefaultStyle(feature)[0]
|
||||
.equals(ol.style.LineDefaults)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns an array with the Polygon default for polygons', function() {
|
||||
feature.setGeometry(new ol.geom.Polygon([[[0, 0], [1, 1], [0, 0]]]));
|
||||
expect(ol.style.Style.applyDefaultStyle(feature)[0]
|
||||
.equals(ol.style.PolygonDefaults)).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.filter.Filter');
|
||||
goog.require('ol.style.Style');
|
||||
Reference in New Issue
Block a user