Add tests to notifications module
[aai/sparky-fe.git] / test / generic-components / notifications / NotificationReducer.test.js
1 import NotificationReducer from 'generic-components/notifications/NotificationReducer';
2 import NotificationConstants from "generic-components/notifications/NotificationConstants";
3
4
5 describe('NotificationReducer', () => {
6     const defaultState = {
7         type: 'default',
8         title: 'some default title',
9         msg: 'some default message',
10         timeout: 1
11     };
12
13     it('Should return default state when action type is not supported', () => {
14         // given
15         const unsupportedAction = {
16             type: undefined
17         };
18
19         // when
20         const actualState = NotificationReducer(defaultState, unsupportedAction);
21
22         // then
23         expect(actualState).toEqual(defaultState);
24     });
25
26     it('Should return state with type default when action type is info', () => {
27         // given
28         const expectedState = {
29             type: 'default',
30             title: 'some title',
31             msg: 'some message',
32             timeout: 5
33         };
34
35         const infoAction =  {
36             type: NotificationConstants.NOTIFY_INFO,
37             data: {
38                 title: "some title",
39                 msg: "some message",
40                 timeout: 5
41             }
42         };
43
44         // when
45         const actualState = NotificationReducer(defaultState, infoAction);
46
47         // then
48         expect(actualState).toEqual(expectedState);
49     });
50
51
52     it('Should return status with type success when action type is success', () => {
53         // given
54         const expectedState = {
55             type: 'success',
56             title: 'some title',
57             msg: 'some message',
58             timeout: 2
59         };
60
61         const infoAction =  {
62             type: NotificationConstants.NOTIFY_SUCCESS,
63             data: {
64                 title: "some title",
65                 msg: "some message",
66                 timeout: 2
67             }
68         };
69
70         // when
71         const actualState = NotificationReducer(defaultState, infoAction);
72
73         // then
74         expect(actualState).toEqual(expectedState);
75     });
76
77     it('Should return status with type success when action type is success', () => {
78         // given
79         const expectedState = {
80             type: 'success',
81             title: 'some title',
82             msg: 'some message',
83             timeout: 2
84         };
85
86         const infoAction =  {
87             type: NotificationConstants.NOTIFY_SUCCESS,
88             data: {
89                 title: "some title",
90                 msg: "some message",
91                 timeout: 2
92             }
93         };
94
95         // when
96         const actualState = NotificationReducer(defaultState, infoAction);
97
98         // then
99         expect(actualState).toEqual(expectedState);
100     });
101
102     it('Should return status with type error when action type is error', () => {
103         // given
104         const expectedState = {
105             type: 'error',
106             title: 'some title',
107             msg: 'some message',
108             timeout: 2
109         };
110
111         const infoAction =  {
112             type: NotificationConstants.NOTIFY_ERROR,
113             data: {
114                 title: "some title",
115                 msg: "some message",
116                 timeout: 2
117             }
118         };
119
120         // when
121         const actualState = NotificationReducer(defaultState, infoAction);
122
123         // then
124         expect(actualState).toEqual(expectedState);
125     });
126
127     it('Should return status with type error when action type is error', () => {
128         // given
129         const expectedState = {
130             type: 'error',
131             title: 'some title',
132             msg: 'some message',
133             timeout: 2
134         };
135
136         const infoAction =  {
137             type: NotificationConstants.NOTIFY_ERROR,
138             data: {
139                 title: "some title",
140                 msg: "some message",
141                 timeout: 2
142             }
143         };
144
145         // when
146         const actualState = NotificationReducer(defaultState, infoAction);
147
148         // then
149         expect(actualState).toEqual(expectedState);
150     });
151
152     it('Should return status with type warning when action type is warning', () => {
153         // given
154         const expectedState = {
155             type: 'warning',
156             title: 'some title',
157             msg: 'some message',
158             timeout: 2
159         };
160
161         const infoAction =  {
162             type: NotificationConstants.NOTIFY_WARNING,
163             data: {
164                 title: "some title",
165                 msg: "some message",
166                 timeout: 2
167             }
168         };
169
170         // when
171         const actualState = NotificationReducer(defaultState, infoAction);
172
173         // then
174         expect(actualState).toEqual(expectedState);
175     });
176
177     it('Should return null when action type is close', () => {
178         // given
179         const expectedState = null;
180
181         const infoAction =  {
182             type: NotificationConstants.NOTIFY_CLOSE,
183             data: {
184                 title: "some title",
185                 msg: "some message",
186                 timeout: 2
187             }
188         };
189
190         // when
191         const actualState = NotificationReducer(defaultState, infoAction);
192
193         // then
194         expect(actualState).toEqual(expectedState);
195     });
196
197 });

© 2017 ONAP. Copyright © The Linux Foundation ®. All Rights Reserved.
The Linux Foundation has registered trademarks and uses trademarks.
For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.
Linux is a registered trademark of Linus Torvalds.
Privacy Policy and Terms of Use