0636aed6e12c57f73a8e9b801b37fae8d5d06323
[sdc.git] / openecomp-ui / test / nfvo-components / modal / globalModal.test.js
1 /*
2  * Copyright © 2016-2017 European Support Limited
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 or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 import GlobalModal, {GlobalModalView, mapStateToProps} from 'src/nfvo-components/modal/GlobalModal.js';
18 import React from 'react';
19 import ShallowRenderer from 'react-test-renderer/shallow';
20 import store from 'sdc-app/AppStore.js';
21 import {actionTypes, typeEnum} from 'src/nfvo-components/modal/GlobalModalConstants.js';
22
23 const title = 'TITLE';
24 const msg = 'message';
25
26 describe('Global Modal tests: ', function () {
27         it (' mapStateToProps exists', function () {
28                 expect(mapStateToProps).toBeTruthy();
29         });
30
31         it ('mapStateToProps should return show as true', () => {
32                 let state = {
33                         modal: {
34                                 type: ''
35                         }
36                 };
37                 let props = mapStateToProps(state);
38                 expect(props.show).toEqual(true);
39         });
40
41         it('modal should show with default values', () => {
42                 store.dispatch({
43                         type: actionTypes.GLOBAL_MODAL_SHOW,
44                         data: {
45                                 title,
46                                 msg
47                         }
48                 });
49                 const modal = store.getState().modal;
50                 expect(modal).toBeTruthy();
51                 expect(modal.title).toBe(title);
52                 expect(modal.msg).toBe(msg);
53         });
54
55         it('global modal should show with type success with connected component', () => {
56                 store.dispatch({type: actionTypes.GLOBAL_MODAL_SHOW, data: {title, msg}});
57
58                 expect(store.getState().modal).toBeTruthy();
59
60                 const renderer = new ShallowRenderer();
61                 renderer.render(<GlobalModal store={store}/>);
62                 let renderedOutput = renderer.getRenderOutput();
63                 expect(renderedOutput).toBeTruthy();
64
65         });
66
67
68         it('global modal should show with type success with connected component and closed after', () => {
69                 store.dispatch({type: actionTypes.GLOBAL_MODAL_SHOW, data: {title, msg}});
70
71                 expect(store.getState().modal).toBeTruthy();
72                 const renderer = new ShallowRenderer();
73                 renderer.render(<GlobalModal store={store}/>);
74                 let renderedOutput = renderer.getRenderOutput();
75                 expect(renderedOutput).toBeTruthy();
76
77                 store.dispatch({type: actionTypes.GLOBAL_MODAL_CLOSE});
78                 expect(store.getState().modal).toBe(null);
79         });
80
81
82         it('checking component default render', ()=> {
83                 expect(window.document).toBeTruthy();
84                 const renderer = new ShallowRenderer();
85                 renderer.render(<GlobalModalView show={true} type={typeEnum.WARNING} title={title} msg={msg} onDeclined={()=>{}} />);
86                 const globalModalView = renderer.getRenderOutput();
87                 expect(globalModalView).toBeTruthy();
88 });
89
90 });
91