sidebarRouteUtils.test.mjs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import assert from 'node:assert/strict'
  2. let selectSidebarRoutes
  3. let getSubsystemHomePath
  4. try {
  5. ({ selectSidebarRoutes, getSubsystemHomePath } = await import('../src/router/sidebarRouteUtils.js'))
  6. } catch {
  7. // The first RED run intentionally reaches this branch before the helper exists.
  8. }
  9. assert.equal(typeof selectSidebarRoutes, 'function', 'sidebar routing must be selected by a shared route helper')
  10. assert.equal(typeof getSubsystemHomePath, 'function', 'subsystem fallback navigation must use canonical route prefixes')
  11. const routes = [
  12. { path: '/index' },
  13. { path: '/system' },
  14. { path: '/subSystem/gas' },
  15. { path: '/subSystem/pipeNetwork' },
  16. { path: '/subSystem/waterSupply' },
  17. { path: '/waterSupply' },
  18. { path: '/pipeNetwork' }
  19. ]
  20. assert.deepEqual(
  21. selectSidebarRoutes('/system/menu', routes).map(route => route.path),
  22. ['/index', '/system'],
  23. 'admin pages must not display subsystem routes, including legacy aliases'
  24. )
  25. assert.deepEqual(
  26. selectSidebarRoutes('/subSystem/waterSupply/whome', routes).map(route => route.path),
  27. ['/subSystem/waterSupply'],
  28. 'the water subsystem must display only its own dynamic route tree'
  29. )
  30. assert.deepEqual(
  31. selectSidebarRoutes('/subSystem/pipeNetwork/index', routes).map(route => route.path),
  32. ['/subSystem/pipeNetwork'],
  33. 'the pipe network subsystem must display only its own dynamic route tree'
  34. )
  35. assert.equal(
  36. getSubsystemHomePath('waterSupply'),
  37. '/subSystem/waterSupply/index',
  38. 'water fallback navigation must target the backend route namespace'
  39. )
  40. assert.equal(
  41. getSubsystemHomePath('pipeNetwork'),
  42. '/subSystem/pipeNetwork/index',
  43. 'pipe network fallback navigation must target the backend route namespace'
  44. )
  45. console.log('sidebarRouteUtils tests passed')