2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import { shallow } from 'enzyme';
|
2021-03-16 22:00:08 +01:00
|
|
|
import { DropdownMenuItem } from './dropdown';
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Dropdown', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
|
|
|
const onClickSpy = sinon.spy();
|
|
|
|
const closeMenuSpy = sinon.spy();
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2018-09-24 18:28:04 +02:00
|
|
|
wrapper = shallow(
|
|
|
|
<DropdownMenuItem
|
2019-11-18 18:49:03 +01:00
|
|
|
onClick={onClickSpy}
|
2019-12-03 21:50:55 +01:00
|
|
|
style={{ test: 'style' }}
|
2019-11-18 18:49:03 +01:00
|
|
|
closeMenu={closeMenuSpy}
|
2020-11-03 00:41:28 +01:00
|
|
|
/>,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('renders li with dropdown-menu-item class', () => {
|
|
|
|
expect(wrapper.find('li.dropdown-menu-item')).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('adds style based on props passed', () => {
|
|
|
|
expect(wrapper.prop('style').test).toStrictEqual('style');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('simulates click event and calls onClick and closeMenu', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.prop('onClick')();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(onClickSpy.callCount).toStrictEqual(1);
|
|
|
|
expect(closeMenuSpy.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|