From 27dff31c3c80ef50ec2b197ea09001d169127cca Mon Sep 17 00:00:00 2001 From: Becky Reamy Date: Thu, 2 Jul 2020 13:12:33 -0400 Subject: [PATCH 1/2] KPMP-1919: Fix results --- .../Validation/FilenameValidationPage.js | 28 ++-- .../Validation/ValidationFailure.js | 112 --------------- src/components/Validation/ValidationResult.js | 68 +++++++++ .../Validation/ValidationSuccess.js | 95 ------------- .../Validation/validationResultHelper.js | 78 +++++++++++ .../Validation/validationResultHelper.test.js | 130 ++++++++++++++++++ 6 files changed, 287 insertions(+), 224 deletions(-) delete mode 100644 src/components/Validation/ValidationFailure.js create mode 100644 src/components/Validation/ValidationResult.js delete mode 100644 src/components/Validation/ValidationSuccess.js create mode 100644 src/components/Validation/validationResultHelper.js create mode 100644 src/components/Validation/validationResultHelper.test.js diff --git a/src/components/Validation/FilenameValidationPage.js b/src/components/Validation/FilenameValidationPage.js index efc144c..294b978 100644 --- a/src/components/Validation/FilenameValidationPage.js +++ b/src/components/Validation/FilenameValidationPage.js @@ -1,7 +1,6 @@ import React, { Component } from 'react'; import { Container, Row, Col, Button } from 'reactstrap'; -import ValidationSuccess from './ValidationSuccess'; -import ValidationFailure from './ValidationFailure'; +import ValidationResult from './ValidationResult'; class FilenameValidationPage extends Component { @@ -35,21 +34,16 @@ class FilenameValidationPage extends Component { if (Object.keys(this.props.validationResult).length !== 0 && this.props.validationResult.constructor === Object) { let filesNotInGlobus = this.props.validationResult.metadataFilesNotFoundInGlobus; let filesNotInMetadata = this.props.validationResult.globusFilesNotFoundInMetadata; - if (!filesNotInGlobus && !filesNotInMetadata) { - return ( - - ); - } else { - return ( - - ); - } + let isSuccess = !filesNotInGlobus && !filesNotInMetadata; + + return ( + + ); + } else { return ( diff --git a/src/components/Validation/ValidationFailure.js b/src/components/Validation/ValidationFailure.js deleted file mode 100644 index 4ca91e1..0000000 --- a/src/components/Validation/ValidationFailure.js +++ /dev/null @@ -1,112 +0,0 @@ -import React, { Component } from 'react'; -import { Container, Row, Col, Button } from 'reactstrap'; -import { Link } from 'react-router-dom'; - -class ValidationFailure extends Component { - - generateTableRows(filesProvided, filesFound) { - let rows = []; - if (filesProvided.length > filesFound.length) { - for (let i=0; i< filesProvided.length; i++) { - let fileProvided = filesProvided[i]; - let fileFound = filesFound.find((file) => file === fileProvided); - rows.push( - - - {fileProvided} - - - {fileFound} - - - ); - } - } else { - for (let i=0; i< filesFound.length; i++) { - let fileFound = filesFound[i]; - let fileProvided = filesProvided.find((file) => file === fileFound); - rows.push( - - - {fileProvided} - - - {fileFound} - - - ); - } - } - return rows; - } - - render() { - let metadataFileName = ''; - let filesProvided = this.props.result.filesFromMetadata.sort(); - let filesFound = this.props.result.filesInGlobus.sort(); - let metadataFileIndex = filesFound.findIndex((file) => file.startsWith('METADATA')); - if (metadataFileIndex > -1) { - metadataFileName = filesFound[metadataFileIndex]; - filesFound.splice(metadataFileIndex, 1); - } - let rows = this.generateTableRows(filesProvided, filesFound); - - return ( - - - - Filename mismatch - - -

Validation Failed!

- -
- - - Package Id: {this.props.result.packageId} - - - - - - Files Provided - - - Files Found - - - {rows} - {metadataFileName !== '' && - - - - - - {metadataFileName} - - - - } - - - - - - - - - - - - -
- ); - } -} - -export default ValidationFailure; \ No newline at end of file diff --git a/src/components/Validation/ValidationResult.js b/src/components/Validation/ValidationResult.js new file mode 100644 index 0000000..cc506df --- /dev/null +++ b/src/components/Validation/ValidationResult.js @@ -0,0 +1,68 @@ +import React, { Component } from 'react'; +import { Container, Row, Col, Button } from 'reactstrap'; +import { Link } from 'react-router-dom'; +import { generateTableRows } from './validationResultHelper'; + +class ValidationFailure extends Component { + + + render() { + + let rows = generateTableRows(this.props.result); + let message = 'Validation Failed!'; + let imgSrc = 'img/fail-kidneys.jpg'; + let altText = 'Filname mismatch'; + if (this.props.isSuccess) { + message = 'Validation Success!'; + imgSrc = 'img/happy-kidneys.jpg'; + altText = 'Filename match'; + } + + return ( + + + + {altText} + + +

{message}

+ +
+ + + Package Id: {this.props.result.packageId} + + + + + + Files Provided + + + Files Found + + + {rows} + + + + + + + + + + + + + +
+ ); + } +} + +export default ValidationFailure; \ No newline at end of file diff --git a/src/components/Validation/ValidationSuccess.js b/src/components/Validation/ValidationSuccess.js deleted file mode 100644 index e511123..0000000 --- a/src/components/Validation/ValidationSuccess.js +++ /dev/null @@ -1,95 +0,0 @@ -import React, { Component } from 'react'; -import { Container, Row, Col, Button } from 'reactstrap'; -import { Link } from 'react-router-dom'; - -class ValidationSuccess extends Component { - - generateTableRows(filesProvided, filesFound) { - let rows = []; - for (let i=0; i< filesProvided.length; i++) { - let fileProvided = filesProvided[i]; - let fileFound = filesFound[i]; - rows.push( - - - {fileProvided} - - - {fileFound} - - - ); - } - return rows; - } - - render() { - let metadataFileName = ''; - let filesProvided = this.props.result.filesFromMetadata.sort(); - let filesFound = this.props.result.filesInGlobus.sort(); - let metadataFileIndex = filesFound.findIndex((file) => file.startsWith('METADATA')); - if (metadataFileIndex > -1) { - metadataFileName = filesFound[metadataFileIndex]; - filesFound.splice(metadataFileIndex, 1); - } - let rows = this.generateTableRows(filesProvided, filesFound); - - return ( - - - - Filename match - - -

Validation Success!

- -
- - - Package Id: {this.props.result.packageId} - - - - - - Files Provided - - - Files Found - - - {rows} - {metadataFileName !== '' && - - - - - - {metadataFileName} - - - - } - - - - - - - - - - - - -
- ); - } -} - -export default ValidationSuccess; \ No newline at end of file diff --git a/src/components/Validation/validationResultHelper.js b/src/components/Validation/validationResultHelper.js new file mode 100644 index 0000000..330927f --- /dev/null +++ b/src/components/Validation/validationResultHelper.js @@ -0,0 +1,78 @@ +import React from 'react'; +import { Row, Col } from 'reactstrap'; + +export const generateTableRows = (results) => { + let filesProvided = results.filesFromMetadata.sort(); + let filesFound = results.filesInGlobus.sort(); + let filesNotInGlobus = results.metadataFilesNotFoundInGlobus; + let globusNotInMetadata = results.globusFilesNotFoundInMetadata; + let rows = []; + let remainingMetadataFiles = filesProvided; + let remainingGlobusFiles = filesFound; + + if (filesNotInGlobus) { + remainingMetadataFiles = filesProvided.filter(x => !filesNotInGlobus.includes(x)); + filesNotInGlobus.forEach((file) => { + rows.push ( + + + {file} + + + + + ); + }); + } + + if (globusNotInMetadata) { + remainingGlobusFiles = filesFound.filter(x => !globusNotInMetadata.includes(x)); + globusNotInMetadata.forEach((file) => { + rows.push( + + + + + {file} + + + ); + }); + } + + let includesMetadataFile = false; + remainingMetadataFiles.forEach((fileProvided) => { + if (fileProvided.startsWith('METADATA')) { + includesMetadataFile = true; + } + let fileFound = filesFound.find((file) => file === fileProvided); + rows.push( + + + {fileProvided} + + + {fileFound} + + + ); + + }); + + let metadataFile = remainingGlobusFiles.find((file) => file.startsWith('METADATA')); + if (metadataFile && !includesMetadataFile) { + rows.push( + + + + + + {metadataFile} + + + ); + } + + + return rows; +} \ No newline at end of file diff --git a/src/components/Validation/validationResultHelper.test.js b/src/components/Validation/validationResultHelper.test.js new file mode 100644 index 0000000..2a8aedc --- /dev/null +++ b/src/components/Validation/validationResultHelper.test.js @@ -0,0 +1,130 @@ +import React from 'react'; +import { Row, Col } from 'reactstrap'; +import { generateTableRows } from './validationResultHelper'; + +describe('generateTableRows', () => { + it('should generate the correct table when files provided matches files found', () => { + let filesProvided = [ 'a', 'b' ]; + let filesFound = [ 'a', 'b' ]; + let metadataFilesNotFoundInGlobus = null; + let globusFilesNotFoundInMetadata = null; + let results = { filesFromMetadata: filesProvided, filesInGlobus: filesFound, + metadataFilesNotFoundInGlobus, globusFilesNotFoundInMetadata }; + + let table = generateTableRows(results); + + expect(table.length).toEqual(2); + expect(table[0]).toEqual(aa); + expect(table[1]).toEqual(bb); + }); + + it('should generate the correct table when files provided matches files found and metadata file included', () => { + let filesProvided = [ 'a', 'METADATA_file.xls' ]; + let filesFound = [ 'a', 'METADATA_file.xls' ]; + let metadataFilesNotFoundInGlobus = null; + let globusFilesNotFoundInMetadata = null; + let results = { filesFromMetadata: filesProvided, filesInGlobus: filesFound, + metadataFilesNotFoundInGlobus, globusFilesNotFoundInMetadata }; + + let table = generateTableRows(results); + + expect(table.length).toEqual(2); + expect(table[0]).toEqual(METADATA_file.xlsMETADATA_file.xls); + expect(table[1]).toEqual(aa); + }); + + it ('should generate the correct table when more files found', () => { + let filesProvided = [ 'b' ]; + let filesFound = [ 'a', 'b' ]; + let metadataFilesNotFoundInGlobus = null; + let globusFilesNotFoundInMetadata = ['a']; + let results = { filesFromMetadata: filesProvided, filesInGlobus: filesFound, + metadataFilesNotFoundInGlobus, globusFilesNotFoundInMetadata }; + + let table = generateTableRows(results); + + expect(table.length).toEqual(2); + expect(table[0]).toEqual(a); + expect(table[1]).toEqual(bb); + + }); + + it ('should generate the correct table when more files provided', () => { + let filesProvided = [ 'a', 'b', 'c' ]; + let filesFound = [ 'a', 'b' ]; + let metadataFilesNotFoundInGlobus = ['c']; + let globusFilesNotFoundInMetadata = null; + let results = { filesFromMetadata: filesProvided, filesInGlobus: filesFound, + metadataFilesNotFoundInGlobus, globusFilesNotFoundInMetadata }; + + let table = generateTableRows(results); + + expect(table.length).toEqual(3); + expect(table[0]).toEqual(c); + expect(table[1]).toEqual(aa); + expect(table[2]).toEqual(bb); + }); + + it ('should generate the correct table when no files found', () => { + let filesProvided = [ 'c' ]; + let filesFound = [ ]; + let metadataFilesNotFoundInGlobus = ['c']; + let globusFilesNotFoundInMetadata = []; + let results = { filesFromMetadata: filesProvided, filesInGlobus: filesFound, + metadataFilesNotFoundInGlobus, globusFilesNotFoundInMetadata }; + + let table = generateTableRows(results); + + expect(table.length).toEqual(1); + expect(table[0]).toEqual(c); + }); + + it ('should generate the correct table when fewer provided than found and no overlap', () => { + let filesProvided = [ 'c' ]; + let filesFound = [ 'a', 'b' ]; + let metadataFilesNotFoundInGlobus = ['c']; + let globusFilesNotFoundInMetadata = ['a', 'b']; + let results = { filesFromMetadata: filesProvided, filesInGlobus: filesFound, + metadataFilesNotFoundInGlobus, globusFilesNotFoundInMetadata }; + + let table = generateTableRows(results); + + expect(table.length).toEqual(3); + expect(table[0]).toEqual(c); + expect(table[1]).toEqual(a); + expect(table[2]).toEqual(b); + }); + + it ('should generate the correct table when fewer found than provided and no overlap', () => { + let filesProvided = [ 'c', 'd' ]; + let filesFound = [ 'a' ]; + let metadataFilesNotFoundInGlobus = ['c', 'd']; + let globusFilesNotFoundInMetadata = ['a']; + let results = { filesFromMetadata: filesProvided, filesInGlobus: filesFound, + metadataFilesNotFoundInGlobus, globusFilesNotFoundInMetadata }; + + let table = generateTableRows(results); + + expect(table.length).toEqual(3); + expect(table[0]).toEqual(c); + expect(table[1]).toEqual(d); + expect(table[2]).toEqual(a); + }); + + it ('should always include the metadata file', () => { + let filesProvided = [ 'c', 'd' ]; + let filesFound = [ 'a', 'METADATA_file.xls' ]; + let metadataFilesNotFoundInGlobus = ['c', 'd']; + let globusFilesNotFoundInMetadata = ['a']; + let results = { filesFromMetadata: filesProvided, filesInGlobus: filesFound, + metadataFilesNotFoundInGlobus, globusFilesNotFoundInMetadata }; + + let table = generateTableRows(results); + + expect(table.length).toEqual(4); + expect(table[0]).toEqual(c); + expect(table[1]).toEqual(d); + expect(table[2]).toEqual(a); + expect(table[]).toEqual(METADATA_file.xls); + }); +}); \ No newline at end of file From 041ba46847629bbccdc17231292a36d271330ed5 Mon Sep 17 00:00:00 2001 From: Becky Reamy Date: Thu, 2 Jul 2020 14:04:44 -0400 Subject: [PATCH 2/2] KPMP-1919: fix test --- src/components/Validation/validationResultHelper.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Validation/validationResultHelper.test.js b/src/components/Validation/validationResultHelper.test.js index 2a8aedc..7f9833f 100644 --- a/src/components/Validation/validationResultHelper.test.js +++ b/src/components/Validation/validationResultHelper.test.js @@ -125,6 +125,6 @@ describe('generateTableRows', () => { expect(table[0]).toEqual(c); expect(table[1]).toEqual(d); expect(table[2]).toEqual(a); - expect(table[]).toEqual(METADATA_file.xls); + expect(table[3]).toEqual(METADATA_file.xls); }); }); \ No newline at end of file