talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [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 TestUtils from 'react-addons-test-utils'; |
| 19 | import {scryRenderedDOMComponentsWithTestId} from 'test-utils/Util.js'; |
| 20 | import deepFreeze from 'deep-freeze'; |
| 21 | import mockRest from 'test-utils/MockRest.js'; |
| 22 | import {cloneAndSet} from 'test-utils/Util.js'; |
| 23 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 24 | |
| 25 | import {actionsEnum as vcActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; |
| 26 | import Configuration from 'sdc-app/config/Configuration.js'; |
| 27 | import {mapStateToProps, mapActionsToProps} from 'sdc-app/onboarding/revisions/Revisions.js'; |
| 28 | import RevisionsView from 'sdc-app/onboarding/revisions/RevisionsView.jsx'; |
| 29 | import RevisionsActionHelper from 'sdc-app/onboarding/revisions/RevisionsActionHelper.js'; |
| 30 | import {RevisionsPagePropsFactory} from 'test-utils/factories/revisions/RevisionsFactories.js'; |
| 31 | import {UserFactory} from 'test-utils/factories/users/UsersFactories.js'; |
| 32 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
| 33 | import {screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js'; |
| 34 | import ReactTestUtils from 'react-addons-test-utils'; |
| 35 | import {enums} from 'sdc-app/onboarding/OnboardingConstants.js'; |
| 36 | |
| 37 | const state = {}; |
| 38 | state.revisions = RevisionsPagePropsFactory.buildList(2); |
| 39 | state.users = {usersList : UserFactory.buildList(2)}; |
| 40 | state.revisions[0].user = state.users.usersList[0].userId; |
| 41 | state.revisions[1].user = state.users.usersList[1].userId; |
| 42 | |
| 43 | |
| 44 | describe('Revision List Tests', () => { |
| 45 | /* |
| 46 | it ('mapStateToProps mapper exists', () => { |
| 47 | |
| 48 | expect(mapStateToProps).toBeTruthy(); |
| 49 | |
| 50 | }); |
| 51 | |
| 52 | it ('should have state in props', () => { |
| 53 | |
| 54 | const props = mapStateToProps(state); |
| 55 | expect(props.revisions.length).toEqual(2); |
| 56 | |
| 57 | }); |
| 58 | |
| 59 | it('simple jsx test', () => { |
| 60 | |
| 61 | const store = storeCreator(); |
| 62 | const dispatch = store.dispatch; |
| 63 | |
| 64 | const props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch, {})); |
| 65 | const renderer = TestUtils.createRenderer(); |
| 66 | renderer.render(<RevisionsView {...props} />); |
| 67 | |
| 68 | const renderedOutput = renderer.getRenderOutput(); |
| 69 | expect(renderedOutput).toBeTruthy(); |
| 70 | |
| 71 | }); |
| 72 | |
| 73 | it('get list data', () => { |
| 74 | |
| 75 | const store = storeCreator(); |
| 76 | const dispatch = store.dispatch; |
| 77 | |
| 78 | const props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch, {})); |
| 79 | |
| 80 | let revisionsView = TestUtils.renderIntoDocument( |
| 81 | <RevisionsView {...props} /> |
| 82 | ); |
| 83 | let list = scryRenderedDOMComponentsWithTestId(revisionsView,'revision-list-item'); |
| 84 | expect(list.length).toEqual(props.revisions.length); |
| 85 | let revert = scryRenderedDOMComponentsWithTestId(revisionsView,'form-submit-button'); |
| 86 | expect(revert[0].innerHTML).toEqual('Revert'); |
| 87 | let date = scryRenderedDOMComponentsWithTestId(revisionsView,'revision-date'); |
| 88 | expect(date.length).toEqual(props.revisions.length); |
| 89 | expect(date[0].children[0].className).toEqual('revision-date'); |
| 90 | expect(date[0].children[1].className).toEqual('revision-time'); |
| 91 | let user = ReactTestUtils.scryRenderedDOMComponentsWithClass(revisionsView, 'svg-icon-label'); |
| 92 | expect(user[0].innerHTML).toEqual(state.users.usersList[0].fullName); |
| 93 | expect(user[1].innerHTML).toEqual(state.users.usersList[1].fullName); |
| 94 | let message = scryRenderedDOMComponentsWithTestId(revisionsView,'revision-message'); |
| 95 | expect(message[0].children[0].innerHTML).toEqual('Show Message With More Mock'); |
| 96 | expect(message[1].children[0].innerHTML).toEqual('Show Message Mock'); |
| 97 | }); |
| 98 | */ |
| 99 | |
| 100 | }); |
| 101 | |
| 102 | |
| 103 | describe('Revisions Action Helper', () => { |
| 104 | let store, dispatch, restPrefix = '', revisions, version; |
| 105 | let itemId = 'testRevisionId'; |
| 106 | |
| 107 | beforeAll(() => { |
| 108 | restPrefix = Configuration.get('restPrefix'); |
| 109 | store = storeCreator(); |
| 110 | dispatch = store.dispatch; |
| 111 | deepFreeze(store.getState()); |
| 112 | revisions = RevisionsPagePropsFactory.buildList(2); |
| 113 | version = VersionFactory.build(); |
| 114 | }); |
| 115 | |
| 116 | beforeEach(() => { |
| 117 | mockRest.resetQueue(); |
| 118 | }); |
| 119 | |
| 120 | |
| 121 | |
| 122 | it('Get revisions list', () => { |
| 123 | |
| 124 | const expectedStore = cloneAndSet(store.getState(), 'revisions', revisions); |
| 125 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 126 | expect(baseUrl).toEqual(`${restPrefix}/v1.0/items/${itemId}/versions/${version.id}/revisions`); |
| 127 | expect(data).toEqual(undefined); |
| 128 | expect(options).toEqual(undefined); |
| 129 | return {results: revisions}; |
| 130 | }); |
| 131 | |
| 132 | return RevisionsActionHelper.fetchRevisions(dispatch, {itemId, version}).then(() => { |
| 133 | expect(store.getState()).toEqual(expectedStore); |
| 134 | expect(store.getState().revisions.length).toEqual(2); |
| 135 | }); |
| 136 | }); |
| 137 | /* |
| 138 | it('Revert to revision software product model', () => { |
| 139 | mockRest.resetQueue(); |
| 140 | let revisionId = revisions[1].id; |
| 141 | mockRest.addHandler('put', ({options, data, baseUrl}) => { |
| 142 | expect(baseUrl).toEqual(`${restPrefix}/v1.0/items/${itemId}/versions/${version.id}/actions`); |
| 143 | expect(data).toEqual({ |
| 144 | action: vcActionsEnum.REVERT, |
| 145 | revisionRequest: { |
| 146 | revisionId: revisionId |
| 147 | } |
| 148 | |
| 149 | }); |
| 150 | expect(options).toEqual(undefined); |
| 151 | return {results: {}}; |
| 152 | }); |
| 153 | |
| 154 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 155 | expect(baseUrl).toEqual(`${restPrefix}/v1.0/items/${itemId}/versions/${version.id}`); |
| 156 | expect(data).toEqual(undefined); |
| 157 | expect(options).toEqual(undefined); |
| 158 | return {results: {}}; |
| 159 | }); |
| 160 | |
| 161 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 162 | expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${itemId}/versions/${version.id}`); |
| 163 | expect(data).toEqual(undefined); |
| 164 | expect(options).toEqual(undefined); |
| 165 | return {results: {}}; |
| 166 | }); |
| 167 | |
| 168 | |
| 169 | |
| 170 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 171 | expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${itemId}/versions/${version.id}/questionnaire`); |
| 172 | expect(data).toEqual(undefined); |
| 173 | expect(options).toEqual(undefined); |
| 174 | return {data: JSON.stringify({}), schema: JSON.stringify({})}; |
| 175 | }); |
| 176 | |
| 177 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 178 | expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${itemId}/versions/${version.id}/components`); |
| 179 | expect(data).toEqual(undefined); |
| 180 | expect(options).toEqual(undefined); |
| 181 | return {results: {}}; |
| 182 | }); |
| 183 | |
| 184 | |
| 185 | return RevisionsActionHelper.revertToRevision(dispatch, {itemId, version, revisionId, itemType: screenTypes.SOFTWARE_PRODUCT}).then(() => { |
| 186 | }); |
| 187 | |
| 188 | }); |
| 189 | */ |
| 190 | it('Revert to revision license model', () => { |
| 191 | |
| 192 | let revisionId = revisions[0].id; |
| 193 | mockRest.addHandler('put', ({options, data, baseUrl}) => { |
| 194 | expect(baseUrl).toEqual(`${restPrefix}/v1.0/items/${itemId}/versions/${version.id}/actions`); |
| 195 | expect(data).toEqual({ |
| 196 | action: vcActionsEnum.REVERT, |
| 197 | revisionRequest: { |
| 198 | revisionId: revisionId |
| 199 | } |
| 200 | |
| 201 | }); |
| 202 | expect(options).toEqual(undefined); |
| 203 | return {results: {}}; |
| 204 | }); |
| 205 | |
| 206 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 207 | expect(baseUrl).toEqual(`${restPrefix}/v1.0/items/${itemId}/versions/${version.id}`); |
| 208 | expect(data).toEqual(undefined); |
| 209 | expect(options).toEqual(undefined); |
| 210 | return {results: {}}; |
| 211 | }); |
| 212 | |
| 213 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 214 | expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-license-models/${itemId}/versions/${version.id}`); |
| 215 | expect(data).toEqual(undefined); |
| 216 | expect(options).toEqual(undefined); |
| 217 | return {results: {}}; |
| 218 | }); |
| 219 | |
| 220 | |
| 221 | let vlmFetched = ['license-agreements', 'feature-groups', 'entitlement-pools', 'license-key-groups']; |
| 222 | vlmFetched.forEach(fetchCall => { |
| 223 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 224 | expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-license-models/${itemId}/versions/${version.id}/` + fetchCall); |
| 225 | expect(data).toEqual(undefined); |
| 226 | expect(options).toEqual(undefined); |
| 227 | return {results: {}}; |
| 228 | }); |
| 229 | }); |
| 230 | |
| 231 | |
| 232 | return RevisionsActionHelper.revertToRevision(dispatch, {itemId, version, revisionId, itemType: screenTypes.LICENSE_MODEL}).then(() => { |
| 233 | }); |
| 234 | |
| 235 | }); |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | }); |