Skip to content

Commit

Permalink
refactor(test): unit test clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff authored and Desplandis committed Mar 15, 2024
1 parent 5d324ca commit f6b6bf4
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 26 deletions.
7 changes: 3 additions & 4 deletions src/Core/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import itowns_stroke_single_before from './StyleChunk/itowns_stroke_single_befor

export const cacheStyle = new Cache();

const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
const matrix = svg.createSVGMatrix();
const matrix = document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGMatrix();
const canvas = document.createElement('canvas');

const inv255 = 1 / 255;
const canvas = (typeof document !== 'undefined') ? document.createElement('canvas') : {};

function baseAltitudeDefault(properties, ctx) {
return ctx?.coordinates?.z || 0;
Expand Down Expand Up @@ -1079,7 +1078,7 @@ const CustomStyle = {
itowns_stroke_single_before,
};

const customStyleSheet = (typeof document !== 'undefined') ? document.createElement('style') : {};
const customStyleSheet = document.createElement('style');
customStyleSheet.type = 'text/css';

Object.keys(CustomStyle).forEach((key) => {
Expand Down
10 changes: 5 additions & 5 deletions src/Layer/C3DTilesLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const update = process3dTilesNode();

/**
* Find tileId of object
*
* @param {THREE.Object3D} object - object
*
* @returns {number} tileId
*/
function findTileID(object) {
Expand All @@ -41,14 +41,13 @@ function findTileID(object) {
currentObject = currentObject.parent;
result = currentObject.tileId;
}

return result;
}

/**
* Check if object3d has feature
*
* @param {THREE.Object3D} object3d - object3d to check
*
* @returns {boolean} - true if object3d has feature
*/
function object3DHasFeature(object3d) {
Expand Down Expand Up @@ -231,11 +230,13 @@ class C3DTilesLayer extends GeometryLayer {
* targets picked under specified coordinates. Intersects can be
* computed with view.pickObjectsAt(..). See fillHTMLWithPickingInfo()
* in 3dTilesHelper.js for an example.
*
* @returns {C3DTileFeature} - the closest C3DTileFeature of the intersects array
*/
getC3DTileFeatureFromIntersectsArray(intersects) {
// find closest intersect with an attributes _BATCHID + face != undefined
let closestIntersect = null;

for (let index = 0; index < intersects.length; index++) {
const i = intersects[index];
if (i.object.geometry &&
Expand Down Expand Up @@ -277,7 +278,6 @@ class C3DTilesLayer extends GeometryLayer {

/**
* Initialize C3DTileFeatures from tileContent
*
* @param {THREE.Object3D} tileContent - tile as THREE.Object3D
*/
initC3DTileFeatures(tileContent) {
Expand Down Expand Up @@ -344,8 +344,8 @@ class C3DTilesLayer extends GeometryLayer {
/**
* Update style of the C3DTFeatures, an allowList of tile id can be passed to only update certain tile.
* Note that this function only update THREE.Object3D materials, in order to see style changes you should call view.notifyChange()
*
* @param {Array<number>|null} [allowTileIdList] - tile ids to allow in updateStyle computation if null all tiles are updated
*
* @returns {boolean} true if style updated false otherwise
*/
updateStyle(allowTileIdList = null) {
Expand Down
6 changes: 3 additions & 3 deletions test/functional/3dtiles_batch_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('3dtiles_batch_table', function _() {
// Verifies that the batch id, batch table and batch table hierarchy
// extension picked information are correct for object at { x: 218, y: 90 }
it('should return the batch table and batch hierarchy picked information',
async () => {
async function _it() {
// Picks the object at (218,90) and gets its closest c3DTileFeature
const pickResult = await page.evaluate(
() => {
Expand Down Expand Up @@ -70,8 +70,8 @@ describe('3dtiles_batch_table', function _() {
},
},
};
const expectedBatchId = 29;
assert.deepStrictEqual(pickResult.batchId, expectedBatchId);

assert.equal(pickResult.batchId, 29);
assert.deepStrictEqual(pickResult.info, expectedPickingInfo);
});
});
4 changes: 2 additions & 2 deletions test/unit/dataSourceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import Feature2Mesh from 'Converter/Feature2Mesh';
import LayeredMaterial from 'Renderer/LayeredMaterial';
import { EMPTY_TEXTURE_ZOOM } from 'Renderer/RasterTile';

const holes = require('../data/geojson/holesPoints.geojson.json');
import holes from '../data/geojson/holesPoints.geojson.json';

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(holes));
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'));

Expand Down
6 changes: 3 additions & 3 deletions test/unit/feature2mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import assert from 'assert';
import GeoJsonParser from 'Parser/GeoJsonParser';
import Feature2Mesh from 'Converter/Feature2Mesh';

const geojson = require('../data/geojson/holes.geojson.json');
const geojson2 = require('../data/geojson/simple.geojson.json');
const geojson3 = require('../data/geojson/points.geojson.json');
import geojson from '../data/geojson/holes.geojson.json';
import geojson2 from '../data/geojson/simple.geojson.json';
import geojson3 from '../data/geojson/points.geojson.json';

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');
Expand Down
2 changes: 1 addition & 1 deletion test/unit/featureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import FeaturesUtils from 'Utils/FeaturesUtils';
import Coordinates from 'Core/Geographic/Coordinates';
import { FEATURE_TYPES } from 'Core/Feature';

const geojson = require('../data/geojson/simple.geojson.json');
import geojson from '../data/geojson/simple.geojson.json';

describe('FeaturesUtils', function () {
const options = { out: { crs: 'EPSG:4326', buildExtent: true, mergeFeatures: false, structure: '3d' } };
Expand Down
6 changes: 3 additions & 3 deletions test/unit/featuregeometrylayererror.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import OBB from 'Renderer/OBB';
import TileMesh from 'Core/TileMesh';
import Renderer from './bootstrap';

const geojson_big = require('../data/geojson/map_big.geojson.json');
const geojson_a = require('../data/geojson/map.geojson.json');
const geojson_small = require('../data/geojson/map_small.geojson.json');
import geojson_big from '../data/geojson/map_big.geojson.json';
import geojson_a from '../data/geojson/map.geojson.json';
import geojson_small from '../data/geojson/map_small.geojson.json';

const files = [geojson_small, geojson_a, geojson_big];
const errors = [3e-4, 5e-2, 35];
Expand Down
6 changes: 3 additions & 3 deletions test/unit/geojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import assert from 'assert';
import GeoJsonParser from 'Parser/GeoJsonParser';
import Extent from 'Core/Geographic/Extent';

const holes = require('../data/geojson/holes.geojson.json');
const gpx = require('../data/geojson/gpx.geojson.json');
const points = require('../data/geojson/points.geojson.json');
import holes from '../data/geojson/holes.geojson.json';
import gpx from '../data/geojson/gpx.geojson.json';
import points from '../data/geojson/points.geojson.json';

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');
Expand Down
2 changes: 1 addition & 1 deletion test/unit/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import FileSource from 'Source/FileSource';
import { HttpsProxyAgent } from 'https-proxy-agent';
import Renderer from './bootstrap';

const geojson = require('../data/geojson/simple.geojson.json');
import geojson from '../data/geojson/simple.geojson.json';

describe('LabelLayer', function () {
let layer;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/vectortiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('Vector tiles', function () {
}).catch(done);
});

it('loads the style from a file', (done) => {
it('loads the style from a file', function _(done) {
const source = new VectorTilesSource({
style: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/vectortiles/style.json',
networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {},
Expand Down

0 comments on commit f6b6bf4

Please sign in to comment.