3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 import React from 'react';
21 import { expect } from 'chai';
22 import { shallow } from 'enzyme';
23 import sinon from 'sinon';
24 import Select from 'react-select';
25 import InputForSingleSelectList from '../InputForSingleSelectList';
27 describe('Settings :: Inputs :: InputForSingleSelectList', () => {
28 it('should render Select', () => {
29 const onChange = sinon.spy();
30 const select = shallow(
31 <InputForSingleSelectList
34 options={['foo', 'bar', 'baz']}
38 expect(select).to.have.length(1);
39 expect(select.prop('name')).to.equal('foo');
40 expect(select.prop('value')).to.equal('bar');
41 expect(select.prop('options')).to.deep.equal([
42 { value: 'foo', label: 'foo' },
43 { value: 'bar', label: 'bar' },
44 { value: 'baz', label: 'baz' }
46 expect(select.prop('onChange')).to.be.a('function');
49 it('should call onChange', () => {
50 const onChange = sinon.spy();
51 const select = shallow(
52 <InputForSingleSelectList
55 options={['foo', 'bar', 'baz']}
59 expect(select).to.have.length(1);
60 expect(select.prop('onChange')).to.be.a('function');
62 select.prop('onChange')({ value: 'baz', label: 'baz' });
63 expect(onChange.called).to.equal(true);
64 expect(onChange.lastCall.args).to.deep.equal(['baz']);