fix(widget-relation): fix displayFields default (#3783)

This commit is contained in:
Erez Rokah 2020-05-19 12:10:48 +03:00 committed by GitHub
parent 2f435f875b
commit 24d96a760a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -155,7 +155,7 @@ export default class RelationControl extends React.Component {
parseHitOptions = hits => {
const { field } = this.props;
const valueField = field.get('valueField');
const displayField = field.get('displayFields') || List(field.get('valueField'));
const displayField = field.get('displayFields') || List([field.get('valueField')]);
const options = hits.reduce((acc, hit) => {
const valuesPaths = expandPath({ data: hit.data, path: valueField });

View File

@ -362,6 +362,16 @@ describe('Relation widget', () => {
});
});
it('should default displayFields to valueField', async () => {
const field = fromJS(fieldConfig).delete('displayFields');
const { getAllByText, input } = setup({ field });
fireEvent.keyDown(input, { key: 'ArrowDown' });
await wait(() => {
expect(getAllByText(/^Post # (\d{1,2})$/)).toHaveLength(20);
});
});
describe('with multiple', () => {
it('should call onChange with correct selectedItem value and metadata', async () => {
const field = fromJS({ ...fieldConfig, multiple: true });