svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 1 | /* |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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 |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 7 | * |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 9 | * |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 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. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | import React from 'react'; |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 18 | import ShallowRenderer from 'react-test-renderer/shallow'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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: [], |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 34 | finalizedSoftwareProductList: [], |
| 35 | archivedSoftwareProductList: [], |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 36 | softwareProduct: { |
| 37 | softwareProductCreation: { |
| 38 | data: {} |
| 39 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 40 | }, |
| 41 | users: { |
| 42 | usersList: [] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 43 | } |
| 44 | }; |
| 45 | let props = mapStateToProps(state); |
| 46 | expect(props.data).toEqual({}); |
| 47 | }); |
| 48 | |
| 49 | it ('should return vsp names list', () => { |
| 50 | let state = { |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 51 | finalizedSoftwareProductList: [], |
| 52 | archivedSoftwareProductList: [], |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 53 | softwareProductList: [{ |
| 54 | name: 'vsp1', |
| 55 | id: 'vsp1_id' |
| 56 | }, { |
| 57 | name: 'vsp2', |
| 58 | id: 'vsp2_id' |
| 59 | }], |
| 60 | softwareProduct: { |
| 61 | softwareProductCreation: { |
| 62 | data: {} |
| 63 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 64 | }, |
| 65 | users: { |
| 66 | usersList: [] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 67 | } |
| 68 | }; |
| 69 | let props = mapStateToProps(state); |
| 70 | expect(props.data).toEqual({}); |
| 71 | expect(props.VSPNames).toEqual({vsp1: 'vsp1_id', vsp2: 'vsp2_id'}); |
| 72 | }); |
| 73 | |
| 74 | it('simple jsx test', () => { |
| 75 | const store = storeCreator(); |
| 76 | let dispatch = store.dispatch; |
| 77 | |
| 78 | let state = { |
| 79 | softwareProductList: [], |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 80 | finalizedSoftwareProductList: [], |
| 81 | archivedSoftwareProductList: [], |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 82 | softwareProduct: { |
| 83 | softwareProductCreation: SoftwareProductCreationFactory.build(), |
| 84 | softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2}) |
| 85 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 86 | finalizedLicenseModelList: FinalizedLicenseModelFactory.buildList(3), |
| 87 | users: { |
| 88 | usersList: [] |
| 89 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 90 | }; |
| 91 | let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch)); |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 92 | const renderer = new ShallowRenderer(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 93 | renderer.render( |
| 94 | <SoftwareProductCreationView {...props}/> |
| 95 | ); |
| 96 | var renderedOutput = renderer.getRenderOutput(); |
| 97 | expect(renderedOutput).toBeTruthy(); |
| 98 | }); |
| 99 | |
| 100 | it('simple jsx test - with selected vendor', () => { |
| 101 | const store = storeCreator(); |
| 102 | let dispatch = store.dispatch; |
| 103 | let finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(3); |
| 104 | let state = { |
| 105 | softwareProductList: [], |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 106 | finalizedSoftwareProductList: [], |
| 107 | archivedSoftwareProductList: [], |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 108 | softwareProduct: { |
| 109 | softwareProductCreation: SoftwareProductCreationFactoryWithSelectedVendor.build({selectedVendorId: finalizedLicenseModelList[0].id}), |
| 110 | softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2}) |
| 111 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 112 | finalizedLicenseModelList, |
| 113 | users: { |
| 114 | usersList: [] |
| 115 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 116 | }; |
| 117 | let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch)); |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 118 | const renderer = new ShallowRenderer(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 119 | renderer.render( |
| 120 | <SoftwareProductCreationView {...props}/> |
| 121 | ); |
| 122 | let renderedOutput = renderer.getRenderOutput(); |
| 123 | expect(renderedOutput).toBeTruthy(); |
| 124 | }); |
| 125 | }); |