blob: be84f157b35741219ad4dc11b7f240cdeecb6945 [file] [log] [blame]
Vodafone804ec682019-03-18 15:46:53 +05301/*
2 * Copyright © 2019 Vodafone Group
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 or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import React from 'react';
18import { Provider } from 'react-redux';
19import { storeCreator } from 'sdc-app/AppStore.js';
20
21import { mapStateToProps } from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidation.js';
22import { mapActionsToProps } from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidation.js';
23import SoftwareProductValidationView from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidationView.jsx';
24import { VSPComplianceCheckedFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
25import { VSPCertificationCheckedFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
26import { VSPChecksFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
Vodafone18750932019-04-05 15:49:06 +053027import { VSPGeneralInfoFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
Vodafone804ec682019-03-18 15:46:53 +053028import { VSPTestsMapFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
29import { tabsMapping } from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidationConstants.js';
30import TestUtils from 'react-dom/test-utils';
Vodafone18750932019-04-05 15:49:06 +053031import { scryRenderedDOMComponentsWithTestId } from 'test-utils/Util.js';
Vodafone804ec682019-03-18 15:46:53 +053032
33describe('SoftwareProductValidation Mapper and View Classes', () => {
34 it('mapStateToProps mapper exists', () => {
35 expect(mapStateToProps).toBeTruthy();
36 });
37
38 it('mapActionsToProps mapper exists', () => {
39 expect(mapActionsToProps).toBeTruthy();
40 });
41
42 it('mapStateToProps data test', () => {
43 const vspChecksList = VSPChecksFactory.build();
44 const vspTestsMap = VSPTestsMapFactory.build();
45 const certificationChecked = VSPCertificationCheckedFactory.build();
46 const complianceChecked = VSPComplianceCheckedFactory.build();
Vodafone18750932019-04-05 15:49:06 +053047 const generalInfo = VSPGeneralInfoFactory.build();
Vodafone804ec682019-03-18 15:46:53 +053048
49 var obj = {
50 softwareProduct: {
51 softwareProductValidation: {
52 vspChecks: vspChecksList,
53 vspTestsMap: vspTestsMap.vspTestsMap,
Vodafone18750932019-04-05 15:49:06 +053054 certificationChecked:
55 certificationChecked.certificationChecked,
Vodafone804ec682019-03-18 15:46:53 +053056 complianceChecked: complianceChecked.complianceChecked,
Vodafone18750932019-04-05 15:49:06 +053057 activeTab: tabsMapping.SETUP,
58 generalInfo: generalInfo.generalInfo
Vodafone804ec682019-03-18 15:46:53 +053059 }
60 }
61 };
62 var results = mapStateToProps(obj);
63 expect(results.softwareProductValidation.vspChecks).toBeTruthy();
64 expect(results.softwareProductValidation.vspTestsMap).toBeTruthy();
65 expect(
66 results.softwareProductValidation.certificationChecked
67 ).toBeTruthy();
68 expect(
69 results.softwareProductValidation.complianceChecked
70 ).toBeTruthy();
71 expect(results.softwareProductValidation.activeTab).toBeTruthy();
Vodafone18750932019-04-05 15:49:06 +053072 expect(results.softwareProductValidation.generalInfo).toBeTruthy();
Vodafone804ec682019-03-18 15:46:53 +053073 });
74
75 it('SoftwareProductValidationView render test', () => {
76 const vspChecksList = VSPChecksFactory.build();
77 const vspTestsMap = VSPTestsMapFactory.build();
78 const certificationChecked = VSPCertificationCheckedFactory.build();
79 const complianceChecked = VSPComplianceCheckedFactory.build();
Vodafone18750932019-04-05 15:49:06 +053080 // let dummyFunc = () => {};
Vodafone804ec682019-03-18 15:46:53 +053081 const version = {
Vodafone18750932019-04-05 15:49:06 +053082 id: 12345,
Vodafone804ec682019-03-18 15:46:53 +053083 name: 1
84 };
85 const softwareProductId = '1234';
86 const status = 'draft';
87 var obj = {
Vodafone18750932019-04-05 15:49:06 +053088 softwareProduct: {
89 version: version,
90 softwareProductId: softwareProductId,
91 status: status,
92 softwareProductValidation: {
93 vspChecks: vspChecksList,
94 vspTestsMap: vspTestsMap.vspTestsMap,
95 certificationChecked:
96 certificationChecked.certificationChecked,
97 complianceChecked: complianceChecked.complianceChecked,
98 activeTab: tabsMapping.SETUP
99 }
Vodafone804ec682019-03-18 15:46:53 +0530100 }
101 };
Vodafone18750932019-04-05 15:49:06 +0530102
Vodafone804ec682019-03-18 15:46:53 +0530103 const store = storeCreator();
Vodafone18750932019-04-05 15:49:06 +0530104 let dispatch = store.dispatch;
105
106 let props = Object.assign(
107 {},
108 mapStateToProps(obj),
109 mapActionsToProps(dispatch)
110 );
111
Vodafone804ec682019-03-18 15:46:53 +0530112 let softwareProductValidationView = TestUtils.renderIntoDocument(
113 <Provider store={store}>
Vodafone18750932019-04-05 15:49:06 +0530114 <SoftwareProductValidationView {...props} />
Vodafone804ec682019-03-18 15:46:53 +0530115 </Provider>
116 );
117
118 expect(softwareProductValidationView).toBeTruthy();
119
Vodafone18750932019-04-05 15:49:06 +0530120 let goToInput = scryRenderedDOMComponentsWithTestId(
121 softwareProductValidationView,
122 'go-to-vsp-validation-inputs'
123 );
124 expect(goToInput).toBeTruthy();
Vodafone804ec682019-03-18 15:46:53 +0530125 // TestUtils.Simulate.click(goToInput[0]);
Vodafone18750932019-04-05 15:49:06 +0530126 // expect(
127 // store.getState().softwareProduct.softwareProductValidation.activeTab
128 // ).toBe(tabsMapping.INPUTS);
129 // let goToSetup = scryRenderedDOMComponentsWithTestId(
Vodafone804ec682019-03-18 15:46:53 +0530130 // softwareProductValidationView,
Vodafone18750932019-04-05 15:49:06 +0530131 // 'go-to-vsp-validation-setup'
Vodafone804ec682019-03-18 15:46:53 +0530132 // );
Vodafone18750932019-04-05 15:49:06 +0530133 // expect(goToSetup).toBeTruthy();
134 // TestUtils.Simulate.click(goToSetup[0]);
135 // expect(
136 // store.getState().softwareProduct.softwareProductValidation.activeTab
137 // ).toBe(tabsMapping.SETUP);
Vodafone804ec682019-03-18 15:46:53 +0530138 });
139});