Migrate sdc-sdc-workflow-designer docs
[sdc/sdc-workflow-designer.git] / workflow-designer-ui / src / main / frontend / src / features / version / inputOutput / __tests__ / inputOutputActions-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 import {
18     NAME_MAX_LEN,
19     STRING,
20     SET_INPUTS_OUTPUTS,
21     CHANGE_ERROR,
22     SHOW_INPUTS,
23     SHOW_OUTPUTS,
24     SEARCH,
25     ADD,
26     CHANGE_NAME,
27     CHANGE_TYPE,
28     CHANGE_MANDATORY,
29     REMOVE
30 } from 'features/version/inputOutput/inputOutputConstants';
31 import {
32     setInputsOutputs,
33     changeError,
34     showInputs,
35     showOutputs,
36     search,
37     add,
38     changeName,
39     changeType,
40     changeMandatory,
41     remove
42 } from 'features/version/inputOutput/inputOutputActions';
43
44 describe('Input/Output Actions', () => {
45     it('should have `setInputsOutputs` action', () => {
46         const inputs = [
47             {
48                 name: 'Input',
49                 type: STRING,
50                 mandatory: false
51             }
52         ];
53
54         const outputs = [
55             {
56                 name: 'Output',
57                 type: STRING,
58                 mandatory: false
59             }
60         ];
61
62         const expected = {
63             type: SET_INPUTS_OUTPUTS,
64             payload: {
65                 inputs,
66                 outputs
67             }
68         };
69
70         expect(setInputsOutputs({ inputs, outputs })).toEqual(expected);
71     });
72
73     it('should have `changeError` action', () => {
74         const payload = { key: 'value' };
75
76         const expected = { type: CHANGE_ERROR, payload };
77
78         expect(changeError(payload)).toEqual(expected);
79     });
80
81     it('should have `showInputs` action', () => {
82         const expected = { type: SHOW_INPUTS };
83
84         expect(showInputs()).toEqual(expected);
85     });
86
87     it('should have `showOutputs` action', () => {
88         const expected = { type: SHOW_OUTPUTS };
89
90         expect(showOutputs()).toEqual(expected);
91     });
92
93     it('should have `search` action', () => {
94         const payload = 'Search Value';
95
96         const expected = { type: SEARCH, payload };
97
98         expect(search(payload)).toEqual(expected);
99     });
100
101     it('should have `add` action', () => {
102         const expected = { type: ADD };
103
104         expect(add()).toEqual(expected);
105     });
106
107     it('should have `changeName` action', () => {
108         let name = 'This is a long name more that more more more and more';
109         let key = 1;
110
111         const expected = {
112             type: CHANGE_NAME,
113             payload: {
114                 name: name.substr(0, NAME_MAX_LEN),
115                 key
116             }
117         };
118
119         expect(changeName(name, key)).toEqual(expected);
120     });
121
122     it('should have `changeType` action', () => {
123         const type = 'String';
124         const key = 1;
125
126         const expected = { type: CHANGE_TYPE, payload: { type, key } };
127
128         expect(changeType(type, key)).toEqual(expected);
129     });
130
131     it('should have `changeMandatory` action', () => {
132         const mandatory = true;
133         const key = 1;
134
135         const expected = {
136             type: CHANGE_MANDATORY,
137             payload: { mandatory, key }
138         };
139
140         expect(changeMandatory(mandatory, key)).toEqual(expected);
141     });
142
143     it('should have `remove` action', () => {
144         const payload = 1;
145
146         const expected = { type: REMOVE, payload };
147
148         expect(remove(payload)).toEqual(expected);
149     });
150 });