blob: 20ca17d3d006ef10920c7e5b71fd8fe413fed033 [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: [],
svishnev091edfd2018-03-19 12:15:19 +020034 finalizedSoftwareProductList: [],
35 archivedSoftwareProductList: [],
AviZi280f8012017-06-09 02:39:56 +030036 softwareProduct: {
37 softwareProductCreation: {
38 data: {}
39 }
talig8e9c0652017-12-20 14:30:43 +020040 },
41 users: {
42 usersList: []
AviZi280f8012017-06-09 02:39:56 +030043 }
44 };
45 let props = mapStateToProps(state);
46 expect(props.data).toEqual({});
47 });
48
49 it ('should return vsp names list', () => {
50 let state = {
svishnev091edfd2018-03-19 12:15:19 +020051 finalizedSoftwareProductList: [],
52 archivedSoftwareProductList: [],
AviZi280f8012017-06-09 02:39:56 +030053 softwareProductList: [{
54 name: 'vsp1',
55 id: 'vsp1_id'
56 }, {
57 name: 'vsp2',
58 id: 'vsp2_id'
59 }],
60 softwareProduct: {
61 softwareProductCreation: {
62 data: {}
63 }
talig8e9c0652017-12-20 14:30:43 +020064 },
65 users: {
66 usersList: []
AviZi280f8012017-06-09 02:39:56 +030067 }
68 };
69 let props = mapStateToProps(state);
70 expect(props.data).toEqual({});
71 expect(props.VSPNames).toEqual({vsp1: 'vsp1_id', vsp2: 'vsp2_id'});
72 });
73
74 it('simple jsx test', () => {
75 const store = storeCreator();
76 let dispatch = store.dispatch;
77
78 let state = {
79 softwareProductList: [],
svishnev091edfd2018-03-19 12:15:19 +020080 finalizedSoftwareProductList: [],
81 archivedSoftwareProductList: [],
AviZi280f8012017-06-09 02:39:56 +030082 softwareProduct: {
83 softwareProductCreation: SoftwareProductCreationFactory.build(),
84 softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2})
85 },
talig8e9c0652017-12-20 14:30:43 +020086 finalizedLicenseModelList: FinalizedLicenseModelFactory.buildList(3),
87 users: {
88 usersList: []
89 }
AviZi280f8012017-06-09 02:39:56 +030090 };
91 let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch));
Einav Weiss Keidard2f57942018-02-14 14:00:07 +020092 const renderer = new ShallowRenderer();
AviZi280f8012017-06-09 02:39:56 +030093 renderer.render(
94 <SoftwareProductCreationView {...props}/>
95 );
96 var renderedOutput = renderer.getRenderOutput();
97 expect(renderedOutput).toBeTruthy();
98 });
99
100 it('simple jsx test - with selected vendor', () => {
101 const store = storeCreator();
102 let dispatch = store.dispatch;
103 let finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(3);
104 let state = {
105 softwareProductList: [],
svishnev091edfd2018-03-19 12:15:19 +0200106 finalizedSoftwareProductList: [],
107 archivedSoftwareProductList: [],
AviZi280f8012017-06-09 02:39:56 +0300108 softwareProduct: {
109 softwareProductCreation: SoftwareProductCreationFactoryWithSelectedVendor.build({selectedVendorId: finalizedLicenseModelList[0].id}),
110 softwareProductCategories: CategoryWithSubFactory.buildList({}, {quantity: 2})
111 },
talig8e9c0652017-12-20 14:30:43 +0200112 finalizedLicenseModelList,
113 users: {
114 usersList: []
115 }
AviZi280f8012017-06-09 02:39:56 +0300116 };
117 let props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch));
Einav Weiss Keidard2f57942018-02-14 14:00:07 +0200118 const renderer = new ShallowRenderer();
AviZi280f8012017-06-09 02:39:56 +0300119 renderer.render(
120 <SoftwareProductCreationView {...props}/>
121 );
122 let renderedOutput = renderer.getRenderOutput();
123 expect(renderedOutput).toBeTruthy();
124 });
125});