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