svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2017 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 |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | import React from 'react'; |
svishnev | aa2eece | 2018-01-18 17:52:06 +0200 | [diff] [blame] | 18 | import TestUtils from 'react-addons-test-utils'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 19 | import {mapStateToProps, mapActionsToProps} from 'sdc-app/onboarding/versionsPage/creation/VersionsPageCreation.js'; |
| 20 | import {VERSION_CREATION_FORM_NAME} from 'sdc-app/onboarding/versionsPage/creation/VersionsPageCreationConstants.js'; |
| 21 | import VersionsPageCreationActionHelper from 'sdc-app/onboarding/versionsPage/creation/VersionsPageCreationActionHelper.js'; |
| 22 | import VersionsPageCreationView from 'sdc-app/onboarding/versionsPage/creation/VersionsPageCreationView.jsx'; |
| 23 | import {VersionsPageCreationFactory, |
| 24 | VersionsPageCreationFieldInfoFactory} from 'test-utils/factories/versionsPage/VersionsPageCreationFactories.js'; |
| 25 | import {VersionsPageAdditionalPropsFactory} from 'test-utils/factories/versionsPage/VersionsPageFactories.js'; |
| 26 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 27 | |
| 28 | describe('Versions Page Creation Module Tests', function() { |
| 29 | |
| 30 | let versionCreationData, genericFieldInfo; |
| 31 | let store, dispatch; |
| 32 | |
| 33 | beforeAll(() => { |
| 34 | store = storeCreator(); |
| 35 | dispatch = store.dispatch; |
| 36 | versionCreationData = VersionsPageCreationFactory.build(); |
| 37 | genericFieldInfo = VersionsPageCreationFieldInfoFactory.build(); |
| 38 | }); |
| 39 | |
| 40 | const additionalProps = VersionsPageAdditionalPropsFactory.build(); |
| 41 | |
| 42 | it ('mapStateToProps mapper exists', () => { |
| 43 | |
| 44 | expect(mapStateToProps).toBeTruthy(); |
| 45 | |
| 46 | }); |
| 47 | |
| 48 | it ('should return empty data', () => { |
| 49 | |
| 50 | const state = { |
| 51 | versionsPage: { |
| 52 | versionCreation: { |
| 53 | data: {}, |
| 54 | genericFieldInfo: {} |
| 55 | } |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | const props = mapStateToProps(state); |
| 60 | expect(props.data).toEqual({}); |
| 61 | expect(props.isFormValid).toEqual(true); |
| 62 | |
| 63 | }); |
| 64 | |
| 65 | it ('should have state in props', () => { |
| 66 | |
| 67 | const state = { |
| 68 | versionsPage: { |
| 69 | versionCreation: { |
| 70 | data: versionCreationData, |
| 71 | genericFieldInfo |
| 72 | } |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | const props = mapStateToProps(state); |
| 77 | expect(props.isFormValid).toEqual(true); |
| 78 | expect(props.data.description).toEqual(versionCreationData.description); |
| 79 | expect(props.genericFieldInfo).toEqual(genericFieldInfo); |
| 80 | |
| 81 | }); |
| 82 | |
| 83 | it('simple jsx test', () => { |
| 84 | |
| 85 | const state = { |
| 86 | versionsPage: { |
| 87 | versionCreation: { |
| 88 | data: versionCreationData, |
| 89 | genericFieldInfo |
| 90 | } |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | const props = Object.assign({}, mapStateToProps(state), mapActionsToProps(dispatch, additionalProps), additionalProps); |
svishnev | aa2eece | 2018-01-18 17:52:06 +0200 | [diff] [blame] | 95 | var renderer = TestUtils.createRenderer(); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 96 | renderer.render(<VersionsPageCreationView {...props} />); |
| 97 | |
| 98 | const renderedOutput = renderer.getRenderOutput(); |
| 99 | expect(renderedOutput).toBeTruthy(); |
| 100 | |
| 101 | }); |
| 102 | |
| 103 | it('open/close form actions', () => { |
| 104 | |
| 105 | VersionsPageCreationActionHelper.open(dispatch, additionalProps); |
| 106 | expect(store.getState().versionsPage.versionCreation.formName).toEqual(VERSION_CREATION_FORM_NAME); |
| 107 | |
| 108 | VersionsPageCreationActionHelper.close(dispatch); |
| 109 | expect(store.getState().versionsPage.versionCreation).toEqual({}); |
| 110 | |
| 111 | }); |
| 112 | |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame] | 113 | }); |