blob: 0b46721da01bee2d49697866368037f2dbd1a3aa [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
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
17import React from 'react';
18import TestUtils from 'react-addons-test-utils';
19import {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));
86 var renderer = TestUtils.createRenderer();
87 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));
110 let renderer = TestUtils.createRenderer();
111 renderer.render(
112 <SoftwareProductCreationView {...props}/>
113 );
114 let renderedOutput = renderer.getRenderOutput();
115 expect(renderedOutput).toBeTruthy();
116 });
117});