svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2016-2017 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 |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 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'; |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +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, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 98 | componentsList: VSPComponentsFactory.buildList(2) |
| 99 | }; |
| 100 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 101 | const store = storeCreator(); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 102 | let vspLandingView = TestUtils.renderIntoDocument( |
| 103 | <Provider store={store}> |
| 104 | <SoftwareProductLandingPageView {...params}/> |
| 105 | </Provider> |
| 106 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 107 | expect(vspLandingView).toBeTruthy(); |
| 108 | }); |
| 109 | |
| 110 | it('vsp landing handleOnDragEnter test ', () => { |
| 111 | |
| 112 | const params = { |
| 113 | currentSoftwareProduct, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 114 | ...currentScreen.props, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 115 | componentsList: VSPComponentsFactory.buildList(2) |
| 116 | }; |
| 117 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 118 | const store = storeCreator(); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 119 | let vspLandingView = TestUtils.renderIntoDocument( |
| 120 | <Provider store={store}> |
| 121 | <SoftwareProductLandingPageView {...params}/> |
| 122 | </Provider> |
| 123 | ); |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 124 | let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType( |
| 125 | vspLandingView, |
| 126 | SoftwareProductLandingPageView |
| 127 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 128 | expect(vspLandingView).toBeTruthy(); |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 129 | vspLandingViewWrapper.handleOnDragEnter(false); |
| 130 | expect(vspLandingViewWrapper.state.dragging).toEqual(true); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 131 | }); |
| 132 | |
| 133 | |
| 134 | it('vsp landing handleImportSubmit test ', () => { |
| 135 | |
| 136 | const params = { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 137 | ...currentScreen.props, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 138 | currentSoftwareProduct, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 139 | componentsList: VSPComponentsFactory.buildList(2), |
| 140 | onUploadConfirmation: dummyFunc, |
| 141 | onUpload: dummyFunc, |
| 142 | onInvalidFileSizeUpload: dummyFunc |
| 143 | }; |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 144 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 145 | const files = [ |
| 146 | { |
| 147 | name: 'aaa', |
| 148 | size: 123 |
| 149 | } |
| 150 | ]; |
| 151 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 152 | const store = storeCreator(); |
| 153 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 154 | let vspLandingView = TestUtils.renderIntoDocument( |
| 155 | <Provider store={store}> |
| 156 | <SoftwareProductLandingPageView {...params}/> |
| 157 | </Provider> |
| 158 | ); |
| 159 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 160 | let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType( |
| 161 | vspLandingView, |
| 162 | SoftwareProductLandingPageView |
| 163 | ); |
| 164 | expect(vspLandingView).toBeTruthy(); |
| 165 | vspLandingViewWrapper.handleImportSubmit(files, false); |
| 166 | expect(vspLandingViewWrapper.state.dragging).toEqual(false); |
| 167 | expect(vspLandingViewWrapper.state.fileName).toEqual(files[0].name); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 168 | const files1 = [ |
| 169 | { |
| 170 | name: 'bbb', |
| 171 | size: 0 |
| 172 | } |
| 173 | ]; |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 174 | vspLandingViewWrapper.handleImportSubmit(files1, false); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 175 | }); |
| 176 | |
| 177 | it('vsp landing handleImportSubmit with damaged file test ', () => { |
| 178 | |
| 179 | const params = { |
| 180 | currentSoftwareProduct, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 181 | ...currentScreen.props, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 182 | componentsList: VSPComponentsFactory.buildList(2), |
| 183 | onUploadConfirmation: dummyFunc, |
| 184 | onUpload: dummyFunc, |
| 185 | onInvalidFileSizeUpload: dummyFunc |
| 186 | }; |
| 187 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 188 | const store = storeCreator(); |
| 189 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 190 | let vspLandingView = TestUtils.renderIntoDocument( |
| 191 | <Provider store={store}> |
| 192 | <SoftwareProductLandingPageView {...params}/> |
| 193 | </Provider> |
| 194 | ); |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 195 | |
| 196 | let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType( |
| 197 | vspLandingView, |
| 198 | SoftwareProductLandingPageView |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 199 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 200 | expect(vspLandingView).toBeTruthy(); |
| 201 | const files = [ |
| 202 | { |
| 203 | name: 'aaa', |
| 204 | size: 0 |
| 205 | } |
| 206 | ]; |
| 207 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 208 | vspLandingViewWrapper.handleImportSubmit(files, false); |
| 209 | expect(vspLandingViewWrapper.state.dragging).toEqual(false); |
| 210 | expect(vspLandingViewWrapper.state.fileName).toEqual(''); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 211 | }); |
| 212 | }); |