1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-12 12:47:14 +01:00
metamask-extension/test/unit/responsive/components/dropdown-test.js

82 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-07-03 00:49:33 +02:00
const assert = require('assert')
2017-07-13 09:40:22 +02:00
2018-07-03 00:49:33 +02:00
const h = require('react-hyperscript')
const sinon = require('sinon')
const path = require('path')
const Dropdown = require(path.join(__dirname, '..', '..', '..', '..', 'ui', 'app', 'components', 'dropdowns', 'index.js')).Dropdown
2017-11-02 18:28:41 +01:00
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: {
2018-07-03 00:49:33 +02:00
},
2017-11-02 18:28:41 +01:00
}
2017-07-13 09:40:22 +02:00
describe('Dropdown components', function () {
2018-07-03 00:49:33 +02:00
let onClickOutside
let closeMenu
let onClick
2017-07-13 09:40:22 +02:00
2018-07-03 00:49:33 +02:00
const dropdownComponentProps = {
2017-11-02 18:28:41 +01:00
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 () {
2018-07-03 00:49:33 +02:00
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 () {
2018-07-03 00:49:33 +02:00
const items = dropdownComponent.find('li')
assert.equal(items.length, 2)
})
2017-07-18 14:23:25 +02:00
2018-07-03 00:49:33 +02:00
it('closes when item clicked', function () {
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
2018-07-03 00:49:33 +02:00
it('invokes click handler when item clicked', function () {
const items = dropdownComponent.find('li')
const node = items.at(0)
node.simulate('click')
assert.equal(onClick.calledOnce, true)
})
})