[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / test / softwareProduct / creation / SoftwareProductCreation.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 import React from 'react';
18 import TestUtils from 'react-addons-test-utils';
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                 };
40                 let props = mapStateToProps(state);
41                 expect(props.data).toEqual({});
42         });
43
44         it ('should return vsp names list', () => {
45                 let state = {
46                         softwareProductList: [{
47                                 name: 'vsp1',
48                                 id: 'vsp1_id'
49                         }, {
50                                 name: 'vsp2',
51                                 id: 'vsp2_id'
52                         }],
53                         softwareProduct: {
54                                 softwareProductCreation: {
55                                         data: {}
56                                 }
57                         }
58                 };
59                 let props = mapStateToProps(state);
60                 expect(props.data).toEqual({});
61                 expect(props.VSPNames).toEqual({vsp1: 'vsp1_id', vsp2: 'vsp2_id'});
62         });
63
64         it('simple jsx test', () => {
65                 const store = storeCreator();
66                 let dispatch = store.dispatch;
67
68                 let state = {
69                         softwareProductList: [],
70                         softwareProduct: {
71                                 softwareProductCreation: SoftwareProductCreationFactory.build(),
72                                 softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2})
73                         },
74                         finalizedLicenseModelList: FinalizedLicenseModelFactory.buildList(3)
75                 };
76                 let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch));
77                 var renderer = TestUtils.createRenderer();
78                 renderer.render(
79                         <SoftwareProductCreationView {...props}/>
80                         );
81                 var renderedOutput = renderer.getRenderOutput();
82                 expect(renderedOutput).toBeTruthy();
83         });
84
85         it('simple jsx test - with selected vendor', () => {
86                 const store = storeCreator();
87                 let dispatch = store.dispatch;
88                 let finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(3);
89                 let state = {
90                         softwareProductList: [],
91                         softwareProduct: {
92                                 softwareProductCreation: SoftwareProductCreationFactoryWithSelectedVendor.build({selectedVendorId: finalizedLicenseModelList[0].id}),
93                                 softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2})
94                         },
95                         finalizedLicenseModelList
96                 };
97                 let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch));
98                 let renderer = TestUtils.createRenderer();
99                 renderer.render(
100                         <SoftwareProductCreationView {...props}/>
101                 );
102                 let renderedOutput = renderer.getRenderOutput();
103                 expect(renderedOutput).toBeTruthy();
104         });
105 });