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