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 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 17 | import React from 'react'; |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 18 | import TestUtils from 'react-dom/test-utils'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 19 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 20 | import {Provider} from 'react-redux'; |
| 21 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 22 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | import {VSPEditorFactory} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js'; |
| 24 | import {CategoryWithSubFactory} from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js'; |
| 25 | import {LicenseAgreementStoreFactory} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js'; |
| 26 | import {FeatureGroupStoreFactory} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js'; |
| 27 | import {default as SoftwareProductQSchemaFactory} from 'test-utils/factories/softwareProduct/SoftwareProductQSchemaFactory.js'; |
| 28 | import {default as VspQdataFactory} from 'test-utils/factories/softwareProduct/VspQdataFactory.js'; |
| 29 | import {VSPComponentsFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsFactories.js'; |
| 30 | import {FinalizedLicenseModelFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 31 | import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 32 | |
| 33 | import {mapStateToProps} from 'sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js'; |
| 34 | import SoftwareProductLandingPageView from 'sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPageView.jsx'; |
| 35 | |
| 36 | |
| 37 | describe('Software Product Landing Page: ', function () { |
| 38 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 39 | let currentSoftwareProduct = {}, softwareProductCategories = [], currentScreen = {}, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 40 | finalizedLicenseModelList, licenseAgreementList, featureGroupsList, qschema, qdata = {}; |
| 41 | const dummyFunc = () => {}; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 42 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 43 | beforeAll(function() { |
| 44 | finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(2); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 45 | currentSoftwareProduct = VSPEditorFactory.build({id:'RTRTG454545', vendorId: finalizedLicenseModelList[0].id, vendorName: finalizedLicenseModelList[0].name, onBoardingMethod: 'HEAT'}); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 46 | softwareProductCategories = CategoryWithSubFactory.buildList(2,{},{quantity: 1}); |
| 47 | licenseAgreementList = LicenseAgreementStoreFactory.buildList(2); |
| 48 | featureGroupsList = FeatureGroupStoreFactory.buildList(2,{referencingLicenseAgreements:[licenseAgreementList[0].id]}); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 49 | currentScreen = CurrentScreenFactory.build(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 50 | qdata = VspQdataFactory.build(); |
| 51 | qschema = SoftwareProductQSchemaFactory.build(qdata); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 52 | }); |
| 53 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 54 | it('should mapper exist', () => { |
| 55 | expect(mapStateToProps).toBeTruthy(); |
| 56 | }); |
| 57 | |
| 58 | it('should mapper return vsp basic data', () => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 59 | const state = { |
| 60 | currentScreen, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 61 | softwareProduct: { |
| 62 | softwareProductEditor: { |
| 63 | data: currentSoftwareProduct |
| 64 | }, |
| 65 | softwareProductCategories, |
| 66 | softwareProductQuestionnaire: { |
| 67 | qdata, |
| 68 | qschema |
| 69 | }, |
| 70 | softwareProductComponents: { |
| 71 | componentsList:[] |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 72 | }, |
| 73 | softwareProductAttachments: { |
| 74 | heatSetup: {} |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 75 | } |
| 76 | }, |
| 77 | finalizedLicenseModelList, |
| 78 | licenseModel: { |
| 79 | licenseAgreement: { |
| 80 | licenseAgreementList |
| 81 | }, |
| 82 | featureGroup: { |
| 83 | featureGroupsList |
| 84 | } |
| 85 | } |
| 86 | }; |
| 87 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 88 | const result = mapStateToProps(state); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 89 | expect(result.currentSoftwareProduct).toBeTruthy(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 90 | |
| 91 | }); |
| 92 | |
| 93 | it('vsp landing basic view', () => { |
| 94 | |
| 95 | const params = { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 96 | ...currentScreen.props, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 97 | currentSoftwareProduct, |
marine | 3453264 | 2021-06-18 17:51:46 +0200 | [diff] [blame] | 98 | componentsList: VSPComponentsFactory.buildList(2), |
xuegao | 6d9f291 | 2021-07-15 08:56:52 +0200 | [diff] [blame] | 99 | features: [{name:'EXTERNAL_LICENSE', active: true}] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 100 | }; |
| 101 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 102 | const store = storeCreator(); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 103 | let vspLandingView = TestUtils.renderIntoDocument( |
| 104 | <Provider store={store}> |
| 105 | <SoftwareProductLandingPageView {...params}/> |
| 106 | </Provider> |
| 107 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 108 | expect(vspLandingView).toBeTruthy(); |
| 109 | }); |
| 110 | |
JerzySzachniewicz | f2c0a41 | 2021-02-12 13:53:13 +0100 | [diff] [blame] | 111 | it('vsp licence agreement type change', () => { |
| 112 | const params = { |
| 113 | ...currentScreen.props, |
| 114 | currentSoftwareProduct, |
marine | 3453264 | 2021-06-18 17:51:46 +0200 | [diff] [blame] | 115 | componentsList: VSPComponentsFactory.buildList(2), |
xuegao | 6d9f291 | 2021-07-15 08:56:52 +0200 | [diff] [blame] | 116 | features: [{name:'EXTERNAL_LICENSE', active: true}] |
JerzySzachniewicz | f2c0a41 | 2021-02-12 13:53:13 +0100 | [diff] [blame] | 117 | }; |
| 118 | const e = { target: { |
| 119 | value: 'INTERNAL' |
| 120 | }}; |
| 121 | const obj = {dummyFunction: x => true}; |
| 122 | const store = storeCreator(); |
| 123 | let vspLandingView = TestUtils.renderIntoDocument( |
| 124 | <Provider store={store}> |
| 125 | <SoftwareProductLandingPageView {...params}/> |
| 126 | </Provider> |
| 127 | ); |
| 128 | let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType( |
| 129 | vspLandingView, |
| 130 | SoftwareProductLandingPageView |
| 131 | ); |
| 132 | const spy = jest.spyOn(obj, "dummyFunction"); |
| 133 | vspLandingViewWrapper.licenceChange(e, currentSoftwareProduct, obj.dummyFunction); |
| 134 | expect(spy).toHaveBeenCalled(); |
| 135 | expect(currentSoftwareProduct.licenseType).toBe("INTERNAL"); |
| 136 | expect(vspLandingViewWrapper).toBeTruthy(); |
| 137 | |
| 138 | }) |
| 139 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 140 | it('vsp landing handleOnDragEnter test ', () => { |
| 141 | |
| 142 | const params = { |
| 143 | currentSoftwareProduct, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 144 | ...currentScreen.props, |
marine | 3453264 | 2021-06-18 17:51:46 +0200 | [diff] [blame] | 145 | componentsList: VSPComponentsFactory.buildList(2), |
xuegao | 6d9f291 | 2021-07-15 08:56:52 +0200 | [diff] [blame] | 146 | features: [{name:'EXTERNAL_LICENSE', active: true}] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 147 | }; |
| 148 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 149 | const store = storeCreator(); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 150 | let vspLandingView = TestUtils.renderIntoDocument( |
| 151 | <Provider store={store}> |
| 152 | <SoftwareProductLandingPageView {...params}/> |
| 153 | </Provider> |
| 154 | ); |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 155 | let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType( |
| 156 | vspLandingView, |
| 157 | SoftwareProductLandingPageView |
| 158 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 159 | expect(vspLandingView).toBeTruthy(); |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 160 | vspLandingViewWrapper.handleOnDragEnter(false); |
| 161 | expect(vspLandingViewWrapper.state.dragging).toEqual(true); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 162 | }); |
| 163 | |
| 164 | |
| 165 | it('vsp landing handleImportSubmit test ', () => { |
| 166 | |
| 167 | const params = { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 168 | ...currentScreen.props, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 169 | currentSoftwareProduct, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 170 | componentsList: VSPComponentsFactory.buildList(2), |
| 171 | onUploadConfirmation: dummyFunc, |
| 172 | onUpload: dummyFunc, |
marine | 3453264 | 2021-06-18 17:51:46 +0200 | [diff] [blame] | 173 | onInvalidFileSizeUpload: dummyFunc, |
xuegao | 6d9f291 | 2021-07-15 08:56:52 +0200 | [diff] [blame] | 174 | features: [{name:'EXTERNAL_LICENSE', active: true}] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 175 | }; |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 176 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 177 | const files = [ |
| 178 | { |
| 179 | name: 'aaa', |
| 180 | size: 123 |
| 181 | } |
| 182 | ]; |
| 183 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 184 | const store = storeCreator(); |
| 185 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 186 | let vspLandingView = TestUtils.renderIntoDocument( |
| 187 | <Provider store={store}> |
| 188 | <SoftwareProductLandingPageView {...params}/> |
| 189 | </Provider> |
| 190 | ); |
| 191 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 192 | let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType( |
| 193 | vspLandingView, |
| 194 | SoftwareProductLandingPageView |
| 195 | ); |
| 196 | expect(vspLandingView).toBeTruthy(); |
| 197 | vspLandingViewWrapper.handleImportSubmit(files, false); |
| 198 | expect(vspLandingViewWrapper.state.dragging).toEqual(false); |
| 199 | expect(vspLandingViewWrapper.state.fileName).toEqual(files[0].name); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 200 | const files1 = [ |
| 201 | { |
| 202 | name: 'bbb', |
| 203 | size: 0 |
| 204 | } |
| 205 | ]; |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 206 | vspLandingViewWrapper.handleImportSubmit(files1, false); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 207 | }); |
| 208 | |
| 209 | it('vsp landing handleImportSubmit with damaged file test ', () => { |
| 210 | |
| 211 | const params = { |
| 212 | currentSoftwareProduct, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 213 | ...currentScreen.props, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 214 | componentsList: VSPComponentsFactory.buildList(2), |
| 215 | onUploadConfirmation: dummyFunc, |
| 216 | onUpload: dummyFunc, |
marine | 3453264 | 2021-06-18 17:51:46 +0200 | [diff] [blame] | 217 | onInvalidFileSizeUpload: dummyFunc, |
xuegao | 6d9f291 | 2021-07-15 08:56:52 +0200 | [diff] [blame] | 218 | features: [{name:'EXTERNAL_LICENSE', active: true}] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 219 | }; |
| 220 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 221 | const store = storeCreator(); |
| 222 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 223 | let vspLandingView = TestUtils.renderIntoDocument( |
| 224 | <Provider store={store}> |
| 225 | <SoftwareProductLandingPageView {...params}/> |
| 226 | </Provider> |
| 227 | ); |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 228 | |
| 229 | let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType( |
| 230 | vspLandingView, |
| 231 | SoftwareProductLandingPageView |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 232 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 233 | expect(vspLandingView).toBeTruthy(); |
| 234 | const files = [ |
| 235 | { |
| 236 | name: 'aaa', |
| 237 | size: 0 |
| 238 | } |
| 239 | ]; |
| 240 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 241 | vspLandingViewWrapper.handleImportSubmit(files, false); |
| 242 | expect(vspLandingViewWrapper.state.dragging).toEqual(false); |
| 243 | expect(vspLandingViewWrapper.state.fileName).toEqual(''); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 244 | }); |
| 245 | }); |