2 * Copyright (c) 2019 Vodafone Group
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.
16 import React, { Component } from 'react';
17 import PropTypes from 'prop-types';
19 import i18n from 'nfvo-utils/i18n/i18n.js';
20 import Button from 'sdc-ui/lib/react/Button.js';
21 import GridSection from 'nfvo-components/grid/GridSection.jsx';
22 import GridItem from 'nfvo-components/grid/GridItem.jsx';
23 import Input from 'nfvo-components/input/validation/Input.jsx';
24 import Form from 'nfvo-components/input/validation/Form.jsx';
26 class VspInputs extends React.Component {
32 shouldComponentUpdate() {
36 changeInputs(e, check, parameterName) {
37 let { testsRequest, generalInfo, setTestsRequest } = this.props;
38 testsRequest[check].parameters[parameterName] = e;
39 generalInfo[check][parameterName] = { isValid: true, errorText: '' };
40 setTestsRequest(testsRequest, generalInfo);
44 let { vspTestsMap, testsRequest, generalInfo } = this.props;
46 <div className="div-clear-both">
48 title={i18n('{title} Inputs :', {
49 title: vspTestsMap[check].title
51 {vspTestsMap[check].parameters.map((parameter, index) => {
53 parameter.type === 'text' &&
54 !parameter.metadata.hidden
57 <GridItem key={index}>
65 isRequired={!parameter.isOptional}
66 label={parameter.description}
68 generalInfo[check][parameter.name]
72 generalInfo[check][parameter.name]
76 parameter.metadata.choices
81 testsRequest[check].parameters[
87 e.target ? e.target.value : e,
93 parameter.metadata.disabled || false
95 {parameter.metadata.choices && (
96 <option key="placeholder" value="">
100 {parameter.metadata.choices &&
101 parameter.metadata.choices.map(
104 key={selectOption.key}
130 {complianceChecked.map(complianceCheck => {
131 if (vspTestsMap[complianceCheck].parameters.length === 0) {
134 return this.renderInputs(complianceCheck);
137 {certificationChecked.map(certificateCheck => {
138 if (vspTestsMap[certificateCheck].parameters.length === 0) {
141 return this.renderInputs(certificateCheck);
149 class VspValidationInputs extends Component {
151 softwareProductValidation: PropTypes.object
159 shouldComponentUpdate() {
164 let areInputsValid = true;
165 let { softwareProductValidation, setGeneralInfo } = this.props;
166 let generalInfo = softwareProductValidation.generalInfo;
167 Object.keys(softwareProductValidation.testsRequest).forEach(
169 let requestParameters =
170 softwareProductValidation.testsRequest[testCaseName]
172 let validationParameters =
173 softwareProductValidation.vspTestsMap[testCaseName]
175 Object.keys(requestParameters).forEach(parameterName => {
176 let parameter = validationParameters.find(
177 o => o.name === parameterName
179 let isParameterValid = true;
182 parameter.type === 'text' &&
183 parameter.metadata.choices
186 !parameter.isOptional &&
187 !requestParameters[parameterName]
189 isParameterValid = false;
190 errorText = i18n('Field is required');
192 } else if (parameter.type === 'text') {
194 !parameter.isOptional &&
195 !requestParameters[parameterName]
197 isParameterValid = false;
198 errorText = i18n('Field is required');
200 (!parameter.isOptional &&
201 !requestParameters[parameterName]) ||
202 (parameter.metadata.maxLength &&
203 requestParameters[parameterName].length >
204 parseInt(parameter.metadata.maxLength)) ||
205 (parameter.metadata.minLength &&
206 requestParameters[parameterName].length <
207 parseInt(parameter.metadata.minLength) &&
208 requestParameters[parameterName].length > 0)
210 isParameterValid = false;
212 'Value Should Be Minimum of {minLength} characters and a Maximum of {maxLength} characters',
214 minLength: parameter.metadata.minLength,
215 maxLength: parameter.metadata.maxLength
220 generalInfo[testCaseName][
222 ].isValid = isParameterValid;
223 generalInfo[testCaseName][
225 ].errorText = errorText;
226 areInputsValid = areInputsValid && isParameterValid;
230 if (!areInputsValid) {
231 setGeneralInfo(generalInfo);
233 return areInputsValid;
243 softwareProductValidation
246 Object.keys(softwareProductValidation.testsRequest).forEach(key => {
247 tests.push(softwareProductValidation.testsRequest[key]);
249 if (this.validateInputs()) {
250 onTestSubmit(softwareProductId, version, status, tests);
254 prepareDataForVspInputs() {
255 let { setTestsRequest } = this.props;
258 certificationChecked,
262 } = this.props.softwareProductValidation;
266 certificationChecked,
275 <div className="vsp-validation-view">
280 onSubmit={() => this.performVSPTests()}
281 isReadOnlyMode={false}>
282 <VspInputs {...this.prepareDataForVspInputs()} />
285 data-test-id="proceed-to-validation-results-btn"
288 className="proceed-to-validation-monitor-btn">
297 export default VspValidationInputs;