2018-02-28 17:27:19 +00:00
|
|
|
import React from 'react'
|
2018-02-28 21:05:24 +00:00
|
|
|
import Dropdown from 'shared/components/Dropdown'
|
|
|
|
import DropdownMenu from 'shared/components/DropdownMenu'
|
|
|
|
|
2018-02-28 17:27:19 +00:00
|
|
|
import {shallow} from 'enzyme'
|
2018-02-28 21:05:24 +00:00
|
|
|
const items = [{text: 'foo'}, {text: 'bar'}]
|
2018-02-28 17:27:19 +00:00
|
|
|
|
|
|
|
const setup = (override = {}) => {
|
|
|
|
const props = {
|
|
|
|
items: [],
|
|
|
|
selected: '',
|
|
|
|
onChoose: jest.fn(),
|
|
|
|
...override,
|
|
|
|
}
|
|
|
|
|
2018-02-28 21:05:24 +00:00
|
|
|
const dropdown = shallow(<Dropdown {...props} />).dive({
|
|
|
|
'data-test': 'dropdown-button',
|
|
|
|
})
|
2018-02-28 17:27:19 +00:00
|
|
|
|
|
|
|
return {
|
2018-02-28 21:05:24 +00:00
|
|
|
dropdown,
|
2018-02-28 17:27:19 +00:00
|
|
|
props,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Components.Shared.Dropdown', () => {
|
|
|
|
describe('rednering', () => {
|
|
|
|
describe('initial render', () => {
|
2018-02-28 21:05:24 +00:00
|
|
|
it('renders the dropdown menu button', () => {
|
|
|
|
const {dropdown} = setup()
|
2018-02-28 17:27:19 +00:00
|
|
|
|
2018-02-28 21:05:24 +00:00
|
|
|
expect(dropdown.exists()).toBe(true)
|
2018-02-28 17:27:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('does not show the list', () => {
|
2018-02-28 21:05:24 +00:00
|
|
|
const {dropdown} = setup({items})
|
2018-02-28 17:27:19 +00:00
|
|
|
|
2018-02-28 21:05:24 +00:00
|
|
|
const menu = dropdown.find(DropdownMenu)
|
|
|
|
expect(menu.exists()).toBe(false)
|
2018-02-28 17:27:19 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('user interactions', () => {
|
2018-02-28 21:05:24 +00:00
|
|
|
it('shows the menu when clicked', () => {
|
|
|
|
const {dropdown} = setup({items})
|
2018-02-28 17:27:19 +00:00
|
|
|
|
|
|
|
dropdown.simulate('click')
|
|
|
|
|
2018-02-28 21:05:24 +00:00
|
|
|
const menu = dropdown.find(DropdownMenu)
|
|
|
|
expect(menu.exists()).toBe(true)
|
2018-02-28 17:27:19 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|