2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import React from 'react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import { fireEvent } from '@testing-library/react';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import { renderWithProvider } from '../../../lib/render-helpers';
|
|
|
|
import { Dropdown } from '../../../../ui/app/components/app/dropdowns/components/dropdown';
|
2017-11-02 18:28:41 +01:00
|
|
|
|
2017-07-13 09:40:22 +02:00
|
|
|
describe('Dropdown components', function () {
|
2020-08-27 00:55:24 +02:00
|
|
|
const mockState = {
|
|
|
|
metamask: {},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-18 19:24:03 +01:00
|
|
|
|
2020-08-27 00:55:24 +02:00
|
|
|
const props = {
|
2017-11-02 18:28:41 +01:00
|
|
|
isOpen: true,
|
|
|
|
zIndex: 11,
|
2020-08-27 00:55:24 +02:00
|
|
|
onClickOutside: sinon.spy(),
|
2017-11-02 18:28:41 +01:00
|
|
|
style: {
|
|
|
|
position: 'absolute',
|
|
|
|
right: 0,
|
|
|
|
top: '36px',
|
|
|
|
},
|
|
|
|
innerStyle: {},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-11-02 18:28:41 +01:00
|
|
|
|
2020-08-27 00:55:24 +02:00
|
|
|
it('invokes click handler when item clicked', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = configureMockStore()(mockState);
|
2017-07-13 09:40:22 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const onClickSpy = sinon.spy();
|
2017-07-13 09:40:22 +02:00
|
|
|
|
2020-08-27 00:55:24 +02:00
|
|
|
const { getByText } = renderWithProvider(
|
|
|
|
<Dropdown {...props}>
|
|
|
|
<li onClick={onClickSpy}>Item 1</li>
|
|
|
|
<li onClick={onClickSpy}>Item 2</li>
|
2020-11-03 00:41:28 +01:00
|
|
|
</Dropdown>,
|
|
|
|
store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2017-07-18 14:23:25 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const item1 = getByText(/Item 1/u);
|
|
|
|
fireEvent.click(item1);
|
2020-08-27 00:55:24 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.ok(onClickSpy.calledOnce);
|
|
|
|
});
|
|
|
|
});
|