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