Skip to content
Merged
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
39 changes: 39 additions & 0 deletions test/combine_ways.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ import { Shape } from 'three';
import { BuildingShapeUtils } from '../src/extras/BuildingShapeUtils.js';
// import { JSDOM } from 'jsdom';

test('Test no combining necessary. one open way', () => {
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/></way>';
let parser = new window.DOMParser();
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
let result = BuildingShapeUtils.combineWays([xml1]);
expect(result.length).toBe(0);
});

test('Test combining 2 ways 1->2', () => {
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/></way>';
var way2 = '<way id="2"><nd ref="3"/><nd ref="4"/><nd ref="1"/></way>';
Expand Down Expand Up @@ -51,3 +59,34 @@ test('Test combining 2 unaligned ways', () => {
let expected = parser.parseFromString(way3, 'text/xml');
expect(result[0].outerHTML).toBe(way3);
});

test('Test combining 3 ways 1->2->3', () => {
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/></way>';
var way2 = '<way id="2"><nd ref="3"/><nd ref="4"/><nd ref="5"/></way>';
var way3 = '<way id="3"><nd ref="5"/><nd ref="6"/><nd ref="1"/></way>';
var way4 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/><nd ref="5"/><nd ref="6"/><nd ref="1"/></way>';
let parser = new window.DOMParser();
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0];
let xml3 = parser.parseFromString(way3, 'text/xml').getElementsByTagName('way')[0];
let result = BuildingShapeUtils.combineWays([xml1, xml2, xml3]);
expect(result.length).toBe(1);
let expected = parser.parseFromString(way4, 'text/xml');
expect(result[0].outerHTML).toBe(way3);
});

test('Test combining 4 ways', () => {
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/></way>';
var way2 = '<way id="2"><nd ref="3"/><nd ref="4"/><nd ref="5"/></way>';
var way3 = '<way id="3"><nd ref="6"/><nd ref="5"/></way>';
var way4 = '<way id="4"><nd ref="6"/><nd ref="1"/><nd ref="1"/></way>';
var way5 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/><nd ref="5"/><nd ref="6"/><nd ref="1"/></way>';
let parser = new window.DOMParser();
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0];
let xml3 = parser.parseFromString(way3, 'text/xml').getElementsByTagName('way')[0];
let result = BuildingShapeUtils.combineWays([xml1, xml2, xml3]);
expect(result.length).toBe(1);
let expected = parser.parseFromString(way4, 'text/xml');
expect(result[0].outerHTML).toBe(way3);
});