2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
13 * or implied. See the License for the specific language governing
14 * permissions and 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';
21 const ITEMS = [{id: '1', name: 'aaa'}, {id: '2', name: 'bbb'}, {id: '3', name: 'ccc'}];
23 describe('dualListBox Module Tests', function () {
26 it('should render basically', () => {
27 var renderer = TestUtils.createRenderer();
28 renderer.render(<DualListboxView onChange={()=>{}}/>);
29 var renderedOutput = renderer.getRenderOutput();
30 expect(renderedOutput).toBeTruthy();
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);
40 it('should add item to selected list', done => {
41 const onChange = (values)=> {
42 expect(values).toEqual([ITEMS[2].id, ITEMS[0].id]);
45 const document = TestUtils.renderIntoDocument(
49 selectedValuesList={[ITEMS[2].id]}/>);
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();
58 TestUtils.Simulate.change(result[0], {target: {selectedOptions: [options[0]]}});
59 expect(listBox.state.selectedValues).toEqual([ITEMS[0].id]);
61 listBox.addToSelectedList();
64 it('should remove item from selected list', done => {
65 const onChange = (values)=> {
66 expect(values).toEqual([ITEMS[0].id]);
69 const document = TestUtils.renderIntoDocument(
73 selectedValuesList={[ITEMS[0].id, ITEMS[1].id]}/>);
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();
82 TestUtils.Simulate.change(result[1], {target: {selectedOptions: [options[2]]}});
83 expect(listBox.state.selectedValues).toEqual([ITEMS[1].id]);
85 listBox.removeFromSelectedList();
88 it('should add all items to selected list', done => {
89 let onChange = (value)=> {
90 expect(value).toEqual(ITEMS.map(item => item.id));
93 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]});
94 expect(view).toBeTruthy();
95 view.addAllToSelectedList();
98 it('should remove all items from selected list', done => {
99 let onChange = (value)=> {
100 expect(value.length).toBe(0);
103 var view = new DualListboxView({availableList:ITEMS, onChange, selectedValuesList:[]});
104 expect(view).toBeTruthy();
105 view.removeAllFromSelectedList();