3d57c9355e208064db536cbd69053e8cedbc27fc
[sdc.git] / openecomp-ui / test / licenseModel / overview / views.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 ShallowRenderer from 'react-test-renderer/shallow';
19 import TestUtils from 'react-dom/test-utils';
20 import {scryRenderedDOMComponentsWithTestId} from 'test-utils/Util.js';
21 import SummaryView from 'sdc-app/onboarding/licenseModel/overview/SummaryView.jsx';
22 import LicenseModelOverviewView from 'sdc-app/onboarding/licenseModel/overview/LicenseModelOverviewView.jsx';
23 import VLMListView from 'sdc-app/onboarding/licenseModel/overview/VLMListView.jsx';
24 import {selectedButton} from 'sdc-app/onboarding/licenseModel/overview/LicenseModelOverviewConstants.js';
25
26 import {FeatureGroupListItemFactory} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
27 import {EntitlementPoolListItemFactory} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js';
28 import {LicenseKeyGroupListItemFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js';
29 import {LicenseAgreementListItemFactory} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js';
30
31 describe('License Model Overview - View: ', function () {
32
33         const lkgChild = LicenseKeyGroupListItemFactory.build();
34
35         const epChild = EntitlementPoolListItemFactory.build();
36
37         const baseFGData =  FeatureGroupListItemFactory.build({isCollapsed: false});
38         const baseLAData =  LicenseAgreementListItemFactory.build({isCollapse: false});
39
40         it('should render SummaryView', () => {
41                 const renderer = new ShallowRenderer();
42                 renderer.render(
43                         <SummaryView isReadOnly={false} />
44                 );
45                 let renderedOutput = renderer.getRenderOutput();
46                 expect(renderedOutput).toBeTruthy();
47         });
48
49         it('should render LicenseModelOverviewView', () => {
50                 let fgData = {...baseFGData};
51                 fgData.children = Array.of(epChild, lkgChild);
52                 let laData = {...baseLAData};
53                 laData.children = [fgData];
54
55                 const params = {
56                         licenseModelId: 'VLM1',
57                         isDisplayModal: false,
58                         modalHeader: undefined,
59                         licensingDataList: [laData],
60                         orphanDataList: [],
61                         selectedTab: selectedButton.VLM_LIST_VIEW,
62                         onTabSelect: () => {}
63                 };
64                 const renderer = new ShallowRenderer();
65                 renderer.render(
66                         <LicenseModelOverviewView {...params}/>
67                 );
68                 let renderedOutput = renderer.getRenderOutput();
69                 expect(renderedOutput).toBeTruthy();
70         });
71
72
73         it('should render empty VLMListView', () => {
74                 const listview = TestUtils.renderIntoDocument( <VLMListView /> );
75                 expect(listview).toBeTruthy();
76                 const elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list');
77                 expect(elem).toBeTruthy();
78                 expect(elem[0].children.length).toBe(0);
79         });
80
81         it('should render VLMListView with licenseAgreement', () => {
82                 const listview = TestUtils.renderIntoDocument( <VLMListView licensingDataList={[baseLAData]}/> );
83                 expect(listview).toBeTruthy();
84                 let elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list');
85                 expect(elem).toBeTruthy();
86                 expect(elem[0].children.length).toBe(1);
87                 elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-la-item');
88                 expect(elem).toBeTruthy();
89                 expect(elem.length).toBe(1);
90         });
91
92         it('should render VLMListView with Feature Group', () => {
93                 let laData = {...baseLAData};
94                 laData.children = [baseFGData];
95                 const listview = TestUtils.renderIntoDocument( <VLMListView licensingDataList={[laData]}/> );
96                 expect(listview).toBeTruthy();
97                 const elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-item-fg');
98                 expect(elem).toBeTruthy();
99                 expect(elem.length).toBe(1);
100         });
101
102         it('should render VLMListView with Entitlement Pool', () => {
103                 let fgData = {...baseFGData};
104                 fgData.children = [epChild];
105                 let laData = {...baseLAData};
106                 laData.children = [fgData];
107
108                 const listview = TestUtils.renderIntoDocument( <VLMListView licensingDataList={[laData]} showInUse={true} /> );
109                 expect(listview).toBeTruthy();
110                 const elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-item-ep');
111                 expect(elem).toBeTruthy();
112                 expect(elem.length).toBe(1);
113         });
114
115         it('should render VLMListView with LicenseKeyGroup', () => {
116                 let fgData = {...baseFGData};
117                 fgData.children = [lkgChild];
118                 let laData = {...baseLAData};
119                 laData.children = [fgData];
120
121                 const listview = TestUtils.renderIntoDocument( <VLMListView licensingDataList={[laData]} showInUse={true} /> );
122                 expect(listview).toBeTruthy();
123                 const elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-item-lkg');
124                 expect(elem).toBeTruthy();
125                 expect(elem.length).toBe(1);
126         });
127
128         it('should render VLMListView with all items', () => {
129                 let fgData = {...baseFGData};
130                 fgData.children = Array.of(epChild, lkgChild);
131                 let laData = {...baseLAData};
132                 laData.children = [fgData];
133
134                 const listview = TestUtils.renderIntoDocument( <VLMListView licensingDataList={[laData]} showInUse={true} /> );
135                 expect(listview).toBeTruthy();
136                 let elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-item-fg');
137                 expect(elem).toBeTruthy();
138                 expect(elem.length).toBe(1);
139                 elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-item-lkg');
140                 expect(elem).toBeTruthy();
141                 expect(elem.length).toBe(1);
142                 elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-item-ep');
143                 expect(elem).toBeTruthy();
144                 expect(elem.length).toBe(1);
145         });
146
147         it('should update collapsing item', () => {
148                 let fgData = {...baseFGData};
149                 fgData.children = Array.of(epChild, lkgChild);
150                 let laData = {...baseLAData};
151                 laData.children = [fgData];
152
153                 var renderer = TestUtils.renderIntoDocument(
154                         <VLMListView licensingDataList={[laData]} showInUse={true}/>
155                 );
156                 expect(renderer).toBeTruthy();
157
158                 renderer.updateCollapsable(new Event('click'), 'LA1');
159                 expect(renderer.state['LA1']).toEqual(true);
160         });
161 });