da23d12f2d722f387e24a360e312174b2869a2ad
[sdc.git] / openecomp-ui / test / softwareProduct / creation / SoftwareProductCreation.test.js
1 /*
2  * Copyright © 2016-2017 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 ShallowRenderer from 'react-test-renderer/shallow';
19 import {mapStateToProps, mapActionsToProps} from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreation.js';
20 import SoftwareProductCreationView from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationView.jsx';
21 import {SoftwareProductCreationFactory, SoftwareProductCreationFactoryWithSelectedVendor} from 'test-utils/factories/softwareProduct/SoftwareProductCreationFactories.js';
22 import {CategoryWithSubFactory} from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js';
23 import {FinalizedLicenseModelFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js';
24 import {storeCreator} from 'sdc-app/AppStore.js';
25
26 describe('Software Product Creation Module Tests', function() {
27         it ('mapStateToProps mapper exists', () => {
28                 expect(mapStateToProps).toBeTruthy();
29         });
30
31         it ('should return empty data', () => {
32                 let state = {
33                         softwareProductList: [],
34                         softwareProduct: {
35                                 softwareProductCreation: {
36                                         data: {}
37                                 }
38                         },
39                         users: {
40                                 usersList: []
41                         }
42                 };
43                 let props = mapStateToProps(state);
44                 expect(props.data).toEqual({});
45         });
46
47         it ('should return vsp names list', () => {
48                 let state = {
49                         softwareProductList: [{
50                                 name: 'vsp1',
51                                 id: 'vsp1_id'
52                         }, {
53                                 name: 'vsp2',
54                                 id: 'vsp2_id'
55                         }],
56                         softwareProduct: {
57                                 softwareProductCreation: {
58                                         data: {}
59                                 }
60                         },
61                         users: {
62                                 usersList: []
63                         }
64                 };
65                 let props = mapStateToProps(state);
66                 expect(props.data).toEqual({});
67                 expect(props.VSPNames).toEqual({vsp1: 'vsp1_id', vsp2: 'vsp2_id'});
68         });
69
70         it('simple jsx test', () => {
71                 const store = storeCreator();
72                 let dispatch = store.dispatch;
73
74                 let state = {
75                         softwareProductList: [],
76                         softwareProduct: {
77                                 softwareProductCreation: SoftwareProductCreationFactory.build(),
78                                 softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2})
79                         },
80                         finalizedLicenseModelList: FinalizedLicenseModelFactory.buildList(3),
81                         users: {
82                                 usersList: []
83                         }
84                 };
85                 let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch));
86                 const renderer = new ShallowRenderer();
87                 renderer.render(
88                         <SoftwareProductCreationView {...props}/>
89                         );
90                 var renderedOutput = renderer.getRenderOutput();
91                 expect(renderedOutput).toBeTruthy();
92         });
93
94         it('simple jsx test - with selected vendor', () => {
95                 const store = storeCreator();
96                 let dispatch = store.dispatch;
97                 let finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(3);
98                 let state = {
99                         softwareProductList: [],
100                         softwareProduct: {
101                                 softwareProductCreation: SoftwareProductCreationFactoryWithSelectedVendor.build({selectedVendorId: finalizedLicenseModelList[0].id}),
102                                 softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2})
103                         },
104                         finalizedLicenseModelList,
105                         users: {
106                                 usersList: []
107                         }
108                 };
109                 let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch));
110                 const renderer = new ShallowRenderer();
111                 renderer.render(
112                         <SoftwareProductCreationView {...props}/>
113                 );
114                 let renderedOutput = renderer.getRenderOutput();
115                 expect(renderedOutput).toBeTruthy();
116         });
117 });