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 { Tab, Tabs } from 'sdc-ui/lib/react';
22 import { tabsMapping } from './SoftwareProductValidationConstants.js';
23 import VspValidationInputs from './inputs/VspValidationInputs.js';
24 import VspValidationSetup from './setup/VspValidationSetup.js';
26 class SoftwareProductValidation extends Component {
28 onErrorThrown: PropTypes.func,
29 softwareProductValidation: PropTypes.object,
30 onTestSubmit: PropTypes.func,
31 setVspTestsMap: PropTypes.func,
32 setActiveTab: PropTypes.func,
33 setComplianceChecked: PropTypes.func,
34 setCertificationChecked: PropTypes.func
40 complianceCheckList: null,
41 certificationCheckList: null,
44 activeTab: tabsMapping.SETUP,
45 goToValidationInput: false
49 setMapAndGeneralData(element, testScenario) {
50 let flatTestMap = this.state.flatTestsMap;
51 let generalInputData = this.state.generalInfo;
52 flatTestMap[element.testCaseName] = {
53 title: element.description,
54 parameters: element.inputs,
55 endpoint: element.endpoint,
56 testCaseName: element.testCaseName,
57 testSuiteName: element.testSuiteName,
58 scenario: testScenario
60 generalInputData[element.testCaseName] = {};
61 element.inputs.forEach(key => {
62 generalInputData[element.testCaseName][key.name] = {
69 flatTestsMap: flatTestMap,
70 generalInfo: generalInputData
74 buildChildElements(setItem, testScenario) {
75 let parentElement = {};
76 parentElement.value = setItem.name;
77 parentElement.label = setItem.description;
78 parentElement.children = [];
79 if (setItem.children !== undefined) {
80 setItem.children.forEach(element => {
81 let childElement = this.buildChildElements(
85 if (childElement.children.length !== 0) {
86 parentElement.children.push(childElement);
90 if (setItem.tests !== undefined) {
91 setItem.tests.forEach(element => {
92 parentElement.children.push({
93 value: element.testCaseName,
94 label: element.description
96 this.setMapAndGeneralData(element, testScenario);
102 buildCheckboxParentNode(parentNode, data) {
103 parentNode.value = data.description;
104 parentNode.label = 'All';
105 parentNode.children = [];
106 let scenario = data.name;
107 data.children.forEach(element => {
108 let childElement = this.buildChildElements(element, scenario);
109 if (childElement.children.length !== 0) {
110 parentNode.children.push(childElement);
113 if (data.tests !== undefined) {
114 data.tests.forEach(element => {
115 parentNode.children.push({
116 value: element.testCaseName,
117 label: element.description
119 this.setMapAndGeneralData(element, scenario);
125 prepareDataForCheckboxes(res) {
126 let complianceData = {};
127 let certificationData = {};
128 let complianceList = [];
129 let certificationList = [];
130 let { setVspTestsMap } = this.props;
131 if (Object.keys(res).length !== 0 && res.children) {
132 res.children.forEach(element => {
133 if (element.name === 'certification') {
134 certificationData = element;
135 } else if (element.name === 'compliance') {
136 complianceData = element;
140 let complianceParentNode = {};
142 Object.keys(complianceData).length !== 0 &&
143 complianceData.children !== undefined
145 complianceParentNode = this.buildCheckboxParentNode(
146 complianceParentNode,
149 if (complianceParentNode.children.length !== 0) {
150 complianceList.push(complianceParentNode);
154 let certificationParentNode = {};
156 Object.keys(certificationData).length !== 0 &&
157 certificationData.children !== undefined
159 certificationParentNode = this.buildCheckboxParentNode(
160 certificationParentNode,
163 if (certificationParentNode.children.length !== 0) {
164 certificationList.push(certificationParentNode);
169 certificationCheckList: certificationList,
170 complianceCheckList: complianceList
172 setVspTestsMap(this.state.flatTestsMap);
177 complianceCheckList: [],
178 certificationCheckList: [],
180 activeTab: tabsMapping.SETUP,
181 goToValidationInput: false
185 componentWillMount() {}
187 shouldComponentUpdate() {
191 componentDidMount() {
192 let { softwareProductValidation } = this.props;
193 if (softwareProductValidation.vspChecks !== undefined) {
194 this.prepareDataForCheckboxes(softwareProductValidation.vspChecks);
198 componentWillUnmount() {
202 componentWillReceiveProps(nextProps) {
204 nextProps.softwareProductValidation.vspChecks !==
205 this.props.softwareProductValidation.vspChecks
207 let { softwareProductValidation, setActiveTab } = nextProps;
208 if (softwareProductValidation.vspChecks !== undefined) {
209 this.prepareDataForCheckboxes(
210 softwareProductValidation.vspChecks
214 activeTab: tabsMapping.SETUP,
215 goToValidationInput: false
217 setActiveTab({ activeTab: tabsMapping.SETUP });
221 prepareDataForValidationInputsSection() {
240 prepareDataForCheckboxTreeSection() {
242 softwareProductValidation,
243 setComplianceChecked,
244 setCertificationChecked
246 let complianceCheckList = this.state.complianceCheckList;
247 let certificationCheckList = this.state.certificationCheckList;
249 softwareProductValidation,
250 setComplianceChecked,
251 setCertificationChecked,
253 certificationCheckList
257 handleTabPress(key) {
258 let { setActiveTab } = this.props;
260 case tabsMapping.SETUP:
261 this.setState({ activeTab: tabsMapping.SETUP });
262 setActiveTab({ activeTab: tabsMapping.SETUP });
264 case tabsMapping.INPUTS:
266 setActiveTab({ activeTab: tabsMapping.INPUTS });
268 goToValidationInput: true,
269 activeTab: tabsMapping.INPUTS
275 fetchDefaultValue(value) {
276 let { softwareProductId, version } = this.props;
277 let versionName = parseFloat(version.name).toFixed(1),
279 versionName > 1 ? (versionName - 1).toFixed(1) : versionName,
280 versionUUID = version.id;
284 : value === '$vspPreviousVersion' ? versionNumber : value;
285 value = value === '$vspVersionUUID' ? versionUUID : value || '';
289 formTestsRequest(item, testsRequest) {
290 let { vspTestsMap } = this.props.softwareProductValidation;
291 testsRequest[item] = {
293 scenario: vspTestsMap[item]['scenario'],
294 testCaseName: vspTestsMap[item]['testCaseName'],
295 testSuiteName: vspTestsMap[item]['testSuiteName'],
296 endpoint: vspTestsMap[item]['endpoint']
298 vspTestsMap[item].parameters.forEach(parameter => {
299 testsRequest[item].parameters[
301 ] = this.fetchDefaultValue(parameter.defaultValue);
309 softwareProductValidation,
312 setActiveTab({ activeTab: tabsMapping.INPUTS });
313 let testsRequest = {};
314 if (softwareProductValidation.complianceChecked) {
315 softwareProductValidation.complianceChecked.forEach(item => {
316 testsRequest = this.formTestsRequest(item, testsRequest);
319 if (softwareProductValidation.certificationChecked) {
320 softwareProductValidation.certificationChecked.forEach(item => {
321 testsRequest = this.formTestsRequest(item, testsRequest);
324 setTestsRequest(testsRequest, this.state.generalInfo);
326 goToValidationInput: true,
327 activeTab: tabsMapping.INPUTS
332 let { setActiveTab } = this.props;
333 setActiveTab({ activeTab: tabsMapping.SETUP });
335 goToValidationInput: false,
336 activeTab: tabsMapping.SETUP
341 let { softwareProductValidation } = this.props;
343 (softwareProductValidation.certificationChecked === undefined ||
344 softwareProductValidation.certificationChecked.length === 0) &&
345 (softwareProductValidation.complianceChecked === undefined ||
346 softwareProductValidation.complianceChecked.length === 0);
349 <div className="vsp-validation-view">
350 <div className="validation-view-controllers">
351 {this.state.activeTab === tabsMapping.SETUP && (
354 data-test-id="go-to-vsp-validation-inputs"
355 disabled={isNextDisabled}
356 className="change-tabs-btn"
357 onClick={() => this.onGoToInputs()}>
361 {this.state.activeTab === tabsMapping.INPUTS && (
364 data-test-id="go-to-vsp-validation-setup"
365 className="change-tabs-btn"
366 onClick={() => this.onGoToSetup()}>
372 className="validation-tabs"
374 activeTab={this.state.activeTab}
375 onTabClick={key => this.handleTabPress(key)}>
377 tabId={tabsMapping.SETUP}
378 title={i18n('Setup')}
379 disabled={this.state.goToValidationInput}>
380 <div className="validation-view-tab">
381 {this.state.complianceCheckList &&
382 this.state.certificationCheckList && (
384 {...this.prepareDataForCheckboxTreeSection()}
390 tabId={tabsMapping.INPUTS}
391 title={i18n('Inputs')}
392 disabled={!this.state.goToValidationInput}>
393 <div className="validation-view-tab">
395 {...this.prepareDataForValidationInputsSection()}
405 export default SoftwareProductValidation;