Obtain and control VSP package upload status
[sdc.git] / openecomp-ui / test / softwareProduct / landingPage / landingPage.test.js
1 /*
2  * Copyright © 2016-2018 European Support Limited
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 or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 import React from 'react';
18 import TestUtils from 'react-dom/test-utils';
19
20 import {Provider} from 'react-redux';
21 import {storeCreator} from 'sdc-app/AppStore.js';
22
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';
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
39         let currentSoftwareProduct = {}, softwareProductCategories = [], currentScreen = {},
40                 finalizedLicenseModelList, licenseAgreementList, featureGroupsList, qschema, qdata = {};
41         const dummyFunc = () => {};
42         const fetchUploadStatusMock = () => { return Promise.resolve({ data: {} }) };
43
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);
53         });
54
55         it('should mapper exist', () => {
56                 expect(mapStateToProps).toBeTruthy();
57         });
58
59         it('should mapper return vsp basic data', () => {
60                 const state = {
61                         currentScreen,
62                         softwareProduct: {
63                                 softwareProductEditor: {
64                                         data: currentSoftwareProduct
65                                 },
66                                 softwareProductCategories,
67                                 softwareProductQuestionnaire: {
68                                         qdata,
69                                         qschema
70                                 },
71                                 softwareProductComponents: {
72                                         componentsList:[]
73                                 },
74                                 softwareProductAttachments: {
75                                         heatSetup: {}
76                                 }
77                         },
78                         finalizedLicenseModelList,
79                         licenseModel: {
80                                 licenseAgreement: {
81                                         licenseAgreementList
82                                 },
83                                 featureGroup: {
84                                         featureGroupsList
85                                 }
86                         }
87                 };
88
89                 const result = mapStateToProps(state);
90                 expect(result.currentSoftwareProduct).toBeTruthy();
91
92         });
93
94         it('vsp landing basic view', () => {
95
96                 const params = {
97                         ...currentScreen.props,
98                         currentSoftwareProduct,
99                         componentsList: VSPComponentsFactory.buildList(2),
100                         features: [{name:'EXTERNAL_LICENSE', active: true}],
101                         fetchUploadStatus: fetchUploadStatusMock
102                 };
103
104                 const store = storeCreator();
105                 let vspLandingView = TestUtils.renderIntoDocument(
106                         <Provider store={store}>
107                                 <SoftwareProductLandingPageView {...params}/>
108                         </Provider>
109                 );
110                 expect(vspLandingView).toBeTruthy();
111         });
112
113         it('vsp licence agreement type change', () => {
114                 const params = {
115                         ...currentScreen.props,
116                         currentSoftwareProduct,
117                         componentsList: VSPComponentsFactory.buildList(2),
118                         features: [{name:'EXTERNAL_LICENSE', active: true}],
119                         fetchUploadStatus: fetchUploadStatusMock
120                 };
121                 const e = { target: {
122                         value: 'INTERNAL'
123                         }};
124                 const obj = {dummyFunction: x => true};
125                 const store = storeCreator();
126                 let vspLandingView = TestUtils.renderIntoDocument(
127                         <Provider store={store}>
128                                 <SoftwareProductLandingPageView {...params}/>
129                         </Provider>
130                 );
131                 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
132                         vspLandingView,
133                         SoftwareProductLandingPageView
134                 );
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();
140
141         })
142
143         it('vsp landing handleOnDragEnter test ', () => {
144
145                 const params = {
146                         currentSoftwareProduct,
147                         ...currentScreen.props,
148                         componentsList: VSPComponentsFactory.buildList(2),
149                         features: [{name:'EXTERNAL_LICENSE', active: true}],
150                         fetchUploadStatus: fetchUploadStatusMock
151                 };
152
153                 const store = storeCreator();
154                 let vspLandingView = TestUtils.renderIntoDocument(
155                         <Provider store={store}>
156                                 <SoftwareProductLandingPageView {...params}/>
157                         </Provider>
158                 );
159                 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
160                         vspLandingView,
161                         SoftwareProductLandingPageView
162                 );
163                 expect(vspLandingView).toBeTruthy();
164                 vspLandingViewWrapper.handleOnDragEnter(false);
165                 expect(vspLandingViewWrapper.state.dragging).toEqual(true);
166         });
167
168
169         it('vsp landing handleImportSubmit test ', () => {
170
171                 const params = {
172                         ...currentScreen.props,
173                         currentSoftwareProduct,
174                         componentsList: VSPComponentsFactory.buildList(2),
175                         onUploadConfirmation:  dummyFunc,
176                         onUpload: dummyFunc,
177                         onInvalidFileSizeUpload: dummyFunc,
178                         features: [{name:'EXTERNAL_LICENSE', active: true}],
179                         fetchUploadStatus: fetchUploadStatusMock
180                 };
181
182                 const files = [
183                         {
184                                 name: 'aaa',
185                                 size: 123
186                         }
187                 ];
188
189                 const store = storeCreator();
190
191                 let vspLandingView = TestUtils.renderIntoDocument(
192                         <Provider store={store}>
193                                 <SoftwareProductLandingPageView {...params}/>
194                         </Provider>
195                 );
196
197                 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
198                         vspLandingView,
199                         SoftwareProductLandingPageView
200                 );
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);
205                 const files1 = [
206                         {
207                                 name: 'bbb',
208                                 size: 0
209                         }
210                 ];
211                 vspLandingViewWrapper.handleImportSubmit(files1, false);
212         });
213
214         it('vsp landing handleImportSubmit with damaged file test ', () => {
215
216                 const params = {
217                         currentSoftwareProduct,
218                         ...currentScreen.props,
219                         componentsList: VSPComponentsFactory.buildList(2),
220                         onUploadConfirmation:  dummyFunc,
221                         onUpload: dummyFunc,
222                         onInvalidFileSizeUpload: dummyFunc,
223                         features: [{name:'EXTERNAL_LICENSE', active: true}],
224                         fetchUploadStatus: fetchUploadStatusMock
225                 };
226
227                 const store = storeCreator();
228
229                 let vspLandingView = TestUtils.renderIntoDocument(
230                         <Provider store={store}>
231                                 <SoftwareProductLandingPageView {...params}/>
232                         </Provider>
233                 );
234
235                 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
236                         vspLandingView,
237                         SoftwareProductLandingPageView
238                 );
239                 expect(vspLandingView).toBeTruthy();
240                 const files = [
241                         {
242                                 name: 'aaa',
243                                 size: 0
244                         }
245                 ];
246
247                 vspLandingViewWrapper.handleImportSubmit(files, false);
248                 expect(vspLandingViewWrapper.state.dragging).toEqual(false);
249                 expect(vspLandingViewWrapper.state.fileName).toEqual('');
250         });
251 });