2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
17 import deepFreeze from 'deep-freeze';
18 import mockRest from 'test-utils/MockRest.js';
19 import { cloneAndSet } from 'test-utils/Util.js';
20 import { storeCreator } from 'sdc-app/AppStore.js';
22 import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js';
23 import { VSPEditorFactoryWithLicensingData } from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js';
24 import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
25 import { default as CurrentScreenFactory } from 'test-utils/factories/common/CurrentScreenFactory.js';
26 import { actionsEnum as VersionControllerActionsEnum } from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
27 import { SyncStates } from 'sdc-app/common/merge/MergeEditorConstants.js';
28 import { itemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
30 describe('Software Product Module Tests', function() {
31 it('Validating readonly screen after submit', () => {
32 const version = VersionFactory.build({}, { isCertified: false });
33 const itemPermissionAndProps = CurrentScreenFactory.build(
37 const softwareProduct = VSPEditorFactoryWithLicensingData.build();
38 deepFreeze(softwareProduct);
40 const store = storeCreator({
41 currentScreen: { ...itemPermissionAndProps },
43 softwareProductEditor: { data: softwareProduct },
44 softwareProductQuestionnaire: {
46 qschema: { type: 'string' }
50 deepFreeze(store.getState());
52 const certifiedVersion = {
53 ...itemPermissionAndProps.props.version,
57 const versionsList = {
58 itemType: itemTypes.SOFTWARE_PRODUCT,
59 itemId: softwareProduct.id,
60 versions: [{ ...certifiedVersion }]
62 const expectedCurrentScreenProps = {
64 ...itemPermissionAndProps.itemPermission,
69 version: certifiedVersion
72 const expectedSuccessModal = {
73 cancelButtonText: 'OK',
74 msg: 'This software product successfully submitted',
76 title: 'Submit Succeeded',
80 let expectedStore = store.getState();
81 expectedStore = cloneAndSet(
83 'currentScreen.itemPermission',
84 expectedCurrentScreenProps.itemPermission
86 expectedStore = cloneAndSet(
88 'currentScreen.props',
89 expectedCurrentScreenProps.props
91 expectedStore = cloneAndSet(
96 expectedStore = cloneAndSet(
98 'versionsPage.versionsList',
102 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
103 expect(baseUrl).toEqual(
104 `/onboarding-api/v1.0/vendor-software-products/${
106 }/versions/${version.id}/actions`
108 expect(data).toEqual({
109 action: VersionControllerActionsEnum.SUBMIT
111 expect(options).toEqual(undefined);
112 return { returnCode: 'OK' };
115 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
116 expect(baseUrl).toEqual(
117 `/onboarding-api/v1.0/vendor-software-products/${
119 }/versions/${version.id}/actions`
121 expect(data).toEqual({
122 action: VersionControllerActionsEnum.CREATE_PACKAGE
124 expect(options).toEqual(undefined);
125 return { returnCode: 'OK' };
128 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
129 expect(baseUrl).toEqual(
130 `/onboarding-api/v1.0/items/${softwareProduct.id}/versions/${
134 expect(data).toEqual(undefined);
135 expect(options).toEqual(undefined);
139 synchronizationState: SyncStates.UP_TO_DATE,
145 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
146 expect(baseUrl).toEqual(
147 `/onboarding-api/v1.0/items/${softwareProduct.id}`
149 expect(data).toEqual(undefined);
150 expect(options).toEqual(undefined);
151 return { ...certifiedVersion };
154 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
155 expect(baseUrl).toEqual(
156 `/onboarding-api/v1.0/items/${softwareProduct.id}/versions`
158 expect(data).toEqual(undefined);
159 expect(options).toEqual(undefined);
160 return { results: [{ ...certifiedVersion }] };
163 return SoftwareProductActionHelper.performSubmitAction(store.dispatch, {
164 softwareProductId: softwareProduct.id,
167 expect(store.getState()).toEqual(expectedStore);