blob: e7ab6bdbaa341a4b010d0c1cd837296edfff7bc5 [file] [log] [blame]
svishnev1eb66b72018-01-11 14:39:45 +02001/*
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02002 * Copyright © 2016-2018 European Support Limited
talig8e9c0652017-12-20 14:30:43 +02003 *
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
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02007 *
svishnev1eb66b72018-01-11 14:39:45 +02008 * http://www.apache.org/licenses/LICENSE-2.0
Einav Weiss Keidard2f57942018-02-14 14:00:07 +02009 *
talig8e9c0652017-12-20 14:30:43 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
svishnev1eb66b72018-01-11 14:39:45 +020012 * 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.
talig8e9c0652017-12-20 14:30:43 +020015 */
16
17import React from 'react';
Einav Weiss Keidard2f57942018-02-14 14:00:07 +020018import ShallowRenderer from 'react-test-renderer/shallow';
talig8e9c0652017-12-20 14:30:43 +020019import {mapStateToProps, mapActionsToProps} from 'sdc-app/onboarding/versionsPage/creation/VersionsPageCreation.js';
20import {VERSION_CREATION_FORM_NAME} from 'sdc-app/onboarding/versionsPage/creation/VersionsPageCreationConstants.js';
21import VersionsPageCreationActionHelper from 'sdc-app/onboarding/versionsPage/creation/VersionsPageCreationActionHelper.js';
22import VersionsPageCreationView from 'sdc-app/onboarding/versionsPage/creation/VersionsPageCreationView.jsx';
23import {VersionsPageCreationFactory,
24 VersionsPageCreationFieldInfoFactory} from 'test-utils/factories/versionsPage/VersionsPageCreationFactories.js';
25import {VersionsPageAdditionalPropsFactory} from 'test-utils/factories/versionsPage/VersionsPageFactories.js';
26import {storeCreator} from 'sdc-app/AppStore.js';
27
28describe('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);
Einav Weiss Keidard2f57942018-02-14 14:00:07 +020095 const renderer = new ShallowRenderer();
talig8e9c0652017-12-20 14:30:43 +020096 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
svishnev1eb66b72018-01-11 14:39:45 +0200113});