[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / test / nfvo-components / input / dualListBox / dualListbox.test.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16
17 import React from 'react';
18 import TestUtils from 'react-addons-test-utils';
19 import DualListboxView from 'nfvo-components/input/dualListbox/DualListboxView.jsx';
20
21 const ITEMS = [{id: '1', name: 'aaa'}, {id: '2', name: 'bbb'}, {id: '3', name: 'ccc'}];
22
23 describe('dualListBox Module Tests', function () {
24
25
26         it('should render basically', () => {
27                 var renderer = TestUtils.createRenderer();
28                 renderer.render(<DualListboxView onChange={()=>{}}/>);
29                 var renderedOutput = renderer.getRenderOutput();
30                 expect(renderedOutput).toBeTruthy();
31         });
32
33         it('should render with available list and 4 control buttons', () => {
34                 var view = TestUtils.renderIntoDocument(<DualListboxView availableList={ITEMS} onChange={()=>{}}/>);
35                 expect(view).toBeTruthy();
36                 var results = TestUtils.scryRenderedDOMComponentsWithClass(view, 'dual-list-option');
37                 expect(results.length).toBe(4);
38         });
39
40         it('should add item to selected list', done => {
41                 const onChange = (values)=> {
42                         expect(values).toEqual([ITEMS[2].id, ITEMS[0].id]);
43                         done();
44                 };
45                 const document = TestUtils.renderIntoDocument(
46                         <DualListboxView
47                                 availableList={ITEMS}
48                                 onChange={onChange}
49                                 selectedValuesList={[ITEMS[2].id]}/>);
50
51                 const result = TestUtils.scryRenderedDOMComponentsWithTag(document, 'select');
52                 const options = TestUtils.scryRenderedDOMComponentsWithTag(document, 'option');
53                 const listBox = TestUtils.findRenderedComponentWithType(document, DualListboxView);
54                 expect(result).toBeTruthy();
55                 expect(options).toBeTruthy();
56                 expect(listBox).toBeTruthy();
57
58                 TestUtils.Simulate.change(result[0], {target: {selectedOptions: [options[0]]}});
59                 expect(listBox.state.selectedValues).toEqual([ITEMS[0].id]);
60
61                 listBox.addToSelectedList();
62         });
63
64         it('should remove item from selected list', done => {
65                 const onChange = (values)=> {
66                         expect(values).toEqual([ITEMS[0].id]);
67                         done();
68                 };
69                 const document = TestUtils.renderIntoDocument(
70                         <DualListboxView
71                                 availableList={ITEMS}
72                                 onChange={onChange}
73                                 selectedValuesList={[ITEMS[0].id, ITEMS[1].id]}/>);
74
75                 const result = TestUtils.scryRenderedDOMComponentsWithTag(document, 'select');
76                 const options = TestUtils.scryRenderedDOMComponentsWithTag(document, 'option');
77                 const listBox = TestUtils.findRenderedComponentWithType(document, DualListboxView);
78                 expect(result).toBeTruthy();
79                 expect(options).toBeTruthy();
80                 expect(listBox).toBeTruthy();
81
82                 TestUtils.Simulate.change(result[1], {target: {selectedOptions: [options[2]]}});
83                 expect(listBox.state.selectedValues).toEqual([ITEMS[1].id]);
84
85                 listBox.removeFromSelectedList();
86         });
87
88         it('should add all items to selected list', done => {
89                 let onChange = (value)=> {
90                         expect(value).toEqual(ITEMS.map(item => item.id));
91                         done();
92                 };
93                 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]});
94                 expect(view).toBeTruthy();
95                 view.addAllToSelectedList();
96         });
97
98         it('should remove all items from selected list', done => {
99                 let onChange = (value)=> {
100                         expect(value.length).toBe(0);
101                         done();
102                 };
103                 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]});
104                 expect(view).toBeTruthy();
105                 view.removeAllFromSelectedList();
106         });
107
108
109 });