AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
| 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 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 |
| 13 | * or implied. See the License for the specific language governing |
| 14 | * permissions and 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 TestUtils from 'react-addons-test-utils'; |
| 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 | let renderer = TestUtils.createRenderer(); |
| 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 | |
| 73 | let renderer = TestUtils.createRenderer(); |
| 74 | renderer.render(<GlobalModal store={store}/>); |
| 75 | let renderedOutput = renderer.getRenderOutput(); |
| 76 | expect(renderedOutput).toBeTruthy(); |
| 77 | |
| 78 | store.dispatch({type: actionTypes.GLOBAL_MODAL_CLOSE}); |
| 79 | expect(store.getState().modal).toBe(null); |
| 80 | }); |
| 81 | |
| 82 | |
| 83 | it('checking component default render', ()=> { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 84 | expect(window.document).toBeTruthy(); |
| 85 | let renderer = TestUtils.createRenderer(); |
| 86 | renderer.render(<GlobalModalView show={true} type={typeEnum.WARNING} title={title} msg={msg} onDeclined={()=>{}} />); |
| 87 | let globalModalView = renderer.getRenderOutput(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 88 | expect(globalModalView).toBeTruthy(); |
| 89 | }); |
| 90 | |
| 91 | }); |
| 92 | |