Commit Graph
2 Commits
Author SHA1 Message Date
Alaister YoungandAlaister Young 960cf92854 [FE-5150] fix(studio): make router hooks follow renderRoute's URL in tests (#53660)
In Studio's vitest setup, `useParams` from `common` is mocked globally
to return `{ ref: 'default' }`, and `next/router`, `next/compat/router`
and `next/navigation` are mocked with `next-router-mock`. `renderRoute`
mounts a real TanStack memory router, but nothing connected it to those
mocks. So components under a route test never saw the route's path or
search params, and `router.push` from legacy code never moved the
TanStack router. Route tests worked around this by hand-mocking
`useParams` to repeat their URL.

Inside `renderRoute`, these hooks now defer to the app's own
`compat/next` shims, which read the memory router, so they match
runtime: kebab-case keys are camelCased, repeated keys collapse to the
first value, and the hooks follow in-test navigation. All other tests
keep the static mocks.

**Changed:**
- `tests/vitestSetup.ts`: the `common` `useParams`, `next/router`,
`next/compat/router` and `next/navigation` mocks are route-aware.
- `tests/lib/route-render.tsx`: the root route provides a
`RenderedRouteContext` marker. The switch keys off this marker rather
than any TanStack router context, because some component tests mount
their own `RouterContextProvider` or mock `@tanstack/react-router`.
- Route tests that relied on the old behavior:
- The EdgeFunctionOverview self-hosted test, `new/$slug` and
`logs/index.platform` now assert on `router.state.location` instead of
`next-router-mock`.
- The `logs` test's `useSignOut` mock is now stable, like the real hook;
an unstable mock made the redirect effect push in a loop.
- The EdgeFunctionOverview periods test now seeds the function detail
under its real slug instead of `undefined`.
- Removed the hand-written `useParams` mocks from the `authorize`,
Stripe `login`, `sign-in-mfa`, Vercel `new-project` and storage
`vectors` route tests; their URLs carry the params now.

**Added:**
- `tests/lib/route-aware-hooks.ts`: `routeAwareHook` and
`mockNextRouter`.
- `tests/lib/route-render.test.tsx`: renders a route at
`/project/abc/probe?query-tab=logs&id=1&id=2`, asserts what
`useParams()`, `useRouter().query` and `usePathname()` return, then
navigates and asserts again.

Addresses
[FE-5150](https://linear.app/supabase/issue/FE-5150/useparams-in-routes-tests-doesnt-return-any-querystring-params)

## To test
- [ ] `pnpm --filter studio exec vitest --run
tests/lib/route-render.test.tsx` passes.
- [ ] With `tests/vitestSetup.ts`, `tests/lib/route-render.tsx` and
`tests/lib/route-aware-hooks.ts` reverted to `master`, the same test
fails with `expected { ref: 'default' } to deeply equal { ref: 'abc',
queryTab: 'logs', id: '1' }`.
- [ ] Regression checks: `pnpm --filter studio exec vitest --run
tests/routes components/interfaces/Functions
components/interfaces/Database/Replication
components/interfaces/Account/Preferences` passes. These include route
tests and the component tests that mount their own TanStack router or
mock `next/router`.

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-11-19 17:01:01 +09:00
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