Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 1 | /*- |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * SDC |
| 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 |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 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========================================================= |
| 19 | */ |
| 20 | |
| 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'; |
| 27 | |
| 28 | describe('Software Product Details: ', function () { |
| 29 | |
| 30 | let currentSoftwareProduct = {}, categories = [], finalizedLicenseModelList, licenseAgreementList, featureGroupsList, vspQschema; |
| 31 | let dummyFunc = () => {}; |
| 32 | |
| 33 | before(function() { |
| 34 | currentSoftwareProduct = { |
| 35 | id: 'D4774719D085414E9D5642D1ACD59D20', |
| 36 | name: 'VSP', |
| 37 | description: 'dfdf', |
| 38 | category: 'category1', |
| 39 | subCategory: 'category1.subCategory', |
| 40 | vendorId: 'VLM_ID1', |
| 41 | vendorName: 'VLM1', |
| 42 | licensingVersion: '1.0', |
| 43 | licensingData: {} |
| 44 | }; |
| 45 | categories = [{ |
| 46 | uniqueId: 'category1', |
| 47 | subcategories: [{ |
| 48 | uniqueId: 'subCategory' |
| 49 | }] |
| 50 | }, { |
| 51 | uniqueId: 'category2', |
| 52 | subcategories: [{ |
| 53 | uniqueId: 'subCategory2' |
| 54 | }] |
| 55 | }]; |
| 56 | finalizedLicenseModelList = [{ |
| 57 | id: 'VLM_ID1', |
| 58 | name: 'VLM1' |
| 59 | }]; |
| 60 | licenseAgreementList = [{id: 'LA_ID1'}, {id: 'LA_ID2'}]; |
| 61 | featureGroupsList = [ |
| 62 | {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']}, |
| 63 | {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']} |
| 64 | ]; |
| 65 | vspQschema = vspQuestionnaireSchema; |
| 66 | }); |
| 67 | |
| 68 | it('should mapper exist', () => { |
| 69 | expect(mapStateToProps).toExist(); |
| 70 | }); |
| 71 | |
| 72 | it('should mapper return vsp basic data', () => { |
| 73 | var obj = { |
| 74 | softwareProduct: { |
| 75 | softwareProductEditor: { |
| 76 | data: currentSoftwareProduct |
| 77 | }, |
| 78 | softwareProductCategories: categories, |
| 79 | softwareProductQuestionnaire: { |
| 80 | qdata: {}, |
| 81 | qschema: vspQschema |
| 82 | } |
| 83 | }, |
| 84 | finalizedLicenseModelList: finalizedLicenseModelList, |
| 85 | licenseModel: { |
| 86 | licenseAgreement: { |
| 87 | licenseAgreementList: [] |
| 88 | }, |
| 89 | featureGroup: { |
| 90 | featureGroupsList: [] |
| 91 | } |
| 92 | } |
| 93 | }; |
| 94 | |
| 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 |
| 102 | }); |
| 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); |
| 109 | }); |
| 110 | |
| 111 | it('should mapper return vsp data with selected licenseAgreement and featureGroup', () => { |
| 112 | let vspWithLicensingData = { |
| 113 | ...currentSoftwareProduct, |
| 114 | licensingData: { |
| 115 | licenseAgreement: 'LA_ID1', |
| 116 | featureGroups: [{enum: 'FG_ID1', title: 'FG1'}] |
| 117 | } |
| 118 | }; |
| 119 | var obj = { |
| 120 | softwareProduct: { |
| 121 | softwareProductEditor: { |
| 122 | data: vspWithLicensingData |
| 123 | }, |
| 124 | softwareProductCategories: categories, |
| 125 | softwareProductQuestionnaire: { |
| 126 | qdata: {}, |
| 127 | qschema: vspQschema |
| 128 | } |
| 129 | }, |
| 130 | finalizedLicenseModelList: finalizedLicenseModelList, |
| 131 | licenseModel: { |
| 132 | licenseAgreement: { |
| 133 | licenseAgreementList: licenseAgreementList |
| 134 | }, |
| 135 | featureGroup: { |
| 136 | featureGroupsList: featureGroupsList |
| 137 | } |
| 138 | } |
| 139 | }; |
| 140 | |
| 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 |
| 148 | }); |
| 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({ |
| 154 | id: fg.enum, |
| 155 | name: fg.title, |
| 156 | referencingLicenseAgreements: [result.currentSoftwareProduct.licensingData.licenseAgreement] |
| 157 | }); |
| 158 | expect(result.featureGroupsList).toInclude(fg); |
| 159 | }); |
| 160 | expect(result.qdata).toEqual({}); |
| 161 | expect(result.qschema).toEqual(vspQschema); |
| 162 | expect(result.isReadOnlyMode).toEqual(true); |
| 163 | }); |
| 164 | |
| 165 | it('VSP Details view test', () => { |
| 166 | let params = { |
| 167 | currentSoftwareProduct: currentSoftwareProduct, |
| 168 | softwareProductCategories: categories, |
| 169 | qdata: {}, |
| 170 | qschema: vspQschema, |
| 171 | finalizedLicenseModelList: [{ |
| 172 | id: 'VLM_ID1', |
| 173 | vendorName: 'VLM1', |
| 174 | version: '2.0', |
| 175 | viewableVersions: ['1.0', '2.0'] |
| 176 | }, { |
| 177 | id: 'VLM_ID2', |
| 178 | vendorName: 'VLM2', |
| 179 | version: '3.0', |
| 180 | viewableVersions: ['1.0', '2.0', '3.0'] |
| 181 | }], |
| 182 | licenseAgreementList: [{id: 'LA_ID1'}, {id: 'LA_ID2'}], |
| 183 | featureGroupsList: [ |
| 184 | {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']}, |
| 185 | {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']} |
| 186 | ] |
| 187 | }; |
| 188 | var renderer = TestUtils.createRenderer(); |
| 189 | renderer.render( |
| 190 | <SoftwareProductDetailsView |
| 191 | {...params} |
| 192 | onSubmit = {dummyFunc} |
| 193 | onDataChanged = {dummyFunc} |
| 194 | onValidityChanged = {dummyFunc} |
| 195 | onQDataChanged = {dummyFunc} |
| 196 | onVendorParamChanged = {dummyFunc}/> |
| 197 | ); |
| 198 | let renderedOutput = renderer.getRenderOutput(); |
| 199 | expect(renderedOutput).toExist(); |
| 200 | }); |
| 201 | |
| 202 | it('in view: should change vendorId and update vsp licensing-version', done => { |
| 203 | let vspWithLicensingData = { |
| 204 | ...currentSoftwareProduct, |
| 205 | licensingData: { |
| 206 | licenseAgreement: 'LA_ID1', |
| 207 | featureGroups: [{enum: 'FG_ID1', title: 'FG1'}] |
| 208 | } |
| 209 | }; |
| 210 | let params = { |
| 211 | currentSoftwareProduct: vspWithLicensingData, |
| 212 | softwareProductCategories: categories, |
| 213 | qdata: {}, |
| 214 | qschema: vspQschema, |
| 215 | finalizedLicenseModelList: [{ |
| 216 | id: 'VLM_ID1', |
| 217 | vendorName: 'VLM1', |
| 218 | version: '2.0', |
| 219 | viewableVersions: ['1.0', '2.0'] |
| 220 | }, { |
| 221 | id: 'VLM_ID2', |
| 222 | vendorName: 'VLM2', |
| 223 | version: '3.0', |
| 224 | viewableVersions: ['1.0', '2.0', '3.0'] |
| 225 | }], |
| 226 | licenseAgreementList: [{id: 'LA_ID1'}, {id: 'LA_ID2'}], |
| 227 | featureGroupsList: [ |
| 228 | {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']}, |
| 229 | {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']} |
| 230 | ] |
| 231 | }; |
| 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({}); |
| 237 | done(); |
| 238 | }; |
| 239 | |
| 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'}); |
| 255 | }); |
| 256 | |
| 257 | it('in view: should change licensing-version and update licensing data', done => { |
| 258 | let params = { |
| 259 | currentSoftwareProduct: currentSoftwareProduct, |
| 260 | softwareProductCategories: categories, |
| 261 | qdata: {}, |
| 262 | qschema: vspQschema, |
| 263 | finalizedLicenseModelList: [{ |
| 264 | id: 'VLM_ID1', |
| 265 | vendorName: 'VLM1', |
| 266 | version: '2.0', |
| 267 | viewableVersions: ['1.0', '2.0'] |
| 268 | }, { |
| 269 | id: 'VLM_ID2', |
| 270 | vendorName: 'VLM2', |
| 271 | version: '3.0', |
| 272 | viewableVersions: ['1.0', '2.0', '3.0'] |
| 273 | }], |
| 274 | licenseAgreementList: [{id: 'LA_ID1'}, {id: 'LA_ID2'}], |
| 275 | featureGroupsList: [ |
| 276 | {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']}, |
| 277 | {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']} |
| 278 | ] |
| 279 | }; |
| 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({}); |
| 285 | done(); |
| 286 | }; |
| 287 | |
| 288 | let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView |
| 289 | {...params} |
| 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'}); |
| 297 | }); |
| 298 | |
| 299 | it('in view: should change subcategory', done => { |
| 300 | let params = { |
| 301 | currentSoftwareProduct: currentSoftwareProduct, |
| 302 | softwareProductCategories: categories, |
| 303 | qdata: {}, |
| 304 | qschema: vspQschema, |
| 305 | finalizedLicenseModelList: [{ |
| 306 | id: 'VLM_ID1', |
| 307 | vendorName: 'VLM1', |
| 308 | version: '2.0', |
| 309 | viewableVersions: ['1.0', '2.0'] |
| 310 | }, { |
| 311 | id: 'VLM_ID2', |
| 312 | vendorName: 'VLM2', |
| 313 | version: '3.0', |
| 314 | viewableVersions: ['1.0', '2.0', '3.0'] |
| 315 | }], |
| 316 | licenseAgreementList: [{id: 'LA_ID1'}, {id: 'LA_ID2'}], |
| 317 | featureGroupsList: [ |
| 318 | {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']}, |
| 319 | {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']} |
| 320 | ] |
| 321 | }; |
| 322 | const onDataChangedListener = ({category, subCategory}) => { |
| 323 | expect(category).toEqual('category2'); |
| 324 | expect(subCategory).toEqual('subCategory2'); |
| 325 | done(); |
| 326 | }; |
| 327 | |
| 328 | let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView |
| 329 | {...params} |
| 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'); |
| 337 | }); |
| 338 | |
| 339 | it('in view: should change feature groups', done => { |
| 340 | let vspWithLicensingData = { |
| 341 | ...currentSoftwareProduct, |
| 342 | licensingData: { |
| 343 | licenseAgreement: 'LA_ID1', |
| 344 | featureGroups: [{enum: 'FG_ID1', title: 'FG1'}] |
| 345 | } |
| 346 | }; |
| 347 | let params = { |
| 348 | currentSoftwareProduct: vspWithLicensingData, |
| 349 | softwareProductCategories: categories, |
| 350 | qdata: {}, |
| 351 | qschema: vspQschema, |
| 352 | finalizedLicenseModelList: [{ |
| 353 | id: 'VLM_ID1', |
| 354 | vendorName: 'VLM1', |
| 355 | version: '2.0', |
| 356 | viewableVersions: ['1.0', '2.0'] |
| 357 | }, { |
| 358 | id: 'VLM_ID2', |
| 359 | vendorName: 'VLM2', |
| 360 | version: '3.0', |
| 361 | viewableVersions: ['1.0', '2.0', '3.0'] |
| 362 | }], |
| 363 | licenseAgreementList: [{id: 'LA_ID1'}, {id: 'LA_ID2'}], |
| 364 | featureGroupsList: [ |
| 365 | {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']}, |
| 366 | {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']} |
| 367 | ] |
| 368 | }; |
| 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'} |
| 374 | ]); |
| 375 | done(); |
| 376 | }; |
| 377 | |
| 378 | let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView |
| 379 | {...params} |
| 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'} |
| 389 | ]}); |
| 390 | }); |
| 391 | |
| 392 | it('in view: should change license agreement', done => { |
| 393 | let vspWithLicensingData = { |
| 394 | ...currentSoftwareProduct, |
| 395 | licensingData: { |
| 396 | licenseAgreement: 'LA_ID1', |
| 397 | featureGroups: [{enum: 'FG_ID1', title: 'FG1'}] |
| 398 | } |
| 399 | }; |
| 400 | let params = { |
| 401 | currentSoftwareProduct: vspWithLicensingData, |
| 402 | softwareProductCategories: categories, |
| 403 | qdata: {}, |
| 404 | qschema: vspQschema, |
| 405 | finalizedLicenseModelList: [{ |
| 406 | id: 'VLM_ID1', |
| 407 | vendorName: 'VLM1', |
| 408 | version: '2.0', |
| 409 | viewableVersions: ['1.0', '2.0'] |
| 410 | }, { |
| 411 | id: 'VLM_ID2', |
| 412 | vendorName: 'VLM2', |
| 413 | version: '3.0', |
| 414 | viewableVersions: ['1.0', '2.0', '3.0'] |
| 415 | }], |
| 416 | licenseAgreementList: [{id: 'LA_ID1'}, {id: 'LA_ID2'}], |
| 417 | featureGroupsList: [ |
| 418 | {id: 'FG_ID1', name: 'FG1', referencingLicenseAgreements: ['LA_ID1']}, |
| 419 | {id: 'FG_ID2', name: 'FG2', referencingLicenseAgreements: ['LA_ID1']} |
| 420 | ] |
| 421 | }; |
| 422 | const onDataChangedListener = ({licensingData}) => { |
| 423 | expect(licensingData.licenseAgreement).toEqual('LA_ID2'); |
| 424 | expect(licensingData.featureGroups).toEqual([]); |
| 425 | done(); |
| 426 | }; |
| 427 | |
| 428 | let vspDetailsView = TestUtils.renderIntoDocument(<SoftwareProductDetailsView |
| 429 | {...params} |
| 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: []}); |
| 437 | }); |
| 438 | }); |