Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Nov 3, 2022
1 parent 1d0e45d commit a510134
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/mui-joy/src/Select/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -593,4 +593,46 @@ describe('Joy <Select />', () => {
expect(isEventHandled).to.equal(true);
});
});

it('should show dropdown if the children of the select button is clicked', () => {
const { getByTestId, getByRole } = render(
<Select defaultValue="1">
<Option value="1">
<span data-testid="test-element" />
Eric
</Option>
</Select>,
);
// Fire Click of the avatar
act(() => {
getByTestId('test-element').click();
});

expect(getByRole('button', { hidden: true })).to.have.attribute('aria-expanded', 'true');
});

it('should not show dropdown if stop propagation is handled', () => {
const handleClick = spy();
const { getByTestId, getByRole } = render(
<Select
defaultValue="1"
startDecorator={
<div
data-testid="test-element"
onMouseDown={(event) => event.stopPropagation()}
onClick={handleClick}
/>
}
>
<Option value="1">Eric</Option>
</Select>,
);
// Fire Click of the avatar
act(() => {
getByTestId('test-element').click();
});

expect(getByRole('button', { hidden: true })).to.have.attribute('aria-expanded', 'false');
expect(handleClick.callCount).to.equal(1);
});
});

0 comments on commit a510134

Please sign in to comment.