2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 import React from 'react';
18 import TestUtils from 'react-dom/test-utils';
20 import {Provider} from 'react-redux';
21 import {storeCreator} from 'sdc-app/AppStore.js';
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';
31 import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
33 import {mapStateToProps} from 'sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js';
34 import SoftwareProductLandingPageView from 'sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPageView.jsx';
37 describe('Software Product Landing Page: ', function () {
39 let currentSoftwareProduct = {}, softwareProductCategories = [], currentScreen = {},
40 finalizedLicenseModelList, licenseAgreementList, featureGroupsList, qschema, qdata = {};
41 const dummyFunc = () => {};
43 beforeAll(function() {
44 finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(2);
45 currentSoftwareProduct = VSPEditorFactory.build({id:'RTRTG454545', vendorId: finalizedLicenseModelList[0].id, vendorName: finalizedLicenseModelList[0].name, onBoardingMethod: 'HEAT'});
46 softwareProductCategories = CategoryWithSubFactory.buildList(2,{},{quantity: 1});
47 licenseAgreementList = LicenseAgreementStoreFactory.buildList(2);
48 featureGroupsList = FeatureGroupStoreFactory.buildList(2,{referencingLicenseAgreements:[licenseAgreementList[0].id]});
49 currentScreen = CurrentScreenFactory.build();
50 qdata = VspQdataFactory.build();
51 qschema = SoftwareProductQSchemaFactory.build(qdata);
54 it('should mapper exist', () => {
55 expect(mapStateToProps).toBeTruthy();
58 it('should mapper return vsp basic data', () => {
62 softwareProductEditor: {
63 data: currentSoftwareProduct
65 softwareProductCategories,
66 softwareProductQuestionnaire: {
70 softwareProductComponents: {
73 softwareProductAttachments: {
77 finalizedLicenseModelList,
88 const result = mapStateToProps(state);
89 expect(result.currentSoftwareProduct).toBeTruthy();
93 it('vsp landing basic view', () => {
96 ...currentScreen.props,
97 currentSoftwareProduct,
98 componentsList: VSPComponentsFactory.buildList(2),
99 features: [{name:'EXTERNAL_LICENSE', active: true}]
102 const store = storeCreator();
103 let vspLandingView = TestUtils.renderIntoDocument(
104 <Provider store={store}>
105 <SoftwareProductLandingPageView {...params}/>
108 expect(vspLandingView).toBeTruthy();
111 it('vsp licence agreement type change', () => {
113 ...currentScreen.props,
114 currentSoftwareProduct,
115 componentsList: VSPComponentsFactory.buildList(2),
116 features: [{name:'EXTERNAL_LICENSE', active: true}]
118 const e = { target: {
121 const obj = {dummyFunction: x => true};
122 const store = storeCreator();
123 let vspLandingView = TestUtils.renderIntoDocument(
124 <Provider store={store}>
125 <SoftwareProductLandingPageView {...params}/>
128 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
130 SoftwareProductLandingPageView
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();
140 it('vsp landing handleOnDragEnter test ', () => {
143 currentSoftwareProduct,
144 ...currentScreen.props,
145 componentsList: VSPComponentsFactory.buildList(2),
146 features: [{name:'EXTERNAL_LICENSE', active: true}]
149 const store = storeCreator();
150 let vspLandingView = TestUtils.renderIntoDocument(
151 <Provider store={store}>
152 <SoftwareProductLandingPageView {...params}/>
155 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
157 SoftwareProductLandingPageView
159 expect(vspLandingView).toBeTruthy();
160 vspLandingViewWrapper.handleOnDragEnter(false);
161 expect(vspLandingViewWrapper.state.dragging).toEqual(true);
165 it('vsp landing handleImportSubmit test ', () => {
168 ...currentScreen.props,
169 currentSoftwareProduct,
170 componentsList: VSPComponentsFactory.buildList(2),
171 onUploadConfirmation: dummyFunc,
173 onInvalidFileSizeUpload: dummyFunc,
174 features: [{name:'EXTERNAL_LICENSE', active: true}]
184 const store = storeCreator();
186 let vspLandingView = TestUtils.renderIntoDocument(
187 <Provider store={store}>
188 <SoftwareProductLandingPageView {...params}/>
192 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
194 SoftwareProductLandingPageView
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);
206 vspLandingViewWrapper.handleImportSubmit(files1, false);
209 it('vsp landing handleImportSubmit with damaged file test ', () => {
212 currentSoftwareProduct,
213 ...currentScreen.props,
214 componentsList: VSPComponentsFactory.buildList(2),
215 onUploadConfirmation: dummyFunc,
217 onInvalidFileSizeUpload: dummyFunc,
218 features: [{name:'EXTERNAL_LICENSE', active: true}]
221 const store = storeCreator();
223 let vspLandingView = TestUtils.renderIntoDocument(
224 <Provider store={store}>
225 <SoftwareProductLandingPageView {...params}/>
229 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
231 SoftwareProductLandingPageView
233 expect(vspLandingView).toBeTruthy();
241 vspLandingViewWrapper.handleImportSubmit(files, false);
242 expect(vspLandingViewWrapper.state.dragging).toEqual(false);
243 expect(vspLandingViewWrapper.state.fileName).toEqual('');