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

66 lines
1.5 KiB
JavaScript
Raw Normal View History

import React from 'react'
import assert from 'assert'
import sinon from 'sinon'
import { createMockStore } from 'redux-test-utils'
import { mountWithStore } from '../../../lib/render-helpers'
import { Dropdown } from '../../../../ui/app/components/app/dropdowns/components/dropdown'
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 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()
onClick = sinon.spy()
2017-07-13 09:40:22 +02:00
2017-11-02 18:28:41 +01:00
store = createMockStore(mockState)
component = mountWithStore((
<Dropdown {...dropdownComponentProps}>
<style>
{
`
.drop-menu-item:hover { background:rgb(235, 235, 235); }
.drop-menu-item i { margin: 11px; }
`
}
</style>
<li onClick={onClick}>Item 1</li>
<li onClick={onClick}>Item 2</li>
</Dropdown>
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('invokes click handler when item clicked', function () {
const items = dropdownComponent.find('li')
const node = items.at(0)
node.simulate('click')
assert.ok(onClick.calledOnce)
2018-07-03 00:49:33 +02:00
})
})