Skip to content

Commit

Permalink
refactor(test): Vectortile and url as source
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Feb 2, 2024
1 parent 7df8e6b commit 945c06c
Showing 1 changed file with 59 additions and 18 deletions.
77 changes: 59 additions & 18 deletions test/unit/vectortiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ import VectorTileParser from 'Parser/VectorTileParser';
import VectorTilesSource from 'Source/VectorTilesSource';
import Extent from 'Core/Geographic/Extent';
import urlParser from 'Parser/MapBoxUrlParser';
/* Need PR #2183 ad it use sinon to stub the fetcher
import Fetcher from 'Provider/Fetcher';
import sinon from 'sinon';
import style from '../data/vectortiles/style.json';
import tilejson from '../data/vectortiles/tilejson.json';
import sprite from '../data/vectortiles/sprite.json';
import mapboxStyle from '../data/mapboxMulti.json';
const resources = {
'test/data/vectortiles/style.json': style,
'https://test/tilejson.json': tilejson,
'https://test/sprite.json': sprite,
'https://api.mapbox.com/v4/mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v7.json': mapboxStyle,
};
*/

describe('Vector tiles', function () {
// this PBF file comes from https://github.com/mapbox/vector-tile-js
Expand Down Expand Up @@ -70,6 +86,20 @@ describe('Vector tiles', function () {
});

describe('VectorTilesSource', function () {
/* Need PR #2183 ad it use sinon to stub the fetcher
let stub;
before(function () {
stub = sinon.stub(Fetcher, 'json')
.callsFake((url) => {
url = url.split('?')[0];
return Promise.resolve(JSON.parse(resources[url]));
});
});
after(function () {
stub.restore();
});
*/

it('throws an error because no style was provided', () => {
assert.throws(() => new VectorTilesSource({}), {
name: 'Error',
Expand All @@ -93,24 +123,32 @@ describe('VectorTilesSource', function () {
.catch(done);
});

// need fetcher !
// it('reads tiles URL from an url', (done) => {
// const source = new VectorTilesSource({
// style: {
// sources: { sourceUrl: { url: 'mapbox://mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v7' } },
// layers: [],
// },
// accessToken: 'pk.eyJ1IjoiZnRvcm9tYW5vZmYiLCJhIjoiY2xrc2Zpa2o3MDQxNTNxcG5sczJyaTlncyJ9.5KFKdMLIiy-b_fAjSVhjCQ',
// });
// source.whenReady
// .then(() => {
// assert.equal(source.url.size, 2);
// // eslint-disable-next-line no-template-curly-in-string
// assert.ok(source.url.has('http://server.geo/${z}/${x}/${y}.pbf'));
// done();
// })
// .catch(done);
// });
/* Need PR #2183 ad it use sinon to stub the fetcher
it('reads tiles URL from an url', (done) => {
const source = new VectorTilesSource({
style: {
sources: { sourceUrl: { url: 'mapbox://mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v7' } },
layers: [{
id: 'building',
source: 'sourceUrl',
'source-layer': 'building',
type: 'fill',
paint: {
'fill-color': 'red',
},
}],
},
accessToken: 'pk.eyJ1IjoiZnRvcm9tYW5vZmYiLCJhIjoiY2xramhzM2xrMDVibjNpcGNvdGRlZWQ5YyJ9.NibhjJNVTxArsNSH4v_kIA',
});
source.whenReady
.then(() => {
assert.equal(source.url, '.');
assert.equal(source.urls.size, 1);
done();
})
.catch(done);
});
*/

it('reads the background layer', (done) => {
const source = new VectorTilesSource({
Expand Down Expand Up @@ -152,6 +190,9 @@ describe('VectorTilesSource', function () {
it('loads the style from a file', (done) => {
const source = new VectorTilesSource({
style: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/vectortiles/style.json',
/* Need PR #2183 ad it use sinon to stub the fetcher
style: 'test/data/vectortiles/style.json',
*/
networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {},
});
source.whenReady.then(() => {
Expand Down

0 comments on commit 945c06c

Please sign in to comment.