Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework unit tests (mocking the fetch()) #2183

Merged
merged 6 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
["babel-plugin-inline-import", {
"extensions": [
".json",
".geojson",
".glsl",
".gltf",
".css"
]
}],
Expand Down
164 changes: 164 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"@babel/preset-env": "^7.22.5",
"@babel/register": "^7.22.5",
"@types/three": "^0.159.0",
"@xmldom/xmldom": "^0.8.10",
"babel-inline-import-loader": "^1.0.1",
"babel-loader": "^9.1.3",
"babel-plugin-inline-import": "^3.0.0",
Expand Down Expand Up @@ -107,6 +108,7 @@
"puppeteer": "^21.6.0",
"q": "^1.5.1",
"replace-in-file": "^7.0.2",
"sinon": "^17.0.1",
"three": "^0.159.0",
"typescript": "^5.3.3",
"webpack": "^5.89.0",
Expand Down
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
*
AnthonyGlt marked this conversation as resolved.
Show resolved Hide resolved
* @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
1 change: 0 additions & 1 deletion src/Process/3dTilesProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ export function process3dTilesNode(cullingTest = $3dTilesCulling, subdivisionTes
return undefined;
}


// do proper culling
const isVisible = cullingTest ? (!cullingTest(layer, context.camera, node, node.matrixWorld)) : true;
node.visible = isVisible;
Expand Down
Loading
Loading