Migrate sdc-sdc-workflow-designer docs
[sdc/sdc-workflow-designer.git] / sdc-workflow-designer-ui / src / main / frontend / src / shared / modal / __tests__ / modalWrapperActions-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
17 'use strict';
18
19 import {
20     SHOW_MODAL,
21     HIDE_MODAL,
22     showInfoModalAction,
23     showAlertModalAction,
24     showErrorModalAction,
25     showCustomModalAction,
26     hideModalAction
27 } from 'shared/modal/modalWrapperActions';
28
29 describe('Modal Wrapper Actions', () => {
30     const actions = [
31         { fn: showInfoModalAction, type: 'info', size: 'small' },
32         { fn: showAlertModalAction, type: 'alert', size: 'small' },
33         { fn: showErrorModalAction, type: 'error', size: 'small' },
34         { fn: showCustomModalAction, type: 'custom', size: 'medium' }
35     ];
36
37     it('returns correct action', () => {
38         actions.forEach(action => {
39             const payload = {
40                 title: 'Title',
41                 body: 'Body',
42                 withButtons: true,
43                 actionButtonText: 'Action Button Text',
44                 actionButtonClick: () => {},
45                 closeButtonText: 'Close Button Text'
46             };
47
48             const expected = {
49                 type: SHOW_MODAL,
50                 payload: {
51                     size: action.size,
52                     ...payload,
53                     type: action.type
54                 }
55             };
56
57             expect(action.fn(payload)).toEqual(expected);
58         });
59     });
60
61     it('returns correct size in action', () => {
62         actions.forEach(action => {
63             const size = 'large';
64
65             const payload = {
66                 size
67             };
68
69             const expected = {
70                 type: SHOW_MODAL,
71                 payload: { size, type: action.type }
72             };
73
74             expect(action.fn(payload)).toEqual(expected);
75         });
76     });
77
78     it('returns hide modal action', () => {
79         const expected = {
80             type: HIDE_MODAL
81         };
82
83         expect(hideModalAction()).toEqual(expected);
84     });
85 });