blob: 51db931a9ae3cdeb7b512d04b56992c417b17702 [file] [log] [blame]
svishnev1eb66b72018-01-11 14:39:45 +02001/*
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02002 * Copyright © 2016-2018 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
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
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02007 *
svishnev1eb66b72018-01-11 14:39:45 +02008 * http://www.apache.org/licenses/LICENSE-2.0
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02009 *
AviZi280f8012017-06-09 02:39:56 +030010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
svishnev1eb66b72018-01-11 14:39:45 +020012 * 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.
AviZi280f8012017-06-09 02:39:56 +030015 */
16
17import React from 'react';
Einav Weiss Keidard2f57942018-02-14 14:00:07 +020018import ShallowRenderer from 'react-test-renderer/shallow';
AviZi280f8012017-06-09 02:39:56 +030019import {mapStateToProps, mapActionsToProps} from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreation.js';
20import SoftwareProductCreationView from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationView.jsx';
21import {SoftwareProductCreationFactory, SoftwareProductCreationFactoryWithSelectedVendor} from 'test-utils/factories/softwareProduct/SoftwareProductCreationFactories.js';
22import {CategoryWithSubFactory} from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js';
23import {FinalizedLicenseModelFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js';
24import {storeCreator} from 'sdc-app/AppStore.js';
25
26describe('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 }
talig8e9c0652017-12-20 14:30:43 +020038 },
39 users: {
40 usersList: []
AviZi280f8012017-06-09 02:39:56 +030041 }
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 }
talig8e9c0652017-12-20 14:30:43 +020060 },
61 users: {
62 usersList: []
AviZi280f8012017-06-09 02:39:56 +030063 }
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 },
talig8e9c0652017-12-20 14:30:43 +020080 finalizedLicenseModelList: FinalizedLicenseModelFactory.buildList(3),
81 users: {
82 usersList: []
83 }
AviZi280f8012017-06-09 02:39:56 +030084 };
85 let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch));
Einav Weiss Keidard2f57942018-02-14 14:00:07 +020086 const renderer = new ShallowRenderer();
AviZi280f8012017-06-09 02:39:56 +030087 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 },
talig8e9c0652017-12-20 14:30:43 +0200104 finalizedLicenseModelList,
105 users: {
106 usersList: []
107 }
AviZi280f8012017-06-09 02:39:56 +0300108 };
109 let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch));
Einav Weiss Keidard2f57942018-02-14 14:00:07 +0200110 const renderer = new ShallowRenderer();
AviZi280f8012017-06-09 02:39:56 +0300111 renderer.render(
112 <SoftwareProductCreationView {...props}/>
113 );
114 let renderedOutput = renderer.getRenderOutput();
115 expect(renderedOutput).toBeTruthy();
116 });
117});