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

fix: menu: adds onclick handler back to main button when secondarybuttonprops fixing menu onchange #813

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
63 changes: 62 additions & 1 deletion src/components/Menu/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Button } from '../Button';
import { IconName } from '../Icon';
import { RadioGroup } from '../RadioButton';
import { SelectorSize } from '../CheckBox';
import { render, screen, waitFor } from '@testing-library/react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';

Enzyme.configure({ adapter: new Adapter() });

Expand Down Expand Up @@ -227,4 +227,65 @@ describe('Menu', () => {
);
expect(container).toMatchSnapshot();
});

test('Menu onChange event is triggered when item is clicked', () => {
const handleChange = jest.fn();

const { getByText } = render(
<Menu
onChange={handleChange}
items={[
{
iconProps: {
path: IconName.mdiCalendar,
},
text: 'Date',
value: 'menu 0',
counter: '8',
secondaryButtonProps: {
iconProps: {
path: IconName.mdiTrashCan,
},
onClick: () => {
console.log('Delete clicked');
},
},
},
]}
/>
);

fireEvent.click(getByText('Date'));

expect(handleChange).toHaveBeenCalled();
});

test('secondaryButtonProps onClick event is triggered when secondary button is clicked', () => {
const handleClick = jest.fn();

const { getByRole } = render(
<Menu
items={[
{
iconProps: {
path: IconName.mdiCalendar,
},
text: 'Date',
value: 'menu 0',
counter: '8',
secondaryButtonProps: {
iconProps: {
path: IconName.mdiTrashCan,
},
onClick: handleClick,
},
},
]}
/>
);

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

expect(handleClick).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const MenuItemButton: FC<MenuItemButtonProps> = forwardRef(
tabIndex={tabIndex}
type={htmlType}
{...rest}
onClick={handleOnClick}
ref={ref}
role={role}
>
Expand Down
Loading