a0c1c9978c04949327fcc655f403a16fe3095157
[sdc.git] / openecomp-ui / test / nfvo-components / listEditor / listEditor.test.js
1 /*
2  * Copyright © 2016-2017 European Support Limited
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 or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 import React from 'react';
18 import {mount} from 'enzyme';
19 import TestUtils from 'react-dom/test-utils';
20 import ListEditorView from 'src/nfvo-components/listEditor/ListEditorView.jsx';
21 import ListEditorItemView from 'src/nfvo-components/listEditor/ListEditorItemView.jsx';
22
23 describe('listEditor Module Tests', function () {
24
25
26         it('list editor view should exist', () => {
27                 expect(ListEditorView).toBeTruthy();
28         });
29
30         it('list editor item view should exist', () => {
31                 expect(ListEditorItemView).toBeTruthy();
32         });
33
34         it('should render list and list item and call onEdit', done => {
35                 let itemView = TestUtils.renderIntoDocument(
36                         <ListEditorView title='some title'>
37                                 <ListEditorItemView onEdit={done}>
38                                         <div></div>
39                                 </ListEditorItemView>
40                         </ListEditorView>
41                 );
42                 expect(itemView).toBeTruthy();
43                 let sliderIcon = TestUtils.findRenderedDOMComponentWithClass(itemView, '__sliders');
44                 TestUtils.Simulate.click(sliderIcon);
45         });
46
47         it('should render list and list item and call onFilter', () => {
48                 let itemView = mount(
49                         <ListEditorView onFilter={()=>{}} children={[(<ListEditorItemView key='id'/>)]} />
50                 );
51                 expect(itemView).toBeTruthy();
52                 let inputComponent = itemView.find('ExpandableInput');
53                 expect(inputComponent.length).toBe(1);
54         });
55
56         it('should render READONLY list item and not call onEdit', done => {
57                 let itemView = TestUtils.renderIntoDocument(
58                         <ListEditorItemView onEdit={done} isReadOnlyMode={true}>
59                                 <div></div>
60                         </ListEditorItemView>
61                 );
62                 expect(itemView).toBeTruthy();
63                 let sliderIcon = TestUtils.findRenderedDOMComponentWithClass(itemView, '__sliders');
64                 TestUtils.Simulate.click(sliderIcon);
65         });
66
67         it('should render list item and call onDelete', done => {
68                 let itemView = TestUtils.renderIntoDocument(
69                         <ListEditorItemView onDelete={done} isReadOnlyMode={false}>
70                                 <div></div>
71                         </ListEditorItemView>
72                 );
73                 expect(itemView).toBeTruthy();
74                 let sliderIcon = TestUtils.findRenderedDOMComponentWithClass(itemView, '__trashO');
75                 TestUtils.Simulate.click(sliderIcon);
76         });
77
78         it('should render READONLY list item and not call onDelete', () => {
79                 let itemView = TestUtils.renderIntoDocument(
80                         <ListEditorItemView onDelete={()=>{}} isReadOnlyMode={true}>
81                                 <div></div>
82                         </ListEditorItemView>
83                 );
84                 expect(itemView).toBeTruthy();
85                 let trashIcon = TestUtils.scryRenderedDOMComponentsWithClass(itemView, '__trashOq');
86                 expect(trashIcon).toEqual([]);
87         });
88
89 });