Add new code new version
[sdc.git] / openecomp-ui / test / nfvo-components / input / dualListBox / dualListbox.test.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
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';
25
26 const ITEMS = [{id: '1', name: 'aaa'}, {id: '2', name: 'bbb'}, {id: '3', name: 'ccc'}];
27
28 describe('dualListBox Module Tests', function () {
29
30
31         it('should render basically', () => {
32                 var renderer = TestUtils.createRenderer();
33                 renderer.render(<DualListboxView onChange={()=>{}}/>);
34                 var renderedOutput = renderer.getRenderOutput();
35                 expect(renderedOutput).toExist();
36         });
37
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);
43         });
44
45         it('should add item to selected list', done => {
46                 const newItemValue = 'new item';
47                 let onChange = (value)=> {
48                         expect(value).toEqual(newItemValue);
49                         done();
50                 };
51                 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]});
52                 expect(view).toExist();
53                 view.refs = {
54                         availableValues: {getValue(){return newItemValue;}}
55                 };
56                 view.addToSelectedList();
57         });
58
59         it('should remove item from selected list', done => {
60                 const selectedValuesList = ['a','b'];
61                 let onChange = (value)=> {
62                         expect(value).toEqual(selectedValuesList[1]);
63                         done();
64                 };
65                 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList});
66                 expect(view).toExist();
67                 view.refs = {
68                         selectedValues: {getValue(){return ['a'];}}
69                 };
70                 view.removeFromSelectedList();
71         });
72
73         it('should add all items to selected list', done => {
74                 let onChange = (value)=> {
75                         expect(value).toEqual(ITEMS.map(item => item.id));
76                         done();
77                 };
78                 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]});
79                 expect(view).toExist();
80                 view.addAllToSelectedList();
81         });
82
83         it('should remove all items from selected list', done => {
84                 let onChange = (value)=> {
85                         expect(value.length).toBe(0);
86                         done();
87                 };
88                 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]});
89                 expect(view).toExist();
90                 view.removeAllFromSelectedList();
91         });
92
93
94 });