|
| 1 | +/* eslint-disable camelcase, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-argument */ |
| 2 | +import {describe, test, expect} from '../../util/vitest'; |
| 3 | +import {parseActiveFloors} from '../../../src/render/indoor_parser'; |
| 4 | +import {CanonicalTileID} from '../../../src/source/tile_id'; |
| 5 | +import Actor from '../../../src/util/actor'; |
| 6 | + |
| 7 | +// Mock Actor |
| 8 | +const mockTarget = { |
| 9 | + addEventListener: () => {}, |
| 10 | + removeEventListener: () => {}, |
| 11 | + postMessage: () => {} |
| 12 | +}; |
| 13 | +const actor = new Actor(mockTarget as any, {} as any, 0); |
| 14 | +actor.send = () => ({cancel: () => {}}); |
| 15 | + |
| 16 | +describe('IndoorParser', () => { |
| 17 | + test('parses buildings with center_lat and center_lon', () => { |
| 18 | + const feature = { |
| 19 | + properties: { |
| 20 | + type: 'structure', |
| 21 | + id: '123', |
| 22 | + name: 'Test Building', |
| 23 | + center_lat: 40.7128, |
| 24 | + center_lon: -74.0060 |
| 25 | + }, |
| 26 | + loadGeometry: () => [] |
| 27 | + }; |
| 28 | + |
| 29 | + const data = { |
| 30 | + layers: { |
| 31 | + 'indoor-layer': { |
| 32 | + length: 1, |
| 33 | + feature: () => feature |
| 34 | + } |
| 35 | + } |
| 36 | + }; |
| 37 | + |
| 38 | + const indoorTileOptions = { |
| 39 | + indoorState: { |
| 40 | + activeFloorsVisible: false, |
| 41 | + activeFloors: new Set(), |
| 42 | + selectedFloorId: '' |
| 43 | + }, |
| 44 | + sourceLayers: new Set(['indoor-layer']) |
| 45 | + }; |
| 46 | + |
| 47 | + let parsedData: any; |
| 48 | + actor.send = (type, data) => { |
| 49 | + if (type === 'setIndoorData') { |
| 50 | + parsedData = data; |
| 51 | + } |
| 52 | + return {cancel: () => {}}; |
| 53 | + }; |
| 54 | + |
| 55 | + parseActiveFloors(data as any, indoorTileOptions as any, actor, new CanonicalTileID(0, 0, 0)); |
| 56 | + |
| 57 | + expect(parsedData).toBeDefined(); |
| 58 | + expect(parsedData.buildings['123']).toBeDefined(); |
| 59 | + expect(parsedData.buildings['123'].center).toEqual([-74.0060, 40.7128]); |
| 60 | + }); |
| 61 | + |
| 62 | + test('parses floors with structure_ids', () => { |
| 63 | + const buildingFeature = { |
| 64 | + properties: { |
| 65 | + type: 'structure', |
| 66 | + id: '123', |
| 67 | + name: 'Test Building', |
| 68 | + center_lat: 40, |
| 69 | + center_lon: -74 |
| 70 | + }, |
| 71 | + loadGeometry: () => [] |
| 72 | + }; |
| 73 | + |
| 74 | + const floorFeature = { |
| 75 | + properties: { |
| 76 | + type: 'floor', |
| 77 | + id: 'f1', |
| 78 | + name: 'Floor 1', |
| 79 | + z_index: 0, |
| 80 | + structure_ids: '123;456' |
| 81 | + }, |
| 82 | + loadGeometry: () => [[[{x: 0, y: 0}, {x: 10, y: 0}, {x: 10, y: 10}, {x: 0, y: 10}, {x: 0, y: 0}]]] |
| 83 | + }; |
| 84 | + |
| 85 | + const data = { |
| 86 | + layers: { |
| 87 | + 'indoor-layer': { |
| 88 | + length: 2, |
| 89 | + feature: (index: number) => (index === 0 ? buildingFeature : floorFeature) |
| 90 | + } |
| 91 | + } |
| 92 | + }; |
| 93 | + |
| 94 | + const indoorTileOptions = { |
| 95 | + indoorState: { |
| 96 | + activeFloorsVisible: false, |
| 97 | + activeFloors: new Set(), |
| 98 | + selectedFloorId: '' |
| 99 | + }, |
| 100 | + sourceLayers: new Set(['indoor-layer']) |
| 101 | + }; |
| 102 | + |
| 103 | + let parsedData: any; |
| 104 | + actor.send = (type, data) => { |
| 105 | + if (type === 'setIndoorData') { |
| 106 | + parsedData = data; |
| 107 | + } |
| 108 | + return {cancel: () => {}}; |
| 109 | + }; |
| 110 | + |
| 111 | + parseActiveFloors(data as any, indoorTileOptions as any, actor, new CanonicalTileID(0, 0, 0)); |
| 112 | + |
| 113 | + expect(parsedData).toBeDefined(); |
| 114 | + expect(parsedData.buildings['123'].floors['f1']).toBeDefined(); |
| 115 | + expect(parsedData.buildings['123'].floors['f1'].buildings.has('123')).toBe(true); |
| 116 | + expect(parsedData.buildings['123'].floors['f1'].buildings.has('456')).toBe(true); |
| 117 | + expect(parsedData.buildings['456']).toBeDefined(); |
| 118 | + expect(parsedData.buildings['456'].floors['f1']).toBeDefined(); |
| 119 | + }); |
| 120 | +}); |
0 commit comments