| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- import { describe, expect, it } from 'vitest'
- import {
- generateObservabilityMenuItems,
- type ObservabilityMenuSection,
- } from './ObservabilityMenu.utils'
- const REF = 'test-project-ref'
- const QUERY_PARAMS = ''
- const sectionTitles = (sections: ObservabilityMenuSection[]) => sections.map((s) => s.title)
- const itemKeys = (section: ObservabilityMenuSection | undefined) =>
- section?.items.map((i) => i.key) ?? []
- const findSection = (sections: ObservabilityMenuSection[], title: string) =>
- sections.find((s) => s.title === title)
- describe('generateObservabilityMenuItems - PRODUCT section', () => {
- it('includes PRODUCT section on platform', () => {
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: false,
- isSupamonitorEnabled: false,
- storageSupported: true,
- isPlatform: true,
- })
- expect(sectionTitles(menu)).toContain('PRODUCT')
- const productSection = findSection(menu, 'PRODUCT')
- expect(itemKeys(productSection)).toEqual([
- 'database',
- 'postgrest',
- 'auth',
- 'edge-functions',
- 'storage',
- 'realtime',
- ])
- })
- it('excludes PRODUCT section in self-hosted mode', () => {
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: false,
- isSupamonitorEnabled: false,
- storageSupported: true,
- isPlatform: false,
- })
- expect(sectionTitles(menu)).not.toContain('PRODUCT')
- expect(menu.length).toBe(1) // Only GENERAL section
- })
- it('excludes Storage from PRODUCT when storageSupported is false', () => {
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: false,
- isSupamonitorEnabled: false,
- storageSupported: false,
- isPlatform: true,
- })
- const productSection = findSection(menu, 'PRODUCT')
- expect(itemKeys(productSection)).not.toContain('storage')
- expect(itemKeys(productSection)).toEqual([
- 'database',
- 'postgrest',
- 'auth',
- 'edge-functions',
- 'realtime',
- ])
- })
- it('includes Storage in PRODUCT when storageSupported is true', () => {
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: false,
- isSupamonitorEnabled: false,
- storageSupported: true,
- isPlatform: true,
- })
- const productSection = findSection(menu, 'PRODUCT')
- expect(itemKeys(productSection)).toContain('storage')
- })
- })
- describe('generateObservabilityMenuItems - GENERAL section', () => {
- it('always includes GENERAL section', () => {
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: false,
- isSupamonitorEnabled: false,
- storageSupported: true,
- isPlatform: false,
- })
- expect(sectionTitles(menu)).toContain('GENERAL')
- })
- it('includes Query Performance when supamonitor is disabled', () => {
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: false,
- isSupamonitorEnabled: false,
- storageSupported: true,
- isPlatform: false,
- })
- const generalSection = findSection(menu, 'GENERAL')
- expect(itemKeys(generalSection)).toContain('query-performance')
- expect(itemKeys(generalSection)).not.toContain('query-insights')
- })
- it('includes Query Insights when supamonitor is enabled', () => {
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: false,
- isSupamonitorEnabled: true,
- storageSupported: true,
- isPlatform: false,
- })
- const generalSection = findSection(menu, 'GENERAL')
- expect(itemKeys(generalSection)).toContain('query-insights')
- expect(itemKeys(generalSection)).not.toContain('query-performance')
- })
- it('includes Overview when showOverview is true', () => {
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: true,
- isSupamonitorEnabled: false,
- storageSupported: true,
- isPlatform: false,
- })
- const generalSection = findSection(menu, 'GENERAL')
- expect(itemKeys(generalSection)).toContain('observability')
- })
- it('excludes Overview when showOverview is false', () => {
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: false,
- isSupamonitorEnabled: false,
- storageSupported: true,
- isPlatform: false,
- })
- const generalSection = findSection(menu, 'GENERAL')
- expect(itemKeys(generalSection)).not.toContain('observability')
- })
- it('includes API Gateway on platform', () => {
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: false,
- isSupamonitorEnabled: false,
- storageSupported: true,
- isPlatform: true,
- })
- const generalSection = findSection(menu, 'GENERAL')
- expect(itemKeys(generalSection)).toContain('api-overview')
- })
- it('excludes API Gateway in self-hosted mode', () => {
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: false,
- isSupamonitorEnabled: false,
- storageSupported: true,
- isPlatform: false,
- })
- const generalSection = findSection(menu, 'GENERAL')
- expect(itemKeys(generalSection)).not.toContain('api-overview')
- })
- })
- describe('generateObservabilityMenuItems - URL construction', () => {
- it('constructs correct URLs with preserved query params', () => {
- const params = '?its=2024-01-01&ite=2024-01-31'
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: params,
- showOverview: false,
- isSupamonitorEnabled: false,
- storageSupported: true,
- isPlatform: true,
- })
- const generalSection = findSection(menu, 'GENERAL')
- const queryPerfItem = generalSection?.items.find((i) => i.key === 'query-performance')
- expect(queryPerfItem?.url).toBe(`/project/${REF}/observability/query-performance${params}`)
- const productSection = findSection(menu, 'PRODUCT')
- const databaseItem = productSection?.items.find((i) => i.key === 'database')
- expect(databaseItem?.url).toBe(`/project/${REF}/observability/database${params}`)
- })
- it('handles undefined ref', () => {
- const menu = generateObservabilityMenuItems({
- ref: undefined,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: false,
- isSupamonitorEnabled: false,
- storageSupported: true,
- isPlatform: true,
- })
- const generalSection = findSection(menu, 'GENERAL')
- const queryPerfItem = generalSection?.items.find((i) => i.key === 'query-performance')
- expect(queryPerfItem?.url).toBe('/project/undefined/observability/query-performance')
- })
- })
- describe('generateObservabilityMenuItems - complete structure', () => {
- it('returns only GENERAL in self-hosted with all standard items', () => {
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: true,
- isSupamonitorEnabled: false,
- storageSupported: true,
- isPlatform: false,
- })
- expect(menu.length).toBe(1)
- expect(menu[0].title).toBe('GENERAL')
- expect(itemKeys(menu[0])).toEqual([
- 'observability', // Overview
- 'query-performance',
- // API Gateway excluded
- ])
- })
- it('returns GENERAL and PRODUCT on platform with all items', () => {
- const menu = generateObservabilityMenuItems({
- ref: REF,
- preservedQueryParams: QUERY_PARAMS,
- showOverview: true,
- isSupamonitorEnabled: true,
- storageSupported: true,
- isPlatform: true,
- })
- expect(menu.length).toBe(2)
- expect(sectionTitles(menu)).toEqual(['GENERAL', 'PRODUCT'])
- const generalSection = findSection(menu, 'GENERAL')
- expect(itemKeys(generalSection)).toEqual([
- 'observability', // Overview
- 'query-insights', // Supamonitor enabled
- 'api-overview', // Platform only
- ])
- const productSection = findSection(menu, 'PRODUCT')
- expect(itemKeys(productSection)).toEqual([
- 'database',
- 'postgrest',
- 'auth',
- 'edge-functions',
- 'storage',
- 'realtime',
- ])
- })
- })
|