NavigationBar.utils.test.tsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import { describe, expect, it } from 'vitest'
  2. import {
  3. generateOtherRoutes,
  4. generateProductRoutes,
  5. generateSettingsRoutes,
  6. generateToolRoutes,
  7. } from './NavigationBar.utils'
  8. import type { Project } from '@/data/projects/project-detail-query'
  9. const REF = 'test-project-ref'
  10. const activeProject = { status: 'ACTIVE_HEALTHY' } as Project
  11. const buildingProject = { status: 'COMING_UP' } as Project
  12. const inactiveProject = { status: 'INACTIVE' } as Project
  13. const keys = (routes: { key: string }[]) => routes.map((r) => r.key)
  14. describe('generateToolRoutes', () => {
  15. it('always returns Table Editor and SQL Editor', () => {
  16. const routes = generateToolRoutes(REF, activeProject)
  17. expect(keys(routes)).toEqual(['editor', 'sql'])
  18. })
  19. it('marks routes as disabled when project is not active', () => {
  20. const routes = generateToolRoutes(REF, inactiveProject)
  21. expect(routes.every((r) => r.disabled)).toBe(true)
  22. })
  23. it('points links to the building URL when project is building', () => {
  24. const routes = generateToolRoutes(REF, buildingProject)
  25. expect(routes.every((r) => r.link === `/project/${REF}`)).toBe(true)
  26. })
  27. it('returns links as false when ref is undefined', () => {
  28. const routes = generateToolRoutes(undefined, activeProject)
  29. expect(routes.every((r) => r.link === undefined)).toBe(true)
  30. })
  31. })
  32. describe('generateProductRoutes', () => {
  33. it('includes all product routes when all features are enabled', () => {
  34. const routes = generateProductRoutes(REF, activeProject, {
  35. auth: true,
  36. storage: true,
  37. edgeFunctions: true,
  38. realtime: true,
  39. })
  40. expect(keys(routes)).toEqual(['database', 'auth', 'storage', 'functions', 'realtime'])
  41. })
  42. it('includes all product routes by default (features default to true)', () => {
  43. const routes = generateProductRoutes(REF, activeProject)
  44. expect(keys(routes)).toEqual(['database', 'auth', 'storage', 'functions', 'realtime'])
  45. })
  46. it('excludes auth when auth feature is disabled', () => {
  47. const routes = generateProductRoutes(REF, activeProject, { auth: false })
  48. expect(keys(routes)).not.toContain('auth')
  49. expect(keys(routes)).toContain('database')
  50. expect(keys(routes)).toContain('storage')
  51. })
  52. it('excludes storage when storage feature is disabled', () => {
  53. const routes = generateProductRoutes(REF, activeProject, { storage: false })
  54. expect(keys(routes)).not.toContain('storage')
  55. })
  56. it('excludes edge functions when edgeFunctions feature is disabled', () => {
  57. const routes = generateProductRoutes(REF, activeProject, { edgeFunctions: false })
  58. expect(keys(routes)).not.toContain('functions')
  59. })
  60. it('excludes realtime when realtime feature is disabled', () => {
  61. const routes = generateProductRoutes(REF, activeProject, { realtime: false })
  62. expect(keys(routes)).not.toContain('realtime')
  63. })
  64. it('links auth to overview page when authOverviewPage is enabled', () => {
  65. const routes = generateProductRoutes(REF, activeProject, { authOverviewPage: true })
  66. const authRoute = routes.find((r) => r.key === 'auth')
  67. expect(authRoute?.link).toBe(`/project/${REF}/auth/overview`)
  68. })
  69. it('links auth to users page by default', () => {
  70. const routes = generateProductRoutes(REF, activeProject)
  71. const authRoute = routes.find((r) => r.key === 'auth')
  72. expect(authRoute?.link).toBe(`/project/${REF}/auth/users`)
  73. })
  74. it('always includes database even when all optional features are disabled', () => {
  75. const routes = generateProductRoutes(REF, activeProject, {
  76. auth: false,
  77. storage: false,
  78. edgeFunctions: false,
  79. realtime: false,
  80. })
  81. expect(keys(routes)).toEqual(['database'])
  82. })
  83. })
  84. describe('generateOtherRoutes', () => {
  85. it('always includes advisors, logs, and integrations', () => {
  86. const routes = generateOtherRoutes(REF, activeProject, { isPlatform: true })
  87. expect(keys(routes)).toContain('advisors')
  88. expect(keys(routes)).toContain('logs')
  89. expect(keys(routes)).toContain('integrations')
  90. })
  91. it('includes observability on platform when reports are enabled', () => {
  92. const routes = generateOtherRoutes(REF, activeProject, {
  93. isPlatform: true,
  94. showReports: true,
  95. })
  96. expect(keys(routes)).toContain('observability')
  97. })
  98. it('excludes observability on platform when reports are disabled', () => {
  99. const routes = generateOtherRoutes(REF, activeProject, {
  100. isPlatform: true,
  101. showReports: false,
  102. })
  103. expect(keys(routes)).not.toContain('observability')
  104. })
  105. it('excludes observability in self-hosted mode even when reports are enabled', () => {
  106. const routes = generateOtherRoutes(REF, activeProject, {
  107. isPlatform: false,
  108. showReports: true,
  109. })
  110. expect(keys(routes)).not.toContain('observability')
  111. })
  112. it('excludes observability in self-hosted mode when reports are disabled', () => {
  113. const routes = generateOtherRoutes(REF, activeProject, {
  114. isPlatform: false,
  115. showReports: false,
  116. })
  117. expect(keys(routes)).not.toContain('observability')
  118. })
  119. it('does not include API Docs nav item', () => {
  120. const routes = generateOtherRoutes(REF, activeProject, { isPlatform: true })
  121. expect(keys(routes)).not.toContain('api')
  122. })
  123. it('links logs to unified logs page when unifiedLogs is enabled', () => {
  124. const routes = generateOtherRoutes(REF, activeProject, {
  125. isPlatform: true,
  126. unifiedLogs: true,
  127. })
  128. const logsRoute = routes.find((r) => r.key === 'logs')
  129. expect(logsRoute?.link).toBe(`/project/${REF}/logs`)
  130. })
  131. it('links logs to explorer page by default', () => {
  132. const routes = generateOtherRoutes(REF, activeProject, { isPlatform: true })
  133. const logsRoute = routes.find((r) => r.key === 'logs')
  134. expect(logsRoute?.link).toBe(`/project/${REF}/logs/explorer`)
  135. })
  136. it('points links to building URL when project is building', () => {
  137. const routes = generateOtherRoutes(REF, buildingProject, {
  138. isPlatform: true,
  139. showReports: true,
  140. })
  141. const observabilityRoute = routes.find((r) => r.key === 'observability')
  142. expect(observabilityRoute?.link).toBe(`/project/${REF}`)
  143. })
  144. it('marks routes as disabled when project is not active', () => {
  145. const routes = generateOtherRoutes(REF, inactiveProject, { isPlatform: true })
  146. const advisorsRoute = routes.find((r) => r.key === 'advisors')
  147. expect(advisorsRoute?.disabled).toBe(true)
  148. })
  149. })
  150. describe('generateSettingsRoutes', () => {
  151. it('links to general settings on platform', () => {
  152. const routes = generateSettingsRoutes(REF, { isPlatform: true })
  153. const settingsRoute = routes.find((r) => r.key === 'settings')
  154. expect(settingsRoute?.link).toBe(`/project/${REF}/settings/general`)
  155. })
  156. it('links to log-drains settings in self-hosted mode', () => {
  157. const routes = generateSettingsRoutes(REF, { isPlatform: false })
  158. const settingsRoute = routes.find((r) => r.key === 'settings')
  159. expect(settingsRoute?.link).toBe(`/project/${REF}/settings/log-drains`)
  160. })
  161. it('returns a link as false when ref is undefined', () => {
  162. const routes = generateSettingsRoutes(undefined, { isPlatform: true })
  163. const settingsRoute = routes.find((r) => r.key === 'settings')
  164. expect(settingsRoute?.link).toBe(undefined)
  165. })
  166. })