diff options
author | 2017-02-19 12:57:33 +0200 | |
---|---|---|
committer | 2017-02-19 13:47:13 +0200 | |
commit | efa037d34be7b1570efdc767c79fad8d4005f10e (patch) | |
tree | cf1036ba2728dea8a61492b678fa91954e629403 /openecomp-ui/test/softwareProduct/components/storage | |
parent | f5f13c4f6b6fe3b4d98e349dfd7db59339803436 (diff) |
Add new code new version
Change-Id: Ic02a76313503b526f17c3df29eb387a29fe6a42a
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-ui/test/softwareProduct/components/storage')
-rw-r--r-- | openecomp-ui/test/softwareProduct/components/storage/test.js | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/openecomp-ui/test/softwareProduct/components/storage/test.js b/openecomp-ui/test/softwareProduct/components/storage/test.js new file mode 100644 index 0000000000..87cad368be --- /dev/null +++ b/openecomp-ui/test/softwareProduct/components/storage/test.js @@ -0,0 +1,132 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +import expect from 'expect'; +import deepFreeze from 'deep-freeze'; +import mockRest from 'test-utils/MockRest.js'; +import {cloneAndSet} from 'test-utils/Util.js'; +import {storeCreator} from 'sdc-app/AppStore.js'; +import Configuration from 'sdc-app/config/Configuration.js'; +import SoftwareProductComponentsActionHelper from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponentsActionHelper.js'; + +const softwareProductId = '123'; +const vspComponentId = '111'; + +describe('Software Product Components Storage Module Tests', function () { + + let restPrefix = ''; + + before(function() { + restPrefix = Configuration.get('restPrefix'); + deepFreeze(restPrefix); + }); + + it('Get Software Products Components Storage', () => { + const store = storeCreator(); + deepFreeze(store.getState()); + + const softwareProductComponentStorage = { + data: JSON.stringify({'backup':{'backupType':'OnSite','backupSolution':'76333'},'snapshotBackup':{'snapshotFrequency':'2'}}), + schema: JSON.stringify({'backup':{'backupType':'OnSite','backupSolution':'76333'},'snapshotBackup':{'snapshotFrequency':'2'}}) + }; + deepFreeze(softwareProductComponentStorage); + + const softwareProductComponentStorageData = { + qdata: JSON.parse(softwareProductComponentStorage.data), + qschema: JSON.parse(softwareProductComponentStorage.schema) + }; + deepFreeze(softwareProductComponentStorageData); + + const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentEditor', softwareProductComponentStorageData); + + mockRest.addHandler('fetch', ({options, data, baseUrl}) => { + expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/components/${vspComponentId}/questionnaire`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); + return softwareProductComponentStorage; + }); + + return SoftwareProductComponentsActionHelper.fetchSoftwareProductComponentQuestionnaire(store.dispatch, {softwareProductId, vspComponentId}).then(() => { + expect(store.getState()).toEqual(expectedStore); + }); + }); + + it('Get Empty Software Products Components Storage', () => { + const store = storeCreator(); + deepFreeze(store.getState()); + + const softwareProductComponentQuestionnaire = { + data: null, + schema: JSON.stringify({'backup':{'backupType':'OnSite','backupSolution':'76333'},'snapshotBackup':{'snapshotFrequency':'2'}}) + }; + deepFreeze(softwareProductComponentQuestionnaire); + + const softwareProductComponentQuestionnaireData = { + qdata: {}, + qschema: JSON.parse(softwareProductComponentQuestionnaire.schema) + }; + deepFreeze(softwareProductComponentQuestionnaireData); + + const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentEditor', softwareProductComponentQuestionnaireData); + + mockRest.addHandler('fetch', ({options, data, baseUrl}) => { + expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/components/${vspComponentId}/questionnaire`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); + return softwareProductComponentQuestionnaire; + }); + + return SoftwareProductComponentsActionHelper.fetchSoftwareProductComponentQuestionnaire(store.dispatch, {softwareProductId, vspComponentId}).then(() => { + expect(store.getState()).toEqual(expectedStore); + }); + }); + + it('Update Software Products Components Storage', () => { + const store = storeCreator({ + softwareProduct: { + softwareProductComponents: { + componentEditor: { + qdata: { + backupType: 'OnSite', + backupStorageSize: 30 + }, + qschema: { + type: 'object', + properties: { + backupType: {type: 'string'}, + backupStorageSize: {type: 'number'} + } + } + } + } + } + }); + deepFreeze(store); + + const data = {backupType: 'OffSite', backupStorageSize: 30}; + deepFreeze(data); + + const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentEditor.qdata', data); + + SoftwareProductComponentsActionHelper.componentQuestionnaireUpdated(store.dispatch, {data}); + + expect(store.getState()).toEqual(expectedStore); + }); +}); |