2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 import React from 'react';
18 import TestUtils from 'react-addons-test-utils';
19 import DualListboxView from 'nfvo-components/input/dualListbox/DualListboxView.jsx';
22 const ITEMS = [{id: '1', name: 'aaa'}, {id: '2', name: 'bbb'}, {id: '3', name: 'ccc'}];
24 describe('dualListBox Module Tests', function () {
27 it('should render basically', () => {
28 var renderer = TestUtils.createRenderer();
29 renderer.render(<DualListboxView onChange={()=>{}}/>);
30 var renderedOutput = renderer.getRenderOutput();
31 expect(renderedOutput).toBeTruthy();
34 it('should render with available list and 4 control buttons', () => {
35 var view = TestUtils.renderIntoDocument(<DualListboxView availableList={ITEMS} onChange={()=>{}}/>);
36 expect(view).toBeTruthy();
37 var results = TestUtils.scryRenderedDOMComponentsWithClass(view, 'dual-list-option');
38 expect(results.length).toBe(4);
41 it('should add item to selected list', done => {
42 const onChange = (values)=> {
43 expect(values).toEqual([ITEMS[2].id, ITEMS[0].id]);
46 const document = TestUtils.renderIntoDocument(
50 selectedValuesList={[ITEMS[2].id]}/>);
52 const result = TestUtils.scryRenderedDOMComponentsWithTag(document, 'select');
53 const options = TestUtils.scryRenderedDOMComponentsWithTag(document, 'option');
54 const listBox = TestUtils.findRenderedComponentWithType(document, DualListboxView);
55 expect(result).toBeTruthy();
56 expect(options).toBeTruthy();
57 expect(listBox).toBeTruthy();
59 TestUtils.Simulate.change(result[0], {target: {selectedOptions: [options[0]]}});
60 expect(listBox.state.selectedValues).toEqual([ITEMS[0].id]);
62 listBox.addToSelectedList();
65 it('should remove item from selected list', done => {
66 const onChange = (values)=> {
67 expect(values).toEqual([ITEMS[0].id]);
70 const document = TestUtils.renderIntoDocument(
74 selectedValuesList={[ITEMS[0].id, ITEMS[1].id]}/>);
76 const result = TestUtils.scryRenderedDOMComponentsWithTag(document, 'select');
77 const options = TestUtils.scryRenderedDOMComponentsWithTag(document, 'option');
78 const listBox = TestUtils.findRenderedComponentWithType(document, DualListboxView);
79 expect(result).toBeTruthy();
80 expect(options).toBeTruthy();
81 expect(listBox).toBeTruthy();
83 TestUtils.Simulate.change(result[1], {target: {selectedOptions: [options[2]]}});
84 expect(listBox.state.selectedValues).toEqual([ITEMS[1].id]);
86 listBox.removeFromSelectedList();
89 it('should add all items to selected list', done => {
90 let onChange = (value)=> {
91 expect(value).toEqual(ITEMS.map(item => item.id));
94 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]});
95 expect(view).toBeTruthy();
96 view.addAllToSelectedList();
99 it('should remove all items from selected list', done => {
100 let onChange = (value)=> {
101 expect(value.length).toBe(0);
104 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]});
105 expect(view).toBeTruthy();
106 view.removeAllFromSelectedList();