Integrations.utils.test.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { describe, expect, it } from 'vitest'
  2. import { getCategoryParamFromAsPath, getIntegrationsPageFromPathname } from './Integrations.utils'
  3. describe('getIntegrationsPageFromPathname', () => {
  4. it('returns section only when no subsection', () => {
  5. expect(getIntegrationsPageFromPathname('/project/abc123/integrations')).toBe('integrations')
  6. })
  7. it('returns section and subsection when both present', () => {
  8. expect(getIntegrationsPageFromPathname('/project/abc123/integrations/xyz-456')).toBe(
  9. 'integrations/xyz-456'
  10. )
  11. })
  12. it('returns empty string when path too short', () => {
  13. expect(getIntegrationsPageFromPathname('/project')).toBe('')
  14. expect(getIntegrationsPageFromPathname('/project/abc123')).toBe('')
  15. expect(getIntegrationsPageFromPathname('/')).toBe('')
  16. expect(getIntegrationsPageFromPathname('')).toBe('')
  17. })
  18. it('returns empty string when project segment not found', () => {
  19. expect(getIntegrationsPageFromPathname('/org/my-org')).toBe('')
  20. })
  21. it('handles trailing slash', () => {
  22. expect(getIntegrationsPageFromPathname('/project/abc123/integrations/')).toBe('integrations')
  23. })
  24. })
  25. describe('getCategoryParamFromAsPath', () => {
  26. it('returns category value when present', () => {
  27. expect(getCategoryParamFromAsPath('/project/ref/integrations?category=wrapper')).toBe('wrapper')
  28. expect(getCategoryParamFromAsPath('/path?category=postgres_extension')).toBe(
  29. 'postgres_extension'
  30. )
  31. })
  32. it('returns null when category absent', () => {
  33. expect(getCategoryParamFromAsPath('/project/ref/integrations')).toBeNull()
  34. expect(getCategoryParamFromAsPath('/path?foo=bar')).toBeNull()
  35. })
  36. it('returns null for invalid input', () => {
  37. expect(getCategoryParamFromAsPath(undefined)).toBeNull()
  38. expect(getCategoryParamFromAsPath('')).toBeNull()
  39. })
  40. })