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 | import deepFreeze from 'deep-freeze'; |
| 17 | import mockRest from 'test-utils/MockRest.js'; |
| 18 | import { cloneAndSet } from 'test-utils/Util.js'; |
| 19 | import { storeCreator } from 'sdc-app/AppStore.js'; |
| 20 | import SoftwareProductValidationActionHelper from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidationActionHelper.js'; |
| 21 | import { tabsMapping } from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidationConstants.js'; |
| 22 | |
| 23 | import Configuration from 'sdc-app/config/Configuration.js'; |
| 24 | |
| 25 | import { VSPComplianceCheckedFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js'; |
| 26 | import { VSPCertificationCheckedFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js'; |
| 27 | import { VSPChecksFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js'; |
| 28 | import { VSPTestsMapFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js'; |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 29 | import { VSPTestsRequestFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js'; |
| 30 | import { VSPGeneralInfoFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js'; |
| 31 | import { VSPTestResultsSuccessFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationResultsFactory.js'; |
| 32 | import { mapActionsToProps } from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidation.js'; |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 33 | |
| 34 | describe('Software Product Validation Action Helper Tests', function() { |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 35 | const store = storeCreator(); |
| 36 | deepFreeze(store.getState()); |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 37 | |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 38 | const vspChecksList = VSPChecksFactory.build(); |
| 39 | const vspTestsMap = VSPTestsMapFactory.build(); |
| 40 | const certificationChecked = VSPCertificationCheckedFactory.build(); |
| 41 | const complianceChecked = VSPComplianceCheckedFactory.build(); |
| 42 | const activeTab = { activeTab: tabsMapping.INPUTS }; |
| 43 | const errorMessage = { msg: 'Test Error Message' }; |
| 44 | const testsRequest = VSPTestsRequestFactory.build(); |
| 45 | const generalInfo = VSPGeneralInfoFactory.build(); |
| 46 | const isValidationDisabled = false; |
| 47 | const vspTestResults = VSPTestResultsSuccessFactory.build(); |
| 48 | let restPrefix = Configuration.get('restPrefix'); |
| 49 | let onClose = () => {}; |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 50 | |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 51 | const modal = { |
| 52 | type: 'error', |
| 53 | title: 'Error', |
| 54 | modalComponentName: 'Error', |
| 55 | modalComponentProps: { |
| 56 | onClose: onClose |
| 57 | }, |
| 58 | msg: { |
| 59 | msg: 'Test Error Message' |
| 60 | }, |
| 61 | cancelButtonText: 'OK' |
| 62 | }; |
| 63 | // deepFreeze(vspTestsMap.vspTestsMap); |
| 64 | // deepFreeze(certificationChecked.certificationChecked); |
| 65 | // deepFreeze(complianceChecked.complianceChecked); |
| 66 | // deepFreeze(activeTab); |
| 67 | // deepFreeze(testsRequest); |
| 68 | // deepFreeze(generalInfo.generalInfo); |
| 69 | // deepFreeze(isVspValidationDisabled); |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 70 | |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 71 | it('Software Products Validation Action Helper : fetch vsp', () => { |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 72 | let expectedStore = cloneAndSet( |
| 73 | store.getState(), |
| 74 | 'softwareProduct.softwareProductValidation.vspChecks', |
| 75 | vspChecksList |
| 76 | ); |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 77 | mockRest.addHandler('fetch', ({ baseUrl }) => { |
| 78 | expect(baseUrl).toEqual( |
| 79 | `${restPrefix}/v1.0/externaltesting/testcasetree` |
| 80 | ); |
| 81 | return vspChecksList; |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 82 | }); |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 83 | return SoftwareProductValidationActionHelper.fetchVspChecks( |
| 84 | store.dispatch |
| 85 | ) |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 86 | .then(() => { |
| 87 | expect(store.getState()).toEqual(expectedStore); |
| 88 | }) |
Vodafone | 1875093 | 2019-04-05 15:49:06 +0530 | [diff] [blame] | 89 | .catch(() => { |
| 90 | console.log('Fetch VSP returned Error'); |
| 91 | }); |
| 92 | }); |
| 93 | |
| 94 | // it('Software Products Validation Action Helper : post test', () => { |
| 95 | // mockRest.addHandler('post', ({ options, data, baseUrl }) => { |
| 96 | // expect(baseUrl).toEqual( |
| 97 | // `${restPrefix}/v1.0/externaltesting/executions` |
| 98 | // ); |
| 99 | // //expect(data).toEqual(testsRequest); |
| 100 | // expect(options).toEqual(undefined); |
| 101 | // return { vspTestResults: vspTestResults }; |
| 102 | // }); |
| 103 | // const version = { |
| 104 | // id: 12345, |
| 105 | // name: 1 |
| 106 | // }; |
| 107 | // const softwareProductId = '1234'; |
| 108 | // const status = 'draft'; |
| 109 | // mapActionsToProps(store.dispatch).onTestSubmit( |
| 110 | // softwareProductId, |
| 111 | // version, |
| 112 | // status, |
| 113 | // testsRequest |
| 114 | // ); |
| 115 | // }); |
| 116 | |
| 117 | it('Software Products Validation Action Helper : setCertificationChecked', () => { |
| 118 | let expectedStore = cloneAndSet( |
| 119 | store.getState(), |
| 120 | 'softwareProduct.softwareProductValidation.certificationChecked', |
| 121 | certificationChecked.certificationChecked |
| 122 | ); |
| 123 | mapActionsToProps(store.dispatch).setCertificationChecked({ |
| 124 | checked: certificationChecked.certificationChecked |
| 125 | }); |
| 126 | expect(store.getState()).toEqual(expectedStore); |
| 127 | }); |
| 128 | |
| 129 | it('Software Products Validation Action Helper : onErrorThrown', () => { |
| 130 | let expectedStore = cloneAndSet(store.getState(), 'modal', modal); |
| 131 | mapActionsToProps(store.dispatch).onErrorThrown(errorMessage); |
| 132 | expect(JSON.stringify(store.getState())).toEqual( |
| 133 | JSON.stringify(expectedStore) |
| 134 | ); |
| 135 | }); |
| 136 | |
| 137 | it('Software Products Validation Action Helper : setComplianceChecked', () => { |
| 138 | let expectedStore = cloneAndSet( |
| 139 | store.getState(), |
| 140 | 'softwareProduct.softwareProductValidation.complianceChecked', |
| 141 | complianceChecked.complianceChecked |
| 142 | ); |
| 143 | mapActionsToProps(store.dispatch).setComplianceChecked({ |
| 144 | checked: complianceChecked.complianceChecked |
| 145 | }); |
| 146 | expect(store.getState()).toEqual(expectedStore); |
| 147 | }); |
| 148 | |
| 149 | it('Software Products Validation Action Helper : setActiveTab', () => { |
| 150 | let expectedStore = cloneAndSet( |
| 151 | store.getState(), |
| 152 | 'softwareProduct.softwareProductValidation.activeTab', |
| 153 | activeTab.activeTab |
| 154 | ); |
| 155 | mapActionsToProps(store.dispatch).setActiveTab(activeTab); |
| 156 | expect(store.getState()).toEqual(expectedStore); |
| 157 | }); |
| 158 | |
| 159 | it('Software Products Validation Action Helper : setGeneralInfo', () => { |
| 160 | let expectedStore = cloneAndSet( |
| 161 | store.getState(), |
| 162 | 'softwareProduct.softwareProductValidation.generalInfo', |
| 163 | generalInfo.generalInfo |
| 164 | ); |
| 165 | mapActionsToProps(store.dispatch).setGeneralInfo( |
| 166 | generalInfo.generalInfo |
| 167 | ); |
| 168 | expect(store.getState()).toEqual(expectedStore); |
| 169 | }); |
| 170 | |
| 171 | it('Software Products Validation Action Helper : setIsVspValidationDisabled', () => { |
| 172 | let expectedStore = cloneAndSet( |
| 173 | store.getState(), |
| 174 | 'softwareProduct.softwareProductValidation.isValidationDisabled', |
| 175 | isValidationDisabled |
| 176 | ); |
| 177 | SoftwareProductValidationActionHelper.setIsVspValidationDisabled( |
| 178 | store.dispatch, |
| 179 | { |
| 180 | isValidationDisabled |
| 181 | } |
| 182 | ); |
| 183 | expect(store.getState()).toEqual(expectedStore); |
| 184 | }); |
| 185 | |
| 186 | it('Software Products Validation Action Helper : setTestsRequest', () => { |
| 187 | let expectedStore = cloneAndSet( |
| 188 | store.getState(), |
| 189 | 'softwareProduct.softwareProductValidation.testsRequest', |
| 190 | testsRequest.testsRequest |
| 191 | ); |
| 192 | expectedStore = cloneAndSet( |
| 193 | expectedStore, |
| 194 | 'softwareProduct.softwareProductValidation.generalInfo', |
| 195 | generalInfo.generalInfo |
| 196 | ); |
| 197 | |
| 198 | mapActionsToProps(store.dispatch).setTestsRequest( |
| 199 | testsRequest.testsRequest, |
| 200 | generalInfo.generalInfo |
| 201 | ); |
| 202 | expect(store.getState()).toEqual(expectedStore); |
| 203 | }); |
| 204 | |
| 205 | it('Software Products Validation Action Helper : setVspTestsMap', () => { |
| 206 | let expectedStore = cloneAndSet( |
| 207 | store.getState(), |
| 208 | 'softwareProduct.softwareProductValidation.vspTestsMap', |
| 209 | vspTestsMap.vspTestsMap |
| 210 | ); |
| 211 | SoftwareProductValidationActionHelper.setVspTestsMap( |
| 212 | store.dispatch, |
| 213 | vspTestsMap.vspTestsMap |
| 214 | ); |
| 215 | |
| 216 | expect(store.getState()).toEqual(expectedStore); |
Vodafone | 804ec68 | 2019-03-18 15:46:53 +0530 | [diff] [blame] | 217 | }); |
| 218 | }); |