Skip to content

Commit

Permalink
Add test for hover state
Browse files Browse the repository at this point in the history
  • Loading branch information
rtexelm committed Apr 4, 2024
1 parent 0d4bf69 commit 60cc1c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,25 @@
* under the License.
*/
import React from 'react';
import { render } from 'spec/helpers/testing-library';
import { render, screen } from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';

import HoverMenu from 'src/dashboard/components/menu/HoverMenu';

test('should render a div.hover-menu', () => {
const { container } = render(<HoverMenu />);
expect(container.querySelector('.hover-menu')).toBeInTheDocument();
});

test('should call onHover when mouse enters and leaves', () => {
const onHover = jest.fn();
render(<HoverMenu onHover={onHover} />);

const hoverMenu = screen.getByTestId('hover-menu');

userEvent.hover(hoverMenu);
expect(onHover).toBeCalledWith({ isHovered: true });

userEvent.unhover(hoverMenu);
expect(onHover).toBeCalledWith({ isHovered: false });
});
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default class HoverMenu extends React.PureComponent<HoverMenuProps> {
)}
onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave}
data-test="hover-menu"
>
{children}
</div>
Expand Down

0 comments on commit 60cc1c4

Please sign in to comment.