2 * Copyright © 2016-2017 European Support Limited
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 or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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';
31 describe('Software Product Details: ', function () {
33 let currentSoftwareProduct = {}, currentSoftwareProductWithLicensingData = {}, softwareProductCategories = [], licensingVersionsList = [], currentScreen = {},
34 finalizedLicenseModelList, licenseAgreementList, featureGroupsList, qdata = {}, dataMap = {}, genericFieldInfo = {}, qGenericFieldInfo = {};
35 let dummyFunc = () => {};
37 beforeAll(function() {
38 finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(2);
39 currentSoftwareProduct = VSPEditorFactory.build({
41 licensingVersion: undefined,
42 vendorId: finalizedLicenseModelList[0].id,
43 vendorName: finalizedLicenseModelList[0].name
45 softwareProductCategories = CategoryWithSubFactory.buildList(2, {}, {quantity: 1});
46 licenseAgreementList = LicenseAgreementStoreFactory.buildList(2);
47 licensingVersionsList = [
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":[]}}
53 featureGroupsList = FeatureGroupStoreFactory.buildList(2, {referencingLicenseAgreements: [licenseAgreementList[0].id]});
54 qdata = VspQdataFactory.build();
55 dataMap = VspDataMapFactory.build();
56 currentSoftwareProductWithLicensingData = {
57 ...currentSoftwareProduct,
59 licenseAgreement: licenseAgreementList[0].id,
60 featureGroups: [featureGroupsList[0].id]
62 licensingVersion : licensingVersionsList[0].id
68 validations: [{type: 'validateName', data: true}, {type: 'maxLength', data: 120}, {
76 validations: [{type: 'required', data: true}]
79 qGenericFieldInfo = SchemaGenericFieldInfoFactory.build();
80 currentScreen = CurrentScreenFactory.build();
83 it('should mapper exist', () => {
84 expect(mapStateToProps).toBeTruthy();
87 it('should mapper return vsp basic data', () => {
92 softwareProductEditor: {
93 data: currentSoftwareProduct,
97 softwareProductCategories,
98 softwareProductQuestionnaire: {
100 genericFieldInfo: qGenericFieldInfo,
104 finalizedLicenseModelList,
107 licenseAgreementList: []
110 featureGroupsList: []
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
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);
131 it('should mapper return vsp data with selected licenseAgreement and featureGroup', () => {
136 softwareProductEditor: {
137 data: currentSoftwareProductWithLicensingData,
139 licensingVersionsList
141 softwareProductCategories,
142 softwareProductQuestionnaire: {
144 genericFieldInfo: qGenericFieldInfo,
148 finalizedLicenseModelList: finalizedLicenseModelList,
151 licenseAgreementList: licenseAgreementList
154 featureGroupsList: featureGroupsList
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
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});
173 expect(result.qdata).toEqual(qdata);
176 it('VSP Details view test', () => {
179 ...currentScreen.props,
180 currentSoftwareProduct,
181 softwareProductCategories,
185 finalizedLicenseModelList,
186 licenseAgreementList,
188 licensingVersionsList,
192 const renderer = new ShallowRenderer();
194 <SoftwareProductDetailsView
196 onSubmit = {dummyFunc}
197 onDataChanged = {dummyFunc}
198 onValidityChanged = {dummyFunc}
199 onQDataChanged = {dummyFunc}
200 onVendorParamChanged = {dummyFunc}/>
202 let renderedOutput = renderer.getRenderOutput();
203 expect(renderedOutput).toBeTruthy();
204 expect(renderedOutput.props.children.props.isReadOnlyMode).toBe(false);
208 it('in view: should change vendorId and update vsp licensing-version', done => {
211 currentSoftwareProduct: currentSoftwareProductWithLicensingData,
212 softwareProductCategories,
218 finalizedLicenseModelList,
219 licenseAgreementList,
220 licensingVersionsList,
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({});
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});
252 it('in view: should change licensing-version and update licensing data', done => {
254 currentSoftwareProduct: currentSoftwareProduct,
255 softwareProductCategories,
258 licensingVersionsList,
262 finalizedLicenseModelList,
263 licenseAgreementList,
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({});
274 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
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]});
285 it('in view: should change subcategory', done => {
287 currentSoftwareProduct: currentSoftwareProduct,
288 softwareProductCategories,
294 licensingVersionsList,
295 finalizedLicenseModelList,
296 licenseAgreementList,
299 const onDataChangedListener = ({category, subCategory}) => {
300 expect(category).toEqual(softwareProductCategories[1].uniqueId);
301 expect(subCategory).toEqual(softwareProductCategories[1].subcategories[0].uniqueId);
305 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
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);
316 it('in view: should change feature groups', done => {
319 currentSoftwareProduct: currentSoftwareProductWithLicensingData,
320 softwareProductCategories,
326 licensingVersionsList,
327 finalizedLicenseModelList,
328 licenseAgreementList,
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}
340 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
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}
355 it('in view: should change license agreement', done => {
357 currentSoftwareProduct: currentSoftwareProductWithLicensingData,
358 softwareProductCategories,
364 licensingVersionsList,
365 finalizedLicenseModelList,
366 licenseAgreementList,
369 const onDataChangedListener = ({licensingData}) => {
370 expect(licensingData.licenseAgreement).toEqual(licenseAgreementList[1].id);
371 expect(licensingData.featureGroups).toEqual([]);
375 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
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: []});