blob: ec1d81e7af43912308330a0af644b13e3c7bb766 [file] [log] [blame]
svishnev1eb66b72018-01-11 14:39:45 +02001/*
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02002 * Copyright © 2016-2018 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
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
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02007 *
svishnev1eb66b72018-01-11 14:39:45 +02008 * http://www.apache.org/licenses/LICENSE-2.0
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02009 *
AviZi280f8012017-06-09 02:39:56 +030010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
svishnev1eb66b72018-01-11 14:39:45 +020012 * 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.
AviZi280f8012017-06-09 02:39:56 +030015 */
16
17import React from 'react';
Einav Weiss Keidard2f57942018-02-14 14:00:07 +020018import ShallowRenderer from 'react-test-renderer/shallow';
19import TestUtils from 'react-dom/test-utils';
AviZi280f8012017-06-09 02:39:56 +030020import {scryRenderedDOMComponentsWithTestId} from 'test-utils/Util.js';
21import SummaryView from 'sdc-app/onboarding/licenseModel/overview/SummaryView.jsx';
22import LicenseModelOverviewView from 'sdc-app/onboarding/licenseModel/overview/LicenseModelOverviewView.jsx';
23import VLMListView from 'sdc-app/onboarding/licenseModel/overview/VLMListView.jsx';
24import {selectedButton} from 'sdc-app/onboarding/licenseModel/overview/LicenseModelOverviewConstants.js';
25
26import {FeatureGroupListItemFactory} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
27import {EntitlementPoolListItemFactory} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js';
28import {LicenseKeyGroupListItemFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js';
29import {LicenseAgreementListItemFactory} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js';
30
31describe('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', () => {
Einav Weiss Keidard2f57942018-02-14 14:00:07 +020041 const renderer = new ShallowRenderer();
AviZi280f8012017-06-09 02:39:56 +030042 renderer.render(
talig8e9c0652017-12-20 14:30:43 +020043 <SummaryView isReadOnly={false} />
AviZi280f8012017-06-09 02:39:56 +030044 );
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],
ilanapc6a41de2017-11-07 11:54:10 +020060 orphanDataList: [],
AviZi280f8012017-06-09 02:39:56 +030061 selectedTab: selectedButton.VLM_LIST_VIEW,
62 onTabSelect: () => {}
63 };
Einav Weiss Keidard2f57942018-02-14 14:00:07 +020064 const renderer = new ShallowRenderer();
AviZi280f8012017-06-09 02:39:56 +030065 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});