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