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'; |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 18 | import {Provider} from 'react-redux'; |
| 19 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 20 | |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 21 | import TestUtils from 'react-dom/test-utils'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 22 | import {defaultStoreFactory} from 'test-utils/factories/onboard/OnboardingCatalogFactories.js'; |
| 23 | import {FinalizedLicenseModelFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; |
| 24 | import {VSPEditorFactory} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js'; |
| 25 | import {mapStateToProps} from 'sdc-app/onboarding/onboard/Onboard.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 26 | import {catalogItemTypes} from 'sdc-app/onboarding/onboard/onboardingCatalog/OnboardingCatalogConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 27 | import OnboardingCatalogView from 'sdc-app/onboarding/onboard/onboardingCatalog/OnboardingCatalogView.jsx'; |
| 28 | import VendorItem from 'sdc-app/onboarding/onboard/onboardingCatalog/VendorItem.jsx'; |
| 29 | import VSPOverlay from 'sdc-app/onboarding/onboard/onboardingCatalog/VSPOverlay.jsx'; |
| 30 | import CatalogItemDetails from 'sdc-app/onboarding/onboard/CatalogItemDetails.jsx'; |
| 31 | import DetailsCatalogView from 'sdc-app/onboarding/onboard/DetailsCatalogView.jsx'; |
| 32 | |
| 33 | describe('OnBoarding Catalog test - View: ', function () { |
| 34 | |
| 35 | |
| 36 | it('mapStateToProps mapper exists', () => { |
| 37 | expect(mapStateToProps).toBeTruthy(); |
| 38 | }); |
| 39 | |
| 40 | it('mapStateToProps data test', () => { |
| 41 | |
| 42 | const licenseModelList = FinalizedLicenseModelFactory.buildList(3); |
| 43 | const softwareProductList = VSPEditorFactory.buildList(4); |
| 44 | const data = defaultStoreFactory.build({licenseModelList, softwareProductList}); |
| 45 | |
| 46 | var results = mapStateToProps(data); |
| 47 | expect(results.softwareProductList).toBeTruthy(); |
| 48 | expect(results.licenseModelList).toBeTruthy(); |
| 49 | expect(results.activeTab).toBeTruthy(); |
| 50 | expect(results.licenseModelList.length).toEqual(3); |
| 51 | }); |
| 52 | |
| 53 | it('licenseModelList creating algorithm test', () => { |
| 54 | |
| 55 | const finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(3); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 56 | const licenseModelList = FinalizedLicenseModelFactory.buildList(3); |
| 57 | const finalizedSoftwareProductList = VSPEditorFactory.buildList(4, {vendorId: finalizedLicenseModelList[0].id}); |
| 58 | const softwareProductList = VSPEditorFactory.buildList(4, {vendorId: finalizedLicenseModelList[1].id}); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 59 | const data = defaultStoreFactory.build({licenseModelList, finalizedLicenseModelList, softwareProductList, finalizedSoftwareProductList}); |
| 60 | |
| 61 | var results = mapStateToProps(data); |
| 62 | expect(results.finalizedLicenseModelList[0].softwareProductList.length).toEqual(finalizedSoftwareProductList.length); |
| 63 | }); |
| 64 | |
| 65 | |
| 66 | it('Catalog view test', () => { |
| 67 | |
| 68 | const dummyFunc = () => {}; |
| 69 | const licenseModelList = FinalizedLicenseModelFactory.buildList(3); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 70 | const softwareProductList = VSPEditorFactory.buildList(4, {vendorId: licenseModelList[0].id}); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 71 | const data = defaultStoreFactory.build({licenseModelList, softwareProductList}); |
| 72 | |
| 73 | const func = { |
| 74 | onAddLicenseModelClick: dummyFunc, |
| 75 | onAddSoftwareProductClick: dummyFunc, |
| 76 | closeVspOverlay: dummyFunc, |
| 77 | onVspOverlayChange: dummyFunc, |
| 78 | onTabClick: dummyFunc, |
| 79 | onSearch: dummyFunc, |
| 80 | onSelectLicenseModel: dummyFunc, |
| 81 | onSelectSoftwareProduct: dummyFunc, |
| 82 | resetOnboardingCatalogStore: '' |
| 83 | }; |
| 84 | |
| 85 | let params = {...func, ...mapStateToProps(data)}; |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 86 | const store = storeCreator(); |
| 87 | |
| 88 | let CatalogView = TestUtils.renderIntoDocument( |
| 89 | <Provider store={store}> |
| 90 | <OnboardingCatalogView |
| 91 | {...params}/> |
| 92 | </Provider>); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 93 | expect(CatalogView).toBeTruthy(); |
| 94 | }); |
| 95 | |
| 96 | it('VendorItem view test', () => { |
| 97 | let vendor = FinalizedLicenseModelFactory.build(); |
| 98 | const dummyFunc = () => {}; |
| 99 | let params = { |
| 100 | softwareProductList: VSPEditorFactory.buildList(4 ,{vendorId: vendor.id}), |
| 101 | vendor, |
| 102 | onSelectVSP: dummyFunc, |
| 103 | shouldShowOverlay: false, |
| 104 | onVendorSelect: dummyFunc, |
| 105 | onAddVSP: dummyFunc, |
| 106 | onVSPIconClick: dummyFunc, |
| 107 | }; |
| 108 | |
| 109 | let VendorItemView = TestUtils.renderIntoDocument(<VendorItem{...params}/>); |
| 110 | expect(VendorItemView).toBeTruthy(); |
| 111 | }); |
| 112 | |
| 113 | |
| 114 | it('VSPOverlay view test', () => { |
| 115 | |
| 116 | let params = { |
| 117 | VSPList: VSPEditorFactory.buildList(10 ,{vendorId: '1'}), |
| 118 | onSelectVSP: () => {} |
| 119 | }; |
| 120 | |
| 121 | let VSPOverlayView = TestUtils.renderIntoDocument(<div><VSPOverlay {...params}/></div>); |
| 122 | expect(VSPOverlayView).toBeTruthy(); |
| 123 | }); |
| 124 | |
| 125 | it('CatalogItemDetails view test', () => { |
| 126 | |
| 127 | let params = { |
| 128 | catalogItemData: FinalizedLicenseModelFactory.build(), |
| 129 | onSelect: () => {}, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 130 | catalogItemTypeClass: catalogItemTypes.LICENSE_MODEL |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | let CatalogItemDetailsView = TestUtils.renderIntoDocument(<div><CatalogItemDetails {...params}/></div>); |
| 134 | expect(CatalogItemDetailsView).toBeTruthy(); |
| 135 | }); |
| 136 | |
| 137 | it('DetailsCatalogView view test', () => { |
| 138 | |
| 139 | let params = { |
| 140 | VLMList: FinalizedLicenseModelFactory.buildList(3), |
| 141 | VSPList: VSPEditorFactory.buildList(4), |
| 142 | onSelectVLM: () => {}, |
| 143 | onSelectVSP: () => {}, |
| 144 | onAddVLM: () => {}, |
| 145 | onAddVSP: () => {}, |
| 146 | filter: '' |
| 147 | }; |
| 148 | |
| 149 | let AllCatalog = TestUtils.renderIntoDocument(<DetailsCatalogView {...params}/>); |
| 150 | expect(AllCatalog).toBeTruthy(); |
| 151 | }); |
| 152 | }); |