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 'sdc-ui/lib/react/Accordion.js';
19 import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
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';
23 import unCamelCasedString from 'nfvo-utils/unCamelCaseString.js';
25 const TestResultComponent = ({ tests }) => {
28 {tests.map((test, index) => {
29 let name = 'errorCircle';
30 let color = 'warning';
33 test.testResult.toLowerCase() === 'pass'
39 test.testResult.toLowerCase() === 'fail'
41 name = 'exclamationTriangleFull';
44 <li type="none" key={index}>
50 <span className="validation-results-test-result-label">
64 class SoftwareProductValidationResultsView extends React.Component {
66 softwareProductValidation: PropTypes.object
72 vspId: this.props.softwareProductId,
73 versionNumber: this.props.version.name
78 let { vspTestsMap } = this.props.softwareProductValidation;
79 let title = vspTestsMap[result.testCaseName]
80 ? vspTestsMap[result.testCaseName].title
83 'Scenario: {scenario} | Title: {title} | Test Case: {testCaseName} | Status: {status}',
85 scenario: result.scenario || i18n('Unknown'),
86 status: result.status || i18n('Unknown'),
87 testCaseName: result.testCaseName || i18n('Unknown'),
98 className="validation-results-test-result-json"
99 value={JSON.stringify(result, null, 2)}
105 renderError(result) {
106 if (Array.isArray(result)) {
107 return result.map((parameter, index) => {
109 <li type="none" key={index}>
113 labelPosition="right"
115 <span className="validation-results-test-result-label">
116 {(parameter.code || '') +
118 (parameter.advice || parameter.message)}
129 labelPosition="right"
131 <span className="validation-results-test-result-label">
132 {(result.code || '') +
134 (result.advice || result.message)}
141 renderResults(result) {
142 if (typeof result === 'string' || result instanceof String) {
148 labelPosition="right"
150 <span className="validation-results-test-result-label">
156 return Object.keys(result).map((key, index) => {
157 let title = unCamelCasedString(key);
159 typeof result[key] === 'string' ||
160 result[key] instanceof String
168 {this.renderString(result[key])}
171 } else if (Array.isArray(result[key])) {
172 if (result[key].length > 0) {
179 <TestResultComponent tests={result[key]} />
189 {i18n('{title} results are not available', {
202 {this.renderJSON(result[key])}
209 renderString(result) {
215 className="validation-results-test-result-string"
222 buildSubAccordions(result) {
223 let results = result.results;
229 dataTestId="vsp-test-no-results"
230 title={this.getTitle(result)}>
231 {this.renderJSON(result)}
234 } else if (typeof results === 'string' || results instanceof String) {
238 dataTestId="vsp-test-string-results"
239 title={this.getTitle(result)}>
240 {this.renderString(results)}
247 dataTestId="vsp-test-object-results"
248 title={this.getTitle(result)}>
249 {Object.keys(results).length === 0
251 i18n('{title} results are not available', {
255 : Object.keys(results).map(key => {
256 if (key === 'errors' || key === 'error') {
257 return this.renderError(results[key]);
258 } else if (key === 'testResults') {
259 return this.renderResults(results[key]);
261 let title = unCamelCasedString(key);
262 if (results[key] instanceof Object) {
268 {this.renderJSON(results[key])}
277 {this.renderString(results[key])}
289 let results = this.props.softwareProductValidation.vspTestResults || [];
290 if (results.length > 0) {
292 <GridSection title={i18n('Validation Results')}>
293 <GridItem colSpan={10}>
296 dataTestId="vsp-validation-test-result"
297 title={i18n('Test Results')}>
298 {results.map(row => this.buildSubAccordions(row))}
305 <GridSection title={i18n('Validation Results')}>
306 <h4>{i18n('No Validation Checks Performed')}</h4>
313 export default SoftwareProductValidationResultsView;