9600a82122845d8978da43b1ffd0590ccd850f97
[aai/sparky-fe.git] / test / components / notificationReducer.test.js
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 import { expect } from 'chai';
22 import NotificationConstants from 'generic-components/notifications/NotificationConstants.js';
23 import reducer from 'generic-components/notifications/NotificationReducer.js';
24
25 describe("Notification reducer test suite", function() {
26         const initialState = {
27                 title: '',
28                 msg: '',
29                 timeout: 0
30         };
31
32         it("NOTIFY_INFO event", function() {
33                 const action = {
34                         type: NotificationConstants.NOTIFY_INFO,
35                         data: {
36                                 title: 'some title',
37                                 msg: 'some message',
38                                 timeout: 1
39                         }
40                 }
41                 const newState = reducer(initialState, action);
42
43                 expect(newState.type).to.equal('default');
44                 expect(newState.title).to.equal('some title');
45                 expect(newState.msg).to.equal('some message');
46                 expect(newState.timeout).to.equal(1);
47         });
48
49         it("NOTIFY_ERROR event", function() {
50                 const action = {
51                         type: NotificationConstants.NOTIFY_ERROR,
52                         data: {
53                                 title: 'some title',
54                                 msg: 'some message',
55                                 timeout: 1
56                         }
57                 }
58                 const newState = reducer(initialState, action);
59
60                 expect(newState.type).to.equal('error');
61                 expect(newState.title).to.equal('some title');
62                 expect(newState.msg).to.equal('some message');
63                 expect(newState.timeout).to.equal(1);
64         });
65
66         it("NOTIFY_WARNING event", function() {
67                 const action = {
68                         type: NotificationConstants.NOTIFY_WARNING,
69                         data: {
70                                 title: 'some title',
71                                 msg: 'some message',
72                                 timeout: 1
73                         }
74                 }
75                 const newState = reducer(initialState, action);
76
77                 expect(newState.type).to.equal('warning');
78                 expect(newState.title).to.equal('some title');
79                 expect(newState.msg).to.equal('some message');
80                 expect(newState.timeout).to.equal(1);
81         });
82
83         it("NOTIFY_SUCCESS event", function() {
84                 const action = {
85                         type: NotificationConstants.NOTIFY_SUCCESS,
86                         data: {
87                                 title: 'some title',
88                                 msg: 'some message',
89                                 timeout: 1
90                         }
91                 }
92                 const newState = reducer(initialState, action);
93
94                 expect(newState.type).to.equal('success');
95                 expect(newState.title).to.equal('some title');
96                 expect(newState.msg).to.equal('some message');
97                 expect(newState.timeout).to.equal(1);
98         });
99
100         it("NOTIFY_CLOSE event", function() {
101                 const action = {
102                         type: NotificationConstants.NOTIFY_CLOSE
103                 }
104                 const newState = reducer(initialState, action);
105
106                 expect(newState).to.be.null;
107         });
108 });