[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / test / softwareProduct / attachments / setup / heatSetupActionHelper.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 HeatSetupActionHelper from 'sdc-app/onboarding/softwareProduct/attachments/setup/HeatSetupActionHelper.js';
18 import {storeCreator} from 'sdc-app/AppStore.js';
19 import deepFreeze from 'deep-freeze';
20 import {heatSetupManifest} from 'test-utils/factories/softwareProduct/SoftwareProductAttachmentsFactories.js';
21 import {actionTypes as HeatSetupActions, fileTypes as HeatSetupFileTypes} from 'sdc-app/onboarding/softwareProduct/attachments/setup/HeatSetupConstants.js';
22
23 describe('Heat Setup Action Helper test', () => {
24
25         it('function does exist', () => {
26                 expect(HeatSetupActionHelper).toBeTruthy();
27         });
28
29         it('manifest load test', () => {
30
31                 const store = storeCreator();
32
33                 const manifest = heatSetupManifest.build();
34                 store.dispatch({
35                         type: HeatSetupActions.MANIFEST_LOADED,
36                         response: manifest
37                 });
38
39                 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.modules.length).toBe(manifest.modules.length);
40                 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.nested.length).toBe(manifest.nested.length);
41                 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.unassigned.length).toBe(manifest.unassigned.length);
42                 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.artifacts.length).toBe(manifest.artifacts.length);
43
44         });
45
46         it('add module action test', () => {
47                 const store = storeCreator();
48                 deepFreeze(store.getState());
49
50                 const manifest = heatSetupManifest.build();
51                 store.dispatch({
52                         type: HeatSetupActions.MANIFEST_LOADED,
53                         response: manifest
54                 });
55                 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.modules.length).toBe(manifest.modules.length);
56                 HeatSetupActionHelper.addModule(store.dispatch);
57                 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.modules.length).toBe(manifest.modules.length + 1);
58
59         });
60
61         it('delete module action test', () => {
62
63                 const store = storeCreator();
64
65                 const manifest = heatSetupManifest.build();
66                 store.dispatch({
67                         type: HeatSetupActions.MANIFEST_LOADED,
68                         response: manifest
69                 });
70                 HeatSetupActionHelper.deleteModule(store.dispatch, manifest.modules[0].name);
71                 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.modules.length).toBe(manifest.modules.length - 1);
72
73         });
74
75         it('rename module action test', () => {
76
77                 const store = storeCreator();
78
79                 const manifest = heatSetupManifest.build();
80                 store.dispatch({
81                         type: HeatSetupActions.MANIFEST_LOADED,
82                         response: manifest
83                 });
84                 const newName = 'newName';
85                 HeatSetupActionHelper.renameModule(store.dispatch, {oldName: manifest.modules[0].name, newName});
86                 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.modules[0].name).toBe(newName);
87
88         });
89
90         it('change module type action test', () => {
91
92                 const store = storeCreator();
93
94                 const manifest = heatSetupManifest.build();
95                 store.dispatch({
96                         type: HeatSetupActions.MANIFEST_LOADED,
97                         response: manifest
98                 });
99                 const newValue = 'newvalue.env';
100                 HeatSetupActionHelper.changeModuleFileType(store.dispatch,
101                         {
102                                 module: manifest.modules[0],
103                                 value: {value: newValue},
104                                 type: HeatSetupFileTypes.ENV.label
105                         });
106                 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.modules[0].env).toBe(newValue);
107         });
108
109         it('change artifacts list action test', () => {
110
111                 const store = storeCreator();
112
113                 const manifest = heatSetupManifest.build();
114                 store.dispatch({
115                         type: HeatSetupActions.MANIFEST_LOADED,
116                         response: manifest
117                 });
118                 const artifacts = store.getState().softwareProduct.softwareProductAttachments.heatSetup.artifacts;
119                 const newArtifacts = [...artifacts,  manifest.unassigned[0]].map(str => (typeof str === 'string' ? {value: str, label: str} : str));;
120                 HeatSetupActionHelper.changeArtifactList(store.dispatch, newArtifacts);
121                 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.artifacts[1]).toBe(manifest.unassigned[0]);
122                 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.unassigned.length).toBe(manifest.unassigned.length - 1);
123         });
124
125         it('add All Unassigned Files To Artifacts action test', () => {
126
127                 const store = storeCreator();
128
129                 const manifest = heatSetupManifest.build();
130                 store.dispatch({
131                         type: HeatSetupActions.MANIFEST_LOADED,
132                         response: manifest
133                 });
134                 const artifacts = store.getState().softwareProduct.softwareProductAttachments.heatSetup.artifacts;
135                 const unassigned = store.getState().softwareProduct.softwareProductAttachments.heatSetup.unassigned;
136                 const newArtifacts = [...artifacts, ...unassigned];
137                 HeatSetupActionHelper.addAllUnassignedFilesToArtifacts(store.dispatch, true);
138                 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.artifacts).toEqual(newArtifacts);
139                 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.unassigned).toEqual([]);
140         });
141
142 });