mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Context Some minor UI issues that I found while reviewing another PR - Fix `NoProjectsOnPaidOrgInfo` prematurely showing while project details is still loading <img width="1249" height="376" alt="image" src="https://github.com/user-attachments/assets/3f41f4a3-849f-4685-bcc4-6fed3b433042" /> - Fix padding alignment for Organization details form group <img width="1115" height="282" alt="image" src="https://github.com/user-attachments/assets/c0865614-208c-4335-87d3-176c4411b6a4" /> - Fix projects list on `/org/[slug]` showing stale projects while switching orgs - just removed `keepPreviousData` so that the card loaders shows up - Fix organization settings in sidebar menu not showing active state while on certain settings pages like audit-log-drains, webhooks, etc
104 lines
4.2 KiB
TypeScript
104 lines
4.2 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
getOrgActiveRoute,
|
|
getOrgSectionKeyFromPathname,
|
|
isOrgMenuActive,
|
|
type OrgNavItem,
|
|
} from './OrgMenuContent.utils'
|
|
|
|
const mockItem = (key: string): OrgNavItem => ({
|
|
key,
|
|
label: key,
|
|
href: `/org/foo/${key}`,
|
|
icon: null,
|
|
})
|
|
|
|
describe('getOrgActiveRoute', () => {
|
|
it('returns segment after org slug', () => {
|
|
expect(getOrgActiveRoute('/org/my-org/team')).toBe('team')
|
|
expect(getOrgActiveRoute('/org/my-org/integrations')).toBe('integrations')
|
|
expect(getOrgActiveRoute('/org/my-org/settings/general')).toBe('settings')
|
|
})
|
|
|
|
it('returns undefined for org home', () => {
|
|
expect(getOrgActiveRoute('/org/my-org')).toBeUndefined()
|
|
expect(getOrgActiveRoute('/org/my-org/')).toBeUndefined()
|
|
})
|
|
|
|
it('returns undefined when path too short', () => {
|
|
expect(getOrgActiveRoute('/org')).toBeUndefined()
|
|
expect(getOrgActiveRoute('/')).toBeUndefined()
|
|
expect(getOrgActiveRoute('')).toBeUndefined()
|
|
})
|
|
|
|
it('returns undefined when org segment not found', () => {
|
|
expect(getOrgActiveRoute('/project/ref/database')).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
describe('isOrgMenuActive', () => {
|
|
it('first item (index 0) is active when activeRoute is undefined', () => {
|
|
expect(isOrgMenuActive(mockItem('projects'), 0, '/org/foo', undefined)).toBe(true)
|
|
})
|
|
|
|
it('first item is not active when activeRoute is defined', () => {
|
|
expect(isOrgMenuActive(mockItem('projects'), 0, '/org/foo/team', 'team')).toBe(false)
|
|
})
|
|
|
|
it('item is active when activeRoute matches item key', () => {
|
|
expect(isOrgMenuActive(mockItem('team'), 1, '/org/foo/team', 'team')).toBe(true)
|
|
expect(
|
|
isOrgMenuActive(mockItem('integrations'), 2, '/org/foo/integrations', 'integrations')
|
|
).toBe(true)
|
|
})
|
|
|
|
it('settings item is active when pathname includes settings sub-routes', () => {
|
|
expect(isOrgMenuActive(mockItem('settings'), 5, '/org/foo/settings/general', 'settings')).toBe(
|
|
true
|
|
)
|
|
expect(isOrgMenuActive(mockItem('settings'), 5, '/org/foo/general', undefined)).toBe(true)
|
|
expect(isOrgMenuActive(mockItem('settings'), 5, '/org/foo/apps', undefined)).toBe(true)
|
|
expect(isOrgMenuActive(mockItem('settings'), 5, '/org/foo/audit', undefined)).toBe(true)
|
|
expect(isOrgMenuActive(mockItem('settings'), 5, '/org/foo/documents', undefined)).toBe(true)
|
|
expect(isOrgMenuActive(mockItem('settings'), 5, '/org/foo/security', undefined)).toBe(true)
|
|
expect(isOrgMenuActive(mockItem('settings'), 5, '/org/foo/sso', undefined)).toBe(true)
|
|
expect(isOrgMenuActive(mockItem('settings'), 5, '/org/foo/audit-log-drains', undefined)).toBe(
|
|
true
|
|
)
|
|
expect(isOrgMenuActive(mockItem('settings'), 5, '/org/foo/webhooks', undefined)).toBe(true)
|
|
expect(isOrgMenuActive(mockItem('settings'), 5, '/org/foo/private-apps', undefined)).toBe(true)
|
|
})
|
|
|
|
it('settings item is not active when pathname has no settings sub-route', () => {
|
|
expect(isOrgMenuActive(mockItem('settings'), 5, '/org/foo/team', 'team')).toBe(false)
|
|
})
|
|
|
|
it('item is not active when activeRoute does not match', () => {
|
|
expect(isOrgMenuActive(mockItem('team'), 1, '/org/foo/team', 'usage')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('getOrgSectionKeyFromPathname', () => {
|
|
it('returns settings for org settings sub-routes', () => {
|
|
expect(getOrgSectionKeyFromPathname('general')).toBe('settings')
|
|
expect(getOrgSectionKeyFromPathname('security')).toBe('settings')
|
|
expect(getOrgSectionKeyFromPathname('sso')).toBe('settings')
|
|
expect(getOrgSectionKeyFromPathname('apps')).toBe('settings')
|
|
expect(getOrgSectionKeyFromPathname('audit')).toBe('settings')
|
|
expect(getOrgSectionKeyFromPathname('documents')).toBe('settings')
|
|
expect(getOrgSectionKeyFromPathname('audit-log-drains')).toBe('settings')
|
|
})
|
|
|
|
it('returns null for non-settings routes', () => {
|
|
expect(getOrgSectionKeyFromPathname('team')).toBeNull()
|
|
expect(getOrgSectionKeyFromPathname('integrations')).toBeNull()
|
|
expect(getOrgSectionKeyFromPathname('billing')).toBeNull()
|
|
expect(getOrgSectionKeyFromPathname('usage')).toBeNull()
|
|
})
|
|
|
|
it('returns null when activeRoute is undefined', () => {
|
|
expect(getOrgSectionKeyFromPathname(undefined)).toBeNull()
|
|
})
|
|
})
|