Files
supabase/apps/studio/components/interfaces/Database/Hooks/HTTPParameters.test.tsx
T
Danny White 70c4659452 chore(studio): reuse key-value field array for params (#44058)
## What kind of change does this PR introduce?

Chore that references DEPR-394.

## What is the current behavior?

This stack is consolidating RHF key/value array UIs in smaller
reviewable steps.

After PR 1, Database Webhooks HTTP parameters and Database Functions
configuration parameters still use separate bespoke implementations.

## What is the new behavior?

- reuses the shared `KeyValueFieldArray` for Database Webhooks HTTP
parameters
- reuses the shared `KeyValueFieldArray` for Database Functions
configuration parameters
- keeps existing form shapes and submission logic intact
- adds focused tests for those two follow-up consumers

## Additional context

This is PR 2 of a 3-PR stack for DEPR-394.

Base PR: #43938
2026-03-25 11:39:36 +11:00

57 lines
1.6 KiB
TypeScript

import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { useForm } from 'react-hook-form'
import { describe, expect, it } from 'vitest'
import { Form_Shadcn_ } from 'ui'
import { type WebhookFormValues } from './EditHookPanel.constants'
import { HTTPParameters } from './HTTPParameters'
const HTTPParametersHarness = () => {
const form = useForm<WebhookFormValues>({
defaultValues: {
name: 'test-hook',
table_id: 'public.messages',
http_method: 'POST',
timeout_ms: 1000,
events: ['INSERT'],
function_type: 'http_request',
http_url: 'https://hooks.example.com/webhook',
httpHeaders: [],
httpParameters: [{ id: 'param-1', name: 'tenant', value: 'prod' }],
},
})
return (
<Form_Shadcn_ {...form}>
<HTTPParameters form={form} />
</Form_Shadcn_>
)
}
describe('HTTPParameters', () => {
it('appends a new parameter row', async () => {
const user = userEvent.setup()
render(<HTTPParametersHarness />)
await user.click(screen.getByRole('button', { name: 'Add a new parameter' }))
expect(screen.getAllByPlaceholderText('Parameter name')).toHaveLength(2)
expect(screen.getAllByPlaceholderText('Parameter value')).toHaveLength(2)
})
it('removes an existing parameter row', async () => {
const user = userEvent.setup()
render(<HTTPParametersHarness />)
expect(screen.getByDisplayValue('tenant')).toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'Remove parameter' }))
expect(screen.queryByDisplayValue('tenant')).not.toBeInTheDocument()
})
})