2017-01-05 15:26:10 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
|
import { noop } from 'lodash';
|
|
|
|
|
|
|
|
|
|
import { DropdownButton } from './DropdownButton';
|
|
|
|
|
|
|
|
|
|
describe('DropdownButton - component', () => {
|
|
|
|
|
it("calls the clicked item's onClick attribute", () => {
|
2020-12-01 18:15:12 +00:00
|
|
|
const optionSpy = jest.fn();
|
2017-01-05 15:26:10 +00:00
|
|
|
const dropdownOptions = [{ label: 'btn1', onClick: noop }, { label: 'btn2', onClick: optionSpy }];
|
|
|
|
|
const component = mount(
|
|
|
|
|
<DropdownButton options={dropdownOptions}>
|
|
|
|
|
New Button
|
2020-07-07 02:31:48 +00:00
|
|
|
</DropdownButton>,
|
2017-01-05 15:26:10 +00:00
|
|
|
);
|
|
|
|
|
|
2019-01-14 21:45:28 +00:00
|
|
|
component.find('button.dropdown-button').simulate('click');
|
2017-01-05 15:26:10 +00:00
|
|
|
expect(component.state().isOpen).toEqual(true);
|
|
|
|
|
|
|
|
|
|
component.find('li.dropdown-button__option').last().find('Button').simulate('click');
|
|
|
|
|
expect(optionSpy).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
});
|