Skip to content

Commit

Permalink
test(examples): add new functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed May 4, 2023
1 parent 2d6abcd commit 8e14fe8
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 5 deletions.
16 changes: 11 additions & 5 deletions test/functional/source_file_geojson_raster.js
Expand Up @@ -25,17 +25,23 @@ describe('source_file_geojson_raster', function _() {

it('should pick feature from Layer with SourceFile', async () => {
const pickedFeatures = await page.evaluate(() => {
/* global itowns */
const precision = view.getPixelsToDegrees(5);
const geoCoord = new itowns.Coordinates('EPSG:4326', 1.41955, 42.88613, 0);
const promises = [];
const layers = view.getLayers(l => l.source && l.source.isFileSource);
for (let i = 0; i < layers.length; i++) {
promises.push(layers[i].source.loadData({}, { crs: 'EPSG:4326', buildExtent: false }));
promises.push(
layers[i].source.loadData({}, { crs: 'EPSG:4326', buildExtent: false })
.then(fc => itowns.FeaturesUtils.filterFeaturesUnderCoordinate(geoCoord, fc, precision)),
);
}

return Promise.all(promises).then(fa => fa.filter(f => itowns
.FeaturesUtils.filterFeaturesUnderCoordinate(geoCoord, f, precision).length));
return Promise.all(promises);
});
assert.equal(1, pickedFeatures.length);

assert.equal(pickedFeatures.length, 2);// 2 layers added
assert.equal(pickedFeatures[0].length, 1, 'feature(s) picked on first layer');
assert.equal(pickedFeatures[1].length, 0, 'feature(s) picked on second layer');
assert.equal(pickedFeatures[0][0].geometry.properties.nom, 'Ariège');
});
});
49 changes: 49 additions & 0 deletions test/functional/source_file_kml_raster.js
@@ -0,0 +1,49 @@
const assert = require('assert');

describe('source_file_kml_raster', function _() {
let result;
before(async () => {
result = await loadExample('examples/source_file_kml_raster.html', this.fullTitle());
});

it('should run', async () => {
assert.ok(result);
});

it('load features data', async () => {
const features = await page.evaluate(() => {
const promises = [];
const layers = view.getLayers(l => l.source && l.source.isFileSource);
for (let i = 0; i < layers.length; i++) {
promises.push(layers[i].source.loadData({}, { crs: 'EPSG:4326' }));
}

return Promise.all(promises);
});
assert.equal(features.length, 2); // the layer and the LabelLayer
assert.equal(features[0].uuid, features[1].uuid);
});

it('should pick feature from Layer with SourceFile', async () => {
const pickedFeatures = await page.evaluate(() => {
/* global itowns */
const precision = view.getPixelsToDegrees(5);
const geoCoord = new itowns.Coordinates('EPSG:4326', 6.80665, 45.91308, 0);
const promises = [];
const layers = view.getLayers(l => l.source && l.source.isFileSource);
for (let i = 0; i < layers.length; i++) {
promises.push(
layers[i].source.loadData({}, { crs: 'EPSG:4326', buildExtent: false })
.then(fc => itowns.FeaturesUtils.filterFeaturesUnderCoordinate(geoCoord, fc, precision)),
);
}
return Promise.all(promises);
});

assert.equal(pickedFeatures.length, 2);// layer and the LabelLayer
assert.equal(pickedFeatures[0].length, 1);// only 1 feature picked on layer
assert.equal(pickedFeatures[1].length, 1);// and 1 on lableLayer
assert.equal(pickedFeatures[0][0].geometry.properties.description, pickedFeatures[1][0].geometry.properties.description, 'same feature');
assert.equal(pickedFeatures[0][0].geometry.properties.description, 'Zone Aiguillette des Houches');
});
});
28 changes: 28 additions & 0 deletions test/functional/source_file_kml_raster_usgs.js
@@ -0,0 +1,28 @@
const assert = require('assert');

describe('source_file_kml_raster_usgs', function _() {
let result;
before(async () => {
result = await loadExample('examples/source_file_kml_raster_usgs.html', this.fullTitle());
});

it('should run', async () => {
assert.ok(result);
});

it('load features data', async () => {
const features = await page.evaluate(() => {
const promises = [];
const layers = view.getLayers(l => l.source && l.source.isFileSource);
for (let i = 0; i < layers.length; i++) {
promises.push(layers[i].source.loadData({}, { crs: 'EPSG:4326' }));
}

return Promise.all(promises);
});
assert.equal(features.length, 2); // the layer and the LabelLayer
assert.equal(features[0].uuid, features[1].uuid);
assert.equal(features[0].features.length, 1);
assert.equal(features[0].features[0].type, 0);
});
});

0 comments on commit 8e14fe8

Please sign in to comment.