Add collaboration feature
[sdc.git] / openecomp-ui / test / softwareProduct / test.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16
17 import 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';
21
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';
29
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({}, {version});
34                 const softwareProduct = VSPEditorFactoryWithLicensingData.build();
35                 deepFreeze(softwareProduct);
36
37                 const store = storeCreator({
38                         currentScreen: {...itemPermissionAndProps},
39                         softwareProduct: {
40                                 softwareProductEditor: {data: softwareProduct},
41                                 softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}}
42                         }
43                 });
44                 deepFreeze(store.getState());
45
46                 const certifiedVersion = {
47                         ...itemPermissionAndProps.props.version,
48                         status: 'Certified'
49                 };
50
51                 const versionsList = {
52                         itemType: itemTypes.SOFTWARE_PRODUCT,
53                         itemId: softwareProduct.id,
54                         versions: [{...certifiedVersion}]
55                 };
56                 const expectedCurrentScreenProps = {
57                         itemPermission: {
58                                 ...itemPermissionAndProps.itemPermission,
59                                 isCertified: true
60                         },
61                         props: {
62                                 isReadOnlyMode: true,
63                                 version: certifiedVersion
64                         }
65                 };
66                 const expectedSuccessModal = {
67                         cancelButtonText: 'OK',
68                         modalClassName: 'notification-modal',
69                         msg: 'This software product successfully submitted',
70                         timeout: 2000,
71                         title: 'Submit Succeeded',
72                         type: 'success'
73                 };
74
75                 let expectedStore = store.getState();
76                 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
77                 expectedStore = cloneAndSet(expectedStore, 'currentScreen.props', expectedCurrentScreenProps.props);
78                 expectedStore = cloneAndSet(expectedStore, 'modal', expectedSuccessModal);
79                 expectedStore = cloneAndSet(expectedStore, 'versionsPage.versionsList', versionsList );
80
81                 mockRest.addHandler('put', ({data, options, baseUrl}) => {
82                         expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProduct.id}/versions/${version.id}/actions`);
83                         expect(data).toEqual({action: VersionControllerActionsEnum.SUBMIT});
84                         expect(options).toEqual(undefined);
85                         return {returnCode: 'OK'};
86                 });
87
88                 mockRest.addHandler('put', ({data, options, baseUrl}) => {
89                         expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProduct.id}/versions/${version.id}/actions`);
90                         expect(data).toEqual({action: VersionControllerActionsEnum.CREATE_PACKAGE});
91                         expect(options).toEqual(undefined);
92                         return {returnCode: 'OK'};
93                 });
94
95                 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
96                         expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${softwareProduct.id}/versions/${version.id}`);
97                         expect(data).toEqual(undefined);
98                         expect(options).toEqual(undefined);
99                         return {...certifiedVersion, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: false}};
100                 });
101
102                 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
103                         expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${softwareProduct.id}/versions`);
104                         expect(data).toEqual(undefined);
105                         expect(options).toEqual(undefined);
106                         return {results: [{...certifiedVersion}]};
107                 });
108
109                 return SoftwareProductActionHelper.performSubmitAction(store.dispatch, {
110                         softwareProductId: softwareProduct.id,
111                         version
112                 }).then(() => {
113                         expect(store.getState()).toEqual(expectedStore);
114                 });
115         });
116 });