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';
18 import Configuration from 'sdc-app/config/Configuration.js';
19 import i18n from 'nfvo-utils/i18n/i18n.js';
20 import { Button } from 'onap-ui-react';
21 import { Tab, Tabs } from 'onap-ui-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
80 parentElement.children = [];
81 if (setItem.children !== undefined) {
82 setItem.children.forEach(element => {
83 let childElement = this.buildChildElements(
87 if (childElement.children.length !== 0) {
88 parentElement.children.push(childElement);
92 if (setItem.tests !== undefined) {
93 setItem.tests.forEach(element => {
95 parentElement.children.push({
96 value: element.testCaseName,
97 label: element.testCaseName
99 this.setMapAndGeneralData(element, testScenario);
103 return parentElement;
106 buildCheckboxParentNode(parentNode, data) {
107 parentNode.value = data.description;
108 parentNode.label = 'All';
109 parentNode.children = [];
110 let scenario = data.name;
111 data.children.forEach(element => {
112 let childElement = this.buildChildElements(element, scenario);
113 if (childElement.children.length !== 0) {
114 parentNode.children.push(childElement);
117 if (data.tests !== undefined) {
118 data.tests.forEach(element => {
119 parentNode.children.push({
120 value: element.testCaseName,
121 label: element.description
122 ? element.description
123 : element.testCaseName
125 this.setMapAndGeneralData(element, scenario);
131 prepareDataForCheckboxes(res) {
132 let complianceData = {};
133 let certificationData = {};
134 let complianceList = [];
135 let certificationList = [];
136 let { setVspTestsMap } = this.props;
137 if (Object.keys(res).length !== 0 && res.children) {
138 let allTestScenario = Configuration.get('allTestScenario');
139 res.children.forEach(element => {
140 if (element.name === 'certification') {
141 certificationData = element;
142 } else if (element.name === allTestScenario) {
143 complianceData = element;
147 let complianceParentNode = {};
149 Object.keys(complianceData).length !== 0 &&
150 complianceData.children !== undefined
152 complianceParentNode = this.buildCheckboxParentNode(
153 complianceParentNode,
156 if (complianceParentNode.children.length !== 0) {
157 complianceList.push(complianceParentNode);
161 let certificationParentNode = {};
163 Object.keys(certificationData).length !== 0 &&
164 certificationData.children !== undefined
166 certificationParentNode = this.buildCheckboxParentNode(
167 certificationParentNode,
170 if (certificationParentNode.children.length !== 0) {
171 certificationList.push(certificationParentNode);
176 certificationCheckList: certificationList,
177 complianceCheckList: complianceList
179 setVspTestsMap(this.state.flatTestsMap);
184 complianceCheckList: [],
185 certificationCheckList: [],
187 activeTab: tabsMapping.SETUP,
188 goToValidationInput: false
192 componentWillMount() {}
194 shouldComponentUpdate() {
198 componentDidMount() {
199 let { softwareProductValidation } = this.props;
200 if (softwareProductValidation.vspChecks !== undefined) {
201 this.prepareDataForCheckboxes(softwareProductValidation.vspChecks);
205 componentWillUnmount() {
209 componentWillReceiveProps(nextProps) {
211 nextProps.softwareProductValidation.vspChecks !==
212 this.props.softwareProductValidation.vspChecks
214 let { softwareProductValidation, setActiveTab } = nextProps;
215 if (softwareProductValidation.vspChecks !== undefined) {
216 this.prepareDataForCheckboxes(
217 softwareProductValidation.vspChecks
221 activeTab: tabsMapping.SETUP,
222 goToValidationInput: false
224 setActiveTab({ activeTab: tabsMapping.SETUP });
228 prepareDataForValidationInputsSection() {
247 prepareDataForCheckboxTreeSection() {
249 softwareProductValidation,
250 setComplianceChecked,
251 setCertificationChecked
253 let complianceCheckList = this.state.complianceCheckList;
254 let certificationCheckList = this.state.certificationCheckList;
256 softwareProductValidation,
257 setComplianceChecked,
258 setCertificationChecked,
260 certificationCheckList
264 handleTabPress(key) {
265 let { setActiveTab } = this.props;
267 case tabsMapping.SETUP:
268 this.setState({ activeTab: tabsMapping.SETUP });
269 setActiveTab({ activeTab: tabsMapping.SETUP });
271 case tabsMapping.INPUTS:
273 setActiveTab({ activeTab: tabsMapping.INPUTS });
275 goToValidationInput: true,
276 activeTab: tabsMapping.INPUTS
282 fetchDefaultValue(value) {
283 let { softwareProductId, version } = this.props;
284 let versionName = parseFloat(version.name).toFixed(1),
286 versionName > 1 ? (versionName - 1).toFixed(1) : versionName,
287 versionUUID = version.id;
291 : value === '$vspPreviousVersion' ? versionNumber : value;
292 value = value === '$vspVersionUUID' ? versionUUID : value || '';
296 formTestsRequest(item, testsRequest) {
297 let { vspTestsMap } = this.props.softwareProductValidation;
298 testsRequest[item] = {
300 scenario: vspTestsMap[item]['scenario'],
301 testCaseName: vspTestsMap[item]['testCaseName'],
302 testSuiteName: vspTestsMap[item]['testSuiteName'],
303 endpoint: vspTestsMap[item]['endpoint']
305 vspTestsMap[item].parameters.forEach(parameter => {
306 testsRequest[item].parameters[
308 ] = this.fetchDefaultValue(parameter.defaultValue);
316 softwareProductValidation,
319 setActiveTab({ activeTab: tabsMapping.INPUTS });
320 let testsRequest = {};
321 if (softwareProductValidation.complianceChecked) {
322 softwareProductValidation.complianceChecked.forEach(item => {
323 testsRequest = this.formTestsRequest(item, testsRequest);
326 if (softwareProductValidation.certificationChecked) {
327 softwareProductValidation.certificationChecked.forEach(item => {
328 testsRequest = this.formTestsRequest(item, testsRequest);
331 setTestsRequest(testsRequest, this.state.generalInfo);
333 goToValidationInput: true,
334 activeTab: tabsMapping.INPUTS
339 let { setActiveTab } = this.props;
340 setActiveTab({ activeTab: tabsMapping.SETUP });
342 goToValidationInput: false,
343 activeTab: tabsMapping.SETUP
348 let { softwareProductValidation } = this.props;
350 (softwareProductValidation.certificationChecked === undefined ||
351 softwareProductValidation.certificationChecked.length === 0) &&
352 (softwareProductValidation.complianceChecked === undefined ||
353 softwareProductValidation.complianceChecked.length === 0);
356 <div className="vsp-validation-view">
357 <div className="validation-view-controllers">
358 {this.state.activeTab === tabsMapping.SETUP && (
361 data-test-id="go-to-vsp-validation-inputs"
362 disabled={isNextDisabled}
363 className="change-tabs-btn"
364 onClick={() => this.onGoToInputs()}>
368 {this.state.activeTab === tabsMapping.INPUTS && (
371 data-test-id="go-to-vsp-validation-setup"
372 className="change-tabs-btn"
373 onClick={() => this.onGoToSetup()}>
379 className="validation-tabs"
381 activeTab={this.state.activeTab}
382 onTabClick={key => this.handleTabPress(key)}>
384 tabId={tabsMapping.SETUP}
385 title={i18n('Setup')}
386 disabled={this.state.goToValidationInput}>
387 <div className="validation-view-tab">
388 {this.state.complianceCheckList &&
389 this.state.certificationCheckList && (
391 {...this.prepareDataForCheckboxTreeSection()}
397 tabId={tabsMapping.INPUTS}
398 title={i18n('Inputs')}
399 disabled={!this.state.goToValidationInput}>
400 <div className="validation-view-tab">
402 {...this.prepareDataForValidationInputsSection()}
412 export default SoftwareProductValidation;