From aced93436e4265b0f68d3e7a2b52a5868cd1e436 Mon Sep 17 00:00:00 2001 From: ftoromanoff Date: Wed, 13 Dec 2023 09:44:41 +0100 Subject: [PATCH] test dataSourceProvider fake fetcher --- test/unit/dataSourceProvider.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/test/unit/dataSourceProvider.js b/test/unit/dataSourceProvider.js index f88f0d55c5..3a23715a77 100644 --- a/test/unit/dataSourceProvider.js +++ b/test/unit/dataSourceProvider.js @@ -6,7 +6,7 @@ import TileMesh from 'Core/TileMesh'; import Extent, { globalExtentTMS } from 'Core/Geographic/Extent'; import OBB from 'Renderer/OBB'; import DataSourceProvider from 'Provider/DataSourceProvider'; -import { supportedFetchers, supportedParsers } from 'Source/Source'; +import { supportedFetchers } from 'Source/Source'; import TileProvider from 'Provider/TileProvider'; import WMTSSource from 'Source/WMTSSource'; import WMSSource from 'Source/WMSSource'; @@ -20,17 +20,18 @@ import Style from 'Core/Style'; import Feature2Mesh from 'Converter/Feature2Mesh'; import LayeredMaterial from 'Renderer/LayeredMaterial'; import { EMPTY_TEXTURE_ZOOM } from 'Renderer/RasterTile'; +import sinon from 'sinon'; import holes from '../data/geojson/holesPoints.geojson.json'; +const stubSupportedFetchers = new Map([ + ['application/json', () => Promise.resolve(JSON.parse(holes))], + ['image/png', () => Promise.resolve(new THREE.Texture())], +]); + describe('Provide in Sources', function () { - // /!\ Avoid to overload fetcher because could troubleshoot the other unit tests? - // formatTag to avoid it - const formatTag = 'dspUnitTest'; - supportedFetchers.set(`${formatTag}image/png`, () => Promise.resolve(new THREE.Texture())); - supportedFetchers.set(`${formatTag}application/json`, () => Promise.resolve(JSON.parse(holes))); - supportedParsers.set(`${formatTag}image/png`, supportedParsers.get('image/png')); - supportedParsers.set(`${formatTag}application/json`, supportedParsers.get('application/json')); + const stub = sinon.stub(supportedFetchers, 'get') + .callsFake(format => stubSupportedFetchers.get(format)); // Misc var to initialize a TileMesh instance const geom = new THREE.BufferGeometry(); @@ -88,7 +89,7 @@ describe('Provide in Sources', function () { featureLayer.source = new WFSSource({ url: 'http://', typeName: 'name', - format: `${formatTag}application/json`, + format: 'application/json', extent: globalExtent, crs: 'EPSG:3857', }); @@ -103,6 +104,8 @@ describe('Provide in Sources', function () { context.elevationLayers = [elevationlayer]; context.colorLayers = [colorlayer]; + stub.restore(); + beforeEach('reset state', function () { // clear commands array context.scheduler.commands = []; @@ -112,7 +115,7 @@ describe('Provide in Sources', function () { colorlayer.source = new WMTSSource({ url: 'http://', name: 'name', - format: `${formatTag}image/png`, + format: 'image/png', tileMatrixSet: 'PM', crs: 'EPSG:3857', extent: globalExtent, @@ -144,7 +147,7 @@ describe('Provide in Sources', function () { elevationlayer.source = new WMTSSource({ url: 'http://', name: 'name', - format: `${formatTag}image/png`, + format: 'image/png', tileMatrixSet: 'PM', crs: 'EPSG:3857', zoom: { @@ -173,7 +176,7 @@ describe('Provide in Sources', function () { colorlayer.source = new WMSSource({ url: 'http://', name: 'name', - format: `${formatTag}image/png`, + format: 'image/png', extent: globalExtent, crs: 'EPSG:3857', zoom: { @@ -306,7 +309,7 @@ describe('Provide in Sources', function () { colorlayer.source = new WMTSSource({ url: 'http://', name: 'name', - format: `${formatTag}image/png`, + format: 'image/png', tileMatrixSet: 'PM', crs: 'EPSG:3857', extent: globalExtent,