Skip to content

Commit

Permalink
[Select][material-ui] Add form submission regression test (#40176)
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert committed Jan 9, 2024
1 parent 329c76c commit dfbee7e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/mui-material/src/Select/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,42 @@ describe('<Select />', () => {
expect(container.getElementsByClassName(classes.select)[0]).to.toHaveComputedStyle(selectStyle);
});

describe('form submission', () => {
it('includes Select value in formData only if the `name` attribute is provided', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
// FormData is not available in JSDOM
this.skip();
}
const handleSubmit = (event) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
expect(formData.get('select-one')).to.equal('2');

const formDataAsObject = Object.fromEntries(formData);
expect(Object.keys(formDataAsObject).length).to.equal(1);
};

const { getByText } = render(
<form onSubmit={handleSubmit}>
<Select defaultValue={2} name="select-one">
<MenuItem value={1} />
<MenuItem value={2} />
</Select>
<Select defaultValue="a">
<MenuItem value="a" />
<MenuItem value="b" />
</Select>
<button type="submit">Submit</button>
</form>,
);

const button = getByText('Submit');
act(() => {
button.click();
});
});
});

describe('theme styleOverrides:', () => {
it('should override with error style when `native select` has `error` state', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
Expand Down

0 comments on commit dfbee7e

Please sign in to comment.