first commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import {render, screen} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import {expect, test, vi} from 'vitest'
|
||||
import {DynamicFormRenderer} from './DynamicFormRenderer'
|
||||
import type {ServiceSchema} from '@/types/schema'
|
||||
|
||||
const schema: ServiceSchema = {
|
||||
cloud: 'aws',
|
||||
service: 'serverless',
|
||||
displayName: 'AWS Lambda',
|
||||
fields: [
|
||||
{
|
||||
name: 'runtime',
|
||||
label: 'Runtime',
|
||||
type: 'select',
|
||||
required: true,
|
||||
defaultValue: 'nodejs22.x',
|
||||
options: [
|
||||
{label: 'Node.js 22.x', value: 'nodejs22.x'},
|
||||
{label: 'Python 3.12', value: 'python3.12'},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'code',
|
||||
label: 'Hello World Source',
|
||||
type: 'textarea',
|
||||
required: false,
|
||||
defaultValueWhen: {
|
||||
field: 'runtime',
|
||||
values: {
|
||||
'nodejs22.x': 'exports.handler = async () => {}',
|
||||
'python3.12': 'def handler(event, context):\n return {}',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
actions: ['create'],
|
||||
filters: [],
|
||||
columns: [],
|
||||
}
|
||||
|
||||
test('replaces Hello World source when the Lambda runtime changes', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<DynamicFormRenderer schema={schema} isSubmitting={false} onSubmit={vi.fn()}/>)
|
||||
|
||||
expect(screen.getByLabelText('Hello World Source')).toHaveValue('exports.handler = async () => {}')
|
||||
await user.selectOptions(screen.getByRole('combobox'), 'python3.12')
|
||||
|
||||
expect(screen.getByLabelText('Hello World Source')).toHaveValue('def handler(event, context):\n return {}')
|
||||
})
|
||||
Reference in New Issue
Block a user