Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 1 | /*- |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * SDC |
| 4 | * ================================================================================ |
| 5 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 6 | * ================================================================================ |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * ============LICENSE_END========================================================= |
| 19 | */ |
| 20 | |
| 21 | import expect from 'expect'; |
| 22 | import React from 'react'; |
| 23 | import TestUtils from 'react-addons-test-utils'; |
| 24 | import store from 'sdc-app/AppStore.js'; |
| 25 | import ConnectedNotificationModal, {NotificationModal} from 'nfvo-components/notifications/NotificationModal.jsx'; |
| 26 | import NotificationConstants from 'nfvo-components/notifications/NotificationConstants.js'; |
| 27 | |
| 28 | const title = 'test title'; |
| 29 | const msg = 'test msg'; |
| 30 | |
| 31 | describe('Notification Modal Mapper and View Class: ', function () { |
| 32 | |
| 33 | it('notification should show with type error', done => { |
| 34 | store.dispatch({type: NotificationConstants.NOTIFY_ERROR, data: {title, msg}}); |
| 35 | setTimeout(()=> { |
| 36 | expect(store.getState().notification).toExist(); |
| 37 | expect(store.getState().notification.type).toBe('error'); |
| 38 | done(); |
| 39 | }, 0); |
| 40 | }); |
| 41 | |
| 42 | it('notification should show with type default', done => { |
| 43 | store.dispatch({type: NotificationConstants.NOTIFY_INFO, data: {title, msg}}); |
| 44 | setTimeout(()=> { |
| 45 | expect(store.getState().notification).toExist(); |
| 46 | expect(store.getState().notification.type).toBe('default'); |
| 47 | done(); |
| 48 | }, 0); |
| 49 | }); |
| 50 | |
| 51 | it('notification should show with type warning', done => { |
| 52 | store.dispatch({type: NotificationConstants.NOTIFY_WARNING, data: {title, msg}}); |
| 53 | setTimeout(()=> { |
| 54 | expect(store.getState().notification).toExist(); |
| 55 | expect(store.getState().notification.type).toBe('warning'); |
| 56 | done(); |
| 57 | }, 0); |
| 58 | }); |
| 59 | |
| 60 | it('notification should show with type success', done => { |
| 61 | store.dispatch({type: NotificationConstants.NOTIFY_SUCCESS, data: {title, msg}}); |
| 62 | setTimeout(()=> { |
| 63 | expect(store.getState().notification).toExist(); |
| 64 | expect(store.getState().notification.type).toBe('success'); |
| 65 | done(); |
| 66 | }, 0); |
| 67 | }); |
| 68 | |
| 69 | it('notification should show with type success with connected component', done => { |
| 70 | store.dispatch({type: NotificationConstants.NOTIFY_SUCCESS, data: {title, msg}}); |
| 71 | setTimeout(()=> { |
| 72 | expect(store.getState().notification).toExist(); |
| 73 | expect(store.getState().notification.type).toBe('success'); |
| 74 | let renderer = TestUtils.createRenderer(); |
| 75 | renderer.render(<ConnectedNotificationModal store={store}/>); |
| 76 | let renderedOutput = renderer.getRenderOutput(); |
| 77 | expect(renderedOutput).toExist(); |
| 78 | done(); |
| 79 | }, 0); |
| 80 | }); |
| 81 | |
| 82 | it('notification should hide with connected component', done => { |
| 83 | setTimeout(()=> { |
| 84 | expect(store.getState().notification).toNotExist(); |
| 85 | let renderer = TestUtils.createRenderer(); |
| 86 | renderer.render(<ConnectedNotificationModal store={store}/>); |
| 87 | let renderedOutput = renderer.getRenderOutput(); |
| 88 | expect(renderedOutput).toExist(); |
| 89 | done(); |
| 90 | }, 0); |
| 91 | store.dispatch({type: NotificationConstants.NOTIFY_CLOSE}); |
| 92 | }); |
| 93 | |
| 94 | it('notification should hide', done => { |
| 95 | store.dispatch({type: NotificationConstants.NOTIFY_CLOSE}); |
| 96 | setTimeout(()=> { |
| 97 | expect(store.getState().notification).toNotExist(); |
| 98 | done(); |
| 99 | }, 0); |
| 100 | }); |
| 101 | |
| 102 | it('NotificationModal should not render', ()=> { |
| 103 | let renderer = TestUtils.createRenderer(); |
| 104 | renderer.render(<NotificationModal show={false} title={title} msg={msg} type='error'/>); |
| 105 | let renderedOutput = renderer.getRenderOutput(); |
| 106 | expect(renderedOutput).toExist(); |
| 107 | }); |
| 108 | |
| 109 | it('NotificationModal basic default render', ()=> { |
| 110 | expect(window.document).toExist(); |
| 111 | let document = TestUtils.renderIntoDocument( |
| 112 | <NotificationModal show={true} title={title} msg={msg} type='default' onCloseClick={()=>{}}/> |
| 113 | ); |
| 114 | var result = TestUtils.findAllInRenderedTree(document, element => element.props.className === 'notification-modal primary'); |
| 115 | expect(result.length).toBeGreaterThan(0); |
| 116 | }); |
| 117 | |
| 118 | it('NotificationModal basic error render', ()=> { |
| 119 | expect(window.document).toExist(); |
| 120 | let document = TestUtils.renderIntoDocument( |
| 121 | <NotificationModal show={true} title={title} msg={msg} type='error' onCloseClick={()=>{}}/> |
| 122 | ); |
| 123 | var result = TestUtils.findAllInRenderedTree(document, element => element.props.className === 'notification-modal danger'); |
| 124 | expect(result.length).toBeGreaterThan(0); |
| 125 | }); |
| 126 | |
| 127 | it('NotificationModal basic warning render', ()=> { |
| 128 | expect(window.document).toExist(); |
| 129 | let document = TestUtils.renderIntoDocument( |
| 130 | <NotificationModal show={true} title={title} msg={msg} type='warning' onCloseClick={()=>{}}/> |
| 131 | ); |
| 132 | var result = TestUtils.findAllInRenderedTree(document, element => element.props.className === 'notification-modal warning'); |
| 133 | expect(result.length).toBeGreaterThan(0); |
| 134 | }); |
| 135 | |
| 136 | it('NotificationModal basic success render', ()=> { |
| 137 | expect(window.document).toExist(); |
| 138 | let document = TestUtils.renderIntoDocument( |
| 139 | <NotificationModal show={true} title={title} msg={msg} type='success' onCloseClick={()=>{}}/> |
| 140 | ); |
| 141 | var result = TestUtils.findAllInRenderedTree(document, element => element.props.className === 'notification-modal success'); |
| 142 | expect(result.length).toBeGreaterThan(0); |
| 143 | }); |
| 144 | }); |