OrganizationLayout.utils.test.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { describe, expect, it } from 'vitest'
  2. import { getPathnameWithoutQuery, isOrgMenuScope } from './OrganizationLayout.utils'
  3. describe('getPathnameWithoutQuery', () => {
  4. it('strips query string from path', () => {
  5. expect(getPathnameWithoutQuery('/org/my-org?foo=bar', undefined)).toBe('/org/my-org')
  6. })
  7. it('returns asPath when no query', () => {
  8. expect(getPathnameWithoutQuery('/org/my-org', undefined)).toBe('/org/my-org')
  9. })
  10. it('uses fallback when asPath is undefined', () => {
  11. expect(getPathnameWithoutQuery(undefined, '/account/me')).toBe('/account/me')
  12. })
  13. it('returns empty string for invalid input', () => {
  14. expect(getPathnameWithoutQuery(undefined, undefined)).toBe('')
  15. expect(getPathnameWithoutQuery('', '')).toBe('')
  16. })
  17. })
  18. describe('isOrgMenuScope', () => {
  19. it('returns true for /org/ routes', () => {
  20. expect(isOrgMenuScope('/org/my-org')).toBe(true)
  21. expect(isOrgMenuScope('/org/my-org/team')).toBe(true)
  22. })
  23. it('returns false for non-org routes', () => {
  24. expect(isOrgMenuScope('/account/me')).toBe(false)
  25. expect(isOrgMenuScope('/project/ref/editor')).toBe(false)
  26. expect(isOrgMenuScope('/organizations')).toBe(false)
  27. })
  28. it('returns false for invalid input', () => {
  29. expect(isOrgMenuScope('')).toBe(false)
  30. expect(isOrgMenuScope(null as any)).toBe(false)
  31. expect(isOrgMenuScope(undefined as any)).toBe(false)
  32. })
  33. it('handles trimmed paths', () => {
  34. expect(isOrgMenuScope(' /org/xyz ')).toBe(true)
  35. })
  36. })