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 { VSPChecksFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
28 import { VSPTestsMapFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
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';
34 describe('Software Product Validation Action Helper Tests', function() {
35 const store = storeCreator();
36 deepFreeze(store.getState());
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 = () => {};
54 modalComponentName: 'Error',
55 modalComponentProps: {
59 msg: 'Test Error Message'
61 cancelButtonText: 'OK'
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);
71 it('Software Products Validation Action Helper : fetch vsp', () => {
72 let expectedStore = cloneAndSet(
74 'softwareProduct.softwareProductValidation.vspChecks',
77 mockRest.addHandler('fetch', ({ baseUrl }) => {
78 expect(baseUrl).toEqual(
79 `${restPrefix}/v1.0/externaltesting/testcasetree`
83 return SoftwareProductValidationActionHelper.fetchVspChecks(
87 expect(store.getState()).toEqual(expectedStore);
90 console.log('Fetch VSP returned Error');
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`
99 // //expect(data).toEqual(testsRequest);
100 // expect(options).toEqual(undefined);
101 // return { vspTestResults: vspTestResults };
107 // const softwareProductId = '1234';
108 // const status = 'draft';
109 // mapActionsToProps(store.dispatch).onTestSubmit(
110 // softwareProductId,
117 it('Software Products Validation Action Helper : setCertificationChecked', () => {
118 let expectedStore = cloneAndSet(
120 'softwareProduct.softwareProductValidation.certificationChecked',
121 certificationChecked.certificationChecked
123 mapActionsToProps(store.dispatch).setCertificationChecked({
124 checked: certificationChecked.certificationChecked
126 expect(store.getState()).toEqual(expectedStore);
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)
137 it('Software Products Validation Action Helper : setComplianceChecked', () => {
138 let expectedStore = cloneAndSet(
140 'softwareProduct.softwareProductValidation.complianceChecked',
141 complianceChecked.complianceChecked
143 mapActionsToProps(store.dispatch).setComplianceChecked({
144 checked: complianceChecked.complianceChecked
146 expect(store.getState()).toEqual(expectedStore);
149 it('Software Products Validation Action Helper : setActiveTab', () => {
150 let expectedStore = cloneAndSet(
152 'softwareProduct.softwareProductValidation.activeTab',
155 mapActionsToProps(store.dispatch).setActiveTab(activeTab);
156 expect(store.getState()).toEqual(expectedStore);
159 it('Software Products Validation Action Helper : setGeneralInfo', () => {
160 let expectedStore = cloneAndSet(
162 'softwareProduct.softwareProductValidation.generalInfo',
163 generalInfo.generalInfo
165 mapActionsToProps(store.dispatch).setGeneralInfo(
166 generalInfo.generalInfo
168 expect(store.getState()).toEqual(expectedStore);
171 it('Software Products Validation Action Helper : setIsVspValidationDisabled', () => {
172 let expectedStore = cloneAndSet(
174 'softwareProduct.softwareProductValidation.isValidationDisabled',
177 SoftwareProductValidationActionHelper.setIsVspValidationDisabled(
183 expect(store.getState()).toEqual(expectedStore);
186 it('Software Products Validation Action Helper : setTestsRequest', () => {
187 let expectedStore = cloneAndSet(
189 'softwareProduct.softwareProductValidation.testsRequest',
190 testsRequest.testsRequest
192 expectedStore = cloneAndSet(
194 'softwareProduct.softwareProductValidation.generalInfo',
195 generalInfo.generalInfo
198 mapActionsToProps(store.dispatch).setTestsRequest(
199 testsRequest.testsRequest,
200 generalInfo.generalInfo
202 expect(store.getState()).toEqual(expectedStore);
205 it('Software Products Validation Action Helper : setVspTestsMap', () => {
206 let expectedStore = cloneAndSet(
208 'softwareProduct.softwareProductValidation.vspTestsMap',
209 vspTestsMap.vspTestsMap
211 SoftwareProductValidationActionHelper.setVspTestsMap(
213 vspTestsMap.vspTestsMap
216 expect(store.getState()).toEqual(expectedStore);