Files
supabase/apps/studio/tests/routes/_app/account/me.test.tsx
Alaister YoungandAlaister Young d2eb58a0e7 [FE-3106] (part 3) – refactor(studio): move account and top-level page bodies (#53212)
Moves the account and top-level app page bodies (`/account/*`,
`/organizations`, `/new`, `/new/$slug`, `/join`, `/claim-project`,
`/aws-marketplace-onboarding`, `/stripe-atlas-application`,
`/support/new`, `/support/link`, `/integrations/github|vercel/*`) from
`pages/**` into their TanStack route files and deletes the pages. Part
of the final pass of the TanStack migration (FE-3106). Part 3 of the
stack, and the first page-move PR.

**Depends on:** #53202

**Changed:**
- `routes/_app/account/**`,
`routes/_app/{organizations,new/index,support/*}.tsx`,
`routes/{new/$slug,join,claim-project,aws-marketplace-onboarding,stripe-atlas-application}.tsx`,
`routes/integrations/**` – page bodies inlined.
`next/router`/`next/link`/`next/head` → `useNavigate`, `Link`,
`<Navigate>` and inline `<title>`. `getLayout` dropped; every old
`getLayout` was checked against the route tree and matches
- `routes/aws-marketplace-onboarding.tsx` – reads `buyer_id` through
`validateSearch` + `Route.useSearch()`
- `tests/lib/route-render.tsx` – new `renderRoute(Route, { routeId, url
})` helper that mounts a file route in a memory router (with the app's
search serializers) so route components can be tested; used by the moved
tests
- `tests/lib/route-mock.ts` – the `next/router` mock now derives its
dynamic-route patterns from `routes/**` instead of globbing `pages/**`,
so tests keep parsing params as pages disappear
- `tests/routes/**` – page tests moved from `tests/pages/**` and
rendered through the route
- `.github/CODEOWNERS` – `pages/new/index.tsx` owner moved to
`routes/_app/new/index.tsx`

**Removed:**
- 19 files under `pages/account/**`, `pages/new/**`,
`pages/support/{new,link}.tsx`, `pages/integrations/**` and the
top-level pages listed above

Addresses
[FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages).

## To test

- Open `/account/me`, `/account/security`, `/account/tokens`,
`/account/audit` – same Account layout, header title and sidebar as
before
- Open an old email-change link (`/account/me#message=...`) – lands on
`/account/security` with the hash
- `/account/tokens/scoped` – redirects to `/account/tokens`
- `/organizations` and `/new/<org>` – render with the same layout; "New
organization" links work
- Vercel install/marketplace flows – navigation keeps `?…` params

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-11-17 14:46:37 +09:00

129 lines
4.3 KiB
TypeScript

import { screen } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { Route } from '@/routes/_app/account/me'
import { renderRoute } from '@/tests/lib/route-render'
const { mockIsPlatform, mockUseIsFeatureEnabled, mockUseProfile } = vi.hoisted(() => ({
mockIsPlatform: { value: true },
mockUseIsFeatureEnabled: vi.fn(),
mockUseProfile: vi.fn(),
}))
vi.mock('@/lib/constants', async () => {
const actual = await vi.importActual<Record<string, unknown>>('@/lib/constants')
return {
...actual,
get IS_PLATFORM() {
return mockIsPlatform.value
},
}
})
vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({
useIsFeatureEnabled: mockUseIsFeatureEnabled,
}))
vi.mock('@/lib/profile', () => ({
useProfile: mockUseProfile,
}))
vi.mock('@/components/interfaces/Account/Preferences/ProfileInformation', () => ({
ProfileInformation: () => <div>ProfileInformation</div>,
}))
vi.mock('@/components/interfaces/Account/Preferences/AccountConnections', () => ({
AccountConnections: () => <div>AccountConnections</div>,
}))
vi.mock('@/components/interfaces/Account/Preferences/ThemeSettings', () => ({
ThemeSettings: () => <div>ThemeSettings</div>,
}))
vi.mock('@/components/interfaces/Account/Preferences/TimezoneSettings', () => ({
TimezoneSettings: () => <div>TimezoneSettings</div>,
}))
vi.mock('@/components/interfaces/Account/Preferences/HotkeySettings', () => ({
HotkeySettings: () => <div>HotkeySettings</div>,
}))
vi.mock('@/components/interfaces/Account/Preferences/DashboardSettings', () => ({
DashboardSettings: () => <div>DashboardSettings</div>,
}))
vi.mock('@/components/interfaces/Account/Preferences/AnalyticsSettings', () => ({
AnalyticsSettings: () => <div>AnalyticsSettings</div>,
}))
vi.mock('@/components/interfaces/Account/Preferences/AccountDeletion', () => ({
AccountDeletion: () => <div>AccountDeletion</div>,
}))
vi.mock('@/components/ui/AlertError', () => ({
AlertError: () => <div>AlertError</div>,
}))
const renderPreferences = (url = '/account/me') =>
renderRoute(Route, { routeId: '/_app/account/me', url })
describe('/account/me', () => {
beforeEach(() => {
mockIsPlatform.value = true
mockUseIsFeatureEnabled.mockClear()
mockUseProfile.mockClear()
mockUseIsFeatureEnabled.mockReturnValue({
profileShowInformation: true,
profileShowAnalyticsAndMarketing: true,
profileShowAccountDeletion: true,
})
mockUseProfile.mockReturnValue({
error: null,
isLoading: false,
isError: false,
isSuccess: true,
})
})
it('renders hosted account sections on platform', async () => {
mockIsPlatform.value = true
await renderPreferences()
expect(screen.getByText('ProfileInformation')).toBeInTheDocument()
expect(screen.getByText('AccountConnections')).toBeInTheDocument()
expect(screen.getByText('ThemeSettings')).toBeInTheDocument()
expect(screen.getByText('TimezoneSettings')).toBeInTheDocument()
expect(screen.getByText('HotkeySettings')).toBeInTheDocument()
expect(screen.getByText('DashboardSettings')).toBeInTheDocument()
expect(screen.getByText('AnalyticsSettings')).toBeInTheDocument()
expect(screen.getByText('AccountDeletion')).toBeInTheDocument()
})
it.each([
'/account/me',
'/account/me#dashboard',
'/account/me#type=recovery',
'/account/me#access_token=test-access&refresh_token=test-refresh&type=email_change',
])('keeps an ordinary Preferences visit at %s', async (url) => {
const { router } = await renderPreferences(url)
expect(router.state.location.pathname).toBe('/account/me')
})
it('renders only local preferences on self-hosted', async () => {
mockIsPlatform.value = false
await renderPreferences()
expect(screen.getByText('ThemeSettings')).toBeInTheDocument()
expect(screen.getByText('TimezoneSettings')).toBeInTheDocument()
expect(screen.getByText('HotkeySettings')).toBeInTheDocument()
expect(screen.getByText('DashboardSettings')).toBeInTheDocument()
expect(screen.queryByText('ProfileInformation')).not.toBeInTheDocument()
expect(screen.queryByText('AccountConnections')).not.toBeInTheDocument()
expect(screen.queryByText('AnalyticsSettings')).not.toBeInTheDocument()
expect(screen.queryByText('AccountDeletion')).not.toBeInTheDocument()
expect(mockUseProfile).not.toHaveBeenCalled()
})
})