UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

75 lines 3.07 kB
import { shallow } from 'enzyme'; import React from 'react'; import { common } from '../../util/generic-tests'; import { SplitButtonDumb as SplitButton } from './SplitButton'; describe('SplitButton', function () { common(SplitButton); describe('click handlers', function () { var handleClick = jest.fn(); var handleOtherClick = jest.fn(); var params = { event: { stopPropagation: jest.fn() } }; var wrapper = shallow( /*#__PURE__*/React.createElement(SplitButton, null, /*#__PURE__*/React.createElement(SplitButton.Button, { onClick: handleClick }), /*#__PURE__*/React.createElement(SplitButton.Button, { onClick: handleOtherClick }), /*#__PURE__*/React.createElement(SplitButton.Button, { onClick: handleOtherClick }), /*#__PURE__*/React.createElement(SplitButton.Button, null))); beforeEach(function () { handleClick.mockClear(); handleOtherClick.mockClear(); params.event.stopPropagation.mockClear(); }); describe('primary button', function () { it('should trigger `handleClick`', function () { var primaryButtonWrapper = wrapper.find('Button').at(0); primaryButtonWrapper.simulate('click', params); expect(params.event.stopPropagation).toBeCalled(); expect(handleClick).toBeCalled(); expect(handleOtherClick).not.toBeCalled(); expect(handleClick.mock.calls[0][0]).toMatchSnapshot(); }); it('should not trigger `handleClick` when the dropdown button is clicked', function () { var dropdownButtonWrapper = wrapper.find('Button').at(1); dropdownButtonWrapper.simulate('click', params); expect(params.event.stopPropagation).not.toBeCalled(); expect(handleClick).not.toBeCalled(); expect(handleOtherClick).not.toBeCalled(); }); }); describe('secondary buttons', function () { it('should call the click handler for the second button when it is selected', function () { wrapper.simulate('select', 0, { event: {} }); expect(handleClick).not.toBeCalled(); expect(handleOtherClick.mock.calls[0][0]).toMatchSnapshot(); }); it('should call the click handler for the third button when it is selected', function () { wrapper.simulate('select', 1, { event: {} }); expect(handleClick).not.toBeCalled(); expect(handleOtherClick.mock.calls[0][0]).toMatchSnapshot(); }); it('should not trigger a handler for a button without an `onClick`', function () { wrapper.simulate('select', 2, { event: {} }); expect(handleClick).not.toBeCalled(); expect(handleOtherClick).not.toBeCalled(); }); it('should not call the click handler for the second button when an invalid index is selected', function () { wrapper.simulate('select', 3, { event: {} }); expect(handleClick).not.toBeCalled(); expect(handleOtherClick).not.toBeCalled(); }); }); }); });