2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import expect from 'expect';
22 import React from 'react';
23 import TestUtils from 'react-addons-test-utils';
24 import {mapStateToProps} from 'sdc-app/onboarding/softwareProduct/details/SoftwareProductDetails.js';
25 import SoftwareProductDetailsView from 'sdc-app/onboarding/softwareProduct/details/SoftwareProductDetailsView.jsx';
26 import {vspQschema as vspQuestionnaireSchema} from './vspQschema.js';
28 describe('Software Product Details: ', function () {
30 let currentSoftwareProduct = {}, categories = [], finalizedLicenseModelList, licenseAgreementList, featureGroupsList, vspQschema;
31 let dummyFunc = () => {};
34 currentSoftwareProduct = {
35 id: 'D4774719D085414E9D5642D1ACD59D20',
38 category: 'category1',
39 subCategory: 'category1.subCategory',
42 licensingVersion: '1.0',
46 uniqueId: 'category1',
48 uniqueId: 'subCategory'
51 uniqueId: 'category2',
53 uniqueId: 'subCategory2'
56 finalizedLicenseModelList = [{
60 licenseAgreementList = [{id: 'LA_ID1'}, {id: 'LA_ID2'}];
62 {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']},
63 {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']}
65 vspQschema = vspQuestionnaireSchema;
68 it('should mapper exist', () => {
69 expect(mapStateToProps).toExist();
72 it('should mapper return vsp basic data', () => {
75 softwareProductEditor: {
76 data: currentSoftwareProduct
78 softwareProductCategories: categories,
79 softwareProductQuestionnaire: {
84 finalizedLicenseModelList: finalizedLicenseModelList,
87 licenseAgreementList: []
95 var result = mapStateToProps(obj);
96 expect(result.currentSoftwareProduct).toEqual(currentSoftwareProduct);
97 expect(result.finalizedLicenseModelList).toEqual(finalizedLicenseModelList);
98 expect(result.finalizedLicenseModelList.length).toBeGreaterThan(0);
99 expect(finalizedLicenseModelList).toInclude({
100 id: result.currentSoftwareProduct.vendorId,
101 name: result.currentSoftwareProduct.vendorName
103 expect(result.softwareProductCategories).toEqual(categories);
104 expect(result.licenseAgreementList).toEqual([]);
105 expect(result.featureGroupsList).toEqual([]);
106 expect(result.qdata).toEqual({});
107 expect(result.qschema).toEqual(vspQschema);
108 expect(result.isReadOnlyMode).toEqual(true);
111 it('should mapper return vsp data with selected licenseAgreement and featureGroup', () => {
112 let vspWithLicensingData = {
113 ...currentSoftwareProduct,
115 licenseAgreement: 'LA_ID1',
116 featureGroups: [{enum: 'FG_ID1', title: 'FG1'}]
121 softwareProductEditor: {
122 data: vspWithLicensingData
124 softwareProductCategories: categories,
125 softwareProductQuestionnaire: {
130 finalizedLicenseModelList: finalizedLicenseModelList,
133 licenseAgreementList: licenseAgreementList
136 featureGroupsList: featureGroupsList
141 var result = mapStateToProps(obj);
142 expect(result.currentSoftwareProduct).toEqual(vspWithLicensingData);
143 expect(result.finalizedLicenseModelList).toEqual(finalizedLicenseModelList);
144 expect(result.finalizedLicenseModelList.length).toBeGreaterThan(0);
145 expect(result.finalizedLicenseModelList).toInclude({
146 id: result.currentSoftwareProduct.vendorId,
147 name: result.currentSoftwareProduct.vendorName
149 expect(result.softwareProductCategories).toEqual(categories);
150 expect(result.licenseAgreementList).toEqual(licenseAgreementList);
151 expect(result.licenseAgreementList).toInclude({id: result.currentSoftwareProduct.licensingData.licenseAgreement});
152 result.currentSoftwareProduct.licensingData.featureGroups.forEach(fg => {
153 expect(featureGroupsList).toInclude({
156 referencingLicenseAgreements: [result.currentSoftwareProduct.licensingData.licenseAgreement]
158 expect(result.featureGroupsList).toInclude(fg);
160 expect(result.qdata).toEqual({});
161 expect(result.qschema).toEqual(vspQschema);
162 expect(result.isReadOnlyMode).toEqual(true);
165 it('VSP Details view test', () => {
167 currentSoftwareProduct: currentSoftwareProduct,
168 softwareProductCategories: categories,
171 finalizedLicenseModelList: [{
175 viewableVersions: ['1.0', '2.0']
180 viewableVersions: ['1.0', '2.0', '3.0']
182 licenseAgreementList: [{id: 'LA_ID1'}, {id: 'LA_ID2'}],
184 {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']},
185 {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']}
188 var renderer = TestUtils.createRenderer();
190 <SoftwareProductDetailsView
192 onSubmit = {dummyFunc}
193 onDataChanged = {dummyFunc}
194 onValidityChanged = {dummyFunc}
195 onQDataChanged = {dummyFunc}
196 onVendorParamChanged = {dummyFunc}/>
198 let renderedOutput = renderer.getRenderOutput();
199 expect(renderedOutput).toExist();
202 it('in view: should change vendorId and update vsp licensing-version', done => {
203 let vspWithLicensingData = {
204 ...currentSoftwareProduct,
206 licenseAgreement: 'LA_ID1',
207 featureGroups: [{enum: 'FG_ID1', title: 'FG1'}]
211 currentSoftwareProduct: vspWithLicensingData,
212 softwareProductCategories: categories,
215 finalizedLicenseModelList: [{
219 viewableVersions: ['1.0', '2.0']
224 viewableVersions: ['1.0', '2.0', '3.0']
226 licenseAgreementList: [{id: 'LA_ID1'}, {id: 'LA_ID2'}],
228 {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']},
229 {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']}
232 const onVendorChangedListener = (deltaData) => {
233 expect(deltaData.vendorId).toEqual('VLM_ID2');
234 expect(deltaData.vendorName).toEqual('VLM2');
235 expect(deltaData.licensingVersion).toEqual('');
236 expect(deltaData.licensingData).toEqual({});
240 var vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
241 currentSoftwareProduct = {params.currentSoftwareProduct}
242 softwareProductCategories = {params.softwareProductCategories}
243 qdata = {params.qdata}
244 qschema = {params.qschema}
245 finalizedLicenseModelList = {params.finalizedLicenseModelList}
246 licenseAgreementList = {params.licenseAgreementList}
247 featureGroupsList = {params.featureGroupsList}
248 onSubmit = {dummyFunc}
249 onDataChanged = {dummyFunc}
250 onValidityChanged = {dummyFunc}
251 onQDataChanged = {dummyFunc}
252 onVendorParamChanged = {(deltaData) => onVendorChangedListener(deltaData)}/>);
253 expect(vspDetailsView).toExist();
254 vspDetailsView.onVendorParamChanged({vendorId: 'VLM_ID2'});
257 it('in view: should change licensing-version and update licensing data', done => {
259 currentSoftwareProduct: currentSoftwareProduct,
260 softwareProductCategories: categories,
263 finalizedLicenseModelList: [{
267 viewableVersions: ['1.0', '2.0']
272 viewableVersions: ['1.0', '2.0', '3.0']
274 licenseAgreementList: [{id: 'LA_ID1'}, {id: 'LA_ID2'}],
276 {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']},
277 {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']}
280 const onVendorChangedListener = (deltaData) => {
281 expect(deltaData.vendorId).toEqual('VLM_ID2');
282 expect(deltaData.vendorName).toEqual('VLM2');
283 expect(deltaData.licensingVersion).toEqual('2.0');
284 expect(deltaData.licensingData).toEqual({});
288 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
290 onSubmit = {dummyFunc}
291 onDataChanged = {dummyFunc}
292 onValidityChanged = {dummyFunc}
293 onQDataChanged = {dummyFunc}
294 onVendorParamChanged = {(deltaData) => onVendorChangedListener(deltaData)}/>);
295 expect(vspDetailsView).toExist();
296 vspDetailsView.onVendorParamChanged({vendorId: 'VLM_ID2', licensingVersion: '2.0'});
299 it('in view: should change subcategory', done => {
301 currentSoftwareProduct: currentSoftwareProduct,
302 softwareProductCategories: categories,
305 finalizedLicenseModelList: [{
309 viewableVersions: ['1.0', '2.0']
314 viewableVersions: ['1.0', '2.0', '3.0']
316 licenseAgreementList: [{id: 'LA_ID1'}, {id: 'LA_ID2'}],
318 {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']},
319 {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']}
322 const onDataChangedListener = ({category, subCategory}) => {
323 expect(category).toEqual('category2');
324 expect(subCategory).toEqual('subCategory2');
328 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
330 onSubmit = {dummyFunc}
331 onDataChanged = {({category, subCategory}) => onDataChangedListener({category, subCategory})}
332 onValidityChanged = {dummyFunc}
333 onQDataChanged = {dummyFunc}
334 onVendorParamChanged = {dummyFunc}/>);
335 expect(vspDetailsView).toExist();
336 vspDetailsView.onSelectSubCategory('subCategory2');
339 it('in view: should change feature groups', done => {
340 let vspWithLicensingData = {
341 ...currentSoftwareProduct,
343 licenseAgreement: 'LA_ID1',
344 featureGroups: [{enum: 'FG_ID1', title: 'FG1'}]
348 currentSoftwareProduct: vspWithLicensingData,
349 softwareProductCategories: categories,
352 finalizedLicenseModelList: [{
356 viewableVersions: ['1.0', '2.0']
361 viewableVersions: ['1.0', '2.0', '3.0']
363 licenseAgreementList: [{id: 'LA_ID1'}, {id: 'LA_ID2'}],
365 {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']},
366 {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']}
369 const onDataChangedListener = ({licensingData}) => {
370 expect(licensingData.licenseAgreement).toEqual('LA_ID1');
371 expect(licensingData.featureGroups).toEqual([
372 {enum: 'FG_ID1', title: 'FG1'},
373 {enum: 'FG_ID2', title: 'FG2'}
378 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
380 onSubmit = {dummyFunc}
381 onDataChanged = {({licensingData}) => onDataChangedListener({licensingData})}
382 onValidityChanged = {dummyFunc}
383 onQDataChanged = {dummyFunc}
384 onVendorParamChanged = {dummyFunc}/>);
385 expect(vspDetailsView).toExist();
386 vspDetailsView.onFeatureGroupsChanged({featureGroups: [
387 {enum: 'FG_ID1', title: 'FG1'},
388 {enum: 'FG_ID2', title: 'FG2'}
392 it('in view: should change license agreement', done => {
393 let vspWithLicensingData = {
394 ...currentSoftwareProduct,
396 licenseAgreement: 'LA_ID1',
397 featureGroups: [{enum: 'FG_ID1', title: 'FG1'}]
401 currentSoftwareProduct: vspWithLicensingData,
402 softwareProductCategories: categories,
405 finalizedLicenseModelList: [{
409 viewableVersions: ['1.0', '2.0']
414 viewableVersions: ['1.0', '2.0', '3.0']
416 licenseAgreementList: [{id: 'LA_ID1'}, {id: 'LA_ID2'}],
418 {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']},
419 {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']}
422 const onDataChangedListener = ({licensingData}) => {
423 expect(licensingData.licenseAgreement).toEqual('LA_ID2');
424 expect(licensingData.featureGroups).toEqual([]);
428 let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView
430 onSubmit = {dummyFunc}
431 onDataChanged = {({licensingData}) => onDataChangedListener({licensingData})}
432 onValidityChanged = {dummyFunc}
433 onQDataChanged = {dummyFunc}
434 onVendorParamChanged = {dummyFunc}/>);
435 expect(vspDetailsView).toExist();
436 vspDetailsView.onLicensingDataChanged({licenseAgreement: 'LA_ID2', featureGroups: []});