2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import expect from 'expect';
22 import React from 'react';
23 import TestUtils from 'react-addons-test-utils';
24 import DualListboxView from 'nfvo-components/input/dualListbox/DualListboxView.jsx';
26 const ITEMS = [{id: '1', name: 'aaa'}, {id: '2', name: 'bbb'}, {id: '3', name: 'ccc'}];
28 describe('dualListBox Module Tests', function () {
31 it('should render basically', () => {
32 var renderer = TestUtils.createRenderer();
33 renderer.render(<DualListboxView onChange={()=>{}}/>);
34 var renderedOutput = renderer.getRenderOutput();
35 expect(renderedOutput).toExist();
38 it('should render with available list and 4 control buttons', () => {
39 var view = TestUtils.renderIntoDocument(<DualListboxView availableList={ITEMS} onChange={()=>{}}/>);
40 expect(view).toExist();
41 var results = TestUtils.scryRenderedDOMComponentsWithClass(view, 'dual-list-option');
42 expect(results.length).toBe(4);
45 it('should add item to selected list', done => {
46 const newItemValue = 'new item';
47 let onChange = (value)=> {
48 expect(value).toEqual(newItemValue);
51 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]});
52 expect(view).toExist();
54 availableValues: {getValue(){return newItemValue;}}
56 view.addToSelectedList();
59 it('should remove item from selected list', done => {
60 const selectedValuesList = ['a','b'];
61 let onChange = (value)=> {
62 expect(value).toEqual(selectedValuesList[1]);
65 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList});
66 expect(view).toExist();
68 selectedValues: {getValue(){return ['a'];}}
70 view.removeFromSelectedList();
73 it('should add all items to selected list', done => {
74 let onChange = (value)=> {
75 expect(value).toEqual(ITEMS.map(item => item.id));
78 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]});
79 expect(view).toExist();
80 view.addAllToSelectedList();
83 it('should remove all items from selected list', done => {
84 let onChange = (value)=> {
85 expect(value.length).toBe(0);
88 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]});
89 expect(view).toExist();
90 view.removeAllFromSelectedList();