blob: 0636aed6e12c57f73a8e9b801b37fae8d5d06323 [file] [log] [blame]
svishnev1eb66b72018-01-11 14:39:45 +02001/*
2 * Copyright © 2016-2017 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
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
svishnev1eb66b72018-01-11 14:39:45 +02007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
AviZi280f8012017-06-09 02:39:56 +030010 * 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.
AviZi280f8012017-06-09 02:39:56 +030015 */
16
17import GlobalModal, {GlobalModalView, mapStateToProps} from 'src/nfvo-components/modal/GlobalModal.js';
18import React from 'react';
svishnev1eb66b72018-01-11 14:39:45 +020019import ShallowRenderer from 'react-test-renderer/shallow';
AviZi280f8012017-06-09 02:39:56 +030020import store from 'sdc-app/AppStore.js';
21import {actionTypes, typeEnum} from 'src/nfvo-components/modal/GlobalModalConstants.js';
22
23const title = 'TITLE';
24const msg = 'message';
25
26describe('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: {
svishnev1eb66b72018-01-11 14:39:45 +020034 type: ''
AviZi280f8012017-06-09 02:39:56 +030035 }
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);
svishnev1eb66b72018-01-11 14:39:45 +020052 expect(modal.msg).toBe(msg);
AviZi280f8012017-06-09 02:39:56 +030053 });
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();
svishnev1eb66b72018-01-11 14:39:45 +020059
60 const renderer = new ShallowRenderer();
AviZi280f8012017-06-09 02:39:56 +030061 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}});
svishnev1eb66b72018-01-11 14:39:45 +020070
AviZi280f8012017-06-09 02:39:56 +030071 expect(store.getState().modal).toBeTruthy();
svishnev1eb66b72018-01-11 14:39:45 +020072 const renderer = new ShallowRenderer();
AviZi280f8012017-06-09 02:39:56 +030073 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', ()=> {
talig8e9c0652017-12-20 14:30:43 +020083 expect(window.document).toBeTruthy();
svishnev1eb66b72018-01-11 14:39:45 +020084 const renderer = new ShallowRenderer();
talig8e9c0652017-12-20 14:30:43 +020085 renderer.render(<GlobalModalView show={true} type={typeEnum.WARNING} title={title} msg={msg} onDeclined={()=>{}} />);
svishnev1eb66b72018-01-11 14:39:45 +020086 const globalModalView = renderer.getRenderOutput();
AviZi280f8012017-06-09 02:39:56 +030087 expect(globalModalView).toBeTruthy();
svishnev1eb66b72018-01-11 14:39:45 +020088});
AviZi280f8012017-06-09 02:39:56 +030089
90});
91