2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
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';
23 describe('Heat Setup Action Helper test', () => {
25 it('function does exist', () => {
26 expect(HeatSetupActionHelper).toBeTruthy();
29 it('manifest load test', () => {
31 const store = storeCreator();
33 const manifest = heatSetupManifest.build();
35 type: HeatSetupActions.MANIFEST_LOADED,
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);
46 it('add module action test', () => {
47 const store = storeCreator();
48 deepFreeze(store.getState());
50 const manifest = heatSetupManifest.build();
52 type: HeatSetupActions.MANIFEST_LOADED,
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);
61 it('delete module action test', () => {
63 const store = storeCreator();
65 const manifest = heatSetupManifest.build();
67 type: HeatSetupActions.MANIFEST_LOADED,
70 HeatSetupActionHelper.deleteModule(store.dispatch, manifest.modules[0].name);
71 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.modules.length).toBe(manifest.modules.length - 1);
75 it('rename module action test', () => {
77 const store = storeCreator();
79 const manifest = heatSetupManifest.build();
81 type: HeatSetupActions.MANIFEST_LOADED,
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);
90 it('change module type action test', () => {
92 const store = storeCreator();
94 const manifest = heatSetupManifest.build();
96 type: HeatSetupActions.MANIFEST_LOADED,
99 const newValue = 'newvalue.env';
100 HeatSetupActionHelper.changeModuleFileType(store.dispatch,
102 module: manifest.modules[0],
103 value: {value: newValue},
104 type: HeatSetupFileTypes.ENV.label
106 expect(store.getState().softwareProduct.softwareProductAttachments.heatSetup.modules[0].env).toBe(newValue);
109 it('change artifacts list action test', () => {
111 const store = storeCreator();
113 const manifest = heatSetupManifest.build();
115 type: HeatSetupActions.MANIFEST_LOADED,
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);
125 it('add All Unassigned Files To Artifacts action test', () => {
127 const store = storeCreator();
129 const manifest = heatSetupManifest.build();
131 type: HeatSetupActions.MANIFEST_LOADED,
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([]);