talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 1 | /*! |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 2 | * Copyright © 2016-2018 European Support Limited |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 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'; |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 19 | import { cloneAndSet } from 'test-utils/Util.js'; |
| 20 | import { storeCreator } from 'sdc-app/AppStore.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 21 | |
| 22 | import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js'; |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 23 | import { VSPEditorFactoryWithLicensingData } from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 24 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 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'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 29 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 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( |
| 34 | {}, |
| 35 | { version } |
| 36 | ); |
| 37 | const softwareProduct = VSPEditorFactoryWithLicensingData.build(); |
| 38 | deepFreeze(softwareProduct); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 39 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 40 | const store = storeCreator({ |
| 41 | currentScreen: { ...itemPermissionAndProps }, |
| 42 | softwareProduct: { |
| 43 | softwareProductEditor: { data: softwareProduct }, |
| 44 | softwareProductQuestionnaire: { |
| 45 | qdata: 'test', |
| 46 | qschema: { type: 'string' } |
| 47 | } |
| 48 | } |
| 49 | }); |
| 50 | deepFreeze(store.getState()); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 51 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 52 | const certifiedVersion = { |
| 53 | ...itemPermissionAndProps.props.version, |
| 54 | status: 'Certified' |
| 55 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 56 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 57 | const versionsList = { |
| 58 | itemType: itemTypes.SOFTWARE_PRODUCT, |
| 59 | itemId: softwareProduct.id, |
| 60 | versions: [{ ...certifiedVersion }] |
| 61 | }; |
| 62 | const expectedCurrentScreenProps = { |
| 63 | itemPermission: { |
| 64 | ...itemPermissionAndProps.itemPermission, |
| 65 | isCertified: true |
| 66 | }, |
| 67 | props: { |
| 68 | isReadOnlyMode: true, |
| 69 | version: certifiedVersion |
| 70 | } |
| 71 | }; |
| 72 | const expectedSuccessModal = { |
| 73 | cancelButtonText: 'OK', |
| 74 | modalClassName: 'notification-modal', |
| 75 | msg: 'This software product successfully submitted', |
| 76 | timeout: 2000, |
| 77 | title: 'Submit Succeeded', |
| 78 | type: 'success' |
| 79 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 80 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 81 | let expectedStore = store.getState(); |
| 82 | expectedStore = cloneAndSet( |
| 83 | expectedStore, |
| 84 | 'currentScreen.itemPermission', |
| 85 | expectedCurrentScreenProps.itemPermission |
| 86 | ); |
| 87 | expectedStore = cloneAndSet( |
| 88 | expectedStore, |
| 89 | 'currentScreen.props', |
| 90 | expectedCurrentScreenProps.props |
| 91 | ); |
| 92 | expectedStore = cloneAndSet( |
| 93 | expectedStore, |
| 94 | 'modal', |
| 95 | expectedSuccessModal |
| 96 | ); |
| 97 | expectedStore = cloneAndSet( |
| 98 | expectedStore, |
| 99 | 'versionsPage.versionsList', |
| 100 | versionsList |
| 101 | ); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 102 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 103 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 104 | expect(baseUrl).toEqual( |
| 105 | `/onboarding-api/v1.0/vendor-software-products/${ |
| 106 | softwareProduct.id |
| 107 | }/versions/${version.id}/actions` |
| 108 | ); |
| 109 | expect(data).toEqual({ |
| 110 | action: VersionControllerActionsEnum.SUBMIT |
| 111 | }); |
| 112 | expect(options).toEqual(undefined); |
| 113 | return { returnCode: 'OK' }; |
| 114 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 115 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 116 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 117 | expect(baseUrl).toEqual( |
| 118 | `/onboarding-api/v1.0/vendor-software-products/${ |
| 119 | softwareProduct.id |
| 120 | }/versions/${version.id}/actions` |
| 121 | ); |
| 122 | expect(data).toEqual({ |
| 123 | action: VersionControllerActionsEnum.CREATE_PACKAGE |
| 124 | }); |
| 125 | expect(options).toEqual(undefined); |
| 126 | return { returnCode: 'OK' }; |
| 127 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 128 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 129 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 130 | expect(baseUrl).toEqual( |
| 131 | `/onboarding-api/v1.0/items/${softwareProduct.id}/versions/${ |
| 132 | version.id |
| 133 | }` |
| 134 | ); |
| 135 | expect(data).toEqual(undefined); |
| 136 | expect(options).toEqual(undefined); |
| 137 | return { |
| 138 | ...certifiedVersion, |
| 139 | state: { |
| 140 | synchronizationState: SyncStates.UP_TO_DATE, |
| 141 | dirty: false |
| 142 | } |
| 143 | }; |
| 144 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 145 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 146 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 147 | expect(baseUrl).toEqual( |
| 148 | `/onboarding-api/v1.0/items/${softwareProduct.id}` |
| 149 | ); |
| 150 | expect(data).toEqual(undefined); |
| 151 | expect(options).toEqual(undefined); |
| 152 | return { ...certifiedVersion }; |
| 153 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 154 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 155 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 156 | expect(baseUrl).toEqual( |
| 157 | `/onboarding-api/v1.0/items/${softwareProduct.id}/versions` |
| 158 | ); |
| 159 | expect(data).toEqual(undefined); |
| 160 | expect(options).toEqual(undefined); |
| 161 | return { results: [{ ...certifiedVersion }] }; |
| 162 | }); |
| 163 | |
| 164 | return SoftwareProductActionHelper.performSubmitAction(store.dispatch, { |
| 165 | softwareProductId: softwareProduct.id, |
| 166 | version |
| 167 | }).then(() => { |
| 168 | expect(store.getState()).toEqual(expectedStore); |
| 169 | }); |
| 170 | }); |
| 171 | }); |