Specify a model while creating a VSP
[sdc.git] / openecomp-ui / test / softwareProduct / creation / SoftwareProductCreation.test.js
1 /*
2  * -
3  *  ============LICENSE_START=======================================================
4  *  Copyright © 2016-2018 European Support Limited
5  *  Modifications Copyright (C) 2021 Nordix Foundation.
6  *  ================================================================================
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
10  *
11  *       http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  *
19  *  SPDX-License-Identifier: Apache-2.0
20  *  ============LICENSE_END=========================================================
21  */
22
23 import React from 'react';
24 import ShallowRenderer from 'react-test-renderer/shallow';
25 import {mapStateToProps, mapActionsToProps} from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreation.js';
26 import SoftwareProductCreationView from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationView.jsx';
27 import {SoftwareProductCreationFactory, SoftwareProductCreationFactoryWithSelectedVendor} from 'test-utils/factories/softwareProduct/SoftwareProductCreationFactories.js';
28 import {CategoryWithSubFactory} from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js';
29 import {FinalizedLicenseModelFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js';
30 import {storeCreator} from 'sdc-app/AppStore.js';
31
32 describe('Software Product Creation Module Tests', function() {
33         it ('mapStateToProps mapper exists', () => {
34                 expect(mapStateToProps).toBeTruthy();
35         });
36
37         it ('should return empty data', () => {
38                 let state = {
39                         softwareProductList: [],
40                         finalizedSoftwareProductList: [],
41                         archivedSoftwareProductList: [],
42                         softwareProduct: {
43                                 softwareProductCreation: {
44                                         data: {}
45                                 }
46                         },
47                         users: {
48                                 usersList: []
49                         }
50                 };
51                 let props = mapStateToProps(state);
52                 expect(props.data).toEqual({});
53         });
54
55         it ('should return vsp names list', () => {
56                 let state = {
57                         finalizedSoftwareProductList: [],
58                         archivedSoftwareProductList: [],
59                         softwareProductList: [{
60                                 name: 'vsp1',
61                                 id: 'vsp1_id'
62                         }, {
63                                 name: 'vsp2',
64                                 id: 'vsp2_id'
65                         }],
66                         softwareProduct: {
67                                 softwareProductCreation: {
68                                         data: {}
69                                 }
70                         },
71                         users: {
72                                 usersList: []
73                         }
74                 };
75                 let props = mapStateToProps(state);
76                 expect(props.data).toEqual({});
77                 expect(props.VSPNames).toEqual({vsp1: 'vsp1_id', vsp2: 'vsp2_id'});
78         });
79
80         it ('should return model list', () => {
81                 const modelList = ["model1", "model2", "model3"];
82                 let state = {
83                         finalizedSoftwareProductList: [],
84                         archivedSoftwareProductList: [],
85                         softwareProductList: [],
86                         softwareProduct: {
87                                 modelList: modelList,
88                                 softwareProductCreation: {}
89                         },
90                         users: {}
91                 };
92                 let props = mapStateToProps(state);
93                 expect(props.modelList).toEqual(modelList);
94         });
95
96         it('simple jsx test', () => {
97                 const store = storeCreator();
98                 let dispatch = store.dispatch;
99
100                 let state = {
101                         softwareProductList: [],
102                         finalizedSoftwareProductList: [],
103                         archivedSoftwareProductList: [],
104                         softwareProduct: {
105                                 softwareProductCreation: SoftwareProductCreationFactory.build(),
106                                 softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2})
107                         },
108                         finalizedLicenseModelList: FinalizedLicenseModelFactory.buildList(3),
109                         users: {
110                                 usersList: []
111                         }
112                 };
113                 let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch));
114                 const renderer = new ShallowRenderer();
115                 renderer.render(
116                         <SoftwareProductCreationView {...props}/>
117                         );
118                 var renderedOutput = renderer.getRenderOutput();
119                 expect(renderedOutput).toBeTruthy();
120         });
121
122         it('simple jsx test - with selected vendor', () => {
123                 const store = storeCreator();
124                 let dispatch = store.dispatch;
125                 let finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(3);
126                 let state = {
127                         softwareProductList: [],
128                         finalizedSoftwareProductList: [],
129                         archivedSoftwareProductList: [],
130                         softwareProduct: {
131                                 softwareProductCreation: SoftwareProductCreationFactoryWithSelectedVendor.build({selectedVendorId: finalizedLicenseModelList[0].id}),
132                                 softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2})
133                         },
134                         finalizedLicenseModelList,
135                         users: {
136                                 usersList: []
137                         }
138                 };
139                 let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch));
140                 const renderer = new ShallowRenderer();
141                 renderer.render(
142                         <SoftwareProductCreationView {...props}/>
143                 );
144                 let renderedOutput = renderer.getRenderOutput();
145                 expect(renderedOutput).toBeTruthy();
146         });
147 });