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 from 'react';
17 import PropTypes from 'prop-types';
18 import { Accordion } from 'onap-ui-react';
19 import { SVGIcon } from 'onap-ui-react';
20 import GridSection from 'nfvo-components/grid/GridSection.jsx';
21 import GridItem from 'nfvo-components/grid/GridItem.jsx';
22 import i18n from 'nfvo-utils/i18n/i18n.js';
24 class SoftwareProductValidationResultsView extends React.Component {
26 softwareProductValidation: PropTypes.object,
27 refreshValidationResults: PropTypes.func
33 vspId: this.props.softwareProductId,
34 versionNumber: this.props.version.name,
35 refreshValidationResults: this.props.refreshValidationResults,
36 vspTestResults: this.props.vspTestResults,
42 this.configBasicTestData();
44 componentDidUpdate() {
45 this.updateTestResultToDisplay();
48 prepareDataForCheckboxes(children, ftm) {
49 for (var val of children) {
51 this.prepareDataForCheckboxes(val.children, ftm);
52 } else if (val.tests) {
53 for (var test of val.tests) {
54 ftm[test.testCaseName] = test.description;
62 let { flatTestsMap: vspTestsMap } = this.state;
63 let title = vspTestsMap[result.testCaseName]
64 ? vspTestsMap[result.testCaseName].split(/\r?\n/)[0]
67 'Scenario: {scenario} | Title: {title} | Test Case: {testCaseName} | Status: {status}',
69 scenario: result.scenario || i18n('Unknown'),
70 status: result.status || i18n('Unknown'),
71 testCaseName: result.testCaseName || i18n('Unknown'),
77 renderJSON(result, indexKey) {
78 if (result.status === 'in-progress') {
79 return this.renderInprogress(i18n('Test is In-progress'), indexKey);
82 <li key={indexKey} type="none">
85 className="validation-results-test-result-json"
86 value={JSON.stringify(result, null, 2)}
92 renderInprogress(result, indexKey) {
94 <li key={indexKey} type="none">
97 name="exclamationTriangleLine"
100 <span className="validation-results-test-result-label">
106 renderError(result, indexKey) {
107 if (Array.isArray(result)) {
108 return result.map((parameter, index) => {
110 <li type="none" key={index}>
114 labelPosition="right"
116 <span className="validation-results-test-result-label">
117 {(parameter.code || '') +
119 (parameter.advice || parameter.message)}
125 typeof result === 'string' ||
126 result.hasOwnProperty('code') ||
127 result.hasOwnProperty('advice') ||
128 result.hasOwnProperty('message') ||
129 result.hasOwnProperty('error')
132 result instanceof Object && result.error instanceof Object
136 <li key={indexKey} type="none">
140 labelPosition="right"
142 <span className="validation-results-test-result-label">
143 {typeof result === 'string'
145 : (result.code || '') +
147 (result.advice || result.message || result.error)}
153 <Accordion key={indexKey} defaultExpanded>
154 {this.renderJSON(result)}
160 renderResults(result, indexKey) {
162 <li key={indexKey} type="none">
166 labelPosition="right"
168 <span className="validation-results-test-result-label">
175 renderString(result, indexKey) {
177 <li key={indexKey} type="none">
181 className="validation-results-test-result-string"
188 buildSubAccordions(result, indexKey) {
189 let results = result.results;
196 dataTestId="vsp-test-no-results"
197 title={this.getTitle(result)}>
198 {this.renderJSON(result, indexKey)}
201 } else if (typeof results === 'string' || results instanceof String) {
206 dataTestId="vsp-test-string-results"
207 title={this.getTitle(result)}>
208 {this.renderString(results, indexKey)}
216 dataTestId="vsp-test-object-results"
217 title={this.getTitle(result)}>
218 {Object.keys(results).length === 0
221 '{title} results are not available',
228 : Array.isArray(results)
229 ? Object.keys(results).map((key, indexKey) => {
230 if (Object.keys(results[key]).length === 0) {
231 return this.renderResults(
232 result.testCaseName +
234 i18n('has passed all checks'),
238 return this.renderError(
244 : this.renderError(results, indexKey)}
249 refreshValidationResult(thisObj) {
250 let { refreshValidationResults } = thisObj.props;
251 var testResultKey = this.props.softwareProductValidationResult
252 .testResultKeys[this.state.vspId + this.state.versionNumber];
253 refreshValidationResults(
254 testResultKey.requestId,
255 testResultKey.endPoints
257 delete this.props.softwareProductValidation.vspTestResults;
259 configBasicTestData() {
261 softwareProductValidationResult,
262 softwareProductValidation
265 softwareProductValidationResult.vspChecks !== undefined &&
266 softwareProductValidationResult.vspChecks.children !== undefined
268 var ftm = this.prepareDataForCheckboxes(
269 this.props.softwareProductValidationResult.vspChecks.children,
276 if (softwareProductValidation.testResultKeys) {
277 if (!this.props.softwareProductValidationResult.testResultKeys) {
278 this.props.softwareProductValidationResult.testResultKeys = {};
280 this.props.softwareProductValidationResult.testResultKeys[
281 this.state.vspId + this.state.versionNumber
283 softwareProductValidation.testResultKeys;
284 delete this.props.softwareProductValidation.testResultKeys;
287 updateTestResultToDisplay() {
288 if (this.props.softwareProductValidation.vspTestResults) {
289 let { updateDisplayTestResultData } = this.props;
290 var testResultToDisplay = this.props.softwareProductValidationResult
291 .testResultToDisplay;
292 testResultToDisplay = testResultToDisplay
293 ? testResultToDisplay
296 this.state.vspId + this.state.versionNumber
297 ] = this.props.softwareProductValidation.vspTestResults;
298 updateDisplayTestResultData(testResultToDisplay);
299 delete this.props.softwareProductValidation.vspTestResults;
300 } else if (this.props.softwareProductValidationResult.vspTestResults) {
301 let { updateDisplayTestResultData } = this.props;
302 var testResultToDisplay = this.props.softwareProductValidationResult
304 ? this.props.softwareProductValidationResult.testResultToDisplay
307 this.state.vspId + this.state.versionNumber
308 ] = this.props.softwareProductValidationResult.vspTestResults;
309 updateDisplayTestResultData(testResultToDisplay);
310 delete this.props.softwareProductValidationResult.vspTestResults;
314 let testResultToDisplay = this.props.softwareProductValidationResult
315 .testResultToDisplay;
316 let results = testResultToDisplay
317 ? testResultToDisplay[this.state.vspId + this.state.versionNumber]
321 <GridSection title={i18n('Test Results')}>
322 <h4>{i18n('No Test Performed')}</h4>
325 } else if (results.length > 0) {
329 onClick={() => this.refreshValidationResult(this)}
330 data-test-id="vsp-validation-refresh-btn"
331 className={'vcp-validation-refresh-btn'}>
336 iconClassName="vcp-validation-refresh-icon"
337 name="versionControllerSync"
340 <GridSection title={i18n('Test Results')}>
341 <GridItem colSpan={10}>
344 dataTestId="vsp-validation-test-result"
345 title={i18n('Test Results')}>
346 {results.map((row, index) =>
347 this.buildSubAccordions(row, index)
358 onClick={() => this.refreshValidationResult(this)}
359 data-test-id="vsp-validation-refresh-btn"
360 className={'vcp-validation-refresh-btn'}>
365 iconClassName="vcp-validation-refresh-icon"
366 name="versionControllerSync"
369 <GridSection title={i18n('Test Results')}>
370 <h4>{i18n('No Test Result Available')}</h4>
378 export default SoftwareProductValidationResultsView;