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 = () => {};
42 const fetchUploadStatusMock = () => { return Promise.resolve({ data: {} }) };
44 beforeAll(function() {
45 finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(2);
46 currentSoftwareProduct = VSPEditorFactory.build({id:'RTRTG454545', vendorId: finalizedLicenseModelList[0].id, vendorName: finalizedLicenseModelList[0].name, onBoardingMethod: 'HEAT'});
47 softwareProductCategories = CategoryWithSubFactory.buildList(2,{},{quantity: 1});
48 licenseAgreementList = LicenseAgreementStoreFactory.buildList(2);
49 featureGroupsList = FeatureGroupStoreFactory.buildList(2,{referencingLicenseAgreements:[licenseAgreementList[0].id]});
50 currentScreen = CurrentScreenFactory.build();
51 qdata = VspQdataFactory.build();
52 qschema = SoftwareProductQSchemaFactory.build(qdata);
55 it('should mapper exist', () => {
56 expect(mapStateToProps).toBeTruthy();
59 it('should mapper return vsp basic data', () => {
63 softwareProductEditor: {
64 data: currentSoftwareProduct
66 softwareProductCategories,
67 softwareProductQuestionnaire: {
71 softwareProductComponents: {
74 softwareProductAttachments: {
78 finalizedLicenseModelList,
89 const result = mapStateToProps(state);
90 expect(result.currentSoftwareProduct).toBeTruthy();
94 it('vsp landing basic view', () => {
97 ...currentScreen.props,
98 currentSoftwareProduct,
99 componentsList: VSPComponentsFactory.buildList(2),
100 features: [{name:'EXTERNAL_LICENSE', active: true}],
101 fetchUploadStatus: fetchUploadStatusMock
104 const store = storeCreator();
105 let vspLandingView = TestUtils.renderIntoDocument(
106 <Provider store={store}>
107 <SoftwareProductLandingPageView {...params}/>
110 expect(vspLandingView).toBeTruthy();
113 it('vsp licence agreement type change', () => {
115 ...currentScreen.props,
116 currentSoftwareProduct,
117 componentsList: VSPComponentsFactory.buildList(2),
118 features: [{name:'EXTERNAL_LICENSE', active: true}],
119 fetchUploadStatus: fetchUploadStatusMock
121 const e = { target: {
124 const obj = {dummyFunction: x => true};
125 const store = storeCreator();
126 let vspLandingView = TestUtils.renderIntoDocument(
127 <Provider store={store}>
128 <SoftwareProductLandingPageView {...params}/>
131 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
133 SoftwareProductLandingPageView
135 const spy = jest.spyOn(obj, "dummyFunction");
136 vspLandingViewWrapper.licenceChange(e, currentSoftwareProduct, obj.dummyFunction);
137 expect(spy).toHaveBeenCalled();
138 expect(currentSoftwareProduct.licenseType).toBe("INTERNAL");
139 expect(vspLandingViewWrapper).toBeTruthy();
143 it('vsp landing handleOnDragEnter test ', () => {
146 currentSoftwareProduct,
147 ...currentScreen.props,
148 componentsList: VSPComponentsFactory.buildList(2),
149 features: [{name:'EXTERNAL_LICENSE', active: true}],
150 fetchUploadStatus: fetchUploadStatusMock
153 const store = storeCreator();
154 let vspLandingView = TestUtils.renderIntoDocument(
155 <Provider store={store}>
156 <SoftwareProductLandingPageView {...params}/>
159 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
161 SoftwareProductLandingPageView
163 expect(vspLandingView).toBeTruthy();
164 vspLandingViewWrapper.handleOnDragEnter(false);
165 expect(vspLandingViewWrapper.state.dragging).toEqual(true);
169 it('vsp landing handleImportSubmit test ', () => {
172 ...currentScreen.props,
173 currentSoftwareProduct,
174 componentsList: VSPComponentsFactory.buildList(2),
175 onUploadConfirmation: dummyFunc,
177 onInvalidFileSizeUpload: dummyFunc,
178 features: [{name:'EXTERNAL_LICENSE', active: true}],
179 fetchUploadStatus: fetchUploadStatusMock
189 const store = storeCreator();
191 let vspLandingView = TestUtils.renderIntoDocument(
192 <Provider store={store}>
193 <SoftwareProductLandingPageView {...params}/>
197 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
199 SoftwareProductLandingPageView
201 expect(vspLandingView).toBeTruthy();
202 vspLandingViewWrapper.handleImportSubmit(files, false);
203 expect(vspLandingViewWrapper.state.dragging).toEqual(false);
204 expect(vspLandingViewWrapper.state.fileName).toEqual(files[0].name);
211 vspLandingViewWrapper.handleImportSubmit(files1, false);
214 it('vsp landing handleImportSubmit with damaged file test ', () => {
217 currentSoftwareProduct,
218 ...currentScreen.props,
219 componentsList: VSPComponentsFactory.buildList(2),
220 onUploadConfirmation: dummyFunc,
222 onInvalidFileSizeUpload: dummyFunc,
223 features: [{name:'EXTERNAL_LICENSE', active: true}],
224 fetchUploadStatus: fetchUploadStatusMock
227 const store = storeCreator();
229 let vspLandingView = TestUtils.renderIntoDocument(
230 <Provider store={store}>
231 <SoftwareProductLandingPageView {...params}/>
235 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
237 SoftwareProductLandingPageView
239 expect(vspLandingView).toBeTruthy();
247 vspLandingViewWrapper.handleImportSubmit(files, false);
248 expect(vspLandingViewWrapper.state.dragging).toEqual(false);
249 expect(vspLandingViewWrapper.state.fileName).toEqual('');