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 tests to @testing-library/react #1294

Merged
merged 15 commits into from
Apr 5, 2024
Merged
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.parcel-cache
/coverage
/lerna-debug.log
.DS_Store

/node_modules
/npm-debug.log
Expand Down
2 changes: 2 additions & 0 deletions packages/uniforms-antd/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ describe('@RTL', () => {
suites.testRadioField(theme.RadioField, { skipHtmlAttributesTest: true });
// 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, { 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