Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | import React from 'react'; |
| 18 | import { Provider } from 'react-redux'; |
| 19 | import { storeCreator } from 'sdc-app/AppStore.js'; |
| 20 | |
| 21 | import { mapStateToProps } from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidation.js'; |
| 22 | import { mapActionsToProps } from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidation.js'; |
| 23 | import SoftwareProductValidationView from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidationView.jsx'; |
| 24 | import { VSPComplianceCheckedFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js'; |
| 25 | import { VSPCertificationCheckedFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js'; |
| 26 | import { VSPChecksFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js'; |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 27 | import { VSPGeneralInfoFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js'; |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 28 | import { VSPTestsMapFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js'; |
| 29 | import { tabsMapping } from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidationConstants.js'; |
| 30 | import TestUtils from 'react-dom/test-utils'; |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 31 | import { scryRenderedDOMComponentsWithTestId } from 'test-utils/Util.js'; |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 32 | |
| 33 | describe('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(); |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 47 | const generalInfo = VSPGeneralInfoFactory.build(); |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 48 | |
| 49 | var obj = { |
| 50 | softwareProduct: { |
| 51 | softwareProductValidation: { |
| 52 | vspChecks: vspChecksList, |
| 53 | vspTestsMap: vspTestsMap.vspTestsMap, |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 54 | certificationChecked: |
| 55 | certificationChecked.certificationChecked, |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 56 | complianceChecked: complianceChecked.complianceChecked, |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 57 | activeTab: tabsMapping.SETUP, |
| 58 | generalInfo: generalInfo.generalInfo |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 59 | } |
| 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(); |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 72 | expect(results.softwareProductValidation.generalInfo).toBeTruthy(); |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 73 | }); |
| 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(); |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 80 | // let dummyFunc = () => {}; |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 81 | const version = { |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 82 | id: 12345, |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 83 | name: 1 |
| 84 | }; |
| 85 | const softwareProductId = '1234'; |
| 86 | const status = 'draft'; |
| 87 | var obj = { |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 88 | 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 | } |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 100 | } |
| 101 | }; |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 102 | |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 103 | const store = storeCreator(); |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 104 | let dispatch = store.dispatch; |
| 105 | |
| 106 | let props = Object.assign( |
| 107 | {}, |
| 108 | mapStateToProps(obj), |
| 109 | mapActionsToProps(dispatch) |
| 110 | ); |
| 111 | |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 112 | let softwareProductValidationView = TestUtils.renderIntoDocument( |
| 113 | <Provider store={store}> |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 114 | <SoftwareProductValidationView {...props} /> |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 115 | </Provider> |
| 116 | ); |
| 117 | |
| 118 | expect(softwareProductValidationView).toBeTruthy(); |
| 119 | |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 120 | let goToInput = scryRenderedDOMComponentsWithTestId( |
| 121 | softwareProductValidationView, |
| 122 | 'go-to-vsp-validation-inputs' |
| 123 | ); |
| 124 | expect(goToInput).toBeTruthy(); |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 125 | // TestUtils.Simulate.click(goToInput[0]); |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 126 | // expect( |
| 127 | // store.getState().softwareProduct.softwareProductValidation.activeTab |
| 128 | // ).toBe(tabsMapping.INPUTS); |
| 129 | // let goToSetup = scryRenderedDOMComponentsWithTestId( |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 130 | // softwareProductValidationView, |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 131 | // 'go-to-vsp-validation-setup' |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 132 | // ); |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 133 | // expect(goToSetup).toBeTruthy(); |
| 134 | // TestUtils.Simulate.click(goToSetup[0]); |
| 135 | // expect( |
| 136 | // store.getState().softwareProduct.softwareProductValidation.activeTab |
| 137 | // ).toBe(tabsMapping.SETUP); |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 138 | }); |
| 139 | }); |