List of Input Parameters for VSP: FE
[sdc.git] / openecomp-ui / test / softwareProduct / validation / SoftwareProductValidationActionHelper.test.js
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';
29
30 describe('Software Product Validation Action Helper Tests', function() {
31     it('Software Products Validation Action Helper : Dsspatch', () => {
32         const store = storeCreator();
33         deepFreeze(store.getState());
34
35         const vspChecksList = VSPChecksFactory.build();
36         const vspTestsMap = VSPTestsMapFactory.build();
37         const certificationChecked = VSPCertificationCheckedFactory.build();
38         const complianceChecked = VSPComplianceCheckedFactory.build();
39         const activeTab = { activeTab: tabsMapping.INPUTS };
40         const errorMessage = { msg: 'Test Error Message' };
41
42         deepFreeze(vspChecksList);
43         deepFreeze(vspTestsMap);
44         deepFreeze(certificationChecked);
45         deepFreeze(complianceChecked);
46         deepFreeze(activeTab);
47
48         let expectedStore = cloneAndSet(
49             store.getState(),
50             'softwareProduct.softwareProductValidation.vspChecks',
51             vspChecksList
52         );
53         expectedStore = cloneAndSet(
54             store.getState(),
55             'softwareProduct.softwareProductValidation.vspTestsMap',
56             vspTestsMap
57         );
58         expectedStore = cloneAndSet(
59             store.getState(),
60             'softwareProduct.softwareProductValidation.certificationChecked',
61             certificationChecked
62         );
63         expectedStore = cloneAndSet(
64             store.getState(),
65             'softwareProduct.softwareProductValidation.complianceChecked',
66             complianceChecked
67         );
68         expectedStore = cloneAndSet(
69             store.getState(),
70             'softwareProduct.softwareProductValidation.activeTab',
71             activeTab
72         );
73         let restPrefix = Configuration.get('restPrefix');
74
75         mockRest.addHandler('fetch', ({ options, data, baseUrl }) => {
76             expect(baseUrl).toEqual(`${restPrefix}/v1.0/externaltesting`);
77             expect(data).toEqual(undefined);
78             expect(options).toEqual(undefined);
79             return { vspChecks: vspChecksList };
80         });
81
82         SoftwareProductValidationActionHelper.setVspTestsMap(store.dispatch, {
83             vspTestsMap
84         });
85         SoftwareProductValidationActionHelper.setComplianceChecked(
86             store.dispatch,
87             { complianceChecked }
88         );
89         SoftwareProductValidationActionHelper.setCertificationChecked(
90             store.dispatch,
91             { certificationChecked }
92         );
93
94         SoftwareProductValidationActionHelper.setActiveTab(store.dispatch, {
95             activeTab
96         });
97
98         SoftwareProductValidationActionHelper.onErrorThrown(store.dispatch, {
99             errorMessage
100         });
101
102         SoftwareProductValidationActionHelper.fetchVspChecks(store.dispatch)
103             .then(() => {
104                 expect(store.getState()).toEqual(expectedStore);
105             })
106             .catch(() => {});
107     });
108 });