svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2016-2017 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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 |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 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. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | import GlobalModal, {GlobalModalView, mapStateToProps} from 'src/nfvo-components/modal/GlobalModal.js'; |
| 18 | import React from 'react'; |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 19 | import ShallowRenderer from 'react-test-renderer/shallow'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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: { |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 34 | type: '' |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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); |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 52 | expect(modal.msg).toBe(msg); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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(); |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 59 | |
| 60 | const renderer = new ShallowRenderer(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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}}); |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 70 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 71 | expect(store.getState().modal).toBeTruthy(); |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 72 | const renderer = new ShallowRenderer(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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', ()=> { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 83 | expect(window.document).toBeTruthy(); |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 84 | const renderer = new ShallowRenderer(); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 85 | renderer.render(<GlobalModalView show={true} type={typeEnum.WARNING} title={title} msg={msg} onDeclined={()=>{}} />); |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 86 | const globalModalView = renderer.getRenderOutput(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 87 | expect(globalModalView).toBeTruthy(); |
svishnev | 1eb66b7 | 2018-01-11 14:39:45 +0200 | [diff] [blame^] | 88 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 89 | |
| 90 | }); |
| 91 | |