mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem In the Edge Function Edit secret sheet, a long secret value (for example a multi-line private key) made the Value textarea grow without a limit. On smaller screens this pushed the Cancel and Save buttons out of view, so the secret couldn't be saved. Fixes [FE-4680](https://linear.app/supabase/issue/FE-4680/cannot-save-long-edge-function-secrets-on-smaller-screens). ## Solution - Replace the hand-rolled auto-resize `Textarea` with the shared `ExpandingTextArea`, the same component the Add new secrets form uses. It grows with its content up to 320px, then scrolls inside itself. - Make the sheet body the scroll area (`grow min-h-0 overflow-y-auto`), so the footer with Cancel and Save stays visible on short windows. - Move the show/hide (eye) toggle to `right-3 top-2` to match the add form, and add right padding so it stays clear of the textarea's scrollbar. - Add a test that pastes a long multi-line value and checks that Save becomes enabled. ## Review instructions 1. Open Edge Functions > Secrets and click Edit on any secret. 2. Paste a very long multi-line value into the Value field. 3. Confirm the field stops growing at about 320px and scrolls internally. 4. Shrink the browser window height and confirm Cancel and Save remain visible and Save is enabled. 5. Confirm the eye toggle doesn't overlap the textarea's scrollbar. Co-authored-by: supabase-vercel-tedd[bot] <336548405+supabase-vercel-tedd[bot]@users.noreply.github.com>
85 lines
3.0 KiB
TypeScript
85 lines
3.0 KiB
TypeScript
import { fireEvent, screen, waitFor } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import { mockAnimationsApi } from 'jsdom-testing-mocks'
|
|
import { HttpResponse } from 'msw'
|
|
import { describe, expect, test, vi } from 'vitest'
|
|
|
|
import { EditSecretSheet } from './EditSecretSheet'
|
|
import type { ProjectSecret } from '@/data/secrets/secrets-query'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
import { addAPIMock } from '@/tests/lib/msw'
|
|
|
|
mockAnimationsApi()
|
|
|
|
const SECRET: ProjectSecret = { name: 'API_KEY', value: '' }
|
|
|
|
const renderSheet = (overrides: { onClose?: () => void } = {}) => {
|
|
const onClose = overrides.onClose ?? vi.fn()
|
|
customRender(<EditSecretSheet visible secret={SECRET} onClose={onClose} />)
|
|
return { onClose }
|
|
}
|
|
|
|
describe('EditSecretSheet', () => {
|
|
test('keeps Save disabled until a value is entered', async () => {
|
|
renderSheet()
|
|
|
|
const save = await screen.findByRole('button', { name: 'Save' })
|
|
expect(save).toBeDisabled()
|
|
|
|
await userEvent.type(screen.getByPlaceholderText('my-secret-value'), 'new-value')
|
|
await waitFor(() => expect(save).toBeEnabled())
|
|
})
|
|
|
|
test('enables Save for a long multi-line value', async () => {
|
|
renderSheet()
|
|
|
|
const save = await screen.findByRole('button', { name: 'Save' })
|
|
const longValue = Array.from({ length: 200 }, (_, i) => `line-${i}-${'x'.repeat(60)}`).join(
|
|
'\n'
|
|
)
|
|
|
|
await userEvent.click(screen.getByPlaceholderText('my-secret-value'))
|
|
await userEvent.paste(longValue)
|
|
|
|
expect(screen.getByPlaceholderText('my-secret-value')).toHaveValue(longValue)
|
|
await waitFor(() => expect(save).toBeEnabled())
|
|
})
|
|
|
|
test('posts the secret and closes on success', async () => {
|
|
const requests: Array<{ ref: string | undefined; body: unknown }> = []
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/v1/projects/:ref/secrets',
|
|
response: async ({ request, params }) => {
|
|
requests.push({ ref: params.ref as string | undefined, body: await request.json() })
|
|
return HttpResponse.json({}, { status: 201 })
|
|
},
|
|
})
|
|
|
|
const { onClose } = renderSheet()
|
|
|
|
await userEvent.type(screen.getByPlaceholderText('my-secret-value'), 'new-value')
|
|
fireEvent.click(await screen.findByRole('button', { name: 'Save' }))
|
|
|
|
await waitFor(() => expect(onClose).toHaveBeenCalledOnce())
|
|
expect(requests).toEqual([{ ref: 'default', body: [{ name: 'API_KEY', value: 'new-value' }] }])
|
|
})
|
|
|
|
test('keeps the sheet open when the mutation fails', async () => {
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/v1/projects/:ref/secrets',
|
|
response: () => HttpResponse.json({ message: 'Something exploded' }, { status: 500 }),
|
|
})
|
|
|
|
const { onClose } = renderSheet()
|
|
|
|
await userEvent.type(screen.getByPlaceholderText('my-secret-value'), 'new-value')
|
|
const save = await screen.findByRole('button', { name: 'Save' })
|
|
fireEvent.click(save)
|
|
|
|
await waitFor(() => expect(save).not.toBeDisabled())
|
|
expect(onClose).not.toHaveBeenCalled()
|
|
})
|
|
})
|