[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / test / softwareProduct / attachments / validation / HeatValidationActionHelper.test.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16
17 import HeatValidationActionHelper from 'sdc-app/onboarding/softwareProduct/attachments/validation/HeatValidationActionHelper.js';
18 import {storeCreator} from 'sdc-app/AppStore.js';
19 import deepFreeze from 'deep-freeze';
20 import {actionTypes} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js';
21 import {nodeFilters} from 'sdc-app/onboarding/softwareProduct/attachments/validation/HeatValidationConstants.js';
22
23 describe('HeatValidationActionHelper ActionHelper', () => {
24
25         it('function does exist', () => {
26                 expect(HeatValidationActionHelper).toBeTruthy();
27         });
28
29         it('toggleExpanded function check', () => {
30
31
32                 const validationData = {
33                         importStructure: {
34                                 HEAT: [
35                                         {
36                                                 fileName: 'hot-mog-0108-bs1271.yml',
37                                                 env: {
38                                                         fileName: 'hot-mog-0108-bs1271.env'
39                                                 },
40                                                 errors: [
41                                                         {
42                                                                 'level': 'WARNING',
43                                                                 'message': 'Port not bind to any NOVA Server, Resource Id [sm02_port_2]'
44                                                         },
45                                                         {
46                                                                 'level': 'WARNING',
47                                                                 'message': 'Port not bind to any NOVA Server, Resource Id [sm01_port_2]'
48                                                         }
49                                                 ]
50                                         }
51                                 ]
52                         }
53                 };
54
55                 const currentSoftwareProduct = {
56                         name: 'VSp',
57                         description: 'dfdf',
58                         vendorName: 'V1',
59                         vendorId: '97B3E2525E0640ACACF87CE6B3753E80',
60                         category: 'resourceNewCategory.application l4+',
61                         subCategory: 'resourceNewCategory.application l4+.database',
62                         id: 'D4774719D085414E9D5642D1ACD59D20',
63                         version: '0.10',
64                         viewableVersions: ['0.1', '0.2'],
65                         status: 'Locked',
66                         lockingUser: 'cs0008',
67                         validationData
68                 };
69
70
71                 const store = storeCreator();
72                 deepFreeze(store.getState());
73                 deepFreeze(currentSoftwareProduct);
74
75                 store.dispatch({
76                         type:actionTypes.SOFTWARE_PRODUCT_LOADED,
77                         response: currentSoftwareProduct
78                 });
79
80                 expect(store.getState().softwareProduct.softwareProductAttachments.heatValidation.attachmentsTree.children[0].expanded).toBe(true);
81                 HeatValidationActionHelper.toggleExpanded(store.dispatch, {path:[0]});
82                 expect(store.getState().softwareProduct.softwareProductAttachments.heatValidation.attachmentsTree.children[0].expanded).toBe(false);
83         });
84
85         it('onSelectNode & onUnselectNode function check', () => {
86
87
88                 const validationData = {
89                         importStructure: {
90                                 heat: [
91                                         {
92                                                 fileName: 'hot-mog-0108-bs1271.yml',
93                                                 env: {
94                                                         fileName: 'hot-mog-0108-bs1271.env'
95                                                 },
96                                                 errors: [
97                                                         {
98                                                                 'level': 'WARNING',
99                                                                 'message': 'Port not bind to any NOVA Server, Resource Id [sm02_port_2]'
100                                                         },
101                                                         {
102                                                                 'level': 'WARNING',
103                                                                 'message': 'Port not bind to any NOVA Server, Resource Id [sm01_port_2]'
104                                                         }
105                                                 ]
106                                         }
107                                 ]
108                         }
109                 };
110
111                 const currentSoftwareProduct = {
112                         name: 'VSp',
113                         description: 'dfdf',
114                         vendorName: 'V1',
115                         vendorId: '97B3E2525E0640ACACF87CE6B3753E80',
116                         category: 'resourceNewCategory.application l4+',
117                         subCategory: 'resourceNewCategory.application l4+.database',
118                         id: 'D4774719D085414E9D5642D1ACD59D20',
119                         version: '0.10',
120                         viewableVersions: ['0.1', '0.2'],
121                         status: 'Locked',
122                         lockingUser: 'cs0008',
123                         validationData
124                 };
125
126                 deepFreeze(currentSoftwareProduct);
127
128                 const store = storeCreator();
129                 deepFreeze(store.getState());
130
131                 store.dispatch({
132                         type:actionTypes.SOFTWARE_PRODUCT_LOADED,
133                         response: currentSoftwareProduct
134                 });
135                 let expectedNodeName = 'name';
136                 expect(store.getState().softwareProduct.softwareProductAttachments.heatValidation.selectedNode).toBe(nodeFilters.ALL);
137                 HeatValidationActionHelper.onSelectNode(store.dispatch, {nodeName:expectedNodeName});
138                 expect(store.getState().softwareProduct.softwareProductAttachments.heatValidation.selectedNode).toBe(expectedNodeName);
139                 HeatValidationActionHelper.onDeselectNode(store.dispatch);
140                 expect(store.getState().softwareProduct.softwareProductAttachments.heatValidation.selectedNode).toBe(nodeFilters.ALL);
141         });
142
143
144 });