Add collaboration feature
[sdc.git] / openecomp-ui / test / softwareProduct / landingPage / landingPage.test.js
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
22 import {Provider} from 'react-redux';
23 import {storeCreator} from 'sdc-app/AppStore.js';
24
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';
33 import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
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
41         let currentSoftwareProduct = {}, softwareProductCategories = [], currentScreen = {},
42                 finalizedLicenseModelList, licenseAgreementList, featureGroupsList, qschema, qdata = {};
43         const dummyFunc = () => {};
44
45         beforeAll(function() {
46                 finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(2);
47                 currentSoftwareProduct = VSPEditorFactory.build({id:'RTRTG454545', vendorId: finalizedLicenseModelList[0].id, vendorName: finalizedLicenseModelList[0].name, onBoardingMethod: 'HEAT'});
48                 softwareProductCategories = CategoryWithSubFactory.buildList(2,{},{quantity: 1});
49                 licenseAgreementList = LicenseAgreementStoreFactory.buildList(2);
50                 featureGroupsList = FeatureGroupStoreFactory.buildList(2,{referencingLicenseAgreements:[licenseAgreementList[0].id]});
51                 currentScreen = CurrentScreenFactory.build();
52                 qdata = VspQdataFactory.build();
53                 qschema = SoftwareProductQSchemaFactory.build(qdata);
54         });
55
56         it('should mapper exist', () => {
57                 expect(mapStateToProps).toBeTruthy();
58         });
59
60         it('should mapper return vsp basic data', () => {
61                 const state = {
62                         currentScreen,
63                         softwareProduct: {
64                                 softwareProductEditor: {
65                                         data: currentSoftwareProduct
66                                 },
67                                 softwareProductCategories,
68                                 softwareProductQuestionnaire: {
69                                         qdata,
70                                         qschema
71                                 },
72                                 softwareProductComponents: {
73                                         componentsList:[]
74                                 },
75                                 softwareProductAttachments: {
76                                         heatSetup: {}
77                                 }
78                         },
79                         finalizedLicenseModelList,
80                         licenseModel: {
81                                 licenseAgreement: {
82                                         licenseAgreementList
83                                 },
84                                 featureGroup: {
85                                         featureGroupsList
86                                 }
87                         }
88                 };
89
90                 const result = mapStateToProps(state);
91                 expect(result.currentSoftwareProduct).toBeTruthy();
92
93         });
94
95         it('vsp landing basic view', () => {
96
97                 const params = {
98                         ...currentScreen.props,
99                         currentSoftwareProduct,
100                         componentsList: VSPComponentsFactory.buildList(2)
101                 };
102
103                 const store = storeCreator();
104                 let vspLandingView = TestUtils.renderIntoDocument(
105                         <Provider store={store}>
106                                 <SoftwareProductLandingPageView {...params}/>
107                         </Provider>
108                 );
109                 expect(vspLandingView).toBeTruthy();
110         });
111
112         it('vsp landing handleOnDragEnter test ', () => {
113
114                 const params = {
115                         currentSoftwareProduct,
116                         ...currentScreen.props,
117                         componentsList: VSPComponentsFactory.buildList(2)
118                 };
119
120                 const store = storeCreator();
121                 let vspLandingView = TestUtils.renderIntoDocument(
122                         <Provider store={store}>
123                                 <SoftwareProductLandingPageView {...params}/>
124                         </Provider>
125                 );
126                 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
127                         vspLandingView,
128                         SoftwareProductLandingPageView
129                 );
130                 expect(vspLandingView).toBeTruthy();
131                 vspLandingViewWrapper.handleOnDragEnter(false);
132                 expect(vspLandingViewWrapper.state.dragging).toEqual(true);
133         });
134
135
136         it('vsp landing handleImportSubmit test ', () => {
137
138                 const params = {
139                         ...currentScreen.props,
140                         currentSoftwareProduct,
141                         componentsList: VSPComponentsFactory.buildList(2),
142                         onUploadConfirmation:  dummyFunc,
143                         onUpload: dummyFunc,
144                         onInvalidFileSizeUpload: dummyFunc
145                 };
146                 
147                 const files = [
148                         {
149                                 name: 'aaa',
150                                 size: 123
151                         }
152                 ];
153
154                 const store = storeCreator();
155
156                 let vspLandingView = TestUtils.renderIntoDocument(
157                         <Provider store={store}>
158                                 <SoftwareProductLandingPageView {...params}/>
159                         </Provider>
160                 );
161
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);
170                 const files1 = [
171                         {
172                                 name: 'bbb',
173                                 size: 0
174                         }
175                 ];
176                 vspLandingViewWrapper.handleImportSubmit(files1, false);
177         });
178
179         it('vsp landing handleImportSubmit with damaged file test ', () => {
180
181                 const params = {
182                         currentSoftwareProduct,
183                         ...currentScreen.props,
184                         componentsList: VSPComponentsFactory.buildList(2),
185                         onUploadConfirmation:  dummyFunc,
186                         onUpload: dummyFunc,
187                         onInvalidFileSizeUpload: dummyFunc
188                 };
189
190                 const store = storeCreator();
191
192                 let vspLandingView = TestUtils.renderIntoDocument(
193                         <Provider store={store}>
194                                 <SoftwareProductLandingPageView {...params}/>
195                         </Provider>
196                 );
197
198                 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
199                         vspLandingView,
200                         SoftwareProductLandingPageView
201                 );      
202                 expect(vspLandingView).toBeTruthy();
203                 const files = [
204                         {
205                                 name: 'aaa',
206                                 size: 0
207                         }
208                 ];
209
210                 vspLandingViewWrapper.handleImportSubmit(files, false);
211                 expect(vspLandingViewWrapper.state.dragging).toEqual(false);
212                 expect(vspLandingViewWrapper.state.fileName).toEqual('');
213         });
214 });