Files
supabase/apps/studio/tests/routes/_auth/sign-up.test.tsx
Alaister YoungandAlaister Young 33ae2caa0d [FE-3106] (part 4) – refactor(studio): move sign-in and standalone page bodies (#53213)
Moves the sign-in and standalone page bodies (`/sign-in`, `/sign-up`,
`/sign-in-sso`, `/sign-in-partner`, `/sign-in-mfa`,
`/sign-in-recovery-code`, `/forgot-password`, `/forgot-password-mfa`,
`/reset-password`, `/cli/login`, `/partners/stripe/projects/login`,
`/authorize`, `/redeem`, `/logout`, `/maintenance`, `/verify-email`,
`/support/csat`, `/mcp/secrets`) into their route files and deletes the
pages (FE-3106). Part 4 of the stack.

**Depends on:** #53212

**Changed:**
- `routes/_auth/**` and the standalone routes – page bodies inlined;
`next/router`/`next/link`/`next/head` → native TanStack (`navigate({ to,
search })`, `search: true` to carry the query, `href` for runtime return
URLs) and inline `<title>`. Layout chains match the old `getLayout`s
- `components/interfaces/CliLogin/CliLoginScreen.tsx` – the CLI login
screen moves out of the page so its test can import it without the route
file exporting it
- `tests/routes/{authorize,_auth/**}.test.tsx` – moved from
`tests/pages/**` and rendered with `renderRoute`

**Removed:**
- 18 page files

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

## To test

- Sign out, open `/sign-in` and `/sign-up` – same layout and title;
switching between them keeps `returnTo`
- Sign in with MFA – `/sign-in-mfa` returns to the original page
- `/cli/login?session_id=…` and `/authorize?…` – flows complete as
before
- `/logout` – redirects to `/sign-in`

---------

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

105 lines
3.9 KiB
TypeScript

import { screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { useState } from 'react'
import { Button } from 'ui'
import { beforeEach, describe, expect, test, vi } from 'vitest'
import {
CHATGPT_IDENTITY_PROVIDER,
GITHUB_IDENTITY_PROVIDER,
type ExternalIdentityProviderConfig,
} from '@/lib/external-identity-providers'
import { Route } from '@/routes/_auth/sign-up'
import { renderRoute } from '@/tests/lib/route-render'
const mocks = vi.hoisted(() => ({
focusProvider: undefined as ExternalIdentityProviderConfig | undefined,
}))
vi.mock('@/components/interfaces/SignIn/SignInWithExternalProvider', () => ({
SignInWithExternalProvider: ({ provider }: { provider: ExternalIdentityProviderConfig }) => (
<Button variant="primary">Continue with {provider.displayName}</Button>
),
}))
vi.mock('@/components/interfaces/SignIn/SignUpForm', () => ({
SignUpForm: ({ onSuccess }: { onSuccess?: () => void }) => {
const [isSubmitted, setIsSubmitted] = useState(false)
return (
<>
<Button
variant="primary"
onClick={() => {
setIsSubmitted(true)
onSuccess?.()
}}
>
Complete email sign-up
</Button>
{isSubmitted && <div>Check your email</div>}
</>
)
},
}))
vi.mock('@/hooks/misc/useEnabledIdentityProviders', () => ({
useEnabledIdentityProviders: () => [GITHUB_IDENTITY_PROVIDER, CHATGPT_IDENTITY_PROVIDER],
}))
vi.mock('@/hooks/misc/useInboundBranding', () => ({
useInboundBranding: () => ({ focusProvider: mocks.focusProvider }),
}))
vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({
useIsFeatureEnabled: () => ({
dashboardAuthSignUp: true,
dashboardAuthSignInWithSso: false,
dashboardAuthSignInWithEmail: true,
}),
}))
const renderSignUp = () => renderRoute(Route, { routeId: '/_auth/sign-up', url: '/sign-up' })
describe('/sign-up', () => {
beforeEach(() => {
mocks.focusProvider = undefined
})
test('hides social sign-up options after email sign-up succeeds', async () => {
const user = userEvent.setup()
await renderSignUp()
expect(screen.getByRole('button', { name: 'Continue with GitHub' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Continue with ChatGPT' })).toBeInTheDocument()
expect(screen.getByText('or')).toBeInTheDocument()
expect(screen.queryByText('Check your email')).not.toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'Complete email sign-up' }))
expect(screen.queryByRole('button', { name: 'Continue with GitHub' })).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Continue with ChatGPT' })).not.toBeInTheDocument()
expect(screen.queryByText('or')).not.toBeInTheDocument()
expect(screen.getByText('Check your email')).toBeInTheDocument()
expect(screen.getByRole('link', { name: 'Sign in' })).toHaveAttribute('href', '/sign-in')
})
test('hides the focused provider after email sign-up succeeds', async () => {
const user = userEvent.setup()
mocks.focusProvider = GITHUB_IDENTITY_PROVIDER
await renderSignUp()
expect(screen.getByRole('button', { name: 'Continue with GitHub' })).toBeInTheDocument()
expect(screen.queryByText('Check your email')).not.toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'Show other options' }))
await user.click(screen.getByRole('button', { name: 'Complete email sign-up' }))
expect(screen.queryByRole('button', { name: 'Continue with GitHub' })).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Continue with ChatGPT' })).not.toBeInTheDocument()
expect(screen.queryByText('or')).not.toBeInTheDocument()
expect(screen.getByText('Check your email')).toBeInTheDocument()
expect(screen.getByRole('link', { name: 'Sign in' })).toHaveAttribute('href', '/sign-in')
})
})