Skip to content

Commit

Permalink
fix(DGT-307/form): fix EnumerationForm doesn't use the newest value t…
Browse files Browse the repository at this point in the history
…o validate value (#5304)
  • Loading branch information
hbhong authored May 7, 2024
1 parent 4f3c5d6 commit b59f982
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eleven-moles-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@talend/react-forms": patch
---

fix EnumerationForm doesn't use the newest value to validate value
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class EnumerationForm extends Component {
onChange(event, payload) {
const { schema, onFinish, onChange } = this.props;
onChange(event, payload);
onFinish(event, { schema });
onFinish(event, { schema, value: payload.value });
}

onImportAppendClick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,37 @@ describe('EnumerationWidget', () => {
expect(onChange).toHaveBeenCalledWith(expect.anything(), { schema: {}, value: [] });
});

it('should pass the newest value to onFinish', async () => {
const onFinish = jest.fn();
render(
<EnumerationWidget
value={[{ values: ['yoo'] }]}
onChange={jest.fn()}
onFinish={onFinish}
onTrigger={jest.fn()}
schema={{}}
/>,
);

// when
await userEvent.click(screen.queryByRole('link', { name: 'Add item' }));
await userEvent.type(screen.queryByRole('textbox', { name: 'Enter new entry name' }), 'foo');
await userEvent.click(screen.queryByRole('link', { name: 'Validate' }));
// then
expect(onFinish).toHaveBeenCalledWith(expect.anything(), {
schema: {},
value: [
{
values: ['yoo'],
displayMode: 'DISPLAY_MODE_DEFAULT',
},
{
values: ['foo'],
},
],
});
});

describe('upload file', () => {
it('should add a upload icon and set data-feature', () => {
// when
Expand Down

0 comments on commit b59f982

Please sign in to comment.