Skip to content

Commit

Permalink
test dataSourceProvider fake fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Dec 15, 2023
1 parent 14643ff commit aced934
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions test/unit/dataSourceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
Expand Down Expand Up @@ -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',
});
Expand All @@ -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 = [];
Expand All @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit aced934

Please sign in to comment.