Skip to content

Commit

Permalink
add test for street-geo with mocha and jsdom
Browse files Browse the repository at this point in the history
  • Loading branch information
Algorush committed May 20, 2024
1 parent 5f1fbf0 commit 57711f3
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"webpack-cli": "^4.7.0"
},
"dependencies": {
"aframe": "^1.5.0",
"aframe-atlas-uvs-component": "^3.0.0",
"babel-polyfill": "^6.26.0",
"latest": "^0.2.0"
Expand Down
108 changes: 108 additions & 0 deletions test/street-geo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
const assert = require('assert');
require('jsdom-global')();
const AFRAME = require('aframe/src');
require('../src/components/street-geo.js');

describe('street-geo component', function() {
let el;

before((done) => {
const scene = document.createElement('a-scene');
document.body.appendChild(scene);
el = document.createElement('a-entity');
el.setAttribute('street-geo', {
longitude: 10,
latitude: 20,
elevation: 30,
maps: 'mapbox2d'
});
scene.appendChild(el);

setTimeout(() => {
done();
}, 500);
});

it('should create a mapbox2d element', () => {
const mapbox2dElement = el.querySelector('[data-layer-name="Mapbox Satellite Streets"]');
assert.ok(mapbox2dElement, 'mapbox2d element not created');
});

it('should create a google3d element and delete mapbox2d element', (done) => {
const mapbox2dElement = el.querySelector('[data-layer-name="Mapbox Satellite Streets"]');
const google3dElement = el.querySelector('[data-layer-name="Google 3D Tiles"]');

assert.ok(mapbox2dElement, 'mapbox2d element not created');

el.setAttribute('street-geo', 'maps', 'google3d');

setTimeout(() => {
setTimeout(() => {
const updatedMapbox2dElement = el.querySelector('[data-layer-name="Mapbox Satellite Streets"]');
const updatedGoogle3dElement = el.querySelector('[data-layer-name="Google 3D Tiles"]');

assert.ok(!updatedMapbox2dElement, 'mapbox2d element not deleted');
assert.ok(updatedGoogle3dElement, 'google3d element not created');

done();
});
});
});

it('should create both mapbox2d and google3d elements', (done) => {
el.setAttribute('street-geo', 'maps', 'mapbox2d, google3d');

setTimeout(() => {
setTimeout(() => {
const mapbox2dElement = el.querySelector('[data-layer-name="Mapbox Satellite Streets"]');
const google3dElement = el.querySelector('[data-layer-name="Google 3D Tiles"]');
assert.ok(mapbox2dElement, 'mapbox2d element not created');
assert.ok(google3dElement, 'google3d element not created');
done();
});
});
});

it('should delete mapbox2d and google3d elements after setting maps attribute to empty', (done) => {
const mapbox2dElement = el.querySelector('[data-layer-name="Mapbox Satellite Streets"]');
const google3dElement = el.querySelector('[data-layer-name="Google 3D Tiles"]');

assert.ok(mapbox2dElement, 'mapbox2d element not created');
assert.ok(google3dElement, 'google3d element not created');

el.setAttribute('street-geo', 'maps', '');

setTimeout(() => {
setTimeout(() => {
const updatedMapbox2dElement = el.querySelector('[data-layer-name="Mapbox Satellite Streets"]');
const updatedGoogle3dElement = el.querySelector('[data-layer-name="Google 3D Tiles"]');

assert.ok(!updatedMapbox2dElement, 'mapbox2d element not deleted');
assert.ok(!updatedGoogle3dElement, 'google3d element not deleted');

done();
});
});
});

it('should update latitude, longitude, and elevation for google3d', (done) => {
el.setAttribute('street-geo', 'maps', 'google3d');
el.setAttribute('street-geo', 'longitude', 40);
el.setAttribute('street-geo', 'latitude', 50);
el.setAttribute('street-geo', 'elevation', 100);

setTimeout(() => {
setTimeout(() => {
const google3dElement = el.querySelector('[data-layer-name="Google 3D Tiles"]');
assert.ok(google3dElement, 'google3d element not created');

const loader3dtilesAttr = google3dElement.getAttribute('loader-3dtiles');
assert.strictEqual(loader3dtilesAttr.long, 40);
assert.strictEqual(loader3dtilesAttr.lat, 50);
assert.strictEqual(loader3dtilesAttr.height, 100 - 32.49158);

done();
});
});
});
});

0 comments on commit 57711f3

Please sign in to comment.