2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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';
30 describe('Software Product Details: ', function () {
32 let currentSoftwareProduct = {}, currentSoftwareProductWithLicensingData = {}, softwareProductCategories = [], licensingVersionsList = [], currentScreen = {},
33 finalizedLicenseModelList, licenseAgreementList, featureGroupsList, qdata = {}, dataMap = {}, genericFieldInfo = {}, qGenericFieldInfo = {};
34 let dummyFunc = () => {};
36 beforeAll(function() {
37 finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(2);
38 currentSoftwareProduct = VSPEditorFactory.build({
40 licensingVersion: undefined,
41 vendorId: finalizedLicenseModelList[0].id,
42 vendorName: finalizedLicenseModelList[0].name
44 softwareProductCategories = CategoryWithSubFactory.buildList(2, {}, {quantity: 1});
45 licenseAgreementList = LicenseAgreementStoreFactory.buildList(2);
46 licensingVersionsList = [
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":[]}}
52 featureGroupsList = FeatureGroupStoreFactory.buildList(2, {referencingLicenseAgreements: [licenseAgreementList[0].id]});
53 qdata = VspQdataFactory.build();
54 dataMap = VspDataMapFactory.build();
55 currentSoftwareProductWithLicensingData = {
56 ...currentSoftwareProduct,
58 licenseAgreement: licenseAgreementList[0].id,
59 featureGroups: [featureGroupsList[0].id]
61 licensingVersion : licensingVersionsList[0].id
67 validations: [{type: 'validateName', data: true}, {type: 'maxLength', data: 120}, {
75 validations: [{type: 'required', data: true}]
78 qGenericFieldInfo = SchemaGenericFieldInfoFactory.build();
79 currentScreen = CurrentScreenFactory.build();
82 it('should mapper exist', () => {
83 expect(mapStateToProps).toBeTruthy();
86 it('should mapper return vsp basic data', () => {
91 softwareProductEditor: {
92 data: currentSoftwareProduct,
96 softwareProductCategories,
97 softwareProductQuestionnaire: {
99 genericFieldInfo: qGenericFieldInfo,
103 finalizedLicenseModelList,
106 licenseAgreementList: []
109 featureGroupsList: []
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
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);
130 it('should mapper return vsp data with selected licenseAgreement and featureGroup', () => {
135 softwareProductEditor: {
136 data: currentSoftwareProductWithLicensingData,
138 licensingVersionsList
140 softwareProductCategories,
141 softwareProductQuestionnaire: {
143 genericFieldInfo: qGenericFieldInfo,
147 finalizedLicenseModelList: finalizedLicenseModelList,
150 licenseAgreementList: licenseAgreementList
153 featureGroupsList: featureGroupsList
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
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});
172 expect(result.qdata).toEqual(qdata);
175 it('VSP Details view test', () => {
178 ...currentScreen.props,
179 currentSoftwareProduct,
180 softwareProductCategories,
184 finalizedLicenseModelList,
185 licenseAgreementList,
187 licensingVersionsList,
191 var renderer = TestUtils.createRenderer();
193 <SoftwareProductDetailsView
195 onSubmit = {dummyFunc}
196 onDataChanged = {dummyFunc}
197 onValidityChanged = {dummyFunc}
198 onQDataChanged = {dummyFunc}
199 onVendorParamChanged = {dummyFunc}/>
201 let renderedOutput = renderer.getRenderOutput();
202 expect(renderedOutput).toBeTruthy();
203 expect(renderedOutput.props.children.props.isReadOnlyMode).toBe(false);
207 it('in view: should change vendorId and update vsp licensing-version', done => {
210 currentSoftwareProduct: currentSoftwareProductWithLicensingData,
211 softwareProductCategories,
217 finalizedLicenseModelList,
218 licenseAgreementList,
219 licensingVersionsList,
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({});
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});
251 it('in view: should change licensing-version and update licensing data', done => {
253 currentSoftwareProduct: currentSoftwareProduct,
254 softwareProductCategories,
257 licensingVersionsList,
261 finalizedLicenseModelList,
262 licenseAgreementList,
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({});
273 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
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]});
284 it('in view: should change subcategory', done => {
286 currentSoftwareProduct: currentSoftwareProduct,
287 softwareProductCategories,
293 licensingVersionsList,
294 finalizedLicenseModelList,
295 licenseAgreementList,
298 const onDataChangedListener = ({category, subCategory}) => {
299 expect(category).toEqual(softwareProductCategories[1].uniqueId);
300 expect(subCategory).toEqual(softwareProductCategories[1].subcategories[0].uniqueId);
304 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
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);
315 it('in view: should change feature groups', done => {
318 currentSoftwareProduct: currentSoftwareProductWithLicensingData,
319 softwareProductCategories,
325 licensingVersionsList,
326 finalizedLicenseModelList,
327 licenseAgreementList,
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}
339 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
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}
354 it('in view: should change license agreement', done => {
356 currentSoftwareProduct: currentSoftwareProductWithLicensingData,
357 softwareProductCategories,
363 licensingVersionsList,
364 finalizedLicenseModelList,
365 licenseAgreementList,
368 const onDataChangedListener = ({licensingData}) => {
369 expect(licensingData.licenseAgreement).toEqual(licenseAgreementList[1].id);
370 expect(licensingData.featureGroups).toEqual([]);
374 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
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: []});