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

Add tests for the new behavior #1

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions packages/material-ui/src/Select/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ describe('<Select />', () => {
</Select>,
);

fireEvent.click(getByRole('button'));
fireEvent.mouseDown(getByRole('button'));
act(() => {
clock.tick(99);
});
Expand Down Expand Up @@ -539,7 +539,7 @@ describe('<Select />', () => {
const { getByRole, queryByRole } = render(<ControlledWrapper />);

act(() => {
getByRole('button').click();
fireEvent.mouseDown(getByRole('button'));
});

expect(getByRole('listbox')).to.be.ok;
Expand Down Expand Up @@ -580,9 +580,7 @@ describe('<Select />', () => {
);
stub(getByRole('button'), 'clientWidth').get(() => 14);

act(() => {
getByRole('button').click();
});
fireEvent.mouseDown(getByRole('button'));

expect(getByTestId('paper').style).to.have.property('minWidth', '14px');
});
Expand All @@ -595,9 +593,7 @@ describe('<Select />', () => {
);
stub(getByRole('button'), 'clientWidth').get(() => 14);

act(() => {
getByRole('button').click();
});
fireEvent.mouseDown(getByRole('button'));

expect(getByTestId('paper').style).to.have.property('minWidth', '');
});
Expand Down Expand Up @@ -716,7 +712,7 @@ describe('<Select />', () => {
});
const { getByRole, getAllByRole } = render(<ControlledSelectInput onChange={onChange} />);

fireEvent.click(getByRole('button'));
fireEvent.mouseDown(getByRole('button'));
fireEvent.click(getAllByRole('option')[2]);

expect(onChange.callCount).to.equal(1);
Expand Down Expand Up @@ -787,4 +783,26 @@ describe('<Select />', () => {
expect(getByRole('button')).to.have.attribute('id', 'select-foo');
});
});

describe('prop: onMouseDown', () => {
it('is forwarded to the trigger button', () => {
const handleMouseDown = spy();
const { getByRole } = render(<Select onMouseDown={handleMouseDown} value="" />);

fireEvent.mouseDown(getByRole('button'));

expect(handleMouseDown.callCount).to.equal(1);
});
});

describe('prop: onClick', () => {
it('is forwarded to the trigger button', () => {
const handleClick = spy();
const { getByRole } = render(<Select onClick={handleClick} value="" />);

fireEvent.click(getByRole('button'));

expect(handleClick.callCount).to.equal(1);
});
});
});
10 changes: 2 additions & 8 deletions packages/material-ui/test/integration/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ describe('<Select> integration', () => {
it('should focus the selected item', async () => {
const { getByTestId, getAllByRole, getByRole, queryByRole } = render(<SelectAndDialog />);

// Let's open the select component
// in the browser user click also focuses
getByRole('button').focus();
getByRole('button').click();
fireEvent.mouseDown(getByRole('button'));

expect(getAllByRole('option')[1]).to.be.focused;

Expand All @@ -60,10 +57,7 @@ describe('<Select> integration', () => {
const { getAllByRole, getByRole, queryByRole } = render(<SelectAndDialog />);
expect(getByRole('button')).to.have.text('Ten');

// Let's open the select component
// in the browser user click also focuses
getByRole('button').focus();
getByRole('button').click();
fireEvent.mouseDown(getByRole('button'));

expect(getAllByRole('option')[1]).to.be.focused;

Expand Down