-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding unit tests for rule based styling
- Loading branch information
Showing
6 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,53 @@ | |||
goog.provide('ol.test.layer.Vector'); | |||
|
|||
describe('ol.layer.Vector', function() { | |||
|
|||
describe('#groupFeaturesBySymbolizerLiteral()', function() { | |||
|
|||
it('groups equal symbolizers', function() { | |||
var layer = new ol.layer.Vector({ | |||
source: new ol.source.Vector({ | |||
projection: ol.Projection.getFromCode('EPSG:4326') | |||
}), | |||
style: new ol.style.Style({ | |||
rules: [ | |||
new ol.style.Rule({ | |||
symbolizers: [ | |||
new ol.style.Line({ | |||
strokeWidth: 2, | |||
strokeStyle: new ol.Expression('colorProperty'), | |||
opacity: 1 | |||
}) | |||
] | |||
}) | |||
] | |||
}) | |||
}); | |||
var features = [ | |||
new ol.Feature({ | |||
g: new ol.geom.LineString([[-10, -10], [10, 10]]), | |||
colorProperty: '#BADA55' | |||
}), | |||
new ol.Feature({ | |||
g: new ol.geom.LineString([[-10, 10], [10, -10]]), | |||
colorProperty: '#013' | |||
}), | |||
new ol.Feature({ | |||
g: new ol.geom.LineString([[10, -10], [-10, -10]]), | |||
colorProperty: '#013' | |||
}) | |||
]; | |||
|
|||
var groups = layer.groupFeaturesBySymbolizerLiteral(features); | |||
expect(groups.length).toBe(2); | |||
expect(groups[0][0].length).toBe(1); | |||
expect(groups[0][1].strokeStyle).toBe('#BADA55'); | |||
expect(groups[1][0].length).toBe(2); | |||
expect(groups[1][1].strokeStyle).toBe('#013'); | |||
|
|||
layer.dispose(); | |||
}); | |||
|
|||
}); | |||
|
|||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
goog.provide('ol.test.style.Rule'); | |||
|
|||
describe('ol.style.Rule', function() { | |||
|
|||
describe('#applies()', function() { | |||
var feature = new ol.Feature(), | |||
rule; | |||
|
|||
it('returns true for a rule without filter', function() { | |||
rule = new ol.style.Rule({}); | |||
expect(rule.applies(feature)).toBe(true); | |||
}); | |||
|
|||
it('returns false when the rule does not apply', function() { | |||
rule = new ol.style.Rule({ | |||
filter: new ol.filter.Filter(function() { return false; }) | |||
}); | |||
expect(rule.applies(feature)).toBe(false); | |||
}); | |||
|
|||
it('returns true when the rule applies', function() { | |||
rule = new ol.style.Rule({ | |||
filter: new ol.filter.Filter(function() { return true; }) | |||
}); | |||
expect(rule.applies(feature)).toBe(true); | |||
}); | |||
}); | |||
|
|||
}); | |||
|
|||
goog.require('ol.Feature'); | |||
goog.require('ol.filter.Filter'); | |||
goog.require('ol.style.Rule'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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'); |