AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
| 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 13 | * or implied. See the License for the specific language governing |
| 14 | * permissions and limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | |
| 19 | import React from 'react'; |
| 20 | import TestUtils from 'react-addons-test-utils'; |
| 21 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 22 | import {Provider} from 'react-redux'; |
| 23 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 24 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 25 | import {VSPEditorFactory} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js'; |
| 26 | import {CategoryWithSubFactory} from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js'; |
| 27 | import {LicenseAgreementStoreFactory} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js'; |
| 28 | import {FeatureGroupStoreFactory} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js'; |
| 29 | import {default as SoftwareProductQSchemaFactory} from 'test-utils/factories/softwareProduct/SoftwareProductQSchemaFactory.js'; |
| 30 | import {default as VspQdataFactory} from 'test-utils/factories/softwareProduct/VspQdataFactory.js'; |
| 31 | import {VSPComponentsFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsFactories.js'; |
| 32 | import {FinalizedLicenseModelFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 33 | import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 34 | |
| 35 | import {mapStateToProps} from 'sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js'; |
| 36 | import SoftwareProductLandingPageView from 'sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPageView.jsx'; |
| 37 | |
| 38 | |
| 39 | describe('Software Product Landing Page: ', function () { |
| 40 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 41 | let currentSoftwareProduct = {}, softwareProductCategories = [], currentScreen = {}, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 42 | finalizedLicenseModelList, licenseAgreementList, featureGroupsList, qschema, qdata = {}; |
| 43 | const dummyFunc = () => {}; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 44 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 45 | beforeAll(function() { |
| 46 | finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(2); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 47 | 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] | 48 | softwareProductCategories = CategoryWithSubFactory.buildList(2,{},{quantity: 1}); |
| 49 | licenseAgreementList = LicenseAgreementStoreFactory.buildList(2); |
| 50 | featureGroupsList = FeatureGroupStoreFactory.buildList(2,{referencingLicenseAgreements:[licenseAgreementList[0].id]}); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 51 | currentScreen = CurrentScreenFactory.build(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 52 | qdata = VspQdataFactory.build(); |
| 53 | qschema = SoftwareProductQSchemaFactory.build(qdata); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 54 | }); |
| 55 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 56 | it('should mapper exist', () => { |
| 57 | expect(mapStateToProps).toBeTruthy(); |
| 58 | }); |
| 59 | |
| 60 | it('should mapper return vsp basic data', () => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 61 | const state = { |
| 62 | currentScreen, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 63 | softwareProduct: { |
| 64 | softwareProductEditor: { |
| 65 | data: currentSoftwareProduct |
| 66 | }, |
| 67 | softwareProductCategories, |
| 68 | softwareProductQuestionnaire: { |
| 69 | qdata, |
| 70 | qschema |
| 71 | }, |
| 72 | softwareProductComponents: { |
| 73 | componentsList:[] |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 74 | }, |
| 75 | softwareProductAttachments: { |
| 76 | heatSetup: {} |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 77 | } |
| 78 | }, |
| 79 | finalizedLicenseModelList, |
| 80 | licenseModel: { |
| 81 | licenseAgreement: { |
| 82 | licenseAgreementList |
| 83 | }, |
| 84 | featureGroup: { |
| 85 | featureGroupsList |
| 86 | } |
| 87 | } |
| 88 | }; |
| 89 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 90 | const result = mapStateToProps(state); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 91 | expect(result.currentSoftwareProduct).toBeTruthy(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 92 | |
| 93 | }); |
| 94 | |
| 95 | it('vsp landing basic view', () => { |
| 96 | |
| 97 | const params = { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 98 | ...currentScreen.props, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 99 | currentSoftwareProduct, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 100 | componentsList: VSPComponentsFactory.buildList(2) |
| 101 | }; |
| 102 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 103 | const store = storeCreator(); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 104 | let vspLandingView = TestUtils.renderIntoDocument( |
| 105 | <Provider store={store}> |
| 106 | <SoftwareProductLandingPageView {...params}/> |
| 107 | </Provider> |
| 108 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 109 | expect(vspLandingView).toBeTruthy(); |
| 110 | }); |
| 111 | |
| 112 | it('vsp landing handleOnDragEnter test ', () => { |
| 113 | |
| 114 | const params = { |
| 115 | currentSoftwareProduct, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 116 | ...currentScreen.props, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 117 | componentsList: VSPComponentsFactory.buildList(2) |
| 118 | }; |
| 119 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 120 | const store = storeCreator(); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 121 | let vspLandingView = TestUtils.renderIntoDocument( |
| 122 | <Provider store={store}> |
| 123 | <SoftwareProductLandingPageView {...params}/> |
| 124 | </Provider> |
| 125 | ); |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 126 | let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType( |
| 127 | vspLandingView, |
| 128 | SoftwareProductLandingPageView |
| 129 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 130 | expect(vspLandingView).toBeTruthy(); |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 131 | vspLandingViewWrapper.handleOnDragEnter(false); |
| 132 | expect(vspLandingViewWrapper.state.dragging).toEqual(true); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 133 | }); |
| 134 | |
| 135 | |
| 136 | it('vsp landing handleImportSubmit test ', () => { |
| 137 | |
| 138 | const params = { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 139 | ...currentScreen.props, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 140 | currentSoftwareProduct, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 141 | componentsList: VSPComponentsFactory.buildList(2), |
| 142 | onUploadConfirmation: dummyFunc, |
| 143 | onUpload: dummyFunc, |
| 144 | onInvalidFileSizeUpload: dummyFunc |
| 145 | }; |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 146 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 147 | const files = [ |
| 148 | { |
| 149 | name: 'aaa', |
| 150 | size: 123 |
| 151 | } |
| 152 | ]; |
| 153 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 154 | const store = storeCreator(); |
| 155 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 156 | let vspLandingView = TestUtils.renderIntoDocument( |
| 157 | <Provider store={store}> |
| 158 | <SoftwareProductLandingPageView {...params}/> |
| 159 | </Provider> |
| 160 | ); |
| 161 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 162 | let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType( |
| 163 | vspLandingView, |
| 164 | SoftwareProductLandingPageView |
| 165 | ); |
| 166 | expect(vspLandingView).toBeTruthy(); |
| 167 | vspLandingViewWrapper.handleImportSubmit(files, false); |
| 168 | expect(vspLandingViewWrapper.state.dragging).toEqual(false); |
| 169 | expect(vspLandingViewWrapper.state.fileName).toEqual(files[0].name); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 170 | const files1 = [ |
| 171 | { |
| 172 | name: 'bbb', |
| 173 | size: 0 |
| 174 | } |
| 175 | ]; |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 176 | vspLandingViewWrapper.handleImportSubmit(files1, false); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 177 | }); |
| 178 | |
| 179 | it('vsp landing handleImportSubmit with damaged file test ', () => { |
| 180 | |
| 181 | const params = { |
| 182 | currentSoftwareProduct, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 183 | ...currentScreen.props, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 184 | componentsList: VSPComponentsFactory.buildList(2), |
| 185 | onUploadConfirmation: dummyFunc, |
| 186 | onUpload: dummyFunc, |
| 187 | onInvalidFileSizeUpload: dummyFunc |
| 188 | }; |
| 189 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 190 | const store = storeCreator(); |
| 191 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 192 | let vspLandingView = TestUtils.renderIntoDocument( |
| 193 | <Provider store={store}> |
| 194 | <SoftwareProductLandingPageView {...params}/> |
| 195 | </Provider> |
| 196 | ); |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 197 | |
| 198 | let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType( |
| 199 | vspLandingView, |
| 200 | SoftwareProductLandingPageView |
| 201 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 202 | expect(vspLandingView).toBeTruthy(); |
| 203 | const files = [ |
| 204 | { |
| 205 | name: 'aaa', |
| 206 | size: 0 |
| 207 | } |
| 208 | ]; |
| 209 | |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 210 | vspLandingViewWrapper.handleImportSubmit(files, false); |
| 211 | expect(vspLandingViewWrapper.state.dragging).toEqual(false); |
| 212 | expect(vspLandingViewWrapper.state.fileName).toEqual(''); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 213 | }); |
| 214 | }); |