2016-11-09 14:26:15 +00:00
|
|
|
import React from 'react';
|
2016-12-21 17:25:54 +00:00
|
|
|
import expect, { createSpy, restoreSpies } from 'expect';
|
2016-11-09 14:26:15 +00:00
|
|
|
import { mount } from 'enzyme';
|
|
|
|
|
|
2016-12-21 17:25:54 +00:00
|
|
|
import Dropdown from 'components/forms/fields/Dropdown';
|
|
|
|
|
import { fillInFormInput } from 'test/helpers';
|
2016-11-09 14:26:15 +00:00
|
|
|
|
|
|
|
|
describe('Dropdown - component', () => {
|
2016-12-21 17:25:54 +00:00
|
|
|
afterEach(restoreSpies);
|
|
|
|
|
|
2016-11-09 14:26:15 +00:00
|
|
|
const options = [
|
|
|
|
|
{ text: 'Users', value: 'users' },
|
|
|
|
|
{ text: 'Groups', value: 'groups' },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const props = {
|
2016-12-21 17:25:54 +00:00
|
|
|
name: 'my-select',
|
2016-11-09 14:26:15 +00:00
|
|
|
options,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
it('renders the dropdown', () => {
|
|
|
|
|
const component = mount(<Dropdown {...props} />);
|
|
|
|
|
const dropdownSelect = component.find('Select');
|
|
|
|
|
|
|
|
|
|
expect(dropdownSelect).toExist();
|
|
|
|
|
});
|
2016-12-21 17:25:54 +00:00
|
|
|
|
|
|
|
|
it('selects a value from dropdown', () => {
|
|
|
|
|
const onChangeSpy = createSpy();
|
|
|
|
|
const component = mount(<Dropdown {...props} onChange={onChangeSpy} />);
|
|
|
|
|
const inputNode = component.find('input');
|
|
|
|
|
|
|
|
|
|
fillInFormInput(inputNode, 'users');
|
|
|
|
|
component.find('.Select-option').first().simulate('mousedown');
|
|
|
|
|
|
|
|
|
|
expect(onChangeSpy).toHaveBeenCalledWith('users');
|
|
|
|
|
});
|
2016-11-09 14:26:15 +00:00
|
|
|
});
|