Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: props recursion test case added #4001

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
Loading