From 280f8015d06af1f41a3ef12e8300801c7a5e0d54 Mon Sep 17 00:00:00 2001 From: AviZi Date: Fri, 9 Jun 2017 02:39:56 +0300 Subject: [SDC-29] Amdocs OnBoard 1707 initial commit. Change-Id: Ie4d12a3f574008b792899b368a0902a8b46b5370 Signed-off-by: AviZi --- .../creation/LicenseModelCreation.test.js | 75 +++++ .../test/licenseModel/entitlementPools/test.js | 177 +++------- .../LicenseModelFeatureGroupEditor.test.js | 74 +++++ .../LicenseModelFeatureGroupListEditor.test.js | 90 ++++++ .../test/licenseModel/featureGroups/test.js | 212 +++++++----- .../test/licenseModel/licenseAgreement/test.js | 172 ++++------ .../test/licenseModel/licenseKeyGroups/test.js | 169 ++++------ .../overview/listItems/EntitlementPool.test.js | 31 ++ .../overview/listItems/FeatureGroup.test.js | 58 ++++ .../overview/listItems/LicenseAgreement.test.js | 54 ++++ .../overview/listItems/LicenseKeyGroup.test.js | 31 ++ .../overview/summary/SummaryCountList.test.js | 87 +++++ .../overview/summary/VendorDataView.test.js | 48 +++ openecomp-ui/test/licenseModel/overview/test.js | 355 +++++++++++++++++++++ .../test/licenseModel/overview/views.test.js | 159 +++++++++ openecomp-ui/test/licenseModel/test.js | 55 ++-- 16 files changed, 1387 insertions(+), 460 deletions(-) create mode 100644 openecomp-ui/test/licenseModel/creation/LicenseModelCreation.test.js create mode 100644 openecomp-ui/test/licenseModel/featureGroups/LicenseModelFeatureGroupEditor.test.js create mode 100644 openecomp-ui/test/licenseModel/featureGroups/LicenseModelFeatureGroupListEditor.test.js create mode 100644 openecomp-ui/test/licenseModel/overview/listItems/EntitlementPool.test.js create mode 100644 openecomp-ui/test/licenseModel/overview/listItems/FeatureGroup.test.js create mode 100644 openecomp-ui/test/licenseModel/overview/listItems/LicenseAgreement.test.js create mode 100644 openecomp-ui/test/licenseModel/overview/listItems/LicenseKeyGroup.test.js create mode 100644 openecomp-ui/test/licenseModel/overview/summary/SummaryCountList.test.js create mode 100644 openecomp-ui/test/licenseModel/overview/summary/VendorDataView.test.js create mode 100644 openecomp-ui/test/licenseModel/overview/test.js create mode 100644 openecomp-ui/test/licenseModel/overview/views.test.js (limited to 'openecomp-ui/test/licenseModel') diff --git a/openecomp-ui/test/licenseModel/creation/LicenseModelCreation.test.js b/openecomp-ui/test/licenseModel/creation/LicenseModelCreation.test.js new file mode 100644 index 0000000000..0d8ce945c8 --- /dev/null +++ b/openecomp-ui/test/licenseModel/creation/LicenseModelCreation.test.js @@ -0,0 +1,75 @@ +/*! + * 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. + */ + +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import {mapStateToProps } from 'sdc-app/onboarding/licenseModel/creation/LicenseModelCreation.js'; +import LicenseModelCreationView from 'sdc-app/onboarding/licenseModel/creation/LicenseModelCreationView.jsx'; +import {LicenseModelCreationFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; + +describe('License Model Creation Module Tests', function() { + it ('mapStateToProps mapper exists', () => { + expect(mapStateToProps).toBeTruthy(); + }); + + it ('should return empty data', () => { + let state = { + licenseModelList: [], + licenseModel: { + licenseModelCreation: { + data: {} + } + } + }; + let props = mapStateToProps(state); + expect(props.data).toEqual({}); + }); + + it ('should return vlm names list', () => { + let state = { + licenseModelList: [{ + vendorName: 'vlm1', + id: 'vlm1_id' + }, { + vendorName: 'vlm2', + id: 'vlm2_id' + }], + licenseModel: { + licenseModelCreation: { + data: {} + } + } + }; + let props = mapStateToProps(state); + expect(props.data).toEqual({}); + expect(props.VLMNames).toEqual({vlm1: 'vlm1_id', vlm2: 'vlm2_id'}); + }); + + it('simple jsx test', () => { + let data = LicenseModelCreationFactory.build(); + var renderer = TestUtils.createRenderer(); + renderer.render( + {}} + onValidateForm={() => {}} + onSubmit={() => {}} + onCancel={() => {}}/> + ); + var renderedOutput = renderer.getRenderOutput(); + expect(renderedOutput).toBeTruthy(); + }); +}); diff --git a/openecomp-ui/test/licenseModel/entitlementPools/test.js b/openecomp-ui/test/licenseModel/entitlementPools/test.js index 32705385b4..15e1deecd6 100644 --- a/openecomp-ui/test/licenseModel/entitlementPools/test.js +++ b/openecomp-ui/test/licenseModel/entitlementPools/test.js @@ -1,52 +1,34 @@ -/*- - * ============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 - * + * + * 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========================================================= + * 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. */ - import deepFreeze from 'deep-freeze'; -import {expect} from 'chai'; import mockRest from 'test-utils/MockRest.js'; -import {cloneAndSet} from 'test-utils/Util.js'; +import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js'; import {storeCreator} from 'sdc-app/AppStore.js'; import EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js'; +import {EntitlementPoolStoreFactory, EntitlementPoolPostFactory} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js'; +import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js'; describe('Entitlement Pools Module Tests', function () { const LICENSE_MODEL_ID = '555'; + const version = VersionControllerUtilsFactory.build().version; it('Load Entitlement Pools List', () => { - const entitlementPoolsList = [ - { - name: 'ep1', - description: 'string', - thresholdValue: 75, - thresholdUnits: '%', - entitlementMetric: {'choice': 'User', 'other': ''}, - increments: 'string', - aggregationFunction: {'choice': 'Average', 'other': ''}, - operationalScope: {'choices': ['Other'], 'other': 'blabla'}, - time: {'choice': 'Hour', 'other': ''}, - sku: 'DEF2-385A-4521-AAAA', - id: '1', - referencingFeatureGroups: [], - partNumber: '51529' - } - ]; + + const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory); deepFreeze(entitlementPoolsList); const store = storeCreator(); deepFreeze(store.getState()); @@ -54,36 +36,20 @@ describe('Entitlement Pools Module Tests', function () { const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', entitlementPoolsList); mockRest.addHandler('fetch', ({data, options, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/entitlement-pools`); - expect(data).to.equal(undefined); - expect(options).to.equal(undefined); + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); return {results: entitlementPoolsList}; }); - return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID}).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => { + expect(store.getState()).toEqual(expectedStore); }); }); it('Delete Entitlement Pool', () => { - const entitlementPoolsList = [ - { - name: 'ep1', - description: 'string', - thresholdValue: 75, - thresholdUnits: '%', - entitlementMetric: {'choice': 'User', 'other': ''}, - increments: 'string', - aggregationFunction: {'choice': 'Average', 'other': ''}, - operationalScope: {'choices': ['Other'], 'other': 'blabla'}, - time: {'choice': 'Hour', 'other': ''}, - sku: 'DEF2-385A-4521-AAAA', - id: '1', - referencingFeatureGroups: [], - partNumber: '51529' - } - ]; + const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory,1); deepFreeze(entitlementPoolsList); const store = storeCreator({ licenseModel: { @@ -97,9 +63,9 @@ describe('Entitlement Pools Module Tests', function () { const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', []); mockRest.addHandler('destroy', ({data, options, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/entitlement-pools/${entitlementPoolsList[0].id}`); - expect(data).to.equal(undefined); - expect(options).to.equal(undefined); + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPoolsList[0].id}`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); return { results: { returnCode: 'OK' @@ -109,9 +75,10 @@ describe('Entitlement Pools Module Tests', function () { return EntitlementPoolsActionHelper.deleteEntitlementPool(store.dispatch, { licenseModelId: LICENSE_MODEL_ID, + version, entitlementPoolId: entitlementPoolsList[0].id }).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + expect(store.getState()).toEqual(expectedStore); }); }); @@ -120,43 +87,20 @@ describe('Entitlement Pools Module Tests', function () { const store = storeCreator(); deepFreeze(store.getState()); - const entitlementPoolPostRequest = { - name: 'ep1', - description: 'string', - thresholdValue: 75, - thresholdUnits: '%', - entitlementMetric: {'choice': 'User', 'other': ''}, - increments: 'string', - aggregationFunction: {'choice': 'Average', 'other': ''}, - operationalScope: {'choices': ['Other'], 'other': 'blabla'}, - time: {'choice': 'Hour', 'other': ''}, - manufacturerReferenceNumber: 'DEF2-385A-4521-AAAA', - }; - const entitlementPoolToAdd = { - name: 'ep1', - description: 'string', - thresholdValue: 75, - thresholdUnits: '%', - entitlementMetric: {'choice': 'User', 'other': ''}, - increments: 'string', - aggregationFunction: {'choice': 'Average', 'other': ''}, - operationalScope: {'choices': ['Other'], 'other': 'blabla'}, - time: {'choice': 'Hour', 'other': ''}, - manufacturerReferenceNumber: 'DEF2-385A-4521-AAAA', - referencingFeatureGroups: [] - }; + const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build(); + + deepFreeze(EntitlementPoolPostRequest); + const entitlementPoolIdFromResponse = 'ADDED_ID'; - const entitlementPoolAfterAdd = { - ...entitlementPoolToAdd, - id: entitlementPoolIdFromResponse - }; + const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({id: entitlementPoolIdFromResponse}); + deepFreeze(entitlementPoolAfterAdd); const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolAfterAdd]); - mockRest.addHandler('create', ({data, options, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/entitlement-pools`); - expect(data).to.deep.equal(entitlementPoolPostRequest); - expect(options).to.equal(undefined); + mockRest.addHandler('post', ({data, options, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`); + expect(data).toEqual(EntitlementPoolPostRequest); + expect(options).toEqual(undefined); return { returnCode: 'OK', value: entitlementPoolIdFromResponse @@ -166,28 +110,18 @@ describe('Entitlement Pools Module Tests', function () { return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, { licenseModelId: LICENSE_MODEL_ID, + version, previousEntitlementPool: null, - entitlementPool: entitlementPoolToAdd + entitlementPool: EntitlementPoolPostRequest } ).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + expect(store.getState()).toEqual(expectedStore); }); }); it('Update Entitlement Pool', () => { - const entitlementPoolsList = [{ - name: 'ep1', - id: '0', - description: 'string', - thresholdValue: 75, - thresholdUnits: '%', - entitlementMetric: {'choice': 'User', 'other': ''}, - increments: 'string', - aggregationFunction: {'choice': 'Average', 'other': ''}, - operationalScope: {'choices': ['Other'], 'other': 'blabla'}, - time: {'choice': 'Hour', 'other': ''}, - manufacturerReferenceNumber: 'DEF2-385A-4521-AAAA' - }]; + + const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory, 1); deepFreeze(entitlementPoolsList); const store = storeCreator({ @@ -197,47 +131,34 @@ describe('Entitlement Pools Module Tests', function () { } } }); + deepFreeze(store.getState()); const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id; const previousEntitlementPoolData = entitlementPoolsList[0]; - const entitlementPoolUpdateData = { - ...entitlementPoolsList[0], - name: 'ep1_UPDATED', - description: 'string_UPDATED' - }; + const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED', id: toBeUpdatedEntitlementPoolId}); deepFreeze(entitlementPoolUpdateData); - const entitlementPoolPutRequest = { - name: 'ep1_UPDATED', - description: 'string_UPDATED', - thresholdValue: 75, - thresholdUnits: '%', - entitlementMetric: {'choice': 'User', 'other': ''}, - increments: 'string', - aggregationFunction: {'choice': 'Average', 'other': ''}, - operationalScope: {'choices': ['Other'], 'other': 'blabla'}, - time: {'choice': 'Hour', 'other': ''}, - manufacturerReferenceNumber: 'DEF2-385A-4521-AAAA' - }; + const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED'}); deepFreeze(entitlementPoolPutRequest); const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolUpdateData]); - mockRest.addHandler('save', ({data, options, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/entitlement-pools/${toBeUpdatedEntitlementPoolId}`); - expect(data).to.deep.equal(entitlementPoolPutRequest); - expect(options).to.equal(undefined); + mockRest.addHandler('put', ({data, options, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${toBeUpdatedEntitlementPoolId}`); + expect(data).toEqual(entitlementPoolPutRequest); + expect(options).toEqual(undefined); return {returnCode: 'OK'}; }); return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, { licenseModelId: LICENSE_MODEL_ID, + version, previousEntitlementPool: previousEntitlementPoolData, entitlementPool: entitlementPoolUpdateData }).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + expect(store.getState()).toEqual(expectedStore); }); }); diff --git a/openecomp-ui/test/licenseModel/featureGroups/LicenseModelFeatureGroupEditor.test.js b/openecomp-ui/test/licenseModel/featureGroups/LicenseModelFeatureGroupEditor.test.js new file mode 100644 index 0000000000..5f5e2a0c9e --- /dev/null +++ b/openecomp-ui/test/licenseModel/featureGroups/LicenseModelFeatureGroupEditor.test.js @@ -0,0 +1,74 @@ +/*! + * 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. + */ + +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import {mapStateToProps} from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupEditor.js'; +import FeatureGroupEditorView from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupEditorView.jsx'; +import {LicenseModelOverviewFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; +import {FeatureGroupStoreFactory} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js'; + +describe('License Model Feature Groups Editor Module Tests', function () { + + it('should mapper exist', () => { + expect(mapStateToProps).toBeTruthy(); + }); + + it('should return empty data', () => { + + let licenseModel = LicenseModelOverviewFactory.build({ + featureGroup: { + featureGroupEditor: { + data: FeatureGroupStoreFactory.build() + }, + featureGroupsList: [] + } + }); + + var results = mapStateToProps({licenseModel}); + expect(results.entitlementPoolsList).toEqual([]); + expect(results.licenseKeyGroupsList).toEqual([]); + }); + + it ('should return fg names list', () => { + let licenseModel = LicenseModelOverviewFactory.build({ + featureGroup: { + featureGroupEditor: { + data: FeatureGroupStoreFactory.build() + }, + featureGroupsList: [{ + name: 'fg1', + id: 'fg1_id' + }, { + name: 'fg2', + id: 'fg2_id' + }] + } + }); + var results = mapStateToProps({licenseModel}); + expect(results.FGNames).toEqual({fg1: 'fg1_id', fg2: 'fg2_id'}); + }); + + it('jsx view test', () => { + var view = TestUtils.renderIntoDocument( {}} + entitlementPoolsList={[{id: '1', name: '1'}]} + licenseKeyGroupsList={[{id: '1', name: '1'}]}/>); + expect(view).toBeTruthy(); + }); + +}); diff --git a/openecomp-ui/test/licenseModel/featureGroups/LicenseModelFeatureGroupListEditor.test.js b/openecomp-ui/test/licenseModel/featureGroups/LicenseModelFeatureGroupListEditor.test.js new file mode 100644 index 0000000000..5dc20047bc --- /dev/null +++ b/openecomp-ui/test/licenseModel/featureGroups/LicenseModelFeatureGroupListEditor.test.js @@ -0,0 +1,90 @@ +/*! + * 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. + */ + +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import {mapStateToProps} from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupListEditor.js'; +import FeatureGroupsListEditorView from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupListEditorView.jsx'; +import { FeatureGroupStoreFactory } from 'test-utils/factories/licenseModel/FeatureGroupFactories.js'; +import {LicenseModelOverviewFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; +import { buildListFromFactory } from 'test-utils/Util.js'; +import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js'; + +describe('License Model Feature Group List Module Tests', function () { + + it('should mapper exist', () => { + expect(mapStateToProps).toBeTruthy(); + }); + + + it('should return empty data', () => { + + + let licenseModel = LicenseModelOverviewFactory.build({ + featureGroup: { + featureGroupEditor: {}, + featureGroupsList: [] + }, + licenseModelEditor: { + data:{ + ...VersionControllerUtilsFactory.build() + } + } + }); + var results = mapStateToProps({licenseModel}); + expect(results.vendorName).toEqual(undefined); + expect(results.featureGroupsModal.show).toEqual(false); + expect(results.featureGroupsModal.editMode).toEqual(false); + expect(results.featureGroupsList).toEqual([]); + }); + + it('should return true for show and edit mode and vendorName should be not empty', () => { + + let licenseModel = LicenseModelOverviewFactory.build({ + featureGroup: { + featureGroupEditor: { + data: FeatureGroupStoreFactory.build() + }, + featureGroupsList: [] + } + }); + var results = mapStateToProps({licenseModel}); + expect(results.featureGroupsModal.show).toEqual(true); + expect(results.featureGroupsModal.editMode).toEqual(true); + expect(results.vendorName).toEqual(licenseModel.licenseModelEditor.data.vendorName); + }); + + it('jsx view test', () => { + var view = TestUtils.renderIntoDocument({}} + featureGroupsList={[]} />); + expect(view).toBeTruthy(); + }); + + it('jsx view list test', () => { + var view = TestUtils.renderIntoDocument({}} + featureGroupsList={buildListFromFactory(FeatureGroupStoreFactory)} />); + expect(view).toBeTruthy(); + }); + +}); diff --git a/openecomp-ui/test/licenseModel/featureGroups/test.js b/openecomp-ui/test/licenseModel/featureGroups/test.js index d334ab758e..7d0d7242b5 100644 --- a/openecomp-ui/test/licenseModel/featureGroups/test.js +++ b/openecomp-ui/test/licenseModel/featureGroups/test.js @@ -1,75 +1,56 @@ -/*- - * ============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 - * + * + * 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========================================================= + * 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. */ - -import {expect} from 'chai'; import deepFreeze from 'deep-freeze'; import mockRest from 'test-utils/MockRest.js'; -import {cloneAndSet} from 'test-utils/Util.js'; +import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js'; import {storeCreator} from 'sdc-app/AppStore.js'; import FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js'; +import { FeatureGroupStoreFactory, FeatureGroupPostFactory, FeatureGroupDispatchFactory, FeatureGroupPutFactory } from 'test-utils/factories/licenseModel/FeatureGroupFactories.js'; +import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js'; describe('Feature Groups Module Tests', function () { const LICENSE_MODEL_ID = '555'; + const version = VersionControllerUtilsFactory.build().version; it('Load Feature Groups List', () => { - const featureGroupsList = [ - { - name: 'fs1', - id: 0, - description: 'fs1-d', - licenseKeyGroupsIds: [1], - entitlementPoolsIds: [1], - refCount: 0 - } - ]; + + const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory); deepFreeze(featureGroupsList); + const store = storeCreator(); deepFreeze(store.getState()); const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', featureGroupsList); mockRest.addHandler('fetch', ({data, options, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/feature-groups`); - expect(data).to.equal(undefined); - expect(options).to.equal(undefined); + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); return {results: featureGroupsList}; }); - return FeatureGroupsActionHelper.fetchFeatureGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID}).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + return FeatureGroupsActionHelper.fetchFeatureGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => { + expect(store.getState()).toEqual(expectedStore); }); }); it('Delete Feature Group', () => { - const featureGroupsList = [ - { - name: 'fs1', - id: 0, - description: 'fs1-d', - licenseKeyGroupsIds: [1], - entitlementPoolsIds: [1], - refCount: 0 - } - ]; + const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1); deepFreeze(featureGroupsList); const store = storeCreator({ licenseModel: { @@ -82,10 +63,12 @@ describe('Feature Groups Module Tests', function () { const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', []); + const idToDelete = featureGroupsList[0].id; + mockRest.addHandler('destroy', ({data, options, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/feature-groups/${featureGroupsList[0].id}`); - expect(data).to.equal(undefined); - expect(options).to.equal(undefined); + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups/${idToDelete}`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); return { results: { returnCode: 'OK' @@ -95,9 +78,10 @@ describe('Feature Groups Module Tests', function () { return FeatureGroupsActionHelper.deleteFeatureGroup(store.dispatch, { licenseModelId: LICENSE_MODEL_ID, - featureGroupId: featureGroupsList[0].id + version, + featureGroupId: idToDelete }).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + expect(store.getState()).toEqual(expectedStore); }); }); @@ -106,56 +90,62 @@ describe('Feature Groups Module Tests', function () { const store = storeCreator(); deepFreeze(store.getState()); - const featureGroupPostRequest = { - name: 'fs1', - description: 'fs1-d', - partNumber: '123', + const FeatureGroupPostRequest = FeatureGroupPostFactory.build({ addedLicenseKeyGroupsIds: [1], addedEntitlementPoolsIds: [1] - }; - const featureGroupToAdd = { - name: 'fs1', - description: 'fs1-d', - partNumber: '123', + }); + const featureGroupToAdd = FeatureGroupDispatchFactory.build({ licenseKeyGroupsIds: [1], entitlementPoolsIds: [1] - }; + }); + const featureGroupIdFromResponse = 'ADDED_ID'; - const featureGroupAfterAdd = { + const featureGroupAfterAdd = FeatureGroupStoreFactory.build({ ...featureGroupToAdd, id: featureGroupIdFromResponse - }; + }); const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupAfterAdd]); - mockRest.addHandler('create', ({data, options, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/feature-groups`); - expect(data).to.deep.equal(featureGroupPostRequest); - expect(options).to.equal(undefined); + mockRest.addHandler('post', ({data, options, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`); + expect(data).toEqual(FeatureGroupPostRequest); + expect(options).toEqual(undefined); return { returnCode: 'OK', value: featureGroupIdFromResponse }; }); + mockRest.addHandler('fetch', ({data, options, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); + return {results: []}; + }); + + mockRest.addHandler('fetch', ({data, options, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); + return {results: []}; + }); + + return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, { licenseModelId: LICENSE_MODEL_ID, + version, featureGroup: featureGroupToAdd }).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + expect(store.getState()).toEqual(expectedStore); }); }); it('Update Feature Group', () => { - const featureGroupsList = [{ - name: 'fs1', - id: 0, - description: 'fs1-d', - partNumber: '123', + const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1, { licenseKeyGroupsIds: [1], - entitlementPoolsIds: [1], - refCount: 0 - }]; + entitlementPoolsIds: [1] + }); deepFreeze(featureGroupsList); const store = storeCreator({ @@ -169,44 +159,92 @@ describe('Feature Groups Module Tests', function () { const toBeUpdatedFeatureGroupId = featureGroupsList[0].id; const previousFeatureGroupData = featureGroupsList[0]; - const featureGroupUpdateData = { - ...featureGroupsList[0], - name: 'fs_UPDATED', - description: 'description_UPDATED', - partNumber: '123_UPDATED', + + const featureGroupUpdateData = FeatureGroupStoreFactory.build({ + ...previousFeatureGroupData, licenseKeyGroupsIds: [7], entitlementPoolsIds: [7] - }; + }); deepFreeze(featureGroupUpdateData); - const featureGroupPutRequest = { - name: 'fs_UPDATED', - description: 'description_UPDATED', - partNumber: '123_UPDATED', + const FeatureGroupPutFactoryRequest = FeatureGroupPutFactory.build({ + name: featureGroupUpdateData.name, + description: featureGroupUpdateData.description, + partNumber: featureGroupUpdateData.partNumber, addedLicenseKeyGroupsIds: [7], addedEntitlementPoolsIds: [7], removedLicenseKeyGroupsIds: [1], removedEntitlementPoolsIds: [1] - }; - deepFreeze(featureGroupPutRequest); + }); + deepFreeze(FeatureGroupPutFactoryRequest); const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupUpdateData]); - mockRest.addHandler('save', ({data, options, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/feature-groups/${toBeUpdatedFeatureGroupId}`); - expect(data).to.deep.equal(featureGroupPutRequest); - expect(options).to.equal(undefined); + mockRest.addHandler('put', ({data, options, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups/${toBeUpdatedFeatureGroupId}`); + expect(data).toEqual(FeatureGroupPutFactoryRequest); + expect(options).toEqual(undefined); return {returnCode: 'OK'}; }); + mockRest.addHandler('fetch', ({data, options, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); + return {results: []}; + }); + + mockRest.addHandler('fetch', ({data, options, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); + return {results: []}; + }); + return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, { licenseModelId: LICENSE_MODEL_ID, + version, previousFeatureGroup: previousFeatureGroupData, featureGroup: featureGroupUpdateData }).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + expect(store.getState()).toEqual(expectedStore); }); + + }); + + it('Open Editor', () => { + + const store = storeCreator(); + deepFreeze(store.getState()); + + const editorData = FeatureGroupStoreFactory.build(); + deepFreeze(editorData); + const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupEditor.data', editorData); + const LICENSE_MODEL_ID = '123'; + + mockRest.addHandler('fetch', ({data, options, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); + return {results: []}; + }); + + mockRest.addHandler('fetch', ({data, options, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); + return {results: []}; + }); + + + FeatureGroupsActionHelper.openFeatureGroupsEditor(store.dispatch, {featureGroup: editorData, licenseModelId: '123', version}); + setTimeout(() =>{ + expect(store.getState()).toEqual(expectedStore); + }, 100); + + + }); }); diff --git a/openecomp-ui/test/licenseModel/licenseAgreement/test.js b/openecomp-ui/test/licenseModel/licenseAgreement/test.js index a6e8a3d363..442f7bf91f 100644 --- a/openecomp-ui/test/licenseModel/licenseAgreement/test.js +++ b/openecomp-ui/test/licenseModel/licenseAgreement/test.js @@ -1,75 +1,54 @@ -/*- - * ============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 - * + * + * 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========================================================= + * 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. */ - -import {expect} from 'chai'; import deepFreeze from 'deep-freeze'; +import pickBy from 'lodash/pickBy'; import mockRest from 'test-utils/MockRest.js'; -import {cloneAndSet} from 'test-utils/Util.js'; +import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js'; import {storeCreator} from 'sdc-app/AppStore.js'; import LicenseAgreementActionHelper from 'sdc-app/onboarding/licenseModel/licenseAgreement/LicenseAgreementActionHelper.js'; +import { LicenseAgreementStoreFactory, LicenseAgreementDispatchFactory, LicenseAgreementPostFactory, LicenseAgreementPutFactory } from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js'; +import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js'; describe('License Agreement Module Tests', () => { const LICENSE_MODEL_ID = '777'; + const version = VersionControllerUtilsFactory.build().version; it('Load License Agreement List', () => { - const licenseAgreementList = [ - { - id: '0', - name: 'name0', - description: 'description0', - licenseTerm: 'licenseTerm0', - requirementsAndConstrains: 'req_and_constraints0', - featureGroupsIds: ['77'] - } - ]; - deepFreeze(licenseAgreementList); + const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory); + const store = storeCreator(); deepFreeze(store.getState()); const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', licenseAgreementList); mockRest.addHandler('fetch', ({options, data, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/license-agreements`); - expect(data).to.equal(undefined); - expect(options).to.equal(undefined); + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); return {results: licenseAgreementList}; }); - return LicenseAgreementActionHelper.fetchLicenseAgreementList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID}).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + return LicenseAgreementActionHelper.fetchLicenseAgreementList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => { + expect(store.getState()).toEqual(expectedStore); }); }); it('Delete License Agreement', () => { - const licenseAgreementList = [ - { - id: '0', - name: 'name0', - description: 'description0', - licenseTerm: 'licenseTerm0', - requirementsAndConstrains: 'req_and_constraints0', - featureGroupsIds: ['77'] - } - ]; - deepFreeze(licenseAgreementList); + const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory, 1); const store = storeCreator({ licenseModel: { licenseAgreement: { @@ -78,57 +57,49 @@ describe('License Agreement Module Tests', () => { } }); deepFreeze(store.getState()); - const toBeDeletedLicenseAgreementId = '0'; + const toBeDeletedLicenseAgreementId = licenseAgreementList[0].id; const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', []); mockRest.addHandler('destroy', ({data, options, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/license-agreements/${toBeDeletedLicenseAgreementId}`); - expect(data).to.equal(undefined); - expect(options).to.equal(undefined); + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements/${toBeDeletedLicenseAgreementId}`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); }); return LicenseAgreementActionHelper.deleteLicenseAgreement(store.dispatch, { licenseAgreementId: toBeDeletedLicenseAgreementId, - licenseModelId: LICENSE_MODEL_ID + licenseModelId: LICENSE_MODEL_ID, + version }).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + expect(store.getState()).toEqual(expectedStore); }); }); it('Add License Agreement', () => { const store = storeCreator(); deepFreeze(store.getState()); - const licenseAgreementPostRequest = { - name: 'name_ADDED_LA', - description: 'description_ADDED_LA', - licenseTerm: 'licenseTerm_ADDED_LA', - requirementsAndConstrains: 'req_and_constraints_ADDED_LA', - addedFeatureGroupsIds: [] - }; - deepFreeze(licenseAgreementPostRequest); - - const licenseAgreementToAdd = { - name: 'name_ADDED_LA', - description: 'description_ADDED_LA', - licenseTerm: 'licenseTerm_ADDED_LA', - requirementsAndConstrains: 'req_and_constraints_ADDED_LA', - featureGroupsIds: [] - }; - deepFreeze(licenseAgreementToAdd); + + const licenseAgreementToAdd = LicenseAgreementDispatchFactory.build(); + + const LicenseAgreementPostRequest = LicenseAgreementPostFactory.build( + pickBy(licenseAgreementToAdd, (val, key) => key !== 'featureGroupsIds') + ); + + deepFreeze(LicenseAgreementPostRequest); const licenseAgreementIdFromResponse = 'ADDED_ID'; - const licenseAgreementAfterAdd = { + const licenseAgreementAfterAdd = LicenseAgreementStoreFactory.build({ ...licenseAgreementToAdd, id: licenseAgreementIdFromResponse - }; + }); deepFreeze(licenseAgreementAfterAdd); const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', [licenseAgreementAfterAdd]); - mockRest.addHandler('create', ({options, data, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/license-agreements`); - expect(data).to.deep.equal(licenseAgreementPostRequest); - expect(options).to.equal(undefined); + mockRest.addHandler('post', ({options, data, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`); + expect(data).toEqual(LicenseAgreementPostRequest); + expect(options).toEqual(undefined); return { value: licenseAgreementIdFromResponse }; @@ -136,23 +107,15 @@ describe('License Agreement Module Tests', () => { return LicenseAgreementActionHelper.saveLicenseAgreement(store.dispatch, { licenseAgreement: licenseAgreementToAdd, - licenseModelId: LICENSE_MODEL_ID + licenseModelId: LICENSE_MODEL_ID, + version }).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + expect(store.getState()).toEqual(expectedStore); }); }); it('Update License Agreement', () => { - const licenseAgreementList = [ - { - id: '0', - name: 'name0', - description: 'description0', - licenseTerm: 'licenseTerm0', - requirementsAndConstrains: 'req_and_constraints0', - featureGroupsIds: ['77'] - } - ]; + const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory, 1, {featureGroupsIds: ['77']}); const store = storeCreator({ licenseModel: { licenseAgreement: { @@ -162,43 +125,40 @@ describe('License Agreement Module Tests', () => { }); deepFreeze(store.getState()); - const toBeUpdatedLicenseAgreementId = licenseAgreementList[0].id; const previousLicenseAgreementData = licenseAgreementList[0]; + const toBeUpdatedLicenseAgreementId = previousLicenseAgreementData.id; + const oldFeatureGroupIds = previousLicenseAgreementData.featureGroupsIds; + + const newFeatureGroupsIds = ['update_id_1', 'update_id_2']; - const licenseAgreementUpdateData = { - ...licenseAgreementList[0], - name: 'name_UPDATED', - description: 'description_UPDATED', - licenseTerm: 'licenseTerm_UPDATED_LA', - requirementsAndConstrains: 'req_and_constraints_UPDATED_LA', - featureGroupsIds: ['update_id_1', 'update_id_2'] - }; + const licenseAgreementUpdateData = LicenseAgreementStoreFactory.build({ + id: toBeUpdatedLicenseAgreementId, + featureGroupsIds: newFeatureGroupsIds + }); deepFreeze(licenseAgreementUpdateData); - const licenseAgreementPutRequest = { - name: 'name_UPDATED', - description: 'description_UPDATED', - licenseTerm: 'licenseTerm_UPDATED_LA', - requirementsAndConstrains: 'req_and_constraints_UPDATED_LA', - addedFeatureGroupsIds: ['update_id_1', 'update_id_2'], - removedFeatureGroupsIds: ['77'] - }; - deepFreeze(licenseAgreementPutRequest); + const LicenseAgreementPutFactoryRequest = LicenseAgreementPutFactory.build({ + addedFeatureGroupsIds: newFeatureGroupsIds, + removedFeatureGroupsIds: oldFeatureGroupIds + }); + + deepFreeze(LicenseAgreementPutFactoryRequest); const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', [licenseAgreementUpdateData]); - mockRest.addHandler('save', ({data, options, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/license-agreements/${toBeUpdatedLicenseAgreementId}`); - expect(data).to.deep.equal(licenseAgreementPutRequest); - expect(options).to.equal(undefined); + mockRest.addHandler('put', ({data, options, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements/${toBeUpdatedLicenseAgreementId}`); + expect(data).toEqual(LicenseAgreementPutFactoryRequest); + expect(options).toEqual(undefined); }); return LicenseAgreementActionHelper.saveLicenseAgreement(store.dispatch, { licenseModelId: LICENSE_MODEL_ID, + version, previousLicenseAgreement: previousLicenseAgreementData, licenseAgreement: licenseAgreementUpdateData }).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + expect(store.getState()).toEqual(expectedStore); }); }); diff --git a/openecomp-ui/test/licenseModel/licenseKeyGroups/test.js b/openecomp-ui/test/licenseModel/licenseKeyGroups/test.js index 944bd44e49..dd09030f4f 100644 --- a/openecomp-ui/test/licenseModel/licenseKeyGroups/test.js +++ b/openecomp-ui/test/licenseModel/licenseKeyGroups/test.js @@ -1,44 +1,36 @@ -/*- - * ============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 - * + * + * 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========================================================= + * 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. */ - -import {expect} from 'chai'; import deepFreeze from 'deep-freeze'; import mockRest from 'test-utils/MockRest.js'; -import {cloneAndSet} from 'test-utils/Util.js'; +import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js'; import {storeCreator} from 'sdc-app/AppStore.js'; +import {LicenseKeyGroupStoreFactory, LicenseKeyGroupPostFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js'; import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js'; +import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js'; describe('License Key Groups Module Tests', function () { const LICENSE_MODEL_ID = '555'; + const version = VersionControllerUtilsFactory.build().version; + it('Load License Key Group', () => { - const licenseKeyGroupsList = [ - { - name: 'lsk1', - description: 'string', - type: 'Unique', - operationalScope: {'choices': ['Data_Center'], 'other': ''}, - id: '0' - } - ]; + + const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory); + deepFreeze(licenseKeyGroupsList); const store = storeCreator(); deepFreeze(store.getState()); @@ -46,27 +38,21 @@ describe('License Key Groups Module Tests', function () { const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', licenseKeyGroupsList); mockRest.addHandler('fetch', ({data, options, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/license-key-groups`); - expect(data).to.equal(undefined); - expect(options).to.equal(undefined); + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); return {results: licenseKeyGroupsList}; }); - return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID}).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => { + expect(store.getState()).toEqual(expectedStore); }); }); it('Delete License Key Group', () => { - const licenseKeyGroupsList = [ - { - name: 'lsk1', - description: 'string', - type: 'Unique', - operationalScope: {'choices': ['Data_Center'], 'other': ''}, - id: '0' - } - ]; + + const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1); + deepFreeze(licenseKeyGroupsList); const store = storeCreator({ licenseModel: { @@ -76,20 +62,21 @@ describe('License Key Groups Module Tests', function () { } }); deepFreeze(store.getState()); - const toBeDeletedLicenseKeyGroupId = '0'; + const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id; const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []); mockRest.addHandler('destroy', ({data, options, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/license-key-groups/${toBeDeletedLicenseKeyGroupId}`); - expect(data).to.equal(undefined); - expect(options).to.equal(undefined); + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeDeletedLicenseKeyGroupId}`); + expect(data).toEqual(undefined); + expect(options).toEqual(undefined); }); return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, { licenseKeyGroupId: toBeDeletedLicenseKeyGroupId, - licenseModelId: LICENSE_MODEL_ID + licenseModelId: LICENSE_MODEL_ID, + version }).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + expect(store.getState()).toEqual(expectedStore); }); }); @@ -98,56 +85,34 @@ describe('License Key Groups Module Tests', function () { const store = storeCreator(); deepFreeze(store.getState()); - const licenseKeyGroupPostRequest = { - name: 'lsk1_ADDED', - description: 'string_ADDED', - type: 'Unique_ADDED', - operationalScope: {'choices': ['Data_Center'], 'other': ''} - }; - deepFreeze(licenseKeyGroupPostRequest); - - const licenseKeyGroupToAdd = { - ...licenseKeyGroupPostRequest - }; - - deepFreeze(licenseKeyGroupToAdd); - - const licenseKeyGroupIdFromResponse = 'ADDED_ID'; - const licenseKeyGroupAfterAdd = { - ...licenseKeyGroupToAdd, - id: licenseKeyGroupIdFromResponse - }; - deepFreeze(licenseKeyGroupAfterAdd); - - const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupAfterAdd]); - - mockRest.addHandler('create', ({options, data, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/license-key-groups`); - expect(data).to.deep.equal(licenseKeyGroupPostRequest); - expect(options).to.equal(undefined); + const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build(); + deepFreeze(LicenseKeyGroupPost); + + const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build(); + deepFreeze(LicenseKeyGroupStore); + + const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [LicenseKeyGroupStore]); + + mockRest.addHandler('post', ({options, data, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); + expect(data).toEqual(LicenseKeyGroupPost); + expect(options).toEqual(undefined); return { - value: licenseKeyGroupIdFromResponse + value: LicenseKeyGroupStore.id }; }); return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, { - licenseKeyGroup: licenseKeyGroupToAdd, - licenseModelId: LICENSE_MODEL_ID + licenseKeyGroup: LicenseKeyGroupPost, + licenseModelId: LICENSE_MODEL_ID, + version }).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + expect(store.getState()).toEqual(expectedStore); }); }); it('Update License Key Group', () => { - const licenseKeyGroupsList = [ - { - name: 'lsk1', - description: 'string', - type: 'Unique', - operationalScope: {'choices': ['Data_Center'], 'other': ''}, - id: '0' - } - ]; + const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1); deepFreeze(licenseKeyGroupsList); const store = storeCreator({ licenseModel: { @@ -160,37 +125,35 @@ describe('License Key Groups Module Tests', function () { const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id; const previousLicenseKeyGroupData = licenseKeyGroupsList[0]; - const licenseKeyGroupUpdateData = { - ...licenseKeyGroupsList[0], + const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({ name: 'lsk1_UPDATE', description: 'string_UPDATE', - type: 'Unique', - operationalScope: {'choices': ['Data_Center'], 'other': ''} - }; - deepFreeze(licenseKeyGroupUpdateData); + id: toBeUpdatedLicenseKeyGroupId + }); + deepFreeze(licenseKeyGroupUpdatedData); - const licenseKeyGroupPutRequest = { + const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({ name: 'lsk1_UPDATE', - description: 'string_UPDATE', - type: 'Unique', - operationalScope: {'choices': ['Data_Center'], 'other': ''} - }; + description: 'string_UPDATE' + }); + deepFreeze(licenseKeyGroupPutRequest); - const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdateData]); + const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdatedData]); - mockRest.addHandler('save', ({data, options, baseUrl}) => { - expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`); - expect(data).to.deep.equal(licenseKeyGroupPutRequest); - expect(options).to.equal(undefined); + mockRest.addHandler('put', ({data, options, baseUrl}) => { + expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`); + expect(data).toEqual(licenseKeyGroupPutRequest); + expect(options).toEqual(undefined); }); return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, { previousLicenseKeyGroup: previousLicenseKeyGroupData, - licenseKeyGroup: licenseKeyGroupUpdateData, - licenseModelId: LICENSE_MODEL_ID + licenseKeyGroup: licenseKeyGroupUpdatedData, + licenseModelId: LICENSE_MODEL_ID, + version }).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + expect(store.getState()).toEqual(expectedStore); }); }); diff --git a/openecomp-ui/test/licenseModel/overview/listItems/EntitlementPool.test.js b/openecomp-ui/test/licenseModel/overview/listItems/EntitlementPool.test.js new file mode 100644 index 0000000000..6c4a05eb16 --- /dev/null +++ b/openecomp-ui/test/licenseModel/overview/listItems/EntitlementPool.test.js @@ -0,0 +1,31 @@ +/*! + * 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. + */ + +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import EntitlementPool from 'src/sdc-app/onboarding/licenseModel/overview/listItems/EntitlementPool.jsx'; +import {EntitlementPoolListItemFactory} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js'; + +describe('Entitlement Pool List Item Module Tests', function () { + it('Entitlement Pool List Item should exist', () => { + expect(EntitlementPool).toBeTruthy(); + }); + it('renders Entitlement Pool List Item', () => { + const epData = EntitlementPoolListItemFactory.build(); + const itemView = TestUtils.renderIntoDocument( ); + expect(itemView).toBeTruthy(); + }); +}); diff --git a/openecomp-ui/test/licenseModel/overview/listItems/FeatureGroup.test.js b/openecomp-ui/test/licenseModel/overview/listItems/FeatureGroup.test.js new file mode 100644 index 0000000000..10b7801889 --- /dev/null +++ b/openecomp-ui/test/licenseModel/overview/listItems/FeatureGroup.test.js @@ -0,0 +1,58 @@ +/*! + * 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. + */ + +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import FeatureGroup from 'src/sdc-app/onboarding/licenseModel/overview/listItems/FeatureGroup.jsx'; +import {scryRenderedDOMComponentsWithTestId} from 'test-utils/Util.js'; +import {FeatureGroupListItemFactory} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js'; +import {EntitlementPoolListItemFactory} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js'; +import {LicenseKeyGroupListItemFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js'; + +describe('Feature Group List Item Module Tests', function () { + it('Feature Group List Item should exist', () => { + expect(FeatureGroup).toBeTruthy(); + }); + + it('renders Feature Group List Item Collapsed', () => { + const fgData = FeatureGroupListItemFactory.build(); + const itemView = TestUtils.renderIntoDocument( ); + expect(itemView).toBeTruthy(); + const elem = TestUtils.scryRenderedDOMComponentsWithClass(itemView,'down'); + expect(elem).toBeTruthy(); + }); + + it('renders Feature Group List Item Expanded', () => { + const fgData = FeatureGroupListItemFactory.build({isCollpased: false}); + const itemView = TestUtils.renderIntoDocument( ); + expect(itemView).toBeTruthy(); + const elem = TestUtils.scryRenderedDOMComponentsWithClass(itemView,'right'); + expect(elem).toBeTruthy(); + }); + + it('renders Feature Group List Item with Children Count', () => { + const children = [EntitlementPoolListItemFactory.build(), LicenseKeyGroupListItemFactory.build()]; + const fgData = FeatureGroupListItemFactory.build({children: children, isCollpased: false}); + const itemView = TestUtils.renderIntoDocument( ); + expect(itemView).toBeTruthy(); + let elem = scryRenderedDOMComponentsWithTestId(itemView,'vlm-list-ep-count-value'); + expect(elem).toBeTruthy(); + expect(elem[0].innerHTML).toBe('1'); + elem = scryRenderedDOMComponentsWithTestId(itemView,'vlm-list-lkg-count-value'); + expect(elem).toBeTruthy(); + expect(elem[0].innerHTML).toBe('1'); + }); +}); diff --git a/openecomp-ui/test/licenseModel/overview/listItems/LicenseAgreement.test.js b/openecomp-ui/test/licenseModel/overview/listItems/LicenseAgreement.test.js new file mode 100644 index 0000000000..608a76965f --- /dev/null +++ b/openecomp-ui/test/licenseModel/overview/listItems/LicenseAgreement.test.js @@ -0,0 +1,54 @@ +/*! + * 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. + */ + +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import LicenseAgreement from 'src/sdc-app/onboarding/licenseModel/overview/listItems/LicenseAgreement.jsx'; +import {scryRenderedDOMComponentsWithTestId} from 'test-utils/Util.js'; +import {LicenseAgreementListItemFactory} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js'; +import {FeatureGroupListItemFactory} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js'; + +describe('License Agreement List Item Module Tests', function () { + it('License Agreement List Item should exist', () => { + expect(LicenseAgreement).toBeTruthy(); + }); + + it('renders License Agreement List Item Collapsed', () => { + const laData = LicenseAgreementListItemFactory.build(); + const itemView = TestUtils.renderIntoDocument( ); + expect(itemView).toBeTruthy(); + const elem = TestUtils.scryRenderedDOMComponentsWithClass(itemView,'down'); + expect(elem).toBeTruthy(); + }); + + it('renders License Agreement List Item Expanded', () => { + const laData = LicenseAgreementListItemFactory.build({isCollpased: false}); + const itemView = TestUtils.renderIntoDocument( ); + expect(itemView).toBeTruthy(); + const elem = TestUtils.scryRenderedDOMComponentsWithClass(itemView,'right'); + expect(elem).toBeTruthy(); + }); + + it('renders License Agreement List Item with Children Count', () => { + const fgData = FeatureGroupListItemFactory.build(); + const laData = LicenseAgreementListItemFactory.build({children: [fgData]}); + const itemView = TestUtils.renderIntoDocument( ); + expect(itemView).toBeTruthy(); + const elem = scryRenderedDOMComponentsWithTestId(itemView,'vlm-list-fg-count-value'); + expect(elem).toBeTruthy(); + expect(elem[0].innerHTML).toBe('1'); + }); +}); diff --git a/openecomp-ui/test/licenseModel/overview/listItems/LicenseKeyGroup.test.js b/openecomp-ui/test/licenseModel/overview/listItems/LicenseKeyGroup.test.js new file mode 100644 index 0000000000..b9c097b0b1 --- /dev/null +++ b/openecomp-ui/test/licenseModel/overview/listItems/LicenseKeyGroup.test.js @@ -0,0 +1,31 @@ +/*! + * 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. + */ + +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import LicenseKeyGroup from 'src/sdc-app/onboarding/licenseModel/overview/listItems/LicenseKeyGroup.jsx'; +import {LicenseKeyGroupListItemFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js'; + +describe('LicenseKeyGroup List Item Module Tests', function () { + it('LicenseKeyGroup List Item should exist', () => { + expect(LicenseKeyGroup).toBeTruthy(); + }); + it('renders LicenseKeyGroup List Item', () => { + const lkgData = LicenseKeyGroupListItemFactory.build(); + const itemView = TestUtils.renderIntoDocument( ); + expect(itemView).toBeTruthy(); + }); +}); diff --git a/openecomp-ui/test/licenseModel/overview/summary/SummaryCountList.test.js b/openecomp-ui/test/licenseModel/overview/summary/SummaryCountList.test.js new file mode 100644 index 0000000000..27f7aa68fd --- /dev/null +++ b/openecomp-ui/test/licenseModel/overview/summary/SummaryCountList.test.js @@ -0,0 +1,87 @@ +/*! + * 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. + */ + +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; + +import {mapStateToProps, SummaryCountList} from 'sdc-app/onboarding/licenseModel/overview/summary/SummaryCountList.js'; +import LicenseModelDescriptionEdit from 'sdc-app/onboarding/licenseModel/overview/summary/LicenseModelDescriptionEdit.jsx'; +import {overviewItems} from 'sdc-app/onboarding/licenseModel/overview/LicenseModelOverviewConstants.js'; +import {LicenseModelOverviewFactory, LicenseModelStoreFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; + +describe('License Model Overview Summary Count List module test', () => { + + it('should mapper exist', () => { + expect(mapStateToProps).toBeTruthy(); + }); + + it('mapper data return test',() => { + + var obj = { + licenseModel: LicenseModelOverviewFactory.build({ + entitlementPool: { + entitlementPoolsList: [] + }, + licenseAgreement: { + licenseAgreementList: [] + }, + featureGroup: { + featureGroupsList: [] + }, + licenseKeyGroup: { + licenseKeyGroupsList: [] + } + }) + }; + + let counts = [ + {name: overviewItems.LICENSE_AGREEMENTS, count: 0}, + {name: overviewItems.FEATURE_GROUPS, count: 0}, + {name: overviewItems.ENTITLEMENT_POOLS, count: 0}, + {name: overviewItems.LICENSE_KEY_GROUPS, count: 0}, + ]; + + var result = mapStateToProps(obj); + expect(result.isReadOnlyMode).toEqual(true); + expect(result.description).toEqual(obj.licenseModel.licenseModelEditor.data.description); + expect(result.counts).toEqual(counts); + }); + + it('jsx view test', () => { + + var counts = [ + {name: overviewItems.LICENSE_AGREEMENTS, count: 0}, + {name: overviewItems.FEATURE_GROUPS, count: 0}, + {name: overviewItems.ENTITLEMENT_POOLS, count: 0}, + {name: overviewItems.LICENSE_KEY_GROUPS, count: 0}, + ]; + + var view = TestUtils.renderIntoDocument(); + expect(view).toBeTruthy(); + }); + + it('description editor jsx view test', () => { + var data = LicenseModelStoreFactory.build(); + var genericFieldInfo = { + description: { + isValid : true + } + } + var view = TestUtils.renderIntoDocument(); + expect(view).toBeTruthy(); + }); + +}); diff --git a/openecomp-ui/test/licenseModel/overview/summary/VendorDataView.test.js b/openecomp-ui/test/licenseModel/overview/summary/VendorDataView.test.js new file mode 100644 index 0000000000..8fea3e4b90 --- /dev/null +++ b/openecomp-ui/test/licenseModel/overview/summary/VendorDataView.test.js @@ -0,0 +1,48 @@ +/*! + * 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. + */ + +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import {mapStateToProps, VendorDataView} from 'sdc-app/onboarding/licenseModel/overview/summary/VendorDataView.js'; +import {LicenseModelOverviewFactory, LicenseModelStoreFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; + + +describe('License Model Overview Summary module test', () => { + + it('should mapper exist', () => { + expect(mapStateToProps).toBeTruthy(); + }); + + it('mapper data return test',() => { + + var state = { + licenseModel: LicenseModelOverviewFactory.build() + }; + + var props = mapStateToProps(state); + expect(props.isReadOnlyMode).toEqual(true); + expect(props.description).toEqual(null); + expect(props.data).toEqual(state.licenseModel.licenseModelEditor.data); + + }); + + it('jsx view test', () => { + var data = LicenseModelStoreFactory.build(); + var view = TestUtils.renderIntoDocument(); + expect(view).toBeTruthy(); + }); + +}); diff --git a/openecomp-ui/test/licenseModel/overview/test.js b/openecomp-ui/test/licenseModel/overview/test.js new file mode 100644 index 0000000000..c78c3e47b1 --- /dev/null +++ b/openecomp-ui/test/licenseModel/overview/test.js @@ -0,0 +1,355 @@ +/*! + * 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. + */ + +import {mapStateToProps} from 'sdc-app/onboarding/licenseModel/overview/LicenseModelOverview.js'; +import {overviewEditorHeaders, selectedButton} from 'sdc-app/onboarding/licenseModel/overview/LicenseModelOverviewConstants.js'; + +import {LicenseModelOverviewFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; +import { EntitlementPoolStoreFactory as EntitlementPool, EntitlementPoolDataListFactory } from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js'; +import { FeatureGroupStoreFactory as FeatureGroup, FeatureGroupDataListFactory} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js'; +import {LicenseAgreementStoreFactory as LicenseAgreement, LicenseAgreementDataListFactory} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js'; +import { LicenseKeyGroupStoreFactory as LicenseKeyGroup, LicenseKeyGroupDataListFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js'; + +describe('License Model Overview: ', function () { + + it('should mapper exist', () => { + expect(mapStateToProps).toBeTruthy(); + }); + + const VLM1 = LicenseModelOverviewFactory.build(); + + it('should mapper return vlm overview basic data', () => { + const state = { + licenseModel: VLM1 + }; + + var props = mapStateToProps(state); + expect(props.isReadOnlyMode).toEqual(true); + expect(props.isDisplayModal).toEqual(false); + expect(props.modalHeader).toEqual(undefined); + expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); + expect(props.licensingDataList).toEqual([]); + expect(props.selectedTab).toEqual(selectedButton.VLM_LIST_VIEW); + }); + + it('should mapper return overview data for show LA modal', () => { + const VLM1 = LicenseModelOverviewFactory.build({ + licenseAgreement: { + licenseAgreementEditor: { + data: LicenseAgreement.build() + } + } + }); + + var state = { + licenseModel: VLM1 + }; + + var props = mapStateToProps(state); + expect(props.isReadOnlyMode).toEqual(true); + expect(props.isDisplayModal).toEqual(true); + expect(props.modalHeader).toEqual(overviewEditorHeaders.LICENSE_AGREEMENT); + expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); + expect(props.licensingDataList).toEqual([]); + expect(props.selectedTab).toEqual(selectedButton.VLM_LIST_VIEW); + }); + + it('should mapper return overview data for show FG modal', () => { + + const VLM1 = LicenseModelOverviewFactory.build({ + featureGroup: { + featureGroupsList: [], + featureGroupEditor: { + data: FeatureGroup.build() + } + }, + entitlementPool: { + entitlementPoolsList: [] + }, + licenseKeyGroup: { + licenseKeyGroupsList: [] + }, + licenseModelOverview: { + selectedTab: selectedButton.NOT_IN_USE + } + }); + + var state = { + licenseModel: VLM1 + }; + + var props = mapStateToProps(state); + expect(props.isReadOnlyMode).toEqual(true); + expect(props.isDisplayModal).toEqual(true); + expect(props.modalHeader).toEqual(overviewEditorHeaders.FEATURE_GROUP); + expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); + expect(props.licensingDataList).toEqual([]); + expect(props.selectedTab).toEqual(selectedButton.NOT_IN_USE); + }); + + it('should mapper return overview data for show EP modal', () => { + const VLM1 = LicenseModelOverviewFactory.build({ + entitlementPool: { + entitlementPoolEditor: { + data: EntitlementPool.build() + } + } + }); + + var state = { + licenseModel: VLM1 + }; + + var props = mapStateToProps(state); + expect(props.isReadOnlyMode).toEqual(true); + expect(props.isDisplayModal).toEqual(true); + expect(props.modalHeader).toEqual(overviewEditorHeaders.ENTITLEMENT_POOL); + expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); + expect(props.licensingDataList).toEqual([]); + expect(props.selectedTab).toEqual(selectedButton.VLM_LIST_VIEW); + }); + + it('should mapper return overview data for show LKG modal', () => { + const VLM1 = LicenseModelOverviewFactory.build({ + licenseKeyGroup: { + licenseKeyGroupsList: [], + licenseKeyGroupsEditor: { + data: LicenseKeyGroup.build() + } + }, + entitlementPool: { + entitlementPoolsList: [] + }, + featureGroup: { + featureGroupsList: [] + }, + licenseModelOverview: { + selectedTab: selectedButton.NOT_IN_USE + } + }); + + var state = { + licenseModel: VLM1 + }; + + var props = mapStateToProps(state); + expect(props.isReadOnlyMode).toEqual(true); + expect(props.isDisplayModal).toEqual(true); + expect(props.modalHeader).toEqual(overviewEditorHeaders.LICENSE_KEY_GROUP); + expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); + expect(props.licensingDataList).toEqual([]); + expect(props.selectedTab).toEqual(selectedButton.NOT_IN_USE); + }); + + it('should mapper return overview data for Full-hierarchy list view', () => { + let EP1 = EntitlementPool.build(); + let LKG1 = LicenseKeyGroup.build(); + let FG1 = FeatureGroup.build({ + entitlementPoolsIds: [EP1.id], + licenseKeyGroupsIds: [LKG1.id] + }); + EP1.referencingFeatureGroups = [FG1.id]; + LKG1.referencingFeatureGroups = [FG1.id]; + let LA1 = LicenseAgreement.build({ + featureGroupsIds: [FG1.id] + }); + FG1.referencingLicenseAgreements = LA1.id; + let LA2 = LicenseAgreement.build(); + + const VLM1 = LicenseModelOverviewFactory.build({ + licenseAgreement: { + licenseAgreementList: [LA1, LA2] + }, + featureGroup: { + featureGroupsList: [FG1] + }, + entitlementPool: { + entitlementPoolsList: [EP1] + }, + licenseKeyGroup: { + licenseKeyGroupsList: [LKG1] + }, + }); + + const state = { + licenseModel: VLM1 + }; + + const expectedLicensingDataList = [ + LicenseAgreementDataListFactory.build({ + ...LA1, + children: [ + FeatureGroupDataListFactory.build({ + ...FG1, + children: [ + EntitlementPoolDataListFactory.build(EP1), + LicenseKeyGroupDataListFactory.build(LKG1) + ] + }) + ] + }), + LicenseAgreementDataListFactory.build(LA2) + ]; + + var props = mapStateToProps(state); + + expect(props.isReadOnlyMode).toEqual(true); + expect(props.isDisplayModal).toEqual(false); + expect(props.modalHeader).toEqual(undefined); + expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); + expect(props.licensingDataList).toEqual(expectedLicensingDataList); + expect(props.selectedTab).toEqual(selectedButton.VLM_LIST_VIEW); + }); + + it('should mapper return overview data for list view with 2 levels', () => { + let EP1 = EntitlementPool.build(); + let LKG1 = LicenseKeyGroup.build(); + let FG1 = FeatureGroup.build(); + let LA1 = LicenseAgreement.build({ + featureGroupsIds: [FG1.id] + }); + let LA2 = LicenseAgreement.build(); + FG1.referencingLicenseAgreements = [LA1.id]; + + const VLM1 = LicenseModelOverviewFactory.build({ + licenseAgreement: { + licenseAgreementList: [LA1, LA2] + }, + featureGroup: { + featureGroupsList: [FG1] + }, + entitlementPool: { + entitlementPoolsList: [EP1] + }, + licenseKeyGroup: { + licenseKeyGroupsList: [LKG1] + }, + }); + + const state = { + licenseModel: VLM1 + }; + + const expectedLicensingDataList = [ + LicenseAgreementDataListFactory.build({ + ...LA1, + children: [ + FeatureGroupDataListFactory.build(FG1) + ] + }), + LicenseAgreementDataListFactory.build(LA2) + ]; + + var props = mapStateToProps(state); + + expect(props.isReadOnlyMode).toEqual(true); + expect(props.isDisplayModal).toEqual(false); + expect(props.modalHeader).toEqual(undefined); + expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); + expect(props.licensingDataList).toEqual(expectedLicensingDataList); + expect(props.selectedTab).toEqual(selectedButton.VLM_LIST_VIEW); + }); + + it('should mapper return overview data for Full NOT-IN-USE list view', () => { + let EP1 = EntitlementPool.build(); + let LKG1 = LicenseKeyGroup.build(); + let FG1 = FeatureGroup.build(); + + const VLM1 = LicenseModelOverviewFactory.build({ + licenseAgreement: { licenseAgreementList: [] }, + featureGroup: { + featureGroupsList: [FG1] + }, + entitlementPool: { + entitlementPoolsList: [EP1] + }, + licenseKeyGroup: { + licenseKeyGroupsList: [LKG1] + }, + licenseModelOverview: { + selectedTab: selectedButton.NOT_IN_USE + } + }); + + const state = { + licenseModel: VLM1 + }; + + const expectedLicensingDataList = [ + FeatureGroupDataListFactory.build(FG1), + EntitlementPoolDataListFactory.build(EP1), + LicenseKeyGroupDataListFactory.build(LKG1) + ]; + + var props = mapStateToProps(state); + + expect(props.isReadOnlyMode).toEqual(true); + expect(props.isDisplayModal).toEqual(false); + expect(props.modalHeader).toEqual(undefined); + expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); + expect(props.licensingDataList).toEqual(expectedLicensingDataList); + expect(props.selectedTab).toEqual(selectedButton.NOT_IN_USE); + }); + + it('should mapper return overview data for NOT-IN-USE list view (FG with children)', () => { + let EP1 = EntitlementPool.build(); + let LKG1 = LicenseKeyGroup.build(); + let FG1 = FeatureGroup.build({ + entitlementPoolsIds: [EP1.id], + licenseKeyGroupsIds: [LKG1.id] + }); + EP1.referencingFeatureGroups = [FG1.id]; + LKG1.referencingFeatureGroups = [FG1.id]; + + const VLM1 = LicenseModelOverviewFactory.build({ + licenseAgreement: { licenseAgreementList: [] }, + featureGroup: { + featureGroupsList: [FG1] + }, + entitlementPool: { + entitlementPoolsList: [EP1] + }, + licenseKeyGroup: { + licenseKeyGroupsList: [LKG1] + }, + licenseModelOverview: { + selectedTab: selectedButton.NOT_IN_USE + } + }); + + const state = { + licenseModel: VLM1 + }; + + const expectedLicensingDataList = [ + FeatureGroupDataListFactory.build({ + ...FG1, + children: [ + EntitlementPoolDataListFactory.build(EP1), + LicenseKeyGroupDataListFactory.build(LKG1)] + }) + ]; + + var props = mapStateToProps(state); + + expect(props.isReadOnlyMode).toEqual(true); + expect(props.isDisplayModal).toEqual(false); + expect(props.modalHeader).toEqual(undefined); + expect(props.licenseModelId).toEqual(VLM1.licenseModelEditor.data.id); + expect(props.licensingDataList).toEqual(expectedLicensingDataList); + expect(props.selectedTab).toEqual(selectedButton.NOT_IN_USE); + }); +}); diff --git a/openecomp-ui/test/licenseModel/overview/views.test.js b/openecomp-ui/test/licenseModel/overview/views.test.js new file mode 100644 index 0000000000..4a38afccca --- /dev/null +++ b/openecomp-ui/test/licenseModel/overview/views.test.js @@ -0,0 +1,159 @@ +/*! + * 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. + */ + +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import {scryRenderedDOMComponentsWithTestId} from 'test-utils/Util.js'; +import SummaryView from 'sdc-app/onboarding/licenseModel/overview/SummaryView.jsx'; +import LicenseModelOverviewView from 'sdc-app/onboarding/licenseModel/overview/LicenseModelOverviewView.jsx'; +import VLMListView from 'sdc-app/onboarding/licenseModel/overview/VLMListView.jsx'; +import {selectedButton} from 'sdc-app/onboarding/licenseModel/overview/LicenseModelOverviewConstants.js'; + +import {FeatureGroupListItemFactory} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js'; +import {EntitlementPoolListItemFactory} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js'; +import {LicenseKeyGroupListItemFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js'; +import {LicenseAgreementListItemFactory} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js'; + +describe('License Model Overview - View: ', function () { + + const lkgChild = LicenseKeyGroupListItemFactory.build(); + + const epChild = EntitlementPoolListItemFactory.build(); + + const baseFGData = FeatureGroupListItemFactory.build({isCollapsed: false}); + const baseLAData = LicenseAgreementListItemFactory.build({isCollapse: false}); + + it('should render SummaryView', () => { + var renderer = TestUtils.createRenderer(); + renderer.render( + + ); + let renderedOutput = renderer.getRenderOutput(); + expect(renderedOutput).toBeTruthy(); + }); + + it('should render LicenseModelOverviewView', () => { + let fgData = {...baseFGData}; + fgData.children = Array.of(epChild, lkgChild); + let laData = {...baseLAData}; + laData.children = [fgData]; + + const params = { + licenseModelId: 'VLM1', + isDisplayModal: false, + modalHeader: undefined, + licensingDataList: [laData], + selectedTab: selectedButton.VLM_LIST_VIEW, + onTabSelect: () => {} + }; + var renderer = TestUtils.createRenderer(); + renderer.render( + + ); + let renderedOutput = renderer.getRenderOutput(); + expect(renderedOutput).toBeTruthy(); + }); + + + it('should render empty VLMListView', () => { + const listview = TestUtils.renderIntoDocument( ); + expect(listview).toBeTruthy(); + const elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list'); + expect(elem).toBeTruthy(); + expect(elem[0].children.length).toBe(0); + }); + + it('should render VLMListView with licenseAgreement', () => { + const listview = TestUtils.renderIntoDocument( ); + expect(listview).toBeTruthy(); + let elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list'); + expect(elem).toBeTruthy(); + expect(elem[0].children.length).toBe(1); + elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-la-item'); + expect(elem).toBeTruthy(); + expect(elem.length).toBe(1); + }); + + it('should render VLMListView with Feature Group', () => { + let laData = {...baseLAData}; + laData.children = [baseFGData]; + const listview = TestUtils.renderIntoDocument( ); + expect(listview).toBeTruthy(); + const elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-item-fg'); + expect(elem).toBeTruthy(); + expect(elem.length).toBe(1); + }); + + it('should render VLMListView with Entitlement Pool', () => { + let fgData = {...baseFGData}; + fgData.children = [epChild]; + let laData = {...baseLAData}; + laData.children = [fgData]; + + const listview = TestUtils.renderIntoDocument( ); + expect(listview).toBeTruthy(); + const elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-item-ep'); + expect(elem).toBeTruthy(); + expect(elem.length).toBe(1); + }); + + it('should render VLMListView with LicenseKeyGroup', () => { + let fgData = {...baseFGData}; + fgData.children = [lkgChild]; + let laData = {...baseLAData}; + laData.children = [fgData]; + + const listview = TestUtils.renderIntoDocument( ); + expect(listview).toBeTruthy(); + const elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-item-lkg'); + expect(elem).toBeTruthy(); + expect(elem.length).toBe(1); + }); + + it('should render VLMListView with all items', () => { + let fgData = {...baseFGData}; + fgData.children = Array.of(epChild, lkgChild); + let laData = {...baseLAData}; + laData.children = [fgData]; + + const listview = TestUtils.renderIntoDocument( ); + expect(listview).toBeTruthy(); + let elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-item-fg'); + expect(elem).toBeTruthy(); + expect(elem.length).toBe(1); + elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-item-lkg'); + expect(elem).toBeTruthy(); + expect(elem.length).toBe(1); + elem = scryRenderedDOMComponentsWithTestId(listview,'vlm-list-item-ep'); + expect(elem).toBeTruthy(); + expect(elem.length).toBe(1); + }); + + it('should update collapsing item', () => { + let fgData = {...baseFGData}; + fgData.children = Array.of(epChild, lkgChild); + let laData = {...baseLAData}; + laData.children = [fgData]; + + var renderer = TestUtils.renderIntoDocument( + + ); + expect(renderer).toBeTruthy(); + + renderer.updateCollapsable(new Event('click'), 'LA1'); + expect(renderer.state['LA1']).toEqual(true); + }); +}); diff --git a/openecomp-ui/test/licenseModel/test.js b/openecomp-ui/test/licenseModel/test.js index c21d18f146..eac1297f3e 100644 --- a/openecomp-ui/test/licenseModel/test.js +++ b/openecomp-ui/test/licenseModel/test.js @@ -1,57 +1,40 @@ -/*- - * ============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 - * + * + * 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========================================================= + * 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. */ - -import {expect} from 'chai'; 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 LicenseModelCreationActionHelper from 'sdc-app/onboarding/licenseModel/creation/LicenseModelCreationActionHelper.js'; +import {LicenseModelPostFactory, LicenseModelDispatchFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; + describe('License Model Module Tests', function () { it('Add License Model', () => { const store = storeCreator(); deepFreeze(store.getState()); - const licenseModelPostRequest = deepFreeze({ - vendorName: 'vlm1', - description: 'string', - iconRef: 'icon' - }); + const licenseModelPostRequest = LicenseModelPostFactory.build(); - const licenseModelToAdd = deepFreeze({ - ...licenseModelPostRequest - }); + const licenseModelToAdd = LicenseModelDispatchFactory.build(); const licenseModelIdFromResponse = 'ADDED_ID'; - const licenseModelAfterAdd = deepFreeze({ - ...licenseModelToAdd, - id: licenseModelIdFromResponse - }); - - const expectedStore = cloneAndSet(store.getState(), 'licenseModelList', [licenseModelAfterAdd]); - - mockRest.addHandler('create', ({options, data, baseUrl}) => { - expect(baseUrl).to.equal('/onboarding-api/v1.0/vendor-license-models/'); - expect(data).to.deep.equal(licenseModelPostRequest); - expect(options).to.equal(undefined); + + mockRest.addHandler('post', ({options, data, baseUrl}) => { + expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-license-models/'); + expect(data).toEqual(licenseModelPostRequest); + expect(options).toEqual(undefined); return { value: licenseModelIdFromResponse }; @@ -59,8 +42,8 @@ describe('License Model Module Tests', function () { return LicenseModelCreationActionHelper.createLicenseModel(store.dispatch, { licenseModel: licenseModelToAdd - }).then(() => { - expect(store.getState()).to.deep.equal(expectedStore); + }).then((response) => { + expect(response.value).toEqual(licenseModelIdFromResponse); }); }); }); -- cgit 1.2.3-korg