Skip to content

Commit

Permalink
Coverage (#53)
Browse files Browse the repository at this point in the history
* Test Building Constructor
  • Loading branch information
Beakerboy authored May 16, 2024
1 parent 96efc5b commit 4430c9c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
4 changes: 0 additions & 4 deletions src/building.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,10 @@ class Building {
const buildingType = xmlData.querySelector('[k="building"]');
const ways = [];
if (xmlData.tagName === 'relation') {
// it is a multipolygon or building relation
window.printError('Tagname is "relation"');
// get all building relation parts
// todo: multipolygon inner and outer roles.
let parts = xmlData.querySelectorAll('member[role="part"]');
var ref = 0;
window.printError('Parts: ' + parts.length);
for (let i = 0; i < parts.length; i++) {
ref = parts[i].getAttribute('ref');
const part = this.fullXmlData.getElementById(ref);
Expand All @@ -231,7 +228,6 @@ class Building {
}
ways.push(xmlData);
}
window.printError('Number of ways: ' + ways.length);
for (let i = 0; i < ways.length; i++) {
const way = ways[i];
if (way.tagName.toLowerCase() === 'way') {
Expand Down
1 change: 0 additions & 1 deletion src/buildingpart.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ class BuildingPart {
* If there is whitespace between the unit and the number, it will remain.
*/
static normalizeLength(length) {
window.printError('length: ' + length);
if (typeof length === 'string' || length instanceof String) {
if (length.includes('km')){
// remove final character.
Expand Down
2 changes: 0 additions & 2 deletions src/multibuildingpart.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ class MultiBuildingPart extends BuildingPart {
const outerMembers = this.way.querySelectorAll('member[role="outer"]');
const innerShapes = [];
var shapes = [];
window.printError('Inner members: ' + innerMembers.length);
for (let i = 0; i < innerMembers.length; i++) {
const way = this.fullXmlData.getElementById(innerMembers[i].getAttribute('ref'));
innerShapes.push(BuildingShapeUtils.createShape(way, this.nodelist));
}
window.printError('Outer members: ' + outerMembers.length);
const ways = [];
for (let j = 0; j < outerMembers.length; j++) {
const way = this.fullXmlData.getElementById(outerMembers[j].getAttribute('ref'));
Expand Down
20 changes: 15 additions & 5 deletions test/building.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* @jest-environment jsdom
*/
import {toBeDeepCloseTo} from 'jest-matcher-deep-close-to';
expect.extend({toBeDeepCloseTo});

import { Shape, Mesh } from 'three';
import { TextEncoder } from 'node:util';
Expand Down Expand Up @@ -55,15 +57,23 @@ beforeEach(() => {
fetch.resetMocks();
});

// test('Test Factory', async() => {
// fetch.mockResponseOnce(data);
// const shape = await Building.create('relation', '4');
// expect(fetch).toHaveBeenCalledTimes(2);
//});
test('Test Constructor', async() => {
const bldg = new Building('4', data);
expect(bldg.home).toBeDeepCloseTo([4.0005, 4.0005], 10);
expect(bldg.parts.length).toBe(0);
});

test('Create Nodelist', () => {
let xmlData = new window.DOMParser().parseFromString(data, 'text/xml');
const list = Building.buildNodeList(xmlData);
expect(Object.keys(list).length).toBe(4);
expect(list['3']).toStrictEqual(['4', '4']);
});

window.printError = printError;

const errors = [];

function printError(txt) {
errors.push[txt];
}

0 comments on commit 4430c9c

Please sign in to comment.