Add new code new version
[sdc.git] / openecomp-ui / test / nfvo-components / listEditor / listEditor.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 ListEditorView from 'src/nfvo-components/listEditor/ListEditorView.jsx';
25 import ListEditorItemView from 'src/nfvo-components/listEditor/ListEditorItemView.jsx';
26
27 describe('listEditor Module Tests', function () {
28
29
30         it('list editor view should exist', () => {
31                 expect(ListEditorView).toExist();
32         });
33
34         it('list editor item view should exist', () => {
35                 expect(ListEditorItemView).toExist();
36         });
37
38         it('should render list and list item and call onEdit', done => {
39                 let itemView = TestUtils.renderIntoDocument(
40                         <ListEditorView title='some title'>
41                                 <ListEditorItemView onEdit={done}>
42                                         <div></div>
43                                 </ListEditorItemView>
44                         </ListEditorView>
45                 );
46                 expect(itemView).toExist();
47                 let sliderIcon = TestUtils.findRenderedDOMComponentWithClass(itemView, 'fa-sliders');
48                 TestUtils.Simulate.click(sliderIcon);
49         });
50
51         it('should render list and list item and call onFilter', done => {
52                 let itemView = TestUtils.renderIntoDocument(
53                         <ListEditorView onFilter={()=>{done();}}>
54                                 <ListEditorItemView>
55                                         <div></div>
56                                 </ListEditorItemView>
57                         </ListEditorView>
58                 );
59                 expect(itemView).toExist();
60                 let filterInput = TestUtils.findRenderedDOMComponentWithTag(itemView, 'input');
61                 TestUtils.Simulate.change(filterInput);
62         });
63
64         it('should render READONLY list item and not call onEdit', done => {
65                 let itemView = TestUtils.renderIntoDocument(
66                         <ListEditorItemView onEdit={done} isReadOnlyMode={true}>
67                                 <div></div>
68                         </ListEditorItemView>
69                 );
70                 expect(itemView).toExist();
71                 let sliderIcon = TestUtils.findRenderedDOMComponentWithClass(itemView, 'fa-sliders');
72                 TestUtils.Simulate.click(sliderIcon);
73         });
74
75         it('should render list item and call onDelete', done => {
76                 let itemView = TestUtils.renderIntoDocument(
77                         <ListEditorItemView onDelete={done} isReadOnlyMode={false}>
78                                 <div></div>
79                         </ListEditorItemView>
80                 );
81                 expect(itemView).toExist();
82                 let sliderIcon = TestUtils.findRenderedDOMComponentWithClass(itemView, 'fa-trash-o');
83                 TestUtils.Simulate.click(sliderIcon);
84         });
85
86         it('should render READONLY list item and not call onDelete', () => {
87                 let itemView = TestUtils.renderIntoDocument(
88                         <ListEditorItemView onDelete={()=>{}} isReadOnlyMode={true}>
89                                 <div></div>
90                         </ListEditorItemView>
91                 );
92                 expect(itemView).toExist();
93                 let sliderIcon = TestUtils.scryRenderedDOMComponentsWithClass(itemView, 'fa-trash-o');
94                 expect(sliderIcon).toEqual(0);
95         });
96 });