Files
supabase/apps/studio/components/interfaces/Support/CsatSurvey/CsatSurvey.test.tsx
Alaister YoungandAlaister Young 0c97b9789b [FE-3107] chore(studio): remove remaining Next.js references (#54426)
Removes the remaining Next.js dependencies, compatibility shims, test
mocks, ESLint/TypeScript presets, and webpack/Next workarounds from
Studio following the TanStack Start migration.

Addresses FE-3107.

**Removed:**

- `next` and `next-router-mock` from `apps/studio/package.json` (and
updated `pnpm-lock.yaml`)
- Orphaned `apps/studio/compat/next/script.tsx` shim, `script.test.tsx`,
`compat/**` knip entry, and `nextCompat()` / `ssr.noExternal` `/^next/`
plumbing from `apps/studio/vite.config.ts`
- `apps/studio/tests/lib/route-mock.ts` and all `next-router-mock`
setup/imports across `tests/vitestSetup.ts`,
`tests/lib/custom-render.tsx`, and 12 test files
- `apps/studio/tests/pages/` directory (moved the 3 remaining tests to
`components/interfaces/Organization/Organization.utils.test.ts` and
`apps/studio/tests/routes/`)
- Unused `'use client'` directives across 23 Studio files
- Next.js/webpack workarounds: `graphiqlViteWorkers()` in
`vite.config.ts`, webpack `import.meta.glob` `try/catch` fallback in
`ConnectStepsSection.tsx`, shell `NODE_ENV=test` override in
`vite.config.ts` / root `package.json` / `studio-e2e-test.yml`, Next
`getPathMatch` and `_next` passthrough in `redirects.shared.*`,
`window.next?.router` check in `monaco-graphiql-coexistence.spec.ts`,
and unused `ANALYZE` env var in `apps/studio/turbo.jsonc`
- Next-only Sentry/chunk-load filters (`NEXT_NOT_FOUND`,
`NEXT_REDIRECT`, Next `/org/[slug]/` regex, `/app:\/\//`, dead
`includeThirdPartyErrorFilter` plumbing, webpack chunk error regex) and
stale Next/Pages Router comments, docs, and `#__next` CSS selector

**Changed:**

- `apps/studio/eslint.config.cjs`: switched from
`eslint-config-supabase/next` to the new `eslint-config-supabase/react`
preset (dropping `@next/next/no-img-element: off`, keeping `.next` /
`next-env.d.ts` ignored for local checkouts with stale pre-migration
build artifacts)
- `apps/studio/tsconfig.json`: extends `tsconfig/base.json` directly
instead of `tsconfig/nextjs.json` (identical resolved compiler options)
- `apps/studio/.github/eslint-rule-baselines.json`: pruned 33 stale
`pages/...` and `types/next.ts` entries without changing any rule
thresholds
- `apps/studio/tests/lib/custom-render.tsx`: backed
`TestFrameworkProvider` with TanStack Router instead of
`next-router-mock`
-
`apps/studio/components/interfaces/Integrations/GraphQL/GraphiQLTab.tsx`:
imports `graphiql/setup-workers/vite` directly
- `apps/studio/styles/globals.css`: replaced `@source
'../pages/**/*.{js,ts,jsx,tsx}'` with `@source
'../routes/**/*.{js,ts,jsx,tsx}'`
- `apps/studio/turbo.jsonc`: declared `"NEXT_PUBLIC_*"` in
`tasks.build.env` now that Turborepo infers `nitro` instead of `nextjs`
-
`apps/studio/components/interfaces/Organization/Organization.utils.ts`:
narrowed `buildOrgUrl`'s `slug` parameter to `string[] | undefined`

**Added:**

- `packages/eslint-config-supabase/shared.js` and
`packages/eslint-config-supabase/react.js` (plus `presets.test.ts`),
decoupling non-Next React apps from `eslint-config-next` with verified
zero non-`@next/*` rule drift while keeping
`eslint-config-supabase/next` unchanged for the Next.js apps

## To test

- Run `pnpm --filter eslint-config-supabase run test` and confirm preset
parity tests pass
- Run `pnpm --filter studio run lint`, `pnpm --filter studio run
lint:ratchet`, `pnpm --filter studio run typecheck`, `pnpm knip
--workspace apps/studio`, and `pnpm --filter studio run test`
- Run `pnpm --filter studio run build` and verify the production build,
prerendered routes, chunk-cycle check, and GraphiQL web workers succeed
- Smoke-test Studio locally (`pnpm dev:studio`): verify GraphiQL loads
cleanly, ConnectSheet framework steps render, and Tailwind styles on
route pages are intact

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-12-02 17:01:50 +08:00

106 lines
3.7 KiB
TypeScript

import { fireEvent, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { http, HttpResponse, type JsonBodyType } from 'msw'
import { describe, expect, test, vi } from 'vitest'
import { CsatSurvey } from './CsatSurvey'
import { API_URL } from '@/lib/constants'
import { customRender } from '@/tests/lib/custom-render'
import { mswServer } from '@/tests/lib/msw'
// The global test setup stubs useParams; restore the real one so the URL query drives the page.
vi.mock('common', async (importOriginal) => {
const actual = await importOriginal<typeof import('common')>()
return { ...actual, useParams: actual.useParams }
})
const CSAT_URL = `${API_URL?.replace('/platform', '')}/platform/support/csat`
const mockSubmit = (status: number, body: JsonBodyType = { result: 'success' }) => {
const requests: unknown[] = []
mswServer.use(
http.post(CSAT_URL, async ({ request }) => {
requests.push(await request.json())
return HttpResponse.json(body, { status })
})
)
return requests
}
// Click-to-submit does not work under the test pointer-event polyfill; submit the form directly.
const submitForm = () => {
const form = screen.getByRole('button', { name: 'Submit' }).closest('form')
if (!form) throw new Error('Survey form not found')
fireEvent.submit(form)
}
const DEFAULT_CSAT_URL = '/support/csat?conversation_id=cnv_1abc2&helpful=yes'
describe('CsatSurvey', () => {
test('shows the ticket error when the link has no ticket reference', () => {
customRender(<CsatSurvey />, { initialUrl: '/support/csat' })
expect(screen.getByText('Invalid or mismatched ticket')).toBeInTheDocument()
})
test('preselects the answer from the link and submits it with a comment', async () => {
const requests = mockSubmit(200)
customRender(<CsatSurvey />, { initialUrl: DEFAULT_CSAT_URL })
expect(screen.getByRole('button', { name: 'Yes' })).toHaveAttribute('aria-pressed', 'true')
await userEvent.type(screen.getByLabelText(/add a comment/i), 'Quick and helpful')
submitForm()
expect(
await screen.findByText('Survey response recorded. You can now close this window.')
).toBeInTheDocument()
expect(requests).toEqual([
{ conversation_id: 'cnv_1abc2', satisfied: true, comment: 'Quick and helpful' },
])
})
test('lets the customer change the answer before submitting', async () => {
const requests = mockSubmit(200)
customRender(<CsatSurvey />, { initialUrl: DEFAULT_CSAT_URL })
await userEvent.click(screen.getByRole('button', { name: 'No' }))
submitForm()
await waitFor(() => expect(requests).toHaveLength(1))
expect(requests[0]).toMatchObject({ conversation_id: 'cnv_1abc2', satisfied: false })
})
test('shows the already-submitted error on a 409', async () => {
mockSubmit(409, { message: 'This survey has already been answered' })
customRender(<CsatSurvey />, { initialUrl: DEFAULT_CSAT_URL })
submitForm()
expect(await screen.findByText('This survey has already been submitted')).toBeInTheDocument()
})
test('shows the ticket error on a 404', async () => {
mockSubmit(404, { message: 'No survey was sent for this conversation' })
customRender(<CsatSurvey />, { initialUrl: DEFAULT_CSAT_URL })
submitForm()
expect(await screen.findByText('Invalid or mismatched ticket')).toBeInTheDocument()
})
test('keeps the form and shows the error on other failures', async () => {
mockSubmit(500, { message: 'Failed to record survey response' })
customRender(<CsatSurvey />, { initialUrl: DEFAULT_CSAT_URL })
submitForm()
expect(await screen.findByText('Failed to record survey response')).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Submit' })).toBeInTheDocument()
})
})