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