2 * Copyright © 2019 Vodafone Group
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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';
23 import Configuration from 'sdc-app/config/Configuration.js';
25 import { VSPComplianceCheckedFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
26 import { VSPCertificationCheckedFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
27 import { VSPTestResultKeysFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationResultsFactory.js';
28 import { VSPChecksFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
29 import { VSPTestsMapFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
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';
34 import { VSPTestRequestFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
36 describe('Software Product Validation Action Helper Tests', function() {
37 const store = storeCreator();
38 deepFreeze(store.getState());
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();
50 const testResultKeys = VSPTestResultKeysFactory.build();
51 let restPrefix = Configuration.get('restPrefix');
52 let onClose = () => {};
53 const vspTestRequest = VSPTestRequestFactory.build();
58 modalComponentName: 'Error',
59 modalComponentProps: {
63 msg: 'Test Error Message'
65 cancelButtonText: 'OK'
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);
75 it('Software Products Validation Action Helper : fetch vsp', () => {
76 let expectedStore = cloneAndSet(
78 'softwareProduct.softwareProductValidation.vspChecks',
81 mockRest.addHandler('fetch', ({ baseUrl }) => {
82 expect(baseUrl).toEqual(
83 `${restPrefix}/v1.0/externaltesting/testcasetree`
87 return SoftwareProductValidationActionHelper.fetchVspChecks(
91 expect(store.getState()).toEqual(expectedStore);
94 console.log('Fetch VSP returned Error');
98 it('Software Products Validation Action Helper : post test', () => {
100 const str = storeCreator({
102 softwareProductValidation: {
103 testResultKeys: testResultKeys.testResultKeys
107 deepFreeze(str.getState());
108 let expectedStore = cloneAndSet(
110 'softwareProduct.softwareProductValidation.vspTestResults',
111 vspTestResults.vspTestResults
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}`
124 return vspTestResults.vspTestResults ;
126 SoftwareProductValidationActionHelper.navigateToSoftwareProductValidationResults(
128 softwareProductId: softwareProductId,
131 tests :vspTestRequest.vspTestRequest,
135 expect(str.getState()).toEqual(expectedStore);
138 console.log('Executions test returned Error');
143 it('Software Products Validation Action Helper : setCertificationChecked', () => {
144 let expectedStore = cloneAndSet(
146 'softwareProduct.softwareProductValidation.certificationChecked',
147 certificationChecked.certificationChecked
149 mapActionsToProps(store.dispatch).setCertificationChecked({
150 checked: certificationChecked.certificationChecked
152 expect(store.getState()).toEqual(expectedStore);
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)
163 it('Software Products Validation Action Helper : setComplianceChecked', () => {
164 let expectedStore = cloneAndSet(
166 'softwareProduct.softwareProductValidation.complianceChecked',
167 complianceChecked.complianceChecked
169 mapActionsToProps(store.dispatch).setComplianceChecked({
170 checked: complianceChecked.complianceChecked
172 expect(store.getState()).toEqual(expectedStore);
175 it('Software Products Validation Action Helper : setActiveTab', () => {
176 let expectedStore = cloneAndSet(
178 'softwareProduct.softwareProductValidation.activeTab',
181 mapActionsToProps(store.dispatch).setActiveTab(activeTab);
182 expect(store.getState()).toEqual(expectedStore);
185 it('Software Products Validation Action Helper : setGeneralInfo', () => {
186 let expectedStore = cloneAndSet(
188 'softwareProduct.softwareProductValidation.generalInfo',
189 generalInfo.generalInfo
191 mapActionsToProps(store.dispatch).setGeneralInfo(
192 generalInfo.generalInfo
194 expect(store.getState()).toEqual(expectedStore);
197 it('Software Products Validation Action Helper : setIsVspValidationDisabled', () => {
198 let expectedStore = cloneAndSet(
200 'softwareProduct.softwareProductValidation.isValidationDisabled',
203 SoftwareProductValidationActionHelper.setIsVspValidationDisabled(
209 expect(store.getState()).toEqual(expectedStore);
212 it('Software Products Validation Action Helper : setTestsRequest', () => {
213 let expectedStore = cloneAndSet(
215 'softwareProduct.softwareProductValidation.testsRequest',
216 testsRequest.testsRequest
218 expectedStore = cloneAndSet(
220 'softwareProduct.softwareProductValidation.generalInfo',
221 generalInfo.generalInfo
224 mapActionsToProps(store.dispatch).setTestsRequest(
225 testsRequest.testsRequest,
226 generalInfo.generalInfo
228 expect(store.getState()).toEqual(expectedStore);
231 it('Software Products Validation Action Helper : setVspTestsMap', () => {
232 let expectedStore = cloneAndSet(
234 'softwareProduct.softwareProductValidation.vspTestsMap',
235 vspTestsMap.vspTestsMap
237 SoftwareProductValidationActionHelper.setVspTestsMap(
239 vspTestsMap.vspTestsMap
242 expect(store.getState()).toEqual(expectedStore);