mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 12:24:39 +00:00
fix(agent): include select option labels and field name in autofill schema
This commit is contained in:
@@ -9,8 +9,11 @@ describe('fieldsToTypeBoxSchema', () => {
|
||||
]
|
||||
const schema = fieldsToTypeBoxSchema(fields)
|
||||
expect(schema.properties.f1.type).toBe('string')
|
||||
expect(schema.properties.f1.description).toBe('The title')
|
||||
expect(schema.properties.f1.title).toBe('Title')
|
||||
expect(schema.properties.f1.description).toBe('Title: The title')
|
||||
expect(schema.properties.f2.type).toBe('string')
|
||||
expect(schema.properties.f2.title).toBe('Desc')
|
||||
expect(schema.properties.f2.description).toBe('Desc')
|
||||
})
|
||||
|
||||
it('converts numeric fields', () => {
|
||||
@@ -20,21 +23,25 @@ describe('fieldsToTypeBoxSchema', () => {
|
||||
]
|
||||
const schema = fieldsToTypeBoxSchema(fields)
|
||||
expect(schema.properties.f1.type).toBe('number')
|
||||
expect(schema.properties.f1.title).toBe('Price')
|
||||
expect(schema.properties.f2.type).toBe('number')
|
||||
expect(schema.properties.f2.title).toBe('Rating')
|
||||
})
|
||||
|
||||
it('converts toggle fields', () => {
|
||||
const fields: AutofillField[] = [{ id: 'f1', config: { name: 'Active', type: 'toggle' } }]
|
||||
const schema = fieldsToTypeBoxSchema(fields)
|
||||
expect(schema.properties.f1.type).toBe('boolean')
|
||||
expect(schema.properties.f1.title).toBe('Active')
|
||||
})
|
||||
|
||||
it('converts select fields with enums', () => {
|
||||
it('converts select fields with enums and option descriptions', () => {
|
||||
const fields: AutofillField[] = [
|
||||
{
|
||||
id: 'f1',
|
||||
description: 'Species of animal',
|
||||
config: {
|
||||
name: 'Status',
|
||||
name: 'Species',
|
||||
type: 'select',
|
||||
select: {
|
||||
options: [
|
||||
@@ -47,7 +54,36 @@ describe('fieldsToTypeBoxSchema', () => {
|
||||
]
|
||||
const schema = fieldsToTypeBoxSchema(fields)
|
||||
expect(schema.properties.f1.type).toBe('string')
|
||||
expect(schema.properties.f1.title).toBe('Species')
|
||||
expect(schema.properties.f1.enum).toEqual(['opt1', 'opt2'])
|
||||
expect(schema.properties.f1.description).toBe(
|
||||
'Species: Species of animal [Allowed options: "opt1" (Option 1), "opt2" (Option 2)]',
|
||||
)
|
||||
})
|
||||
|
||||
it('converts selectMulti fields with array enums and option descriptions', () => {
|
||||
const fields: AutofillField[] = [
|
||||
{
|
||||
id: 'f1',
|
||||
config: {
|
||||
name: 'Tags',
|
||||
type: 'selectMulti',
|
||||
selectMulti: {
|
||||
options: [
|
||||
{ id: 'opt1', displayName: 'Tag 1', color: 'red' },
|
||||
{ id: 'opt2', displayName: 'Tag 2', color: 'blue' },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
const schema = fieldsToTypeBoxSchema(fields)
|
||||
expect(schema.properties.f1.type).toBe('array')
|
||||
expect(schema.properties.f1.title).toBe('Tags')
|
||||
expect(schema.properties.f1.items.enum).toEqual(['opt1', 'opt2'])
|
||||
expect(schema.properties.f1.description).toBe(
|
||||
'Tags [Allowed options: "opt1" (Tag 1), "opt2" (Tag 2)]',
|
||||
)
|
||||
})
|
||||
|
||||
it('defaults to string for unknown types', () => {
|
||||
@@ -57,5 +93,6 @@ describe('fieldsToTypeBoxSchema', () => {
|
||||
]
|
||||
const schema = fieldsToTypeBoxSchema(fields)
|
||||
expect(schema.properties.f1.type).toBe('string')
|
||||
expect(schema.properties.f1.title).toBe('Unknown')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user