blob: 4da0ec98d47f74d2285069f471df85246ffd55d6 [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
17
18
19import React from 'react';
20import TestUtils from 'react-addons-test-utils';
21
22import {VSPEditorFactory} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js';
23import {CategoryWithSubFactory} from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js';
24import {LicenseAgreementStoreFactory} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js';
25import {FeatureGroupStoreFactory} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
26import {default as SoftwareProductQSchemaFactory} from 'test-utils/factories/softwareProduct/SoftwareProductQSchemaFactory.js';
27import {default as VspQdataFactory} from 'test-utils/factories/softwareProduct/VspQdataFactory.js';
28import {VSPComponentsFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsFactories.js';
29import {FinalizedLicenseModelFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js';
30
Avi Zivb8e2faf2017-07-18 19:45:38 +030031import { Provider } from 'react-redux';
32import {storeCreator} from 'sdc-app/AppStore.js';
AviZi280f8012017-06-09 02:39:56 +030033
34import {mapStateToProps} from 'sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js';
35import SoftwareProductLandingPageView from 'sdc-app/onboarding/softwareProduct/landingPage/SoftwareProductLandingPageView.jsx';
36
37
38describe('Software Product Landing Page: ', function () {
39
40 let currentSoftwareProduct = {}, softwareProductCategories = [],
41 finalizedLicenseModelList, licenseAgreementList, featureGroupsList, qschema, qdata = {};
42 const dummyFunc = () => {};
43 beforeAll(function() {
44 finalizedLicenseModelList = FinalizedLicenseModelFactory.buildList(2);
45 currentSoftwareProduct = VSPEditorFactory.build({id:'RTRTG454545', vendorId: finalizedLicenseModelList[0].id, vendorName: finalizedLicenseModelList[0].name});
46 softwareProductCategories = CategoryWithSubFactory.buildList(2,{},{quantity: 1});
47 licenseAgreementList = LicenseAgreementStoreFactory.buildList(2);
48 featureGroupsList = FeatureGroupStoreFactory.buildList(2,{referencingLicenseAgreements:[licenseAgreementList[0].id]});
49 qdata = VspQdataFactory.build();
50 qschema = SoftwareProductQSchemaFactory.build(qdata);
51
52 });
53
54
55
56 it('should mapper exist', () => {
57 expect(mapStateToProps).toBeTruthy();
58 });
59
60 it('should mapper return vsp basic data', () => {
61 const obj = {
62 softwareProduct: {
63 softwareProductEditor: {
64 data: currentSoftwareProduct
65 },
66 softwareProductCategories,
67 softwareProductQuestionnaire: {
68 qdata,
69 qschema
70 },
71 softwareProductComponents: {
72 componentsList:[]
73 }
74 },
75 finalizedLicenseModelList,
76 licenseModel: {
77 licenseAgreement: {
78 licenseAgreementList
79 },
80 featureGroup: {
81 featureGroupsList
82 }
83 }
84 };
85
86 const result = mapStateToProps(obj);
87 expect(result.currentSoftwareProduct).toBeTruthy();
88 expect(result.isReadOnlyMode).toEqual(true);
89
90 });
91
92 it('vsp landing basic view', () => {
93
94 const params = {
95 currentSoftwareProduct,
96 isReadOnlyMode: false,
97 componentsList: VSPComponentsFactory.buildList(2)
98 };
99
Avi Zivb8e2faf2017-07-18 19:45:38 +0300100 const store = storeCreator();
101 let vspLandingView = TestUtils.renderIntoDocument(<Provider store={store}><SoftwareProductLandingPageView
102 {...params}/></Provider>);
AviZi280f8012017-06-09 02:39:56 +0300103 expect(vspLandingView).toBeTruthy();
104 });
105
106 it('vsp landing handleOnDragEnter test ', () => {
107
108 const params = {
109 currentSoftwareProduct,
110 isReadOnlyMode: false,
111 componentsList: VSPComponentsFactory.buildList(2)
112 };
113
Avi Zivb8e2faf2017-07-18 19:45:38 +0300114 const store = storeCreator();
115 let vspLandingView = TestUtils.renderIntoDocument(<Provider store={store}><SoftwareProductLandingPageView
116 {...params}/></Provider>);
117 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
118 vspLandingView,
119 SoftwareProductLandingPageView
120 );
AviZi280f8012017-06-09 02:39:56 +0300121 expect(vspLandingView).toBeTruthy();
Avi Zivb8e2faf2017-07-18 19:45:38 +0300122 vspLandingViewWrapper.handleOnDragEnter(false);
123 expect(vspLandingViewWrapper.state.dragging).toEqual(true);
AviZi280f8012017-06-09 02:39:56 +0300124 });
125
126
127 it('vsp landing handleImportSubmit test ', () => {
128
129 const params = {
130 currentSoftwareProduct,
131 isReadOnlyMode: false,
132 componentsList: VSPComponentsFactory.buildList(2),
133 onUploadConfirmation: dummyFunc,
134 onUpload: dummyFunc,
135 onInvalidFileSizeUpload: dummyFunc
136 };
Avi Zivb8e2faf2017-07-18 19:45:38 +0300137
AviZi280f8012017-06-09 02:39:56 +0300138 const files = [
139 {
140 name: 'aaa',
141 size: 123
142 }
143 ];
144
Avi Zivb8e2faf2017-07-18 19:45:38 +0300145 const store = storeCreator();
146
147 let vspLandingView = TestUtils.renderIntoDocument(<Provider store={store}><SoftwareProductLandingPageView {...params}/></Provider>);
148 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
149 vspLandingView,
150 SoftwareProductLandingPageView
151 );
152 expect(vspLandingView).toBeTruthy();
153 vspLandingViewWrapper.handleImportSubmit(files, false);
154 expect(vspLandingViewWrapper.state.dragging).toEqual(false);
155 expect(vspLandingViewWrapper.state.fileName).toEqual(files[0].name);
AviZi280f8012017-06-09 02:39:56 +0300156 const files1 = [
157 {
158 name: 'bbb',
159 size: 0
160 }
161 ];
Avi Zivb8e2faf2017-07-18 19:45:38 +0300162 vspLandingViewWrapper.handleImportSubmit(files1, false);
AviZi280f8012017-06-09 02:39:56 +0300163 });
164
165 it('vsp landing handleImportSubmit with damaged file test ', () => {
166
167 const params = {
168 currentSoftwareProduct,
169 isReadOnlyMode: false,
170 componentsList: VSPComponentsFactory.buildList(2),
171 onUploadConfirmation: dummyFunc,
172 onUpload: dummyFunc,
173 onInvalidFileSizeUpload: dummyFunc
174 };
175
Avi Zivb8e2faf2017-07-18 19:45:38 +0300176 const store = storeCreator();
177
178 let vspLandingView = TestUtils.renderIntoDocument(<Provider store={store}><SoftwareProductLandingPageView
179 {...params}/></Provider>);
180
181 let vspLandingViewWrapper = TestUtils.findRenderedComponentWithType(
182 vspLandingView,
183 SoftwareProductLandingPageView
184 );
AviZi280f8012017-06-09 02:39:56 +0300185 expect(vspLandingView).toBeTruthy();
186 const files = [
187 {
188 name: 'aaa',
189 size: 0
190 }
191 ];
192
Avi Zivb8e2faf2017-07-18 19:45:38 +0300193 vspLandingViewWrapper.handleImportSubmit(files, false);
194 expect(vspLandingViewWrapper.state.dragging).toEqual(false);
195 expect(vspLandingViewWrapper.state.fileName).toEqual('');
AviZi280f8012017-06-09 02:39:56 +0300196 });
197});