[SDC] Onboarding 1710 rebase.
[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 {VSPEditorFactory} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js';
23 import {CategoryWithSubFactory}  from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js';
24 import {LicenseAgreementStoreFactory}  from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js';
25 import {FeatureGroupStoreFactory}  from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
26 import {default as SoftwareProductQSchemaFactory}  from 'test-utils/factories/softwareProduct/SoftwareProductQSchemaFactory.js';
27 import {default as VspQdataFactory}  from 'test-utils/factories/softwareProduct/VspQdataFactory.js';
28 import {VSPComponentsFactory}  from 'test-utils/factories/softwareProduct/SoftwareProductComponentsFactories.js';
29 import {FinalizedLicenseModelFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js';
30
31 import { Provider } from 'react-redux';
32 import {storeCreator} from 'sdc-app/AppStore.js';
33
34 import {mapStateToProps} from 'sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js';
35 import SoftwareProductLandingPageView from 'sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPageView.jsx';
36
37
38 describe('Software Product Landing Page: ', function () {
39
40         let currentSoftwareProduct = {}, softwareProductCategories = [],
41                 finalizedLicenseModelList, licenseAgreementList, featureGroupsList, qschema, qdata = {};
42         const dummyFunc = () => {};
43         beforeAll(function() {
44                 finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(2);
45                 currentSoftwareProduct = VSPEditorFactory.build({id:'RTRTG454545', vendorId: finalizedLicenseModelList[0].id, vendorName: finalizedLicenseModelList[0].name});
46                 softwareProductCategories = CategoryWithSubFactory.buildList(2,{},{quantity: 1});
47                 licenseAgreementList = LicenseAgreementStoreFactory.buildList(2);
48                 featureGroupsList = FeatureGroupStoreFactory.buildList(2,{referencingLicenseAgreements:[licenseAgreementList[0].id]});
49                 qdata = VspQdataFactory.build();
50                 qschema = SoftwareProductQSchemaFactory.build(qdata);
51
52         });
53
54
55
56         it('should mapper exist', () => {
57                 expect(mapStateToProps).toBeTruthy();
58         });
59
60         it('should mapper return vsp basic data', () => {
61                 const obj = {
62                         softwareProduct: {
63                                 softwareProductEditor: {
64                                         data: currentSoftwareProduct
65                                 },
66                                 softwareProductCategories,
67                                 softwareProductQuestionnaire: {
68                                         qdata,
69                                         qschema
70                                 },
71                                 softwareProductComponents: {
72                                         componentsList:[]
73                                 }
74                         },
75                         finalizedLicenseModelList,
76                         licenseModel: {
77                                 licenseAgreement: {
78                                         licenseAgreementList
79                                 },
80                                 featureGroup: {
81                                         featureGroupsList
82                                 }
83                         }
84                 };
85
86                 const result = mapStateToProps(obj);
87                 expect(result.currentSoftwareProduct).toBeTruthy();
88                 expect(result.isReadOnlyMode).toEqual(true);
89
90         });
91
92         it('vsp landing basic view', () => {
93
94                 const params = {
95                         currentSoftwareProduct,
96                         isReadOnlyMode: false,
97                         componentsList: VSPComponentsFactory.buildList(2)
98                 };
99
100                 const store = storeCreator();
101                 let vspLandingView = TestUtils.renderIntoDocument(<Provider store={store}><SoftwareProductLandingPageView
102                         {...params}/></Provider>);
103                 expect(vspLandingView).toBeTruthy();
104         });
105
106         it('vsp landing handleOnDragEnter test ', () => {
107
108                 const params = {
109                         currentSoftwareProduct,
110                         isReadOnlyMode: false,
111                         componentsList: VSPComponentsFactory.buildList(2)
112                 };
113
114                 const store = storeCreator();
115                 let vspLandingView = TestUtils.renderIntoDocument(<Provider store={store}><SoftwareProductLandingPageView
116                         {...params}/></Provider>);
117                 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
118                         vspLandingView,
119                         SoftwareProductLandingPageView
120                 );
121                 expect(vspLandingView).toBeTruthy();
122                 vspLandingViewWrapper.handleOnDragEnter(false);
123                 expect(vspLandingViewWrapper.state.dragging).toEqual(true);
124         });
125
126
127         it('vsp landing handleImportSubmit test ', () => {
128
129                 const params = {
130                         currentSoftwareProduct,
131                         isReadOnlyMode: false,
132                         componentsList: VSPComponentsFactory.buildList(2),
133                         onUploadConfirmation:  dummyFunc,
134                         onUpload: dummyFunc,
135                         onInvalidFileSizeUpload: dummyFunc
136                 };
137                 
138                 const files = [
139                         {
140                                 name: 'aaa',
141                                 size: 123
142                         }
143                 ];
144
145                 const store = storeCreator();
146
147                 let vspLandingView = TestUtils.renderIntoDocument(<Provider store={store}><SoftwareProductLandingPageView {...params}/></Provider>);
148                 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
149                         vspLandingView,
150                         SoftwareProductLandingPageView
151                 );
152                 expect(vspLandingView).toBeTruthy();
153                 vspLandingViewWrapper.handleImportSubmit(files, false);
154                 expect(vspLandingViewWrapper.state.dragging).toEqual(false);
155                 expect(vspLandingViewWrapper.state.fileName).toEqual(files[0].name);
156                 const files1 = [
157                         {
158                                 name: 'bbb',
159                                 size: 0
160                         }
161                 ];
162                 vspLandingViewWrapper.handleImportSubmit(files1, false);
163         });
164
165         it('vsp landing handleImportSubmit with damaged file test ', () => {
166
167                 const params = {
168                         currentSoftwareProduct,
169                         isReadOnlyMode: false,
170                         componentsList: VSPComponentsFactory.buildList(2),
171                         onUploadConfirmation:  dummyFunc,
172                         onUpload: dummyFunc,
173                         onInvalidFileSizeUpload: dummyFunc
174                 };
175
176                 const store = storeCreator();
177
178                 let vspLandingView = TestUtils.renderIntoDocument(<Provider store={store}><SoftwareProductLandingPageView
179                         {...params}/></Provider>);
180
181                 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
182                         vspLandingView,
183                         SoftwareProductLandingPageView
184                 );      
185                 expect(vspLandingView).toBeTruthy();
186                 const files = [
187                         {
188                                 name: 'aaa',
189                                 size: 0
190                         }
191                 ];
192
193                 vspLandingViewWrapper.handleImportSubmit(files, false);
194                 expect(vspLandingViewWrapper.state.dragging).toEqual(false);
195                 expect(vspLandingViewWrapper.state.fileName).toEqual('');
196         });
197 });