Skip to content

Commit

Permalink
refactor(test): wait for PR2183
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Feb 7, 2024
1 parent daba543 commit a394721
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Source/VectorTilesSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}

Expand Down
81 changes: 68 additions & 13 deletions test/unit/vectortiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
});
*/
Expand All @@ -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: {
Expand All @@ -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);
Expand Down Expand Up @@ -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) } : {},
Expand Down Expand Up @@ -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);
Expand All @@ -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);
});
});
*/
});

0 comments on commit a394721

Please sign in to comment.