blob: 8b193befa94370c9717212787a50decfb0605bf1 [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';
Yarin Dekel811fb482018-11-04 15:00:34 +020018import { Provider } from 'react-redux';
19import { storeCreator } from 'sdc-app/AppStore.js';
svishnev091edfd2018-03-19 12:15:19 +020020
Einav Weiss Keidard2f57942018-02-14 14:00:07 +020021import TestUtils from 'react-dom/test-utils';
Yarin Dekel811fb482018-11-04 15:00:34 +020022import { defaultStoreFactory } from 'test-utils/factories/onboard/OnboardingCatalogFactories.js';
23import { FinalizedLicenseModelFactory } from 'test-utils/factories/licenseModel/LicenseModelFactories.js';
24import { VSPEditorFactory } from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js';
25import { mapStateToProps } from 'sdc-app/onboarding/onboard/Onboard.js';
26import { catalogItemTypes } from 'sdc-app/onboarding/onboard/onboardingCatalog/OnboardingCatalogConstants.js';
AviZi280f8012017-06-09 02:39:56 +030027import OnboardingCatalogView from 'sdc-app/onboarding/onboard/onboardingCatalog/OnboardingCatalogView.jsx';
28import VendorItem from 'sdc-app/onboarding/onboard/onboardingCatalog/VendorItem.jsx';
29import VSPOverlay from 'sdc-app/onboarding/onboard/onboardingCatalog/VSPOverlay.jsx';
30import CatalogItemDetails from 'sdc-app/onboarding/onboard/CatalogItemDetails.jsx';
31import DetailsCatalogView from 'sdc-app/onboarding/onboard/DetailsCatalogView.jsx';
Yarin Dekel811fb482018-11-04 15:00:34 +020032import {
33 searchValueObj,
34 tabsMapping
35} from 'sdc-app/onboarding/onboard/OnboardConstants';
AviZi280f8012017-06-09 02:39:56 +030036
Yarin Dekel811fb482018-11-04 15:00:34 +020037describe('OnBoarding Catalog test - View: ', function() {
38 it('mapStateToProps mapper exists', () => {
39 expect(mapStateToProps).toBeTruthy();
40 });
AviZi280f8012017-06-09 02:39:56 +030041
Yarin Dekel811fb482018-11-04 15:00:34 +020042 it('mapStateToProps data test', () => {
43 const licenseModelList = FinalizedLicenseModelFactory.buildList(3);
44 const softwareProductList = VSPEditorFactory.buildList(4);
45 const data = defaultStoreFactory.build({
46 licenseModelList,
47 softwareProductList
48 });
AviZi280f8012017-06-09 02:39:56 +030049
Yarin Dekel811fb482018-11-04 15:00:34 +020050 var results = mapStateToProps(data);
51 expect(results.softwareProductList).toBeTruthy();
52 expect(results.licenseModelList).toBeTruthy();
53 expect(results.activeTab).toBeTruthy();
54 expect(results.licenseModelList.length).toEqual(3);
55 });
AviZi280f8012017-06-09 02:39:56 +030056
Yarin Dekel811fb482018-11-04 15:00:34 +020057 it('licenseModelList creating algorithm test', () => {
58 const finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(
59 3
60 );
61 const licenseModelList = FinalizedLicenseModelFactory.buildList(3);
62 const finalizedSoftwareProductList = VSPEditorFactory.buildList(4, {
63 vendorId: finalizedLicenseModelList[0].id
64 });
65 const softwareProductList = VSPEditorFactory.buildList(4, {
66 vendorId: finalizedLicenseModelList[1].id
67 });
68 const data = defaultStoreFactory.build({
69 licenseModelList,
70 finalizedLicenseModelList,
71 softwareProductList,
72 finalizedSoftwareProductList
73 });
AviZi280f8012017-06-09 02:39:56 +030074
Yarin Dekel811fb482018-11-04 15:00:34 +020075 var results = mapStateToProps(data);
76 expect(
77 results.finalizedLicenseModelList[0].softwareProductList.length
78 ).toEqual(finalizedSoftwareProductList.length);
79 });
AviZi280f8012017-06-09 02:39:56 +030080
Yarin Dekel811fb482018-11-04 15:00:34 +020081 it('Catalog view test', () => {
82 const dummyFunc = () => {};
83 const licenseModelList = FinalizedLicenseModelFactory.buildList(3);
84 const softwareProductList = VSPEditorFactory.buildList(4, {
85 vendorId: licenseModelList[0].id
86 });
87 const data = defaultStoreFactory.build({
88 licenseModelList,
89 softwareProductList
90 });
AviZi280f8012017-06-09 02:39:56 +030091
Yarin Dekel811fb482018-11-04 15:00:34 +020092 const func = {
93 onAddLicenseModelClick: dummyFunc,
94 onAddSoftwareProductClick: dummyFunc,
95 closeVspOverlay: dummyFunc,
96 onVspOverlayChange: dummyFunc,
97 onTabClick: dummyFunc,
98 onSearch: dummyFunc,
99 onSelectLicenseModel: dummyFunc,
100 onSelectSoftwareProduct: dummyFunc,
101 resetOnboardingCatalogStore: ''
102 };
AviZi280f8012017-06-09 02:39:56 +0300103
Yarin Dekel811fb482018-11-04 15:00:34 +0200104 let params = { ...func, ...mapStateToProps(data) };
105 const store = storeCreator();
AviZi280f8012017-06-09 02:39:56 +0300106
Yarin Dekel811fb482018-11-04 15:00:34 +0200107 let CatalogView = TestUtils.renderIntoDocument(
108 <Provider store={store}>
109 <OnboardingCatalogView {...params} />
110 </Provider>
111 );
112 expect(CatalogView).toBeTruthy();
113 });
AviZi280f8012017-06-09 02:39:56 +0300114
Yarin Dekel811fb482018-11-04 15:00:34 +0200115 it('VendorItem view test', () => {
116 let vendor = FinalizedLicenseModelFactory.build();
117 const dummyFunc = () => {};
118 let params = {
119 softwareProductList: VSPEditorFactory.buildList(4, {
120 vendorId: vendor.id
121 }),
122 vendor,
123 onSelectVSP: dummyFunc,
124 shouldShowOverlay: false,
125 onVendorSelect: dummyFunc,
126 onAddVSP: dummyFunc,
127 onVSPIconClick: dummyFunc
128 };
AviZi280f8012017-06-09 02:39:56 +0300129
Yarin Dekel811fb482018-11-04 15:00:34 +0200130 let VendorItemView = TestUtils.renderIntoDocument(
131 <VendorItem {...params} />
132 );
133 expect(VendorItemView).toBeTruthy();
134 });
AviZi280f8012017-06-09 02:39:56 +0300135
Yarin Dekel811fb482018-11-04 15:00:34 +0200136 it('VSPOverlay view test', () => {
137 let params = {
138 VSPList: VSPEditorFactory.buildList(10, { vendorId: '1' }),
139 onSelectVSP: () => {}
140 };
AviZi280f8012017-06-09 02:39:56 +0300141
Yarin Dekel811fb482018-11-04 15:00:34 +0200142 let VSPOverlayView = TestUtils.renderIntoDocument(
143 <div>
144 <VSPOverlay {...params} />
145 </div>
146 );
147 expect(VSPOverlayView).toBeTruthy();
148 });
AviZi280f8012017-06-09 02:39:56 +0300149
Yarin Dekel811fb482018-11-04 15:00:34 +0200150 it('CatalogItemDetails view test', () => {
151 let params = {
152 catalogItemData: FinalizedLicenseModelFactory.build(),
153 onSelect: () => {},
154 catalogItemTypeClass: catalogItemTypes.LICENSE_MODEL
155 };
svishnev091edfd2018-03-19 12:15:19 +0200156
Yarin Dekel811fb482018-11-04 15:00:34 +0200157 let CatalogItemDetailsView = TestUtils.renderIntoDocument(
158 <div>
159 <CatalogItemDetails {...params} />
160 </div>
161 );
162 expect(CatalogItemDetailsView).toBeTruthy();
163 });
AviZi280f8012017-06-09 02:39:56 +0300164
Yarin Dekel811fb482018-11-04 15:00:34 +0200165 it('DetailsCatalogView view test when filter obj', () => {
166 let params = {
167 VLMList: FinalizedLicenseModelFactory.buildList(3),
168 VSPList: VSPEditorFactory.buildList(4),
169 onSelectVLM: () => {},
170 onSelectVSP: () => {},
171 onAddVLM: () => {},
172 onAddVSP: () => {},
173 filter: searchValueObj,
174 activeTabName: Object.keys(tabsMapping)[0]
175 };
AviZi280f8012017-06-09 02:39:56 +0300176
Yarin Dekel811fb482018-11-04 15:00:34 +0200177 let AllCatalog = TestUtils.renderIntoDocument(
178 <DetailsCatalogView {...params} />
179 );
180 expect(AllCatalog).toBeTruthy();
181 });
AviZi280f8012017-06-09 02:39:56 +0300182});