cockpitRoofPilotConfig.test.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import assert from 'node:assert/strict'
  2. import test from 'node:test'
  3. import { existsSync, readFileSync } from 'node:fs'
  4. import { loadCockpitConfig, resetCockpitConfigForTest } from '../src/modules/cockpit/services/cockpitConfig.js'
  5. const prefix = '/gis/cad-bim/city-regions-v10-cs33'
  6. const coarse = `${prefix}/coarse-tileset.json`
  7. const baseline = `${prefix}/runtime-manifest.json`
  8. const pilot = `${prefix}-t132-pilot/runtime-manifest.json`
  9. const raw = { map: { tilesets: [{ url: coarse, regionManifest: baseline }] } }
  10. async function load(href, env = { DEV: true }, input = raw) {
  11. resetCockpitConfigForTest()
  12. const { config } = await loadCockpitConfig({ env, scope: { location: new URL(href), __COCKPIT_CONFIG__: input } })
  13. return config.map.tilesets
  14. }
  15. test('the explicit local development pilot selects the candidate without changing the coarse tileset', async () => {
  16. const [tile] = await load('http://localhost:8000/?roofPilot=132#/cockpit')
  17. assert.equal(tile.regionManifest, pilot)
  18. assert.equal(tile.url, coarse)
  19. assert.equal(raw.map.tilesets[0].regionManifest, baseline)
  20. })
  21. test('the default tab, production build, non-loopback host and other batches are untouched', async () => {
  22. for (const [href, env] of [
  23. ['http://localhost:8000/#/cockpit', { DEV: true }],
  24. ['http://localhost:8000/?roofPilot=132#/cockpit', { DEV: false }],
  25. ['http://192.0.2.5:8000/?roofPilot=132#/cockpit', { DEV: true }],
  26. ]) assert.equal((await load(href, env))[0].regionManifest, baseline)
  27. const different = { map: { tilesets: [{ url: '/gis/coarse.json', regionManifest: '/gis/other.json' }] } }
  28. assert.equal((await load('http://127.0.0.1:8000/?roofPilot=132', { DEV: true }, different))[0].regionManifest, '/gis/other.json')
  29. })
  30. const assetRoot = new URL('../tools/city-massing/city/cad-bim/', import.meta.url)
  31. const originalManifest = new URL('city-regions-v10-cs33/runtime-manifest.json', assetRoot)
  32. const candidateManifest = new URL('city-regions-v10-cs33-t132-pilot/runtime-manifest.json', assetRoot)
  33. test('the candidate manifest preserves all baseline routes except region 44', {
  34. skip: !existsSync(originalManifest) || !existsSync(candidateManifest) ? 'local pilot assets are not installed' : false,
  35. }, () => {
  36. const original = JSON.parse(readFileSync(originalManifest))
  37. const candidate = JSON.parse(readFileSync(candidateManifest))
  38. assert.deepEqual(candidate.transform, original.transform)
  39. assert.deepEqual(candidate.lodLevels, original.lodLevels)
  40. const originalRoot = new URL(baseline, 'http://localhost:8000')
  41. const candidateRoot = new URL(pilot, originalRoot)
  42. assert.equal(candidate.regions.length, 113)
  43. for (let i = 0; i < original.regions.length; i++) {
  44. const { url: before, ...a } = original.regions[i]
  45. const { url: after, ...b } = candidate.regions[i]
  46. assert.deepEqual(a, b)
  47. const want = new URL(before, a.id === 44 ? candidateRoot : originalRoot).href
  48. assert.equal(new URL(after, candidateRoot).href, want)
  49. }
  50. })