Skip to content

Commit

Permalink
Migrated SelectField tests to @testing-library/react (#1294)
Browse files Browse the repository at this point in the history
Co-authored-by: Adrian Mucha <[email protected]>
  • Loading branch information
zaxovaiko and kestarumper authored Apr 5, 2024
1 parent 8b3f6f5 commit 49715f4
Show file tree
Hide file tree
Showing 17 changed files with 668 additions and 3,004 deletions.
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

0 comments on commit 49715f4

Please sign in to comment.