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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
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';
32 describe('Software Product Creation Module Tests', function() {
33 it ('mapStateToProps mapper exists', () => {
34 expect(mapStateToProps).toBeTruthy();
37 it ('should return empty data', () => {
39 softwareProductList: [],
40 finalizedSoftwareProductList: [],
41 archivedSoftwareProductList: [],
43 softwareProductCreation: {
51 let props = mapStateToProps(state);
52 expect(props.data).toEqual({});
55 it ('should return vsp names list', () => {
57 finalizedSoftwareProductList: [],
58 archivedSoftwareProductList: [],
59 softwareProductList: [{
67 softwareProductCreation: {
75 let props = mapStateToProps(state);
76 expect(props.data).toEqual({});
77 expect(props.VSPNames).toEqual({vsp1: 'vsp1_id', vsp2: 'vsp2_id'});
80 it ('should return model list', () => {
81 const modelList = ["model1", "model2", "model3"];
83 finalizedSoftwareProductList: [],
84 archivedSoftwareProductList: [],
85 softwareProductList: [],
88 softwareProductCreation: {}
92 let props = mapStateToProps(state);
93 expect(props.modelList).toEqual(modelList);
96 it('simple jsx test', () => {
97 const store = storeCreator();
98 let dispatch = store.dispatch;
101 softwareProductList: [],
102 finalizedSoftwareProductList: [],
103 archivedSoftwareProductList: [],
105 softwareProductCreation: SoftwareProductCreationFactory.build(),
106 softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2})
108 finalizedLicenseModelList: FinalizedLicenseModelFactory.buildList(3),
113 let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch));
114 const renderer = new ShallowRenderer();
116 <SoftwareProductCreationView {...props}/>
118 var renderedOutput = renderer.getRenderOutput();
119 expect(renderedOutput).toBeTruthy();
122 it('simple jsx test - with selected vendor', () => {
123 const store = storeCreator();
124 let dispatch = store.dispatch;
125 let finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(3);
127 softwareProductList: [],
128 finalizedSoftwareProductList: [],
129 archivedSoftwareProductList: [],
131 softwareProductCreation: SoftwareProductCreationFactoryWithSelectedVendor.build({selectedVendorId: finalizedLicenseModelList[0].id}),
132 softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2})
134 finalizedLicenseModelList,
139 let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch));
140 const renderer = new ShallowRenderer();
142 <SoftwareProductCreationView {...props}/>
144 let renderedOutput = renderer.getRenderOutput();
145 expect(renderedOutput).toBeTruthy();