AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
| 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | import React from 'react'; |
| 18 | import TestUtils from 'react-addons-test-utils'; |
| 19 | import {mapStateToProps, mapActionsToProps} from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreation.js'; |
| 20 | import SoftwareProductCreationView from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationView.jsx'; |
| 21 | import {SoftwareProductCreationFactory, SoftwareProductCreationFactoryWithSelectedVendor} from 'test-utils/factories/softwareProduct/SoftwareProductCreationFactories.js'; |
| 22 | import {CategoryWithSubFactory} from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js'; |
| 23 | import {FinalizedLicenseModelFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; |
| 24 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 25 | |
| 26 | describe('Software Product Creation Module Tests', function() { |
| 27 | it ('mapStateToProps mapper exists', () => { |
| 28 | expect(mapStateToProps).toBeTruthy(); |
| 29 | }); |
| 30 | |
| 31 | it ('should return empty data', () => { |
| 32 | let state = { |
| 33 | softwareProductList: [], |
| 34 | softwareProduct: { |
| 35 | softwareProductCreation: { |
| 36 | data: {} |
| 37 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 38 | }, |
| 39 | users: { |
| 40 | usersList: [] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 41 | } |
| 42 | }; |
| 43 | let props = mapStateToProps(state); |
| 44 | expect(props.data).toEqual({}); |
| 45 | }); |
| 46 | |
| 47 | it ('should return vsp names list', () => { |
| 48 | let state = { |
| 49 | softwareProductList: [{ |
| 50 | name: 'vsp1', |
| 51 | id: 'vsp1_id' |
| 52 | }, { |
| 53 | name: 'vsp2', |
| 54 | id: 'vsp2_id' |
| 55 | }], |
| 56 | softwareProduct: { |
| 57 | softwareProductCreation: { |
| 58 | data: {} |
| 59 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 60 | }, |
| 61 | users: { |
| 62 | usersList: [] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 63 | } |
| 64 | }; |
| 65 | let props = mapStateToProps(state); |
| 66 | expect(props.data).toEqual({}); |
| 67 | expect(props.VSPNames).toEqual({vsp1: 'vsp1_id', vsp2: 'vsp2_id'}); |
| 68 | }); |
| 69 | |
| 70 | it('simple jsx test', () => { |
| 71 | const store = storeCreator(); |
| 72 | let dispatch = store.dispatch; |
| 73 | |
| 74 | let state = { |
| 75 | softwareProductList: [], |
| 76 | softwareProduct: { |
| 77 | softwareProductCreation: SoftwareProductCreationFactory.build(), |
| 78 | softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2}) |
| 79 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 80 | finalizedLicenseModelList: FinalizedLicenseModelFactory.buildList(3), |
| 81 | users: { |
| 82 | usersList: [] |
| 83 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 84 | }; |
| 85 | let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch)); |
| 86 | var renderer = TestUtils.createRenderer(); |
| 87 | renderer.render( |
| 88 | <SoftwareProductCreationView {...props}/> |
| 89 | ); |
| 90 | var renderedOutput = renderer.getRenderOutput(); |
| 91 | expect(renderedOutput).toBeTruthy(); |
| 92 | }); |
| 93 | |
| 94 | it('simple jsx test - with selected vendor', () => { |
| 95 | const store = storeCreator(); |
| 96 | let dispatch = store.dispatch; |
| 97 | let finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(3); |
| 98 | let state = { |
| 99 | softwareProductList: [], |
| 100 | softwareProduct: { |
| 101 | softwareProductCreation: SoftwareProductCreationFactoryWithSelectedVendor.build({selectedVendorId: finalizedLicenseModelList[0].id}), |
| 102 | softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2}) |
| 103 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 104 | finalizedLicenseModelList, |
| 105 | users: { |
| 106 | usersList: [] |
| 107 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 108 | }; |
| 109 | let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch)); |
| 110 | let renderer = TestUtils.createRenderer(); |
| 111 | renderer.render( |
| 112 | <SoftwareProductCreationView {...props}/> |
| 113 | ); |
| 114 | let renderedOutput = renderer.getRenderOutput(); |
| 115 | expect(renderedOutput).toBeTruthy(); |
| 116 | }); |
| 117 | }); |