Skip to content

Commit

Permalink
Enable AntD SelectField tests suite (#1312)
Browse files Browse the repository at this point in the history
Co-authored-by: Volodymyr Zakhovaiko <[email protected]>
  • Loading branch information
kestarumper and zaxovaiko authored Apr 5, 2024
1 parent 9dec81c commit b90343c
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 188 deletions.
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

0 comments on commit b90343c

Please sign in to comment.