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