Files
supabase/apps/studio/components/layouts/Navigation/NavigationBar/MobileProjectSwitcher.utils.test.ts
Joshen Lim 607dc2bfde Chore/cleanup dead code in project branch selector (#52691)
## Context

Just some housekeeping here while going through the repo, realised that
there's dead code in `ProjectBranchSwitcher`

## Changes involved:
- `ProjectBranchSelector` is only rendered by `MobileNavigationBar`,
which `DefaultLayout` only mounts when `useBreakpoint('md')` is true.
The selector's own `isMobile` check used the same breakpoint, so its
desktop `Popover` branch could never run.

- The name `ProjectBranchSelector` is also misleading since the sheet
switches more than just the project's branch + it's mobile-only, so
opting to rename it to `MobileProjectSwitcher` instead

- Also fix org rows in the sheet being tighter than project rows.
`compactPadding` was inverted, so the embedded list got `p-0.5` on the
item and lost the default `px-2 py-1.5`

- Align buttons in `ProjectBranchSelector` across all tabs + use outline
variant for secondary action

| Previous | Updated |
|---|---|
| <img width="352" height="174" alt="image"
src="https://github.com/user-attachments/assets/24cb2985-b568-4bc1-8f53-ab3914ef0804"
/> | <img width="351" height="161" alt="image"
src="https://github.com/user-attachments/assets/e6e9b0e9-c075-4235-93ca-80c5d070c287"
/> |
| <img width="336" height="248" alt="image"
src="https://github.com/user-attachments/assets/4071b73f-f741-4598-ba01-8dc7bb6ba57a"
/> | <img width="335" height="313" alt="image"
src="https://github.com/user-attachments/assets/2bea398d-ebe9-4641-9bfe-c4a7b6b10c51"
/> |

If you meant a different table, tell me what the two columns should be.
For example, file and change, or before and after behaviour.
2026-11-04 13:33:05 +08:00

86 lines
2.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { getMobileProjectSwitcherState } from './MobileProjectSwitcher.utils'
describe('getMobileProjectSwitcherState', () => {
it('returns main branch when branching disabled', () => {
const result = getMobileProjectSwitcherState({
selectedBranch: undefined,
isBranchingEnabled: false,
selectedOrganization: undefined,
})
expect(result.isMainBranch).toBe(true)
expect(result.branchDisplayName).toBe('main')
})
it('returns main when branching enabled and selected branch is default', () => {
const result = getMobileProjectSwitcherState({
selectedBranch: {
id: '1',
name: 'main',
project_ref: 'ref',
is_default: true,
created_at: '',
} as any,
isBranchingEnabled: true,
selectedOrganization: undefined,
})
expect(result.isMainBranch).toBe(true)
expect(result.branchDisplayName).toBe('main')
})
it('returns non-main when branching enabled and selected branch is not default', () => {
const result = getMobileProjectSwitcherState({
selectedBranch: {
id: '2',
name: 'feature-x',
project_ref: 'ref-2',
is_default: false,
created_at: '',
} as any,
isBranchingEnabled: true,
selectedOrganization: undefined,
})
expect(result.isMainBranch).toBe(false)
expect(result.branchDisplayName).toBe('feature-x')
})
it('returns main when selected branch undefined and branching enabled', () => {
const result = getMobileProjectSwitcherState({
selectedBranch: undefined,
isBranchingEnabled: true,
selectedOrganization: undefined,
})
expect(result.branchDisplayName).toBe('main')
})
it('returns organization href when org has slug', () => {
const result = getMobileProjectSwitcherState({
selectedBranch: undefined,
isBranchingEnabled: false,
selectedOrganization: { slug: 'my-org', name: 'My Org' } as any,
})
expect(result.organizationHref).toBe('/org/my-org')
expect(result.selectedOrgInitial).toBe('M')
})
it('returns organizations fallback when no org slug', () => {
const result = getMobileProjectSwitcherState({
selectedBranch: undefined,
isBranchingEnabled: false,
selectedOrganization: undefined,
})
expect(result.organizationHref).toBe('/organizations')
expect(result.selectedOrgInitial).toBe('O')
})
it('handles org name with leading/trailing spaces for initial', () => {
const result = getMobileProjectSwitcherState({
selectedBranch: undefined,
isBranchingEnabled: false,
selectedOrganization: { slug: 'x', name: ' Acme ' } as any,
})
expect(result.selectedOrgInitial).toBe('A')
})
})