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