AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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 React from 'react'; |
| 18 | import {mount} from 'enzyme'; |
| 19 | import {mapStateToProps} from 'sdc-app/onboarding/softwareProduct/dependencies/SoftwareProductDependencies.js'; |
| 20 | import { |
| 21 | SoftwareProductDependenciesResponseFactory, |
| 22 | SoftwareProductDependenciesStoreFactory} from 'test-utils/factories/softwareProduct/SoftwareProductDependenciesFactories.js'; |
| 23 | import {VSPComponentsFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsFactories.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 24 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 25 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 26 | import {cloneAndSet} from 'test-utils/Util.js'; |
| 27 | import mockRest from 'test-utils/MockRest.js'; |
| 28 | |
| 29 | import SoftwareProductComponentsActionHelper from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponentsActionHelper.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 30 | import {relationTypes, NEW_RULE_TEMP_ID} from 'sdc-app/onboarding/softwareProduct/dependencies/SoftwareProductDependenciesConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 31 | import SoftwareProductDependenciesActionHelper from 'sdc-app/onboarding/softwareProduct/dependencies/SoftwareProductDependenciesActionHelper.js'; |
| 32 | import SoftwareProductDependenciesView from 'sdc-app/onboarding/softwareProduct/dependencies/SoftwareProductDependenciesView.jsx'; |
| 33 | import {VSPEditorFactory} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js'; |
| 34 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 35 | function addNewRowElement(arr, data) { |
| 36 | if (data === undefined) { |
| 37 | arr.push({id: NEW_RULE_TEMP_ID, targetId: null, sourceId: null, relationType: relationTypes.DEPENDS_ON}); |
| 38 | } else { |
| 39 | arr.push(data); |
| 40 | } |
| 41 | } |
| 42 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 43 | describe('Software Product Dependencies Module Tests', function () { |
| 44 | const softwareProductId = '555'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 45 | const version = VersionFactory.build(); |
| 46 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 47 | |
| 48 | it('mapStateToProps mapper exists', () => { |
| 49 | expect(mapStateToProps).toBeTruthy(); |
| 50 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 51 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 52 | it('Get Software Product Dependencies List', () => { |
| 53 | const store = storeCreator(); |
| 54 | const dispatch = store.dispatch; |
| 55 | |
| 56 | let DependenciesListResponse = SoftwareProductDependenciesResponseFactory.buildList(2); |
| 57 | let DependenciesListStore = DependenciesListResponse.map(dependency => SoftwareProductDependenciesStoreFactory.build(dependency)); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 58 | addNewRowElement(DependenciesListStore); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 59 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductDependencies', DependenciesListStore); |
| 60 | |
| 61 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 62 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/component-dependencies`); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 63 | expect(data).toEqual(undefined); |
| 64 | expect(options).toEqual(undefined); |
| 65 | return {results: DependenciesListResponse}; |
| 66 | }); |
| 67 | |
| 68 | return SoftwareProductDependenciesActionHelper.fetchDependencies(dispatch, {softwareProductId, version}).then(() => { |
| 69 | const state = store.getState(); |
| 70 | const depndenciesWithGeneratedId = state.softwareProduct.softwareProductDependencies; |
| 71 | const currentDependencies = expectedStore.softwareProduct.softwareProductDependencies; |
| 72 | let expectedStoreDependencies = currentDependencies.map((dependency, index) => ({...dependency, id: depndenciesWithGeneratedId[index].id})); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 73 | const newExpectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductDependencies', expectedStoreDependencies); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 74 | expect(state).toEqual(newExpectedStore); |
| 75 | }); |
| 76 | }); |
| 77 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 78 | /* |
| 79 | Test update: |
| 80 | - fetch initial item |
| 81 | - update existing item |
| 82 | - auto fetch again |
| 83 | */ |
| 84 | it('Update Software Product Dependency', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 85 | const store = storeCreator(); |
| 86 | const dispatch = store.dispatch; |
| 87 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 88 | let DependenciesListResponse = SoftwareProductDependenciesResponseFactory.buildList(1); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 89 | let DependenciesListStore = DependenciesListResponse.map(dependency => SoftwareProductDependenciesStoreFactory.build(dependency)); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 90 | addNewRowElement(DependenciesListStore); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 91 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductDependencies', DependenciesListStore); |
| 92 | |
| 93 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 94 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/component-dependencies`); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 95 | expect(data).toEqual(undefined); |
| 96 | expect(options).toEqual(undefined); |
| 97 | return {results: DependenciesListResponse}; |
| 98 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 99 | return SoftwareProductDependenciesActionHelper.fetchDependencies(dispatch, {softwareProductId, version}).then(() => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 100 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 101 | const state = store.getState(); |
| 102 | const depndenciesWithGeneratedId = state.softwareProduct.softwareProductDependencies; |
| 103 | const currentDependencies = expectedStore.softwareProduct.softwareProductDependencies; |
| 104 | let expectedStoreDependencies = currentDependencies.map((dependency, index) => ({...dependency, id: depndenciesWithGeneratedId[index].id})); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 105 | let item = expectedStoreDependencies.find((dep) => dep.id !== NEW_RULE_TEMP_ID); |
| 106 | item.targetId = 'testChangeTarget'; |
| 107 | item.sourceId = 'testChangesource'; |
| 108 | // removing 'new row' from response |
| 109 | expectedStoreDependencies = expectedStoreDependencies.slice(0, expectedStoreDependencies.length - 1); |
| 110 | let expDependenciesListStore = expectedStoreDependencies.map(dependency => SoftwareProductDependenciesStoreFactory.build(dependency)); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 111 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 112 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 113 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/component-dependencies/${item.id}`); |
| 114 | expect(data.targetId).toEqual('testChangeTarget'); |
| 115 | expect(data.sourceId).toEqual('testChangesource'); |
| 116 | expect(options).toEqual(undefined); |
| 117 | return {results: null}; |
| 118 | }); |
| 119 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 120 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/component-dependencies`); |
| 121 | expect(data).toEqual(undefined); |
| 122 | expect(options).toEqual(undefined); |
| 123 | return {results: expDependenciesListStore}; |
| 124 | }); |
| 125 | |
| 126 | addNewRowElement(expectedStoreDependencies); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 127 | const newExpectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductDependencies', expectedStoreDependencies); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 128 | return SoftwareProductDependenciesActionHelper.updateDependency(dispatch, {softwareProductId, version, item}).then(() => { |
| 129 | const newState = store.getState(); |
| 130 | expect(newState).toEqual(newExpectedStore); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 131 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 132 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 133 | }); |
| 134 | }); |
| 135 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 136 | /* |
| 137 | - Fetch item list |
| 138 | - Delete item from list |
| 139 | - Fetch again |
| 140 | */ |
| 141 | it('Delete Software Product Dependency', () => { |
| 142 | const store = storeCreator(); |
| 143 | const dispatch = store.dispatch; |
| 144 | let DependenciesListResponse = SoftwareProductDependenciesResponseFactory.buildList(1); |
| 145 | let DependenciesListStore = DependenciesListResponse.map(dependency => SoftwareProductDependenciesStoreFactory.build(dependency)); |
| 146 | addNewRowElement(DependenciesListStore); |
| 147 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductDependencies', DependenciesListStore); |
| 148 | |
| 149 | let deleteItem = DependenciesListStore.find((dep) => dep.id !== NEW_RULE_TEMP_ID); |
| 150 | |
| 151 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 152 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/component-dependencies`); |
| 153 | expect(data).toEqual(undefined); |
| 154 | expect(options).toEqual(undefined); |
| 155 | return {results: DependenciesListResponse}; |
| 156 | }); |
| 157 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
| 158 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/component-dependencies/${deleteItem.id}`); |
| 159 | expect(data).toEqual(undefined); |
| 160 | expect(options).toEqual(undefined); |
| 161 | return {results: null}; |
| 162 | }); |
| 163 | return SoftwareProductDependenciesActionHelper.fetchDependencies(dispatch, {softwareProductId, version}).then(() => { |
| 164 | const state = store.getState(); |
| 165 | const depndenciesWithGeneratedId = state.softwareProduct.softwareProductDependencies; |
| 166 | const currentDependencies = expectedStore.softwareProduct.softwareProductDependencies; |
| 167 | let expectedStoreDependencies = currentDependencies.map((dependency, index) => ({...dependency, id: depndenciesWithGeneratedId[index].id})) |
| 168 | |
| 169 | const newExpectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductDependencies', expectedStoreDependencies); |
| 170 | expect(state).toEqual(newExpectedStore); |
| 171 | |
| 172 | expectedStoreDependencies = expectedStoreDependencies.filter((dep) => dep.id !== deleteItem.id); |
| 173 | const postDeleteExpectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductDependencies', expectedStoreDependencies); |
| 174 | |
| 175 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 176 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/component-dependencies`); |
| 177 | expect(data).toEqual(undefined); |
| 178 | expect(options).toEqual(undefined); |
| 179 | return {results: []}; |
| 180 | }); |
| 181 | |
| 182 | return SoftwareProductDependenciesActionHelper.removeDependency(dispatch, {softwareProductId, version, item: deleteItem}).then(() => { |
| 183 | const state = store.getState(); |
| 184 | const depndenciesWithGeneratedId = state.softwareProduct.softwareProductDependencies; |
| 185 | const currentDependencies = postDeleteExpectedStore.softwareProduct.softwareProductDependencies; |
| 186 | expect(depndenciesWithGeneratedId).toEqual(currentDependencies); |
| 187 | }); |
| 188 | }); |
| 189 | }); |
| 190 | |
| 191 | /* |
| 192 | - Create initial list |
| 193 | - Update the new row and make sure there is no API call |
| 194 | - Submit the new row |
| 195 | - Getch data with reset new row and new entity with info from the new item |
| 196 | */ |
| 197 | |
| 198 | it('Create Software Product Dependency', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 199 | const store = storeCreator(); |
| 200 | const dispatch = store.dispatch; |
| 201 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 202 | let DependenciesListResponse = SoftwareProductDependenciesResponseFactory.buildList(1); |
| 203 | let DependenciesListStore = DependenciesListResponse.map(dependency => SoftwareProductDependenciesStoreFactory.build(dependency)); |
| 204 | addNewRowElement(DependenciesListStore); |
| 205 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductDependencies', DependenciesListStore); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 206 | |
| 207 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 208 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/component-dependencies`); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 209 | expect(data).toEqual(undefined); |
| 210 | expect(options).toEqual(undefined); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 211 | return {results: DependenciesListResponse}; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 212 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 213 | return SoftwareProductDependenciesActionHelper.fetchDependencies(dispatch, {softwareProductId, version}).then(() => { |
| 214 | // setting properties on the 'new role' should not call an API |
| 215 | let addItem = {id: NEW_RULE_TEMP_ID, sourceId: 'sId', targetId : 'tId',relationType: relationTypes.DEPENDS_ON}; |
| 216 | try { |
| 217 | SoftwareProductDependenciesActionHelper.updateDependency(dispatch, {softwareProductId, version, item: addItem}).then(()=> { |
| 218 | //go to error that fetch was not defined |
| 219 | }); |
| 220 | } catch (error) { |
| 221 | if(error.name === 'TypeError') { |
| 222 | // Expected error because we expected there is no promise |
| 223 | } else { |
| 224 | fail('Error:' + error); |
| 225 | } |
| 226 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 227 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 228 | const state = store.getState(); |
| 229 | const depndenciesWithGeneratedId = state.softwareProduct.softwareProductDependencies; |
| 230 | const currentDependencies = expectedStore.softwareProduct.softwareProductDependencies; |
| 231 | let expectedStoreDependencies = currentDependencies.map((dependency, index) => ({...dependency, id: depndenciesWithGeneratedId[index].id})); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 232 | // creating the new item |
| 233 | let item = SoftwareProductDependenciesResponseFactory.buildList(1, |
| 234 | {sourceId: 'sId', targetId : 'tId',relationType: relationTypes.DEPENDS_ON})[0]; |
| 235 | addNewRowElement(expectedStoreDependencies, item); |
| 236 | expectedStoreDependencies = expectedStoreDependencies.filter((dep) => dep.id !== NEW_RULE_TEMP_ID); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 237 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 238 | mockRest.addHandler('post', ({data, options, baseUrl}) => { |
| 239 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/component-dependencies`); |
| 240 | expect(data.targetId).toEqual('tId'); |
| 241 | expect(data.sourceId).toEqual('sId'); |
| 242 | expect(data.id).toEqual(undefined); |
| 243 | expect(options).toEqual(undefined); |
| 244 | return {results: item.id}; |
| 245 | }); |
| 246 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 247 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/component-dependencies`); |
| 248 | expect(data).toEqual(undefined); |
| 249 | expect(options).toEqual(undefined); |
| 250 | return {results: expectedStoreDependencies}; |
| 251 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 252 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 253 | let PostCreateItemListStore = expectedStoreDependencies.map(dependency => SoftwareProductDependenciesStoreFactory.build(dependency)); |
| 254 | addNewRowElement(PostCreateItemListStore); |
| 255 | const newExpectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductDependencies', PostCreateItemListStore); |
| 256 | |
| 257 | return SoftwareProductDependenciesActionHelper.createDependency(dispatch, {softwareProductId, version, item: addItem}).then(() => { |
| 258 | const newState = store.getState(); |
| 259 | expect(newState.softwareProduct.softwareProductDependencies.length).toEqual(3); |
| 260 | expect(newState).toEqual(newExpectedStore); |
| 261 | }); |
| 262 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 263 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 264 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 265 | }); |
| 266 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 267 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 268 | it('Get Software Product Dependencies List with loop, and render to JSX', () => { |
| 269 | const store = storeCreator(); |
| 270 | const dispatch = store.dispatch; |
| 271 | |
| 272 | let components = VSPComponentsFactory.buildList(2); |
| 273 | let vspEditor = VSPEditorFactory.build({id: softwareProductId, version}); |
| 274 | |
| 275 | let DependenciesListResponse = SoftwareProductDependenciesResponseFactory.buildList(2); |
| 276 | let firstDependecy = DependenciesListResponse[0]; |
| 277 | let secondDependency = DependenciesListResponse[1]; |
| 278 | firstDependecy.sourceId = components[0].id; |
| 279 | secondDependency.sourceId = components[1].id; |
| 280 | firstDependecy.targetId = secondDependency.sourceId; |
| 281 | secondDependency.targetId = firstDependecy.sourceId; |
| 282 | |
| 283 | let DependenciesListStore = DependenciesListResponse.map(dependency => SoftwareProductDependenciesStoreFactory.build({...dependency, hasCycle: true})); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 284 | addNewRowElement(DependenciesListStore); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 285 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductDependencies', DependenciesListStore); |
| 286 | |
| 287 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 288 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/component-dependencies`); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 289 | expect(data).toEqual(undefined); |
| 290 | expect(options).toEqual(undefined); |
| 291 | return {results: DependenciesListResponse}; |
| 292 | }); |
| 293 | |
| 294 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 295 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/components`); |
| 296 | expect(data).toEqual(undefined); |
| 297 | expect(options).toEqual(undefined); |
| 298 | return {results: components}; |
| 299 | }); |
| 300 | |
| 301 | return SoftwareProductDependenciesActionHelper.fetchDependencies(dispatch, {softwareProductId, version}).then(() => { |
| 302 | return SoftwareProductComponentsActionHelper.fetchSoftwareProductComponents(dispatch, {softwareProductId, version}); |
| 303 | }).then(() => { |
ilanap | 1965d16 | 2018-01-04 11:34:59 +0200 | [diff] [blame^] | 304 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 305 | const state = store.getState(); |
| 306 | state.softwareProduct.softwareProductEditor = {data: vspEditor}; |
| 307 | const depndenciesWithGeneratedId = state.softwareProduct.softwareProductDependencies; |
| 308 | const currentDependencies = expectedStore.softwareProduct.softwareProductDependencies; |
| 309 | let expectedStoreDependencies = currentDependencies.map((dependency, index) => ({...dependency, id: depndenciesWithGeneratedId[index].id})); |
| 310 | |
| 311 | const newExpectedStore = { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 312 | ...expectedStore, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 313 | softwareProduct: { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 314 | ...expectedStore.softwareProduct, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 315 | softwareProductDependencies: expectedStoreDependencies, |
| 316 | softwareProductEditor: {data: vspEditor}, |
| 317 | softwareProductComponents: { |
| 318 | ...expectedStore.softwareProduct.softwareProductComponents, |
| 319 | componentsList: components |
| 320 | } |
| 321 | } |
| 322 | }; |
| 323 | |
| 324 | expect(state).toEqual(newExpectedStore); |
| 325 | |
| 326 | const props = mapStateToProps(state); |
| 327 | expect(props.softwareProductDependencies).toEqual(expectedStoreDependencies); |
ilanap | 1965d16 | 2018-01-04 11:34:59 +0200 | [diff] [blame^] | 328 | /* |
| 329 | Fails on some weird react error about 2 react's loaded - may be some dependency |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 330 | const wrapper = mount(<SoftwareProductDependenciesView {...props}/>); |
| 331 | expect(wrapper).toBeTruthy(); |
ilanap | 1965d16 | 2018-01-04 11:34:59 +0200 | [diff] [blame^] | 332 | */ |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 333 | }); |
| 334 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 335 | |
| 336 | }); |