1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 02:58:09 +01:00
metamask-extension/test/unit/responsive/components/dropdown-test.js

82 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-11-02 18:28:41 +01:00
const assert = require('assert');
2017-07-13 09:40:22 +02:00
const h = require('react-hyperscript');
const sinon = require('sinon');
const path = require('path');
2017-11-02 18:28:41 +01:00
const Dropdown = require(path.join(__dirname, '..', '..', '..', '..', 'ui', 'app', 'components', 'dropdowns', 'index.js')).Dropdown;
const { createMockStore } = require('redux-test-utils')
2017-11-26 01:37:12 +01:00
const { mountWithStore } = require('../../../lib/shallow-with-store')
2017-11-02 18:28:41 +01:00
const mockState = {
metamask: {
}
}
2017-07-13 09:40:22 +02:00
describe('Dropdown components', function () {
2017-07-18 14:23:25 +02:00
let onClickOutside;
let closeMenu;
let onClick;
2017-07-13 09:40:22 +02:00
2017-11-02 18:28:41 +01:00
let dropdownComponentProps = {
isOpen: true,
zIndex: 11,
onClickOutside,
style: {
position: 'absolute',
right: 0,
top: '36px',
},
innerStyle: {},
}
let dropdownComponent
let store
let component
2017-07-18 14:23:25 +02:00
beforeEach(function () {
onClickOutside = sinon.spy();
closeMenu = sinon.spy();
onClick = sinon.spy();
2017-07-13 09:40:22 +02:00
2017-11-02 18:28:41 +01:00
store = createMockStore(mockState)
2017-11-26 01:37:12 +01:00
component = mountWithStore(h(
2017-07-18 14:23:25 +02:00
Dropdown,
dropdownComponentProps,
[
h('style', `
.drop-menu-item:hover { background:rgb(235, 235, 235); }
.drop-menu-item i { margin: 11px; }
`),
2017-11-02 18:28:41 +01:00
h('li', {
2017-07-18 14:23:25 +02:00
closeMenu,
onClick,
}, 'Item 1'),
2017-11-02 18:28:41 +01:00
h('li', {
2017-07-18 14:23:25 +02:00
closeMenu,
onClick,
}, 'Item 2'),
]
2017-11-02 18:28:41 +01:00
), store)
2017-11-26 01:37:12 +01:00
dropdownComponent = component
2017-11-02 18:28:41 +01:00
})
2017-07-13 09:40:22 +02:00
2017-11-02 18:28:41 +01:00
it('can render two items', function () {
const items = dropdownComponent.find('li');
2017-07-13 09:40:22 +02:00
assert.equal(items.length, 2);
});
2017-07-18 14:23:25 +02:00
it('closes when item clicked', function() {
2017-11-02 18:28:41 +01:00
const items = dropdownComponent.find('li');
const node = items.at(0);
node.simulate('click');
assert.equal(node.props().closeMenu, closeMenu);
2017-07-18 14:23:25 +02:00
});
it('invokes click handler when item clicked', function() {
2017-11-02 18:28:41 +01:00
const items = dropdownComponent.find('li');
const node = items.at(0);
node.simulate('click');
2017-07-18 14:23:25 +02:00
assert.equal(onClick.calledOnce, true);
});
});