Test for vector source load method
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
goog.provide('ol.source.FeatureCache');
|
goog.provide('ol.source.FeatureCache');
|
||||||
goog.provide('ol.source.Vector');
|
goog.provide('ol.source.Vector');
|
||||||
goog.provide('ol.source.VectorEventType');
|
goog.provide('ol.source.VectorEventType');
|
||||||
|
goog.provide('ol.source.VectorLoadState');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.async.nextTick');
|
goog.require('goog.async.nextTick');
|
||||||
|
|||||||
@@ -3,21 +3,65 @@ goog.provide('ol.test.source.Vector');
|
|||||||
|
|
||||||
describe('ol.source.Vector', function() {
|
describe('ol.source.Vector', function() {
|
||||||
|
|
||||||
|
var url = 'spec/ol/source/vectorsource/single-feature.json';
|
||||||
|
|
||||||
describe('constructor', function() {
|
describe('constructor', function() {
|
||||||
it('creates an instance', function() {
|
it('creates an instance', function() {
|
||||||
var source = new ol.source.Vector();
|
var source = new ol.source.Vector();
|
||||||
expect(source).to.be.a(ol.source.Vector);
|
expect(source).to.be.a(ol.source.Vector);
|
||||||
expect(source).to.be.a(ol.source.Source);
|
expect(source).to.be.a(ol.source.Source);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('accepts features', function() {
|
||||||
|
var features = [new ol.Feature()];
|
||||||
|
var source = new ol.source.Vector({
|
||||||
|
features: features
|
||||||
|
});
|
||||||
|
expect(source).to.be.a(ol.source.Vector);
|
||||||
|
expect(source.getFeatures()).to.eql(features);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('accepts url and parser', function() {
|
||||||
|
var source = new ol.source.Vector({
|
||||||
|
url: url,
|
||||||
|
parser: new ol.parser.GeoJSON()
|
||||||
|
});
|
||||||
|
expect(source).to.be.a(ol.source.Vector);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#load()', function() {
|
||||||
|
it('triggers loading of features', function() {
|
||||||
|
var source = new ol.source.Vector({
|
||||||
|
url: url,
|
||||||
|
parser: new ol.parser.GeoJSON()
|
||||||
|
});
|
||||||
|
expect(source.loadState_).to.be(ol.source.VectorLoadState.IDLE);
|
||||||
|
var triggered = source.load([-1, -1, 1, 1], ol.proj.get('EPSG:4326'));
|
||||||
|
expect(triggered).to.be(true);
|
||||||
|
expect(source.loadState_).to.be(ol.source.VectorLoadState.LOADING);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false when already loading', function() {
|
||||||
|
var source = new ol.source.Vector({
|
||||||
|
url: url,
|
||||||
|
parser: new ol.parser.GeoJSON()
|
||||||
|
});
|
||||||
|
source.load([-1, -1, 1, 1], ol.proj.get('EPSG:4326'));
|
||||||
|
// second call with same extent
|
||||||
|
var triggered = source.load([-1, -1, 1, 1], ol.proj.get('EPSG:4326'));
|
||||||
|
expect(triggered).to.be(false);
|
||||||
|
expect(source.loadState_).to.be(ol.source.VectorLoadState.LOADING);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#addFeatures()', function() {
|
describe('#addFeatures()', function() {
|
||||||
|
|
||||||
it('allows adding features', function() {
|
it('allows adding features', function() {
|
||||||
var source = new ol.source.Vector();
|
var source = new ol.source.Vector();
|
||||||
source.addFeatures([new ol.Feature(), new ol.Feature()]);
|
var features = [new ol.Feature()];
|
||||||
expect(goog.object.getCount(source.featureCache_.getFeaturesObject()))
|
source.addFeatures(features);
|
||||||
.to.eql(2);
|
expect(source.getFeatures()).to.eql(features);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -88,7 +132,10 @@ goog.require('goog.object');
|
|||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
|
goog.require('ol.parser.GeoJSON');
|
||||||
|
goog.require('ol.proj');
|
||||||
goog.require('ol.source.FeatureCache');
|
goog.require('ol.source.FeatureCache');
|
||||||
goog.require('ol.source.Source');
|
goog.require('ol.source.Source');
|
||||||
goog.require('ol.source.Vector');
|
goog.require('ol.source.Vector');
|
||||||
goog.require('ol.source.VectorEventType');
|
goog.require('ol.source.VectorEventType');
|
||||||
|
goog.require('ol.source.VectorLoadState');
|
||||||
|
|||||||
16
test/spec/ol/source/vectorsource/single-feature.json
Normal file
16
test/spec/ol/source/vectorsource/single-feature.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"type": "FeatureCollection",
|
||||||
|
"features": [
|
||||||
|
{
|
||||||
|
"type": "Feature",
|
||||||
|
"id": "point_1",
|
||||||
|
"geometry": {
|
||||||
|
"coordinates": [1, 2],
|
||||||
|
"type": "Point"
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"name": "point"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user