1a5c5efbeef63bfcb086245cb66f59799f664009
[sdc.git] / openecomp-ui / test / softwareProduct / details / detailsView.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 import React from 'react';
17 import TestUtils from 'react-dom/test-utils';
18 import ShallowRenderer from 'react-test-renderer/shallow';
19 import {mapStateToProps} from 'sdc-app/onboarding/softwareProduct/details/SoftwareProductDetails.js';
20 import SoftwareProductDetailsView from 'sdc-app/onboarding/softwareProduct/details/SoftwareProductDetailsView.jsx';
21 import {VSPEditorFactory} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js';
22 import {CategoryWithSubFactory}  from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js';
23 import {LicenseAgreementStoreFactory}  from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js';
24 import {FeatureGroupStoreFactory}  from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
25 import {SchemaGenericFieldInfoFactory}  from 'test-utils/factories/softwareProduct/SoftwareProductQSchemaFactory.js';
26 import {default as VspQdataFactory, VspDataMapFactory}  from 'test-utils/factories/softwareProduct/VspQdataFactory.js';
27 import {FinalizedLicenseModelFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js';
28 import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
29 import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
30
31 describe('Software Product Details: ', function () {
32
33         let currentSoftwareProduct = {}, currentSoftwareProductWithLicensingData = {}, softwareProductCategories = [], licensingVersionsList = [], currentScreen = {},
34                 finalizedLicenseModelList, licenseAgreementList, featureGroupsList, qdata = {}, dataMap = {}, genericFieldInfo = {}, qGenericFieldInfo = {};
35         let dummyFunc = () => {};
36
37         beforeAll(function() {
38                 finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(2);
39                 currentSoftwareProduct = VSPEditorFactory.build({
40                         id: 'RTRTG454545',
41                         licensingVersion: undefined,
42                         vendorId: finalizedLicenseModelList[0].id,
43                         vendorName: finalizedLicenseModelList[0].name
44                 });
45                 softwareProductCategories = CategoryWithSubFactory.buildList(2, {}, {quantity: 1});
46                 licenseAgreementList = LicenseAgreementStoreFactory.buildList(2);
47                 licensingVersionsList = [
48                         {
49                                 "id":"0127b419e9574a11aab8e031a78fc534",
50                                 "name":"1.0","description":"Initial version",
51                                 "baseId":"","status":"Certified","creationTime":1506409288390,"modificationTime":1506409288390,"additionalInfo":{"OptionalCreationMethods":["minor"]}},{"id":"ea159ffedd9a4f9a8a56d53ba66b7314","name":"2.0","description":"ggggg","baseId":"0127b419e9574a11aab8e031a78fc534","status":"Draft","creationTime":1508839019802,"modificationTime":1508839019802,"additionalInfo":{"OptionalCreationMethods":[]}}
52                 ];
53                 featureGroupsList = FeatureGroupStoreFactory.buildList(2, {referencingLicenseAgreements: [licenseAgreementList[0].id]});
54                 qdata = VspQdataFactory.build();
55                 dataMap = VspDataMapFactory.build();
56                 currentSoftwareProductWithLicensingData = {
57                         ...currentSoftwareProduct,
58                         licensingData: {
59                                 licenseAgreement: licenseAgreementList[0].id,
60                                 featureGroups: [featureGroupsList[0].id]
61                         },
62                         licensingVersion : licensingVersionsList[0].id
63                 };
64                 genericFieldInfo = {
65                         'name': {
66                                 isValid: true,
67                                 errorText: '',
68                                 validations: [{type: 'validateName', data: true}, {type: 'maxLength', data: 120}, {
69                                         type: 'required',
70                                         data: true
71                                 }]
72                         },
73                         'description': {
74                                 isValid: true,
75                                 errorText: '',
76                                 validations: [{type: 'required', data: true}]
77                         }
78                 };
79                 qGenericFieldInfo = SchemaGenericFieldInfoFactory.build();
80                 currentScreen = CurrentScreenFactory.build();
81         });
82
83         it('should mapper exist', () => {
84                 expect(mapStateToProps).toBeTruthy();
85         });
86
87         it('should mapper return vsp basic data', () => {
88
89                 var obj = {
90                         currentScreen,
91                         softwareProduct: {
92                                 softwareProductEditor: {
93                                         data: currentSoftwareProduct,
94                                         genericFieldInfo,
95                                         licensingVersionsList
96                                 },
97                                 softwareProductCategories,
98                                 softwareProductQuestionnaire: {
99                                         qdata,
100                                         genericFieldInfo: qGenericFieldInfo,
101                                         dataMap
102                                 }
103                         },
104                         finalizedLicenseModelList,
105                         licenseModel: {
106                                 licenseAgreement: {
107                                         licenseAgreementList: []
108                                 },
109                                 featureGroup: {
110                                         featureGroupsList: []
111                                 }
112                         }
113                 };
114
115                 var result = mapStateToProps(obj);
116                 expect(result.currentSoftwareProduct).toEqual(currentSoftwareProduct);
117                 expect(result.finalizedLicenseModelList).toEqual(finalizedLicenseModelList);
118                 expect(result.finalizedLicenseModelList.length).toBeGreaterThan(0);
119                 expect(finalizedLicenseModelList[0]).toMatchObject({
120                         id: result.currentSoftwareProduct.vendorId,
121                         name: result.currentSoftwareProduct.vendorName
122                 });
123                 expect(result.softwareProductCategories).toEqual(softwareProductCategories);
124                 expect(result.licenseAgreementList).toEqual([]);
125                 expect(result.featureGroupsList).toEqual([]);
126                 expect(result.qdata).toEqual(qdata);
127                 expect(result.dataMap).toEqual(dataMap);
128                 expect(result.isFormValid).toEqual(true);
129         });
130
131         it('should mapper return vsp data with selected licenseAgreement and featureGroup', () => {
132
133                 var obj = {
134                         currentScreen,
135                         softwareProduct: {
136                                 softwareProductEditor: {
137                                         data: currentSoftwareProductWithLicensingData,
138                                         genericFieldInfo,
139                                         licensingVersionsList
140                                 },
141                                 softwareProductCategories,
142                                 softwareProductQuestionnaire: {
143                                         qdata,
144                                         genericFieldInfo: qGenericFieldInfo,
145                                         dataMap
146                                 }
147                         },
148                         finalizedLicenseModelList: finalizedLicenseModelList,
149                         licenseModel: {
150                                 licenseAgreement: {
151                                         licenseAgreementList: licenseAgreementList
152                                 },
153                                 featureGroup: {
154                                         featureGroupsList: featureGroupsList
155                                 }
156                         }
157                 };
158
159                 var result = mapStateToProps(obj);
160                 expect(result.currentSoftwareProduct).toEqual(currentSoftwareProductWithLicensingData);
161                 expect(result.finalizedLicenseModelList).toEqual(finalizedLicenseModelList);
162                 expect(result.finalizedLicenseModelList.length).toBeGreaterThan(0);
163                 expect(result.finalizedLicenseModelList[0]).toMatchObject({
164                         id: result.currentSoftwareProduct.vendorId,
165                         name: result.currentSoftwareProduct.vendorName
166                 });
167                 expect(result.softwareProductCategories).toEqual(softwareProductCategories);
168                 expect(result.licenseAgreementList).toEqual(licenseAgreementList);
169                 expect(result.licenseAgreementList[0]).toMatchObject({...licenseAgreementList[0], id: result.currentSoftwareProduct.licensingData.licenseAgreement});
170                 result.currentSoftwareProduct.licensingData.featureGroups.forEach(fg => {
171                         expect(featureGroupsList[0]).toMatchObject({...featureGroupsList[0], id: fg});
172                 });
173                 expect(result.qdata).toEqual(qdata);
174         });
175
176         it('VSP Details view test', () => {
177
178                 let params = {
179                         ...currentScreen.props,
180                         currentSoftwareProduct,
181                         softwareProductCategories,
182                         qdata,
183                         dataMap,
184                         isFormValid: true,
185                         finalizedLicenseModelList,
186                         licenseAgreementList,
187                         featureGroupsList,
188                         licensingVersionsList,
189                         genericFieldInfo,
190                         qGenericFieldInfo,
191                 };
192                 const renderer = new ShallowRenderer();
193                 renderer.render(
194                         <SoftwareProductDetailsView
195                                 {...params}
196                                 onSubmit = {dummyFunc}
197                                 onDataChanged = {dummyFunc}
198                                 onValidityChanged = {dummyFunc}
199                                 onQDataChanged = {dummyFunc}
200                                 onVendorParamChanged = {dummyFunc}/>
201                 );
202                 let renderedOutput = renderer.getRenderOutput();
203                 expect(renderedOutput).toBeTruthy();
204                 expect(renderedOutput.props.children.props.isReadOnlyMode).toBe(false);
205
206         });
207
208         it('in view: should change vendorId and update vsp licensing-version', done => {
209
210                 let params = {
211                         currentSoftwareProduct: currentSoftwareProductWithLicensingData,
212                         softwareProductCategories,
213                         qdata,
214                         dataMap,
215                         isFormValid: true,
216                         genericFieldInfo,
217                         qGenericFieldInfo,
218                         finalizedLicenseModelList,
219                         licenseAgreementList,
220                         licensingVersionsList,
221                         featureGroupsList
222                 };
223                 const onVendorChangedListener = (deltaData) => {
224                         expect(deltaData.vendorId).toEqual(finalizedLicenseModelList[1].id);
225                         expect(deltaData.vendorName).toEqual(finalizedLicenseModelList[1].name);
226                         expect(deltaData.licensingVersion).toEqual('');
227                         expect(deltaData.licensingData).toEqual({});
228                         done();
229                 };
230
231                 var vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
232                         currentSoftwareProduct = {params.currentSoftwareProduct}
233                         softwareProductCategories = {params.softwareProductCategories}
234                         qdata = {params.qdata}
235                         qGenericFieldInfo = {params.qGenericFieldInfo}
236                         genericFieldInfo = {params.genericFieldInfo}
237                         licensingVersionsList={params.licensingVersionsList}
238                         isFormValid={params.isFormValid}
239                         dataMap={params.dataMap}
240                         finalizedLicenseModelList = {params.finalizedLicenseModelList}
241                         licenseAgreementList = {params.licenseAgreementList}
242                         featureGroupsList = {params.featureGroupsList}
243                         onSubmit = {dummyFunc}
244                         onDataChanged = {dummyFunc}
245                         onValidityChanged = {dummyFunc}
246                         onQDataChanged = {dummyFunc}
247                         onVendorParamChanged = {(deltaData) => onVendorChangedListener(deltaData)}/>);
248                 expect(vspDetailsView).toBeTruthy();
249                 vspDetailsView.onVendorParamChanged({vendorId: finalizedLicenseModelList[1].id});
250         });
251
252         it('in view: should change licensing-version and update licensing data', done => {
253                 let params = {
254                         currentSoftwareProduct: currentSoftwareProduct,
255                         softwareProductCategories,
256                         qdata,
257                         dataMap,
258                         licensingVersionsList,
259                         isFormValid: true,
260                         genericFieldInfo,
261                         qGenericFieldInfo,
262                         finalizedLicenseModelList,
263                         licenseAgreementList,
264                         featureGroupsList
265                 };
266                 const onVendorChangedListener = (deltaData) => {
267                         expect(deltaData.vendorId).toEqual(finalizedLicenseModelList[1].id);
268                         expect(deltaData.vendorName).toEqual(finalizedLicenseModelList[1].name);
269                         expect(deltaData.licensingVersion).toEqual(licensingVersionsList[1]);
270                         expect(deltaData.licensingData).toEqual({});
271                         done();
272                 };
273
274                 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
275                         {...params}
276                         onSubmit = {dummyFunc}
277                         onDataChanged = {dummyFunc}
278                         onValidityChanged = {dummyFunc}
279                         onQDataChanged = {dummyFunc}
280                         onVendorParamChanged = {(deltaData) => onVendorChangedListener(deltaData)}/>);
281                 expect(vspDetailsView).toBeTruthy();
282                 vspDetailsView.onVendorParamChanged({vendorId: finalizedLicenseModelList[1].id, licensingVersion: licensingVersionsList[1]});
283         });
284
285         it('in view: should change subcategory', done => {
286                 let params = {
287                         currentSoftwareProduct: currentSoftwareProduct,
288                         softwareProductCategories,
289                         qdata,
290                         dataMap,
291                         isFormValid: true,
292                         genericFieldInfo,
293                         qGenericFieldInfo,
294                         licensingVersionsList,
295                         finalizedLicenseModelList,
296                         licenseAgreementList,
297                         featureGroupsList
298                 };
299                 const onDataChangedListener = ({category, subCategory}) => {
300                         expect(category).toEqual(softwareProductCategories[1].uniqueId);
301                         expect(subCategory).toEqual(softwareProductCategories[1].subcategories[0].uniqueId);
302                         done();
303                 };
304
305                 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
306                         {...params}
307                         onSubmit = {dummyFunc}
308                         onDataChanged = {({category, subCategory}) => onDataChangedListener({category, subCategory})}
309                         onValidityChanged = {dummyFunc}
310                         onQDataChanged = {dummyFunc}
311                         onVendorParamChanged = {dummyFunc}/>);
312                 expect(vspDetailsView).toBeTruthy();
313                 vspDetailsView.onSelectSubCategory(softwareProductCategories[1].subcategories[0].uniqueId);
314         });
315
316         it('in view: should change feature groups', done => {
317
318                 let params = {
319                         currentSoftwareProduct: currentSoftwareProductWithLicensingData,
320                         softwareProductCategories,
321                         qdata,
322                         dataMap,
323                         isFormValid: true,
324                         genericFieldInfo,
325                         qGenericFieldInfo,
326                         licensingVersionsList,
327                         finalizedLicenseModelList,
328                         licenseAgreementList,
329                         featureGroupsList
330                 };
331                 const onDataChangedListener = ({licensingData}) => {
332                         expect(licensingData.licenseAgreement).toEqual(licenseAgreementList[0].id);
333                         expect(licensingData.featureGroups).toEqual([
334                                 {enum: featureGroupsList[0].id, title: featureGroupsList[0].name},
335                                 {enum: featureGroupsList[1].id, title: featureGroupsList[1].name}
336                         ]);
337                         done();
338                 };
339
340                 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
341                         {...params}
342                         onSubmit = {dummyFunc}
343                         onDataChanged = {({licensingData}) => onDataChangedListener({licensingData})}
344                         onValidityChanged = {dummyFunc}
345                         onQDataChanged = {dummyFunc}
346                         onVendorParamChanged = {dummyFunc}/>);
347                 expect(vspDetailsView).toBeTruthy();
348                 vspDetailsView.onFeatureGroupsChanged({featureGroups: [
349                         {enum: featureGroupsList[0].id, title: featureGroupsList[0].name},
350                         {enum: featureGroupsList[1].id, title: featureGroupsList[1].name}
351                 ]});
352         });
353
354
355         it('in view: should change license agreement', done => {
356                 let params = {
357                         currentSoftwareProduct: currentSoftwareProductWithLicensingData,
358                         softwareProductCategories,
359                         qdata,
360                         dataMap,
361                         isFormValid: true,
362                         genericFieldInfo,
363                         qGenericFieldInfo,
364                         licensingVersionsList,
365                         finalizedLicenseModelList,
366                         licenseAgreementList,
367                         featureGroupsList
368                 };
369                 const onDataChangedListener = ({licensingData}) => {
370                         expect(licensingData.licenseAgreement).toEqual(licenseAgreementList[1].id);
371                         expect(licensingData.featureGroups).toEqual([]);
372                         done();
373                 };
374
375                 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
376                         {...params}
377                         onSubmit = {dummyFunc}
378                         onDataChanged = {({licensingData}) => onDataChangedListener({licensingData})}
379                         onValidityChanged = {dummyFunc}
380                         onQDataChanged = {dummyFunc}
381                         onVendorParamChanged = {dummyFunc}/>);
382                 expect(vspDetailsView).toBeTruthy();
383                 vspDetailsView.onLicensingDataChanged({licenseAgreement: licenseAgreementList[1].id, featureGroups: []});
384         });
385
386 });