From 1ddc47f3d3c0cabe9e63e38b05dd719264845aa0 Mon Sep 17 00:00:00 2001 From: ftoromanoff Date: Mon, 18 Dec 2023 15:57:42 +0100 Subject: [PATCH] 3 more --- test/unit/3dtileslayerprocess.js | 2 +- test/unit/3dtileslayerstyle.js | 77 +++++++++++++++++++------------- test/unit/entwine.js | 36 +++++++++++++-- 3 files changed, 79 insertions(+), 36 deletions(-) diff --git a/test/unit/3dtileslayerprocess.js b/test/unit/3dtileslayerprocess.js index a788523c75..56f61fdff5 100644 --- a/test/unit/3dtileslayerprocess.js +++ b/test/unit/3dtileslayerprocess.js @@ -6,8 +6,8 @@ import View from 'Core/View'; import GlobeView from 'Core/Prefab/GlobeView'; import { HttpsProxyAgent } from 'https-proxy-agent'; import Coordinates from 'Core/Geographic/Coordinates'; -import Fetcher from 'Provider/Fetcher'; import sinon from 'sinon'; +import Fetcher from 'Provider/Fetcher'; import Renderer from './bootstrap'; import tilesetDiscretLOD from '../data/unitTest/3dTiles/tilesetDiscretLOD.json'; diff --git a/test/unit/3dtileslayerstyle.js b/test/unit/3dtileslayerstyle.js index fb4fda7493..8e93c64310 100644 --- a/test/unit/3dtileslayerstyle.js +++ b/test/unit/3dtileslayerstyle.js @@ -7,55 +7,70 @@ import PlanarView from 'Core/Prefab/PlanarView'; import C3DTBatchTable from 'Core/3DTiles/C3DTBatchTable'; import C3DTilesSource from 'Source/C3DTilesSource'; import C3DTilesLayer from 'Layer/C3DTilesLayer'; +import sinon from 'sinon'; +import Fetcher from 'Provider/Fetcher'; import Renderer from './bootstrap'; +import tileset from '../data/unitTest/3dTiles/tileset.json'; + describe('3DTilesLayer Style', () => { - // Define crs - proj4.defs('EPSG:3946', '+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'); + let view; + let createTileContent; + let stubFetcherJson; + + before(function () { + stubFetcherJson = sinon.stub(Fetcher, 'json') + .callsFake(() => Promise.resolve(JSON.parse(tileset))); + + // Define crs + proj4.defs('EPSG:3946', '+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'); - // Define geographic extent: CRS, min/max X, min/max Y - const extent = new Extent('EPSG:3946', - 1840816.94334, 1843692.32501, - 5175036.4587, 5177412.82698); + // Define geographic extent: CRS, min/max X, min/max Y + const extent = new Extent('EPSG:3946', + 1840816.94334, 1843692.32501, + 5175036.4587, 5177412.82698); - const renderer = new Renderer(); + const renderer = new Renderer(); - const view = new PlanarView(renderer.domElement, extent, { renderer, noControls: true }); + view = new PlanarView(renderer.domElement, extent, { renderer, noControls: true }); - // Create a 'fake' tile content for this test purpose - const createTileContent = (tileId) => { - const geometry = new THREE.SphereGeometry(15, 32, 16); - const material = new THREE.MeshBasicMaterial({ color: 0xffff00 }); + // Create a 'fake' tile content for this test purpose + createTileContent = (tileId) => { + const geometry = new THREE.SphereGeometry(15, 32, 16); + const material = new THREE.MeshBasicMaterial({ color: 0xffff00 }); - // Add _BATCHID geometry attributes - const array = []; - let currentBatchId = Math.round(Math.random() * 50); - for (let index = 0; index < geometry.attributes.position.count; index++) { - array.push(currentBatchId); + // Add _BATCHID geometry attributes + const array = []; + let currentBatchId = Math.round(Math.random() * 50); + for (let index = 0; index < geometry.attributes.position.count; index++) { + array.push(currentBatchId); - // Change randomly batch id - if (Math.random() > 0.5) { - currentBatchId = Math.round(Math.random() * 50); + // Change randomly batch id + if (Math.random() > 0.5) { + currentBatchId = Math.round(Math.random() * 50); + } } - } - geometry.setAttribute('_BATCHID', new THREE.BufferAttribute(Int32Array.from(array), 1)); + geometry.setAttribute('_BATCHID', new THREE.BufferAttribute(Int32Array.from(array), 1)); - const result = new THREE.Mesh(geometry, material); + const result = new THREE.Mesh(geometry, material); - result.batchTable = new C3DTBatchTable(); - result.tileId = tileId; + result.batchTable = new C3DTBatchTable(); + result.tileId = tileId; - return result; - }; + return result; + }; + + after(() => { + stubFetcherJson.restore(); + }); + }); let $3dTilesLayer; let source; - - const url = 'test/data/unitTest/3dTiles/tileset.json'; - it('should instance C3DTilesLayer', function (done) { source = new C3DTilesSource({ - url, + url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/' + + '3DTiles/lyon1_with_surface_type_2018/tileset.json', networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, }); diff --git a/test/unit/entwine.js b/test/unit/entwine.js index d45d81cbcf..e3343f9ebc 100644 --- a/test/unit/entwine.js +++ b/test/unit/entwine.js @@ -6,13 +6,41 @@ import Coordinates from 'Core/Geographic/Coordinates'; import EntwinePointTileSource from 'Source/EntwinePointTileSource'; import EntwinePointTileLayer from 'Layer/EntwinePointTileLayer'; import EntwinePointTileNode from 'Core/EntwinePointTileNode'; +import sinon from 'sinon'; +import Fetcher from 'Provider/Fetcher'; import Renderer from './bootstrap'; +import ept from '../data/unitTest/entwine/ept.json'; +import eptHierarchy from '../data/unitTest/entwine/ept-hierarchy/0-0-0-0.json'; + +const urlEpt = 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/entwine/ept.json'; +const urlEptHierarchy = 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/entwine/ept-hierarchy/0-0-0-0.json'; + +const resources = { + [urlEpt]: ept, + [urlEptHierarchy]: eptHierarchy, +}; + describe('Entwine Point Tile', function () { - const source = new EntwinePointTileSource({ - // url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/entwine', - url: 'test/data/unitTest/entwine', - networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, + let source; + let stubFetcherJson; + let stubFetcherArrayBuf; + + before(function () { + stubFetcherJson = sinon.stub(Fetcher, 'json') + .callsFake(url => Promise.resolve(JSON.parse(resources[url]))); + stubFetcherArrayBuf = sinon.stub(Fetcher, 'arrayBuffer') + .callsFake(() => Promise.resolve(new ArrayBuffer(8).buffer)); + + source = new EntwinePointTileSource({ + url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/entwine', + networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, + }); + }); + + after(function () { + stubFetcherJson.restore(); + stubFetcherArrayBuf.restore(); }); it('loads the EPT structure', (done) => {