blob: 37c5df507912e44145f0bf5bc87728672cef614f [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * 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
AviZi280f8012017-06-09 02:39:56 +03007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
AviZi280f8012017-06-09 02:39:56 +030012 * 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.
Michael Landoefa037d2017-02-19 12:57:33 +020015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import React from 'react';
17import TestUtils from 'react-addons-test-utils';
18import {mapStateToProps} from 'sdc-app/onboarding/softwareProduct/details/SoftwareProductDetails.js';
19import SoftwareProductDetailsView from 'sdc-app/onboarding/softwareProduct/details/SoftwareProductDetailsView.jsx';
AviZi280f8012017-06-09 02:39:56 +030020import {VSPEditorFactory} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js';
21import {CategoryWithSubFactory} from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js';
22import {LicenseAgreementStoreFactory} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js';
23import {FeatureGroupStoreFactory} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
24import {SchemaGenericFieldInfoFactory} from 'test-utils/factories/softwareProduct/SoftwareProductQSchemaFactory.js';
25import {default as VspQdataFactory, VspDataMapFactory} from 'test-utils/factories/softwareProduct/VspQdataFactory.js';
26import {FinalizedLicenseModelFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js';
Michael Landoefa037d2017-02-19 12:57:33 +020027
28describe('Software Product Details: ', function () {
29
AviZi280f8012017-06-09 02:39:56 +030030 let currentSoftwareProduct = {}, currentSoftwareProductWithLicensingData = {}, softwareProductCategories = [],
31 finalizedLicenseModelList, licenseAgreementList, featureGroupsList, qdata = {}, dataMap = {}, genericFieldInfo = {}, qGenericFieldInfo = {};
Michael Landoefa037d2017-02-19 12:57:33 +020032 let dummyFunc = () => {};
33
AviZi280f8012017-06-09 02:39:56 +030034 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 }
Michael Landoefa037d2017-02-19 12:57:33 +020052 };
AviZi280f8012017-06-09 02:39:56 +030053 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();
Michael Landoefa037d2017-02-19 12:57:33 +020069 });
70
71 it('should mapper exist', () => {
AviZi280f8012017-06-09 02:39:56 +030072 expect(mapStateToProps).toBeTruthy();
Michael Landoefa037d2017-02-19 12:57:33 +020073 });
74
75 it('should mapper return vsp basic data', () => {
AviZi280f8012017-06-09 02:39:56 +030076
Michael Landoefa037d2017-02-19 12:57:33 +020077 var obj = {
78 softwareProduct: {
79 softwareProductEditor: {
AviZi280f8012017-06-09 02:39:56 +030080 data: currentSoftwareProduct,
81 genericFieldInfo
Michael Landoefa037d2017-02-19 12:57:33 +020082 },
AviZi280f8012017-06-09 02:39:56 +030083 softwareProductCategories,
Michael Landoefa037d2017-02-19 12:57:33 +020084 softwareProductQuestionnaire: {
AviZi280f8012017-06-09 02:39:56 +030085 qdata,
86 genericFieldInfo: qGenericFieldInfo,
87 dataMap
Michael Landoefa037d2017-02-19 12:57:33 +020088 }
89 },
AviZi280f8012017-06-09 02:39:56 +030090 finalizedLicenseModelList,
Michael Landoefa037d2017-02-19 12:57:33 +020091 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);
AviZi280f8012017-06-09 02:39:56 +0300105 expect(finalizedLicenseModelList[0]).toMatchObject({
Michael Landoefa037d2017-02-19 12:57:33 +0200106 id: result.currentSoftwareProduct.vendorId,
AviZi280f8012017-06-09 02:39:56 +0300107 vendorName: result.currentSoftwareProduct.vendorName
Michael Landoefa037d2017-02-19 12:57:33 +0200108 });
AviZi280f8012017-06-09 02:39:56 +0300109 expect(result.softwareProductCategories).toEqual(softwareProductCategories);
Michael Landoefa037d2017-02-19 12:57:33 +0200110 expect(result.licenseAgreementList).toEqual([]);
111 expect(result.featureGroupsList).toEqual([]);
AviZi280f8012017-06-09 02:39:56 +0300112 expect(result.qdata).toEqual(qdata);
113 expect(result.dataMap).toEqual(dataMap);
114 expect(result.isFormValid).toEqual(true);
Michael Landoefa037d2017-02-19 12:57:33 +0200115 expect(result.isReadOnlyMode).toEqual(true);
116 });
117
118 it('should mapper return vsp data with selected licenseAgreement and featureGroup', () => {
AviZi280f8012017-06-09 02:39:56 +0300119
Michael Landoefa037d2017-02-19 12:57:33 +0200120 var obj = {
121 softwareProduct: {
122 softwareProductEditor: {
AviZi280f8012017-06-09 02:39:56 +0300123 data: currentSoftwareProductWithLicensingData,
124 genericFieldInfo
Michael Landoefa037d2017-02-19 12:57:33 +0200125 },
AviZi280f8012017-06-09 02:39:56 +0300126 softwareProductCategories,
Michael Landoefa037d2017-02-19 12:57:33 +0200127 softwareProductQuestionnaire: {
AviZi280f8012017-06-09 02:39:56 +0300128 qdata,
129 genericFieldInfo: qGenericFieldInfo,
130 dataMap
Michael Landoefa037d2017-02-19 12:57:33 +0200131 }
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);
AviZi280f8012017-06-09 02:39:56 +0300145 expect(result.currentSoftwareProduct).toEqual(currentSoftwareProductWithLicensingData);
Michael Landoefa037d2017-02-19 12:57:33 +0200146 expect(result.finalizedLicenseModelList).toEqual(finalizedLicenseModelList);
147 expect(result.finalizedLicenseModelList.length).toBeGreaterThan(0);
AviZi280f8012017-06-09 02:39:56 +0300148 expect(result.finalizedLicenseModelList[0]).toMatchObject({
Michael Landoefa037d2017-02-19 12:57:33 +0200149 id: result.currentSoftwareProduct.vendorId,
AviZi280f8012017-06-09 02:39:56 +0300150 vendorName: result.currentSoftwareProduct.vendorName
Michael Landoefa037d2017-02-19 12:57:33 +0200151 });
AviZi280f8012017-06-09 02:39:56 +0300152 expect(result.softwareProductCategories).toEqual(softwareProductCategories);
Michael Landoefa037d2017-02-19 12:57:33 +0200153 expect(result.licenseAgreementList).toEqual(licenseAgreementList);
AviZi280f8012017-06-09 02:39:56 +0300154 expect(result.licenseAgreementList[0]).toMatchObject({...licenseAgreementList[0], id: result.currentSoftwareProduct.licensingData.licenseAgreement});
Michael Landoefa037d2017-02-19 12:57:33 +0200155 result.currentSoftwareProduct.licensingData.featureGroups.forEach(fg => {
AviZi280f8012017-06-09 02:39:56 +0300156 expect(featureGroupsList[0]).toMatchObject({...featureGroupsList[0], id: fg});
Michael Landoefa037d2017-02-19 12:57:33 +0200157 });
AviZi280f8012017-06-09 02:39:56 +0300158 expect(result.qdata).toEqual(qdata);
Michael Landoefa037d2017-02-19 12:57:33 +0200159 expect(result.isReadOnlyMode).toEqual(true);
160 });
161
162 it('VSP Details view test', () => {
AviZi280f8012017-06-09 02:39:56 +0300163
Michael Landoefa037d2017-02-19 12:57:33 +0200164 let params = {
AviZi280f8012017-06-09 02:39:56 +0300165 currentSoftwareProduct,
166 softwareProductCategories,
167 qdata,
168 dataMap,
169 isFormValid: true,
170 finalizedLicenseModelList,
171 licenseAgreementList,
172 featureGroupsList,
173 genericFieldInfo,
174 qGenericFieldInfo,
Michael Landoefa037d2017-02-19 12:57:33 +0200175 };
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();
AviZi280f8012017-06-09 02:39:56 +0300187 expect(renderedOutput).toBeTruthy();
Michael Landoefa037d2017-02-19 12:57:33 +0200188 });
189
190 it('in view: should change vendorId and update vsp licensing-version', done => {
AviZi280f8012017-06-09 02:39:56 +0300191
Michael Landoefa037d2017-02-19 12:57:33 +0200192 let params = {
AviZi280f8012017-06-09 02:39:56 +0300193 currentSoftwareProduct: currentSoftwareProductWithLicensingData,
194 softwareProductCategories,
195 qdata,
196 dataMap,
197 isFormValid: true,
198 genericFieldInfo,
199 qGenericFieldInfo,
200 finalizedLicenseModelList,
201 licenseAgreementList,
202 featureGroupsList
Michael Landoefa037d2017-02-19 12:57:33 +0200203 };
204 const onVendorChangedListener = (deltaData) => {
AviZi280f8012017-06-09 02:39:56 +0300205 expect(deltaData.vendorId).toEqual(finalizedLicenseModelList[1].id);
206 expect(deltaData.vendorName).toEqual(finalizedLicenseModelList[1].vendorName);
Michael Landoefa037d2017-02-19 12:57:33 +0200207 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}
AviZi280f8012017-06-09 02:39:56 +0300216 qGenericFieldInfo = {params.qGenericFieldInfo}
217 genericFieldInfo = {params.genericFieldInfo}
218 isFormValid={params.isFormValid}
219 dataMap={params.dataMap}
Michael Landoefa037d2017-02-19 12:57:33 +0200220 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)}/>);
AviZi280f8012017-06-09 02:39:56 +0300228 expect(vspDetailsView).toBeTruthy();
229 vspDetailsView.onVendorParamChanged({vendorId: finalizedLicenseModelList[1].id});
Michael Landoefa037d2017-02-19 12:57:33 +0200230 });
231
232 it('in view: should change licensing-version and update licensing data', done => {
233 let params = {
234 currentSoftwareProduct: currentSoftwareProduct,
AviZi280f8012017-06-09 02:39:56 +0300235 softwareProductCategories,
236 qdata,
237 dataMap,
238 isFormValid: true,
239 genericFieldInfo,
240 qGenericFieldInfo,
241 finalizedLicenseModelList,
242 licenseAgreementList,
243 featureGroupsList
Michael Landoefa037d2017-02-19 12:57:33 +0200244 };
245 const onVendorChangedListener = (deltaData) => {
AviZi280f8012017-06-09 02:39:56 +0300246 expect(deltaData.vendorId).toEqual(finalizedLicenseModelList[1].id);
247 expect(deltaData.vendorName).toEqual(finalizedLicenseModelList[1].vendorName);
248 expect(deltaData.licensingVersion).toEqual(finalizedLicenseModelList[1].viewableVersion[0]);
Michael Landoefa037d2017-02-19 12:57:33 +0200249 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)}/>);
AviZi280f8012017-06-09 02:39:56 +0300260 expect(vspDetailsView).toBeTruthy();
261 vspDetailsView.onVendorParamChanged({vendorId: finalizedLicenseModelList[1].id, licensingVersion: finalizedLicenseModelList[1].viewableVersion[0]});
Michael Landoefa037d2017-02-19 12:57:33 +0200262 });
263
264 it('in view: should change subcategory', done => {
265 let params = {
266 currentSoftwareProduct: currentSoftwareProduct,
AviZi280f8012017-06-09 02:39:56 +0300267 softwareProductCategories,
268 qdata,
269 dataMap,
270 isFormValid: true,
271 genericFieldInfo,
272 qGenericFieldInfo,
273 finalizedLicenseModelList,
274 licenseAgreementList,
275 featureGroupsList
Michael Landoefa037d2017-02-19 12:57:33 +0200276 };
277 const onDataChangedListener = ({category, subCategory}) => {
AviZi280f8012017-06-09 02:39:56 +0300278 expect(category).toEqual(softwareProductCategories[1].uniqueId);
279 expect(subCategory).toEqual(softwareProductCategories[1].subcategories[0].uniqueId);
Michael Landoefa037d2017-02-19 12:57:33 +0200280 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}/>);
AviZi280f8012017-06-09 02:39:56 +0300290 expect(vspDetailsView).toBeTruthy();
291 vspDetailsView.onSelectSubCategory(softwareProductCategories[1].subcategories[0].uniqueId);
Michael Landoefa037d2017-02-19 12:57:33 +0200292 });
293
294 it('in view: should change feature groups', done => {
AviZi280f8012017-06-09 02:39:56 +0300295
Michael Landoefa037d2017-02-19 12:57:33 +0200296 let params = {
AviZi280f8012017-06-09 02:39:56 +0300297 currentSoftwareProduct: currentSoftwareProductWithLicensingData,
298 softwareProductCategories,
299 qdata,
300 dataMap,
301 isFormValid: true,
302 genericFieldInfo,
303 qGenericFieldInfo,
304 finalizedLicenseModelList,
305 licenseAgreementList,
306 featureGroupsList
Michael Landoefa037d2017-02-19 12:57:33 +0200307 };
308 const onDataChangedListener = ({licensingData}) => {
AviZi280f8012017-06-09 02:39:56 +0300309 expect(licensingData.licenseAgreement).toEqual(licenseAgreementList[0].id);
Michael Landoefa037d2017-02-19 12:57:33 +0200310 expect(licensingData.featureGroups).toEqual([
AviZi280f8012017-06-09 02:39:56 +0300311 {enum: featureGroupsList[0].id, title: featureGroupsList[0].name},
312 {enum: featureGroupsList[1].id, title: featureGroupsList[1].name}
Michael Landoefa037d2017-02-19 12:57:33 +0200313 ]);
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}/>);
AviZi280f8012017-06-09 02:39:56 +0300324 expect(vspDetailsView).toBeTruthy();
Michael Landoefa037d2017-02-19 12:57:33 +0200325 vspDetailsView.onFeatureGroupsChanged({featureGroups: [
AviZi280f8012017-06-09 02:39:56 +0300326 {enum: featureGroupsList[0].id, title: featureGroupsList[0].name},
327 {enum: featureGroupsList[1].id, title: featureGroupsList[1].name}
Michael Landoefa037d2017-02-19 12:57:33 +0200328 ]});
329 });
330
331 it('in view: should change license agreement', done => {
AviZi280f8012017-06-09 02:39:56 +0300332
Michael Landoefa037d2017-02-19 12:57:33 +0200333 let params = {
AviZi280f8012017-06-09 02:39:56 +0300334 currentSoftwareProduct: currentSoftwareProductWithLicensingData,
335 softwareProductCategories,
336 qdata,
337 dataMap,
338 isFormValid: true,
339 genericFieldInfo,
340 qGenericFieldInfo,
341 finalizedLicenseModelList,
342 licenseAgreementList,
343 featureGroupsList
Michael Landoefa037d2017-02-19 12:57:33 +0200344 };
345 const onDataChangedListener = ({licensingData}) => {
AviZi280f8012017-06-09 02:39:56 +0300346 expect(licensingData.licenseAgreement).toEqual(licenseAgreementList[1].id);
Michael Landoefa037d2017-02-19 12:57:33 +0200347 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}/>);
AviZi280f8012017-06-09 02:39:56 +0300358 expect(vspDetailsView).toBeTruthy();
359 vspDetailsView.onLicensingDataChanged({licenseAgreement: licenseAgreementList[1].id, featureGroups: []});
Michael Landoefa037d2017-02-19 12:57:33 +0200360 });
361});