|
| 1 | +/** |
| 2 | + * @jest-environment jsdom |
| 3 | + */ |
| 4 | + |
| 5 | +import {toBeDeepCloseTo} from 'jest-matcher-deep-close-to'; |
| 6 | +expect.extend({toBeDeepCloseTo}); |
| 7 | + |
| 8 | +import { TextEncoder } from 'node:util'; |
| 9 | +global.TextEncoder = TextEncoder; |
| 10 | + |
| 11 | +import { Shape } from 'three'; |
| 12 | + |
| 13 | +import { BuildingShapeUtils } from '../src/extras/BuildingShapeUtils.js'; |
| 14 | +// import { JSDOM } from 'jsdom'; |
| 15 | + |
| 16 | +test('Test combining 2 ways 1->2', () => { |
| 17 | + var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/></way>'; |
| 18 | + var way2 = '<way id="2"><nd ref="3"/><nd ref="4"/><nd ref="1"/></way>'; |
| 19 | + var way3 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/><nd ref="1"/></way>'; |
| 20 | + let parser = new window.DOMParser(); |
| 21 | + let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0]; |
| 22 | + let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0]; |
| 23 | + let result = BuildingShapeUtils.combineWays([xml1, xml2]); |
| 24 | + expect(result.length).toBe(1); |
| 25 | + let expected = parser.parseFromString(way3, 'text/xml'); |
| 26 | + expect(result[0].outerHTML).toBe(way3); |
| 27 | +}); |
| 28 | + |
| 29 | +test('Test combining 2 ways 2->1', () => { |
| 30 | + var way2 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/></way>'; |
| 31 | + var way1 = '<way id="2"><nd ref="3"/><nd ref="4"/><nd ref="1"/></way>'; |
| 32 | + var way3 = '<way id="2"><nd ref="3"/><nd ref="4"/><nd ref="1"/><nd ref="2"/><nd ref="3"/></way>'; |
| 33 | + let parser = new window.DOMParser(); |
| 34 | + let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0]; |
| 35 | + let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0]; |
| 36 | + let result = BuildingShapeUtils.combineWays([xml1, xml2]); |
| 37 | + expect(result.length).toBe(1); |
| 38 | + let expected = parser.parseFromString(way3, 'text/xml'); |
| 39 | + expect(result[0].outerHTML).toBe(way3); |
| 40 | +}); |
| 41 | + |
| 42 | +test('Test combining 2 unaligned ways', () => { |
| 43 | + var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/></way>'; |
| 44 | + var way2 = '<way id="2"><nd ref="1"/><nd ref="4"/><nd ref="3"/></way>'; |
| 45 | + var way3 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/><nd ref="1"/></way>'; |
| 46 | + let parser = new window.DOMParser(); |
| 47 | + let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0]; |
| 48 | + let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0]; |
| 49 | + let result = BuildingShapeUtils.combineWays([xml1, xml2]); |
| 50 | + expect(result.length).toBe(1); |
| 51 | + let expected = parser.parseFromString(way3, 'text/xml'); |
| 52 | + expect(result[0].outerHTML).toBe(way3); |
| 53 | +}); |
0 commit comments