Migrate sdc-sdc-workflow-designer docs
[sdc/sdc-workflow-designer.git] / sdc-workflow-designer-ui / src / main / frontend / src / shared / notifications / __tests__ / notificationsReducer-test.js
1 /*
2 * Copyright © 2018 European Support Limited
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
7 *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10  * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
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.
15 */
16 import notificationsReducer from 'shared/notifications/notificationsReducer';
17 import { actionTypes } from 'shared/notifications/notificationsConstants';
18
19 describe('Notifications Reducer', () => {
20     it('Returns empty state array', () => {
21         expect(notificationsReducer(undefined, {})).toEqual([]);
22     });
23     it('Add notification obj to the notification arr in store', () => {
24         const action = {
25             type: actionTypes.ADD_NOTIFICATION,
26             payload: {
27                 title: 'Notification1',
28                 message: 'This is a test',
29                 type: 'info',
30                 id: '4a2b0038-e442-4ccb-b577-5d04eee6fdfb',
31                 timeout: 200
32             }
33         };
34         expect(notificationsReducer([], action)).toEqual([action.payload]);
35     });
36     it('Remove notification instance from store', () => {
37         const resultState = [
38             {
39                 title: 'Notification1',
40                 message: 'This is a test',
41                 type: 'info',
42                 id: '4a2b0038-e442-4ccb-b577-5d04eee6fdfb',
43                 timeout: 200
44             }
45         ];
46         const removeAction = {
47             type: actionTypes.REMOVE_NOTIFICATION,
48             payload: {
49                 title: 'Notification1',
50                 message: 'This is a test',
51                 type: 'info',
52                 id: '4a2b0038-e442-4ccb-b577-5d04eee6fdfb',
53                 timeout: 200
54             }
55         };
56         expect(notificationsReducer([], removeAction)).toEqual([]);
57         expect(notificationsReducer(resultState, removeAction)).toEqual(
58             resultState.filter(item => item.id !== removeAction.payload.id)
59         );
60     });
61 });