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

Migrated SelectField AntD tests to @testing-library/react #1312

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/uniforms-antd/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('@RTL', () => {
// FIXME: AntD has problem with toHaveValue check
suites.testSubmitField(theme.SubmitField, { skipValueTest: true });
// FIXME: AntD select does not work with new RTL test implementation
// suites.testSelectField(theme.SelectField, { antdTests: true });
suites.testSelectField(theme.SelectField, { theme: 'antd' });
suites.testTextField(theme.TextField);
suites.testValidatedForm(theme.ValidatedForm);
suites.testValidatedQuickForm(theme.ValidatedQuickForm);
Expand Down
48 changes: 26 additions & 22 deletions packages/uniforms-antd/src/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,33 @@ export type SelectFieldProps = CheckboxesProps | SelectProps;

function Select(props: SelectFieldProps) {
const Group = props.fieldType === Array ? CheckboxGroup : RadioGroup;
const filteredDOMProps = filterDOMProps(props);
return wrapField(
props,
props.checkboxes ? (
// @ts-expect-error: Incorrect `value` type.
<Group
{...filterDOMProps(props)}
disabled={props.disabled}
name={props.name}
onChange={(eventOrValue: any) => {
if (!props.readOnly) {
props.onChange(
// FIXME: Argument type depends on `props.fieldType`.
props.fieldType === Array
? eventOrValue
: eventOrValue.target.value,
);
}
}}
options={props.options?.map(option => ({
...option,
label: option.label ?? option.value,
}))}
value={props.value}
/>
<span {...filteredDOMProps}>
{/* @ts-expect-error: Incorrect `value` type. */}
<Group
{...filteredDOMProps}
disabled={props.disabled}
name={props.name}
onChange={(eventOrValue: any) => {
if (!props.readOnly) {
props.onChange(
// FIXME: Argument type depends on `props.fieldType`.
props.fieldType === Array
? eventOrValue
: eventOrValue.target.value,
);
}
}}
options={props.options?.map(option => ({
...option,
label: option.label ?? option.value,
}))}
value={props.value}
/>
</span>
) : (
<SelectAntD<any>
allowClear={!props.required}
Expand All @@ -86,13 +89,14 @@ function Select(props: SelectFieldProps) {
: []
: props.value
}
{...filterDOMProps(props)}
{...filteredDOMProps}
>
{props.options?.map(option => (
<SelectAntD.Option
disabled={option.disabled}
key={option.key ?? option.value}
value={option.value}
id={`${props.id}-${option.key ?? escape(option.value)}`}
>
{option.label ?? option.value}
</SelectAntD.Option>
Expand Down
Loading
Loading