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