2 * Copyright © 2016-2017 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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';
23 const title = 'TITLE';
24 const msg = 'message';
26 describe('Global Modal tests: ', function () {
27 it (' mapStateToProps exists', function () {
28 expect(mapStateToProps).toBeTruthy();
31 it ('mapStateToProps should return show as true', () => {
37 let props = mapStateToProps(state);
38 expect(props.show).toEqual(true);
41 it('modal should show with default values', () => {
43 type: actionTypes.GLOBAL_MODAL_SHOW,
49 const modal = store.getState().modal;
50 expect(modal).toBeTruthy();
51 expect(modal.title).toBe(title);
52 expect(modal.msg).toBe(msg);
55 it('global modal should show with type success with connected component', () => {
56 store.dispatch({type: actionTypes.GLOBAL_MODAL_SHOW, data: {title, msg}});
58 expect(store.getState().modal).toBeTruthy();
60 const renderer = new ShallowRenderer();
61 renderer.render(<GlobalModal store={store}/>);
62 let renderedOutput = renderer.getRenderOutput();
63 expect(renderedOutput).toBeTruthy();
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}});
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();
77 store.dispatch({type: actionTypes.GLOBAL_MODAL_CLOSE});
78 expect(store.getState().modal).toBe(null);
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();