-
-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
renderWithZod using AutoForm, fix some tests ListAddDelField, RadioField
- Loading branch information
1 parent
5f87cf5
commit 2b839fe
Showing
11 changed files
with
31 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,23 @@ | ||
import { render as renderOnScreen } from '@testing-library/react'; | ||
import React, { ReactElement } from 'react'; | ||
import { BaseForm, Context, context, randomIds } from 'uniforms'; | ||
import React, { ComponentProps, ReactElement } from 'react'; | ||
import { ZodBridge } from 'uniforms-bridge-zod'; | ||
import { TypeOf, ZodObject, ZodRawShape } from 'zod'; | ||
import { AutoForm } from 'uniforms-unstyled'; | ||
import { ZodObject, ZodRawShape } from 'zod'; | ||
|
||
export function renderWithZod<Props, Schema extends ZodObject<ZodRawShape>>({ | ||
element, | ||
schema, | ||
...contextValueOverride | ||
...autoFormProps | ||
}: { | ||
element: ReactElement<Props>; | ||
schema: Schema; | ||
} & Omit<Partial<Context<TypeOf<Schema>>>, 'schema'>) { | ||
} & Partial<Omit<ComponentProps<typeof AutoForm>, 'schema'>>) { | ||
return renderOnScreen(element, { | ||
wrapper({ children }) { | ||
const value = { | ||
changed: false, | ||
changedMap: Object.create(null), | ||
error: null, | ||
formRef: null as unknown as BaseForm<TypeOf<Schema>>, | ||
model: Object.create(null), | ||
name: [], | ||
onChange() {}, | ||
onSubmit() {}, | ||
randomId: randomIds(), | ||
submitted: false, | ||
submitting: false, | ||
validating: false, | ||
...contextValueOverride, | ||
schema: new ZodBridge({ | ||
schema, | ||
}), | ||
state: { | ||
disabled: false, | ||
readOnly: false, | ||
showInlineError: false, | ||
...contextValueOverride?.state, | ||
}, | ||
}; | ||
|
||
return <context.Provider children={children} value={value} />; | ||
const bridge = new ZodBridge({ schema }); | ||
return ( | ||
<AutoForm {...autoFormProps} schema={bridge} children={children} /> | ||
); | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters