| 12345678910111213141516171819202122232425262728 |
- import assert from 'node:assert/strict'
- import { readFile } from 'node:fs/promises'
- import { register } from 'node:module'
- register('./t32-adapter-io-loader.mjs',import.meta.url)
- const { createCesiumPipeModels } = await import('../../../src/modules/cockpit/services/cesiumPipeModels.js')
- globalThis.t32Models=[];globalThis.t32TerrainFails=false
- globalThis.window={location:{href:'http://test.invalid/cockpit/',origin:'http://test.invalid'}}
- const nativeFetch=globalThis.fetch
- try {
- globalThis.fetch=async input=>String(input).startsWith('blob:')?nativeFetch(input):new Response(await readFile(new URL('../../../public/cockpit/models/pipes/spline.gltf',import.meta.url),'utf8'))
- const source={entities:{values:[{id:'pipe:ready',show:true,polyline:{}},{id:'pipe:no-diameter',show:true,polyline:{}}]}}
- const viewer={terrainProvider:{},isDestroyed:()=>false,scene:{requestRender(){},primitives:{add(){},remove(model){model.destroy()}}}}
- const layer=createCesiumPipeModels(viewer,{source,base:'/',viewMode:'ground'})
- const pipe=(code,diameter)=>({code,diameter,industry:'GAS',positions:[[110.39,28.44],[110.3901,28.44]]})
- await layer.sync({pipes:[pipe('ready',400),{...pipe('no-diameter',null),industry:'UNKNOWN'}],components:[]})
- const guides=()=>source.entities.values.map(e=>e.polyline.distanceDisplayCondition.near)
- assert.deepEqual(guides(),[0,0],'pending objects keep ground guides at all distances')
- globalThis.t32Models[0].readyEvent.raiseEvent()
- assert.deepEqual(guides(),[0,0],'ground view must not hide ready pipe guide below 600m')
- const loads=globalThis.t32Models.length
- layer.setViewMode('pipeline')
- assert.deepEqual(guides(),[600,0],'only ready model guides hide close up in underground view')
- layer.setViewMode('ground')
- assert.deepEqual(guides(),[0,0],'returning to ground restores all guides immediately')
- assert.equal(globalThis.t32Models.length,loads,'view changes cannot rebuild GPU batches')
- layer.destroy()
- console.log('PASS ground/pipeline guide distances respect current view without model reload')
- } finally {globalThis.fetch=nativeFetch}
|