Skip to content

Commit

Permalink
feat: props recursion test case added (#4001)
Browse files Browse the repository at this point in the history
* feat: test added

* fix: filterProperties test case
  • Loading branch information
nicetooo authored Oct 23, 2023
1 parent c90b1df commit d8716ea
Showing 1 changed file with 85 additions and 2 deletions.
87 changes: 85 additions & 2 deletions packages/react/src/__tests__/schema.markup.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ describe('recursion field', () => {
<RecursionField
schema={schema}
filterProperties={(schema) => {
if (schema['x-component'] === 'Input') return
return true
if (schema['x-component'] === 'Input') return true
return false
}}
/>
</div>
Expand Down Expand Up @@ -1054,3 +1054,86 @@ test('records scope', async () => {
expect(queryByTestId('text')?.textContent).toBe('3')
})
})

test('propsRecursion as true', () => {
const form = createForm()
const CustomObject: React.FC = () => {
const schema = useFieldSchema()
return (
<div data-testid="object">
<RecursionField
schema={schema}
propsRecursion={true}
filterProperties={(schema) => {
if (schema['x-component'] === 'Input') {
return false
}
return true
}}
/>
</div>
)
}

const SchemaField = createSchemaField({
components: {
Input,
CustomObject,
},
})
const { queryAllByTestId } = render(
<FormProvider form={form}>
<SchemaField>
<SchemaField.Object x-component="CustomObject">
<SchemaField.String x-component="Input" />
<SchemaField.Object>
<SchemaField.String x-component="Input" />
</SchemaField.Object>
</SchemaField.Object>
</SchemaField>
</FormProvider>
)
expect(queryAllByTestId('input').length).toEqual(0)
expect(queryAllByTestId('object').length).toEqual(1)
})

test('propsRecursion as empty', () => {
const form = createForm()
const CustomObject: React.FC = () => {
const schema = useFieldSchema()
return (
<div data-testid="object">
<RecursionField
schema={schema}
filterProperties={(schema) => {
if (schema['x-component'] === 'Input') {
return false
}
return true
}}
/>
</div>
)
}

const SchemaField = createSchemaField({
components: {
Input,
CustomObject,
},
})
const { queryAllByTestId } = render(
<FormProvider form={form}>
<SchemaField>
<SchemaField.Object x-component="CustomObject">
<SchemaField.String x-component="Input" />
<SchemaField.Object>
<SchemaField.String x-component="Input" />
</SchemaField.Object>
</SchemaField.Object>
</SchemaField>
</FormProvider>
)
expect(queryAllByTestId('input').length).toEqual(1)
expect(queryAllByTestId('object').length).toEqual(1)
})

0 comments on commit d8716ea

Please sign in to comment.