2 * Copyright © 2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 } from 'features/version/inputOutput/inputOutputConstants';
22 import inputOutputReducer, {
25 } from 'features/version/inputOutput/inputOutputReducer';
37 } from 'features/version/inputOutput/inputOutputActions';
39 describe('Input/Output Reducer', () => {
40 it('should return initialState', () => {
41 expect(inputOutputReducer(undefined, {})).toEqual(initialState);
44 it('should set inputs/outputs', () => {
61 inputOutputReducer(undefined, setInputsOutputs(payload))
62 ).toEqual({ ...initialState, ...payload });
65 it('should change input/output error', () => {
67 alreadyExists: [1, 2],
68 invalidCharacteres: [3, 4]
70 [INPUTS, OUTPUTS].forEach(current => {
71 const state = { ...initialState, current };
72 expect(inputOutputReducer(state, changeError(payload))).toEqual({
82 it('should show inputs', () => {
83 expect(inputOutputReducer(undefined, showInputs())).toEqual({
89 it('should show outputs', () => {
90 expect(inputOutputReducer(undefined, showOutputs())).toEqual({
96 it('should add input/output', () => {
97 [INPUTS, OUTPUTS].forEach(current => {
98 const state = { ...initialState, current };
99 expect(inputOutputReducer(state, add())).toEqual({
101 [current]: [...state[current], defaultInputOutput[current]]
106 it('should add search', () => {
107 const payload = 'Search string';
108 expect(inputOutputReducer(undefined, search(payload))).toEqual({
114 it('should change input/output name/type/mandatory', () => {
115 const name = 'New name';
116 const type = 'New Type';
117 const mandatory = true;
136 [INPUTS, OUTPUTS].forEach(current => {
139 action: changeName(name, key),
144 action: changeType(type, key),
149 action: changeMandatory(mandatory, key),
153 ].forEach(actionMap => {
154 const actual = inputOutputReducer(
155 { ...state, current },
157 )[current][key][actionMap.field];
159 const expected = actionMap.value;
161 expect(actual).toEqual(expected);
166 it('should remove input/output ', () => {
185 [INPUTS, OUTPUTS].forEach(current => {
187 inputOutputReducer({ ...state, current }, remove(key))[current]