From a394721097f3a5d361e611d41352e6671a152324 Mon Sep 17 00:00:00 2001 From: ftoromanoff Date: Wed, 7 Feb 2024 15:07:34 +0100 Subject: [PATCH] refactor(test): wait for PR2183 --- src/Source/VectorTilesSource.js | 2 +- test/unit/vectortiles.js | 81 +++++++++++++++++++++++++++------ 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/src/Source/VectorTilesSource.js b/src/Source/VectorTilesSource.js index 6a20dc87a7..601bbc9d6e 100644 --- a/src/Source/VectorTilesSource.js +++ b/src/Source/VectorTilesSource.js @@ -140,7 +140,7 @@ class VectorTilesSource extends TMSSource { } return (Promise.resolve([this.url])); }).then((TMSUrlList) => { - this.urls = new Set(TMSUrlList); + this.urls = Array.from(new Set(TMSUrlList)); }); } diff --git a/test/unit/vectortiles.js b/test/unit/vectortiles.js index b5c3e74c46..f3e2e7f4a5 100644 --- a/test/unit/vectortiles.js +++ b/test/unit/vectortiles.js @@ -5,7 +5,8 @@ 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 +/* Need PR #2183 as it uses sinon to stub the fetcher +import { supportedFetchers } from 'Source/Source'; import Fetcher from 'Provider/Fetcher'; import sinon from 'sinon'; @@ -86,16 +87,26 @@ describe('Vector tiles', function () { }); describe('VectorTilesSource', function () { - /* Need PR #2183 ad it use sinon to stub the fetcher + /* Need PR #2183 as it uses sinon to stub the fetcher + let stubFetcherjson; let stub; before(function () { - stub = sinon.stub(Fetcher, 'json') + stubFetcherjson = sinon.stub(Fetcher, 'json') .callsFake((url) => { url = url.split('?')[0]; return Promise.resolve(JSON.parse(resources[url])); }); + const multipolygon = fs.readFileSync('test/data/pbf/multipolygon.pbf'); + const stubSupportedFetchers = new Map([ + // ['application/json', () => Promise.resolve(JSON.parse(holes))], + // ['image/png', () => Promise.resolve(new THREE.Texture())], + ['application/x-protobuf;type=mapbox-vector', () => Promise.resolve(multipolygon)], + ]); + stub = sinon.stub(supportedFetchers, 'get') + .callsFake(format => stubSupportedFetchers.get(format)); }); after(function () { + stubFetcherjson.restore(); stub.restore(); }); */ @@ -115,15 +126,15 @@ describe('VectorTilesSource', function () { }, }); source.whenReady.then(() => { - assert.equal(source.urls.size, 1); + assert.equal(source.urls.length, 1); // eslint-disable-next-line no-template-curly-in-string - assert.ok(source.urls.has('http://server.geo/${z}/${x}/${y}.pbf')); + assert.ok(source.urls.includes('http://server.geo/${z}/${x}/${y}.pbf')); done(); }) .catch(done); }); - /* Need PR #2183 ad it use sinon to stub the fetcher + /* Need PR #2183 as it uses sinon to stub the fetcher it('reads tiles URL from an url', (done) => { const source = new VectorTilesSource({ style: { @@ -143,7 +154,7 @@ describe('VectorTilesSource', function () { source.whenReady .then(() => { assert.equal(source.url, '.'); - assert.equal(source.urls.size, 1); + assert.equal(source.urls.length, 1); done(); }) .catch(done); @@ -190,7 +201,7 @@ 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 + /* Need PR #2183 as it uses sinon to stub the fetcher style: 'test/data/vectortiles/style.json', */ networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, @@ -308,11 +319,11 @@ describe('VectorTilesSource', function () { }); source.whenReady .then(() => { - assert.equal(source.urls.size, 2); + assert.equal(source.urls.length, 2); // eslint-disable-next-line no-template-curly-in-string - assert.ok(source.urls.has('http://server.geo/${z}/${x}/${y}.pbf')); + assert.ok(source.urls.includes('http://server.geo/${z}/${x}/${y}.pbf')); // eslint-disable-next-line no-template-curly-in-string - assert.ok(source.urls.has('http://server.geo2/${z}/${x}/${y}.pbf')); + assert.ok(source.urls.includes('http://server.geo2/${z}/${x}/${y}.pbf')); done(); }) .catch(done); @@ -335,12 +346,56 @@ describe('VectorTilesSource', function () { }); source.whenReady .then(() => { - assert.equal(source.urls.size, 1); + assert.equal(source.urls.length, 1); // eslint-disable-next-line no-template-curly-in-string - assert.ok(source.urls.has('http://server.geo/${z}/${x}/${y}.pbf')); + assert.ok(source.urls.includes('http://server.geo/${z}/${x}/${y}.pbf')); done(); }) .catch(done); }); }); + /* Need PR #2183 as it uses sinon to stub the fetcher + describe('loadData', function () { + it('with multisource', (done) => { + const source = new VectorTilesSource({ + style: { + sources: { + source1: { + type: 'vector', + tiles: ['http://server.geo/{z}/{x}/{y}.pbf'], + }, + source2: { + type: 'vector', + tiles: ['http://server.geo2/{z}/{x}/{y}.pbf'], + }, + }, + layers: [{ + id: 'geojson', + source: 'source1', + 'source-layer': 'geojson', + type: 'fill', + paint: { + 'fill-color': 'red', + }, + }], + }, + }); + + source.whenReady + .then(() => { + source.onLayerAdded({ out: { crs: 'EPSG:4326' } }); + const extent = new Extent('TMS', 1, 1, 1); + source.loadData(extent, { crs: 'EPSG:4326' }) + .then((featureCollection) => { + assert.equal(featureCollection.features[0].vertices.length, 20); + done(); + }) + .catch((err) => { + done(err); + }); + }) + .catch(done); + }); + }); + */ });