sidebarRouteUtils.test.mjs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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/waterSupply' },
  16. { path: '/waterSupply' },
  17. { path: '/pipeNetwork' }
  18. ]
  19. assert.deepEqual(
  20. selectSidebarRoutes('/system/menu', routes).map(route => route.path),
  21. ['/index', '/system'],
  22. 'admin pages must not display subsystem routes, including legacy aliases'
  23. )
  24. assert.deepEqual(
  25. selectSidebarRoutes('/subSystem/waterSupply/whome', routes).map(route => route.path),
  26. ['/subSystem/waterSupply'],
  27. 'the water subsystem must display only its own dynamic route tree'
  28. )
  29. assert.equal(
  30. getSubsystemHomePath('waterSupply'),
  31. '/subSystem/waterSupply/index',
  32. 'water fallback navigation must target the backend route namespace'
  33. )
  34. console.log('sidebarRouteUtils tests passed')