diff --git a/app/cypress/e2e/0-ndr-core-tests/gp_upload_workflow_step2_individual_patient_document_upload.cy.js b/app/cypress/e2e/0-ndr-core-tests/gp_upload_workflow_step2_individual_patient_document_upload.cy.js index d19da1dc2..5fccdad58 100644 --- a/app/cypress/e2e/0-ndr-core-tests/gp_upload_workflow_step2_individual_patient_document_upload.cy.js +++ b/app/cypress/e2e/0-ndr-core-tests/gp_upload_workflow_step2_individual_patient_document_upload.cy.js @@ -58,29 +58,42 @@ const testStartAgainButton = () => { cy.url().should('eq', baseUrl); }; -const uploadedFilePathNames = [ - 'cypress/fixtures/test_patient_record.pdf', - 'cypress/fixtures/test_patient_record_two.pdf', -]; - -const uploadedImagesPathNames = [ - 'cypress/fixtures/test-images/test_image.jpg', - 'cypress/fixtures/test-images/test_image_two.jpg', - 'cypress/fixtures/test-images/test_image_three.jpg', - 'cypress/fixtures/test-images/test_image_four.jpg', - 'cypress/fixtures/test-images/test_image_five.jpg', - 'cypress/fixtures/test-images/test_image_six.jpg', - 'cypress/fixtures/test-images/test_image_seven.jpg', - 'cypress/fixtures/test-images/test_image_eight.jpg', - 'cypress/fixtures/test-images/test_image_nine.jpg', - 'cypress/fixtures/test-images/test_image_ten.jpg', - 'cypress/fixtures/test-images/test_image_eleven.jpg', -]; +const singleFileUsecaseIndex = 0; +const multiFileUSecaseIndex = 1; + +const uploadedFilePathNames = { + ARF: [ + 'cypress/fixtures/test_patient_record.pdf', + [ + 'cypress/fixtures/test_patient_record.pdf', + 'cypress/fixtures/test_patient_record_two.pdf', + ], + ], + LG: [ + 'cypress/fixtures/lg-files/1of1_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf', + [ + 'cypress/fixtures/lg-files/1of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf', + 'cypress/fixtures/lg-files/2of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf', + ], + ], +}; + +const uploadedFileNames = { + ARF: ['test_patient_record.pdf', ['test_patient_record.pdf', 'test_patient_record_two.pdf']], + LG: [ + '1of1_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf', + [ + '1of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf', + '2of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf', + ], + ], +}; beforeEach(() => { cy.visit(baseUrl); navigateToUploadPage(); }); + describe('[ALL] GP Upload Workflow Step 2: Uploads docs and tests it looks OK', () => { it.skip('(Smoke test) On Start now button click, redirect to uploads is successful', () => { cy.url().should('include', 'upload'); @@ -109,8 +122,8 @@ describe('[ALL] GP Upload Workflow Step 2: Uploads docs and tests it looks OK', }); } - selectForm(formTypes.ARF).selectFile(uploadedFilePathNames[0]); - selectForm(formTypes.LG).selectFile(uploadedFilePathNames[1]); + selectForm(formTypes.ARF).selectFile(uploadedFilePathNames.ARF[singleFileUsecaseIndex]); + selectForm(formTypes.LG).selectFile(uploadedFilePathNames.LG[singleFileUsecaseIndex]); clickUploadButton(); @@ -120,10 +133,12 @@ describe('[ALL] GP Upload Workflow Step 2: Uploads docs and tests it looks OK', cy.get('#successful-uploads-dropdown').click(); cy.get('#successful-uploads tbody tr').should('have.length', 2); - cy.get('#successful-uploads tbody tr').eq(0).should('contain', 'test_patient_record.pdf'); + cy.get('#successful-uploads tbody tr') + .eq(0) + .should('contain', uploadedFileNames.ARF[singleFileUsecaseIndex]); cy.get('#successful-uploads tbody tr') .eq(1) - .should('contain', 'test_patient_record_two.pdf'); + .should('contain', uploadedFileNames.LG[singleFileUsecaseIndex]); cy.get('#close-page-warning').should('be.visible'); testStartAgainButton(); @@ -134,14 +149,14 @@ Object.values(formTypes).forEach((type) => { describe(`[${type}] GP Upload Workflow Step 2: Uploads docs and tests it looks OK`, () => { it.skip(`(Smoke test) Single file - On Choose files button click, file selection is visible for ${type} input`, () => { cy.get('#selected-documents-table').should('not.exist'); - selectForm(type).selectFile(uploadedFilePathNames[0]); + selectForm(type).selectFile(uploadedFilePathNames[type][singleFileUsecaseIndex]); cy.get('#selected-documents-table').should('be.visible'); cy.get('#selected-documents-table tbody tr').should('have.length', 1); cy.get('#selected-documents-table tbody tr') .first() .get('td') .first() - .should('have.text', 'test_patient_record.pdf'); + .should('contain.text', uploadedFileNames[type][singleFileUsecaseIndex]); }); it.skip(`Single file - On Upload button click, renders Upload Summary with error box when DocumentReference returns a 500 for ${type} input`, () => { @@ -150,7 +165,7 @@ Object.values(formTypes).forEach((type) => { statusCode: 500, }); - selectForm(type).selectFile(uploadedFilePathNames[0]); + selectForm(type).selectFile(uploadedFilePathNames[type][singleFileUsecaseIndex]); clickUploadButton(); @@ -161,7 +176,7 @@ Object.values(formTypes).forEach((type) => { .first() .get('td') .first() - .should('contain', 'test_patient_record.pdf'); + .should('contain', uploadedFileNames[type][0]); cy.get('#failed-uploads').should('contain', '1 of 1 files failed to upload'); cy.get('#close-page-warning').should('be.visible'); @@ -174,7 +189,7 @@ Object.values(formTypes).forEach((type) => { statusCode: 404, }); - selectForm(type).selectFile(uploadedFilePathNames[1]); + selectForm(type).selectFile(uploadedFilePathNames[type][singleFileUsecaseIndex]); clickUploadButton(); @@ -183,9 +198,9 @@ Object.values(formTypes).forEach((type) => { cy.get('#failed-uploads tbody tr').should('have.length', 1); cy.get('#failed-uploads tbody tr') .first() - .get('td') + .children() .first() - .should('contain', 'test_patient_record_two.pdf'); + .should('contain', uploadedFileNames[type][singleFileUsecaseIndex]); cy.get('#failed-uploads').should('contain', '1 of 1 files failed to upload'); cy.get('#close-page-warning').should('be.visible'); @@ -200,7 +215,7 @@ Object.values(formTypes).forEach((type) => { statusCode: 500, }); - selectForm(type).selectFile(uploadedImagesPathNames[0]); + selectForm(type).selectFile(uploadedFilePathNames[type][singleFileUsecaseIndex]); clickUploadButton(); @@ -209,9 +224,9 @@ Object.values(formTypes).forEach((type) => { cy.get('#failed-uploads tbody tr').should('have.length', 1); cy.get('#failed-uploads tbody tr') .first() - .get('td') + .children() .first() - .should('contain', 'test_image.jpg'); + .should('contain.text', uploadedFileNames[type][singleFileUsecaseIndex]); cy.get('#failed-uploads').should('contain', '1 of 1 files failed to upload'); cy.get('#close-page-warning').should('be.visible'); @@ -220,17 +235,20 @@ Object.values(formTypes).forEach((type) => { it.skip(`(Smoke test) Multiple files - On Choose files button click, file selection is visible for ${type} input`, () => { cy.get('#selected-documents-table').should('not.exist'); - selectForm(type).selectFile(uploadedFilePathNames); + selectForm(type).selectFile(uploadedFilePathNames[type][multiFileUSecaseIndex]); cy.get('#selected-documents-table').should('be.visible'); cy.get('#selected-documents-table tbody tr').should('have.length', 2); + cy.get('#selected-documents-table tbody tr') .first() - .get('td') + .children() .first() - .should('have.text', 'test_patient_record.pdf'); + .should('have.text', uploadedFileNames[type][multiFileUSecaseIndex][0]); cy.get('#selected-documents-table tbody tr') - .next() - .contains('td', 'test_patient_record_two.pdf'); + .eq(1) + .children() + .first() + .should('have.text', uploadedFileNames[type][multiFileUSecaseIndex][1]); }); it.skip(`(Smoke test) Multiple files - On Upload button click, renders Upload Summary for successful upload for ${type} input`, () => { @@ -255,7 +273,7 @@ Object.values(formTypes).forEach((type) => { }); } - selectForm(type).selectFile(uploadedFilePathNames); + selectForm(type).selectFile(uploadedFilePathNames[type][multiFileUSecaseIndex]); clickUploadButton(); @@ -265,9 +283,9 @@ Object.values(formTypes).forEach((type) => { cy.get('#successful-uploads tbody tr').should('have.length', 2); cy.get('#successful-uploads tbody tr') .first() - .get('td') + .children() .first() - .should('contain', 'test_patient_record.pdf'); + .should('contain', uploadedFileNames[type][multiFileUSecaseIndex][0]); cy.get('#close-page-warning').should('be.visible'); testStartAgainButton(); @@ -277,30 +295,24 @@ Object.values(formTypes).forEach((type) => { cy.intercept('POST', '**/DocumentReference*', (req) => { req.reply({ statusCode: 200, + delay: 1500, body: { url: bucketUrlIdentifer, fields: { - key: '382d3db4-9625-4bd9-ad46-c2e31451efd2', + key: 'xxxxxxxxxxxx2', 'x-amz-algorithm': 'AWS4-HMAC-SHA256', 'x-amz-credential': - 'ASIAXYSUA44VYD2FFBHK/20230904/eu-west-2/s3/aws4_request', + 'xxxxxxxxxxxxxxxxxx/20230904/eu-west-2/s3/aws4_request', 'x-amz-date': '20230904T125954Z', - 'x-amz-security-token': - 'IQoJb3JpZ2luX2VjEG0aCWV1LXdlc3QtMiJHMEUCIQC1Mx4VTrF2alA9s8P5HJ+j9y2XJmAF5ODdZGEui/QMGwIgRdGiuXVqq8Uq6l5dJZpAx39b1kro7x1Q0FQn6rWRUvUqggMIRhABGgw1MzM4MjU5MDY0NzUiDOeBIQxpj1BmAtTeVSrfAsugZpo7cQzj+R0uwE9o3bxMyR7lqdVCkaAb/ZVF4iBY/Cn7FYCB+pO3nvS6CWLClcIbNhhZkqgJOZvBJ+fua5QvchxX4LO+sq0Or+s29Ym8mSNHpB4mLi3iyQZ08Iw1p9c52Mfo6B5mh5IGKu8gvKf1y9gOWKAJTTuLbuzKKkbII4tRr+1PSAeFwLgSSzeDInv9QnTbKAPSbVMAWBic07MTlQpeMD3SNiXqKz+f/HNiujCOxfvUO0Yvw5GXx0FBrGjaHY979YGJuuC35yMqnFG0tvdd/8OfdUhHDM6XqRMGmceMkdMldQsw4VwhSd+uI4qIrHopMNQ+XKdqDjrkmlRprATIT9boO1fQ1GFO2l1YVVM2WzORIwVd2hGQr6anfXyOePk8N8MYNuzwZdgOiEKPwS2b6vByMBr/U7jNUuUZNd9rhbZIv5dsMF2xszXq8co3ZngvPjWKYsdZF6eGUDDHqdenBjqeAYZZ0oBZqtgVF3ebT86UWZ40zS0vGZSzSt5P5DhlTP01LRPeQCARoETZ/IsUzvrP5QLwmkOjSoJlYIu/U1SeqvVZblnPHsHVi/0QI4FuZhPL9LnA628+euBTaO6I2DSf1ugPmwMc/YMYwHQdkSKNsejAPczYSxAyPAWLtiLckMPqo5YyyiRYMHpmZwrqJsdbAVogVhIgfYx53OJIhblI', - policy: 'eyJleHBpcmF0aW9uIjogIjIwMjMtMDktMDRUMTM6Mjk6NTRaIi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URqcmttbFJwckFUSVQ5Ym9PMWZRMUdGTzJsMVlWVk0yV3pPUkl3VmQyaEdRcjZhbmZYeU9lUGs4TjhNWU51endaZGdPaUVLUHdTMmI2dkJ5TUJyL1U3ak5VdVVaTmQ5cmhiWkl2NWRzTUYyeHN6WHE4Y28zWm5ndlBqV0tZc2RaRjZlR1VEREhxZGVuQmpxZUFZWlowb0JacXRnVkYzZWJUODZVV1o0MHpTMHZHWlN6U3Q1UDVEaGxUUDAxTFJQZVFDQVJvRVRaL0lzVXp2clA1UUx3bWtPalNvSmxZSXUvVTFTZXF2VlpibG5QSHNIVmkvMFFJNEZ1WmhQTDlMbkE2MjgrZXVCVGFPNkkyRFNmMXVnUG13TWMvWU1Zd0hRZGtTS05zZWpBUGN6WVN4QXlQQVdMdGlMY2tNUHFvNVl5eWlSWU1IcG1ad3JxSnNkYkFWb2dWaElnZll4NTNPSkloYmxJIn1dfQ==', - 'x-amz-signature': - '9e861ee405f4930c8fd992e631fa202563b50b23c2f505cbfcbd407198cd594d', + 'x-amz-security-token': 'xxxxxxxxxxxxxxxx', + policy: 'xxxxxxxxx====', + 'x-amz-signature': 'xxxxxxxxx', }, }, }); - req.on('response', (res) => { - // Throttle the response to 1 Mbps to simulate a - // mobile 3G connection - res.setThrottle(1000); - }); }); - selectForm(type).selectFile(uploadedImagesPathNames); + selectForm(type).selectFile(uploadedFilePathNames[type][multiFileUSecaseIndex]); clickUploadButton(); @@ -313,19 +325,29 @@ Object.values(formTypes).forEach((type) => { statusCode: 500, }); - selectForm(type).selectFile(uploadedImagesPathNames); + selectForm(type).selectFile(uploadedFilePathNames[type][1]); clickUploadButton(); cy.get('#failed-document-uploads-summary-title').should('be.visible'); cy.get('#failed-uploads').should('be.visible'); - cy.get('#failed-uploads tbody tr').should('have.length', 11); + cy.get('#failed-uploads tbody tr').should( + 'have.length', + uploadedFilePathNames[type][1].length, + ); + cy.get('#failed-uploads tbody tr') .first() - .get('td') + .children() .first() - .should('contain', 'test_image.jpg'); - cy.get('#failed-uploads').should('contain', '11 of 11 files failed to upload'); + .should('contain.text', uploadedFileNames[type][multiFileUSecaseIndex][0]); + + const fileCount = uploadedFilePathNames[type][multiFileUSecaseIndex].length; + cy.get('#failed-uploads').should( + 'contain', + fileCount + ' of ' + fileCount + ' files failed to upload', + ); + cy.get('#close-page-warning').should('be.visible'); testStartAgainButton(); @@ -337,19 +359,29 @@ Object.values(formTypes).forEach((type) => { statusCode: 404, }); - selectForm(type).selectFile(uploadedImagesPathNames); + selectForm(type).selectFile(uploadedFilePathNames[type][multiFileUSecaseIndex]); clickUploadButton(); cy.get('#failed-document-uploads-summary-title').should('be.visible'); cy.get('#failed-uploads').should('be.visible'); - cy.get('#failed-uploads tbody tr').should('have.length', 11); + cy.get('#failed-uploads tbody tr').should( + 'have.length', + uploadedFilePathNames[type][multiFileUSecaseIndex].length, + ); + cy.get('#failed-uploads tbody tr') .first() - .get('td') + .children() .first() - .should('contain', 'test_image.jpg'); - cy.get('#failed-uploads').should('contain', '11 of 11 files failed to upload'); + .should('contain.text', uploadedFileNames[type][multiFileUSecaseIndex][0]); + + const fileCount = uploadedFilePathNames[type][multiFileUSecaseIndex].length; + cy.get('#failed-uploads').should( + 'contain', + fileCount + ' of ' + fileCount + ' files failed to upload', + ); + cy.get('#close-page-warning').should('be.visible'); testStartAgainButton(); @@ -361,16 +393,13 @@ Object.values(formTypes).forEach((type) => { body: { url: bucketUrlIdentifer, fields: { - key: '382d3db4-9625-4bd9-ad46-c2e31451efd2', + key: 'xxxxxxxxxxxx2', 'x-amz-algorithm': 'AWS4-HMAC-SHA256', - 'x-amz-credential': - 'ASIAXYSUA44VYD2FFBHK/20230904/eu-west-2/s3/aws4_request', + 'x-amz-credential': 'xxxxxxxxxxxxxxxxxx/20230904/eu-west-2/s3/aws4_request', 'x-amz-date': '20230904T125954Z', - 'x-amz-security-token': - 'IQoJb3JpZ2luX2VjEG0aCWV1LXdlc3QtMiJHMEUCIQC1Mx4VTrF2alA9s8P5HJ+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lowb0JacXRnVkYzZWJUODZVV1o0MHpTMHZHWlN6U3Q1UDVEaGxUUDAxTFJQZVFDQVJvRVRaL0lzVXp2clA1UUx3bWtPalNvSmxZSXUvVTFTZXF2VlpibG5QSHNIVmkvMFFJNEZ1WmhQTDlMbkE2MjgrZXVCVGFPNkkyRFNmMXVnUG13TWMvWU1Zd0hRZGtTS05zZWpBUGN6WVN4QXlQQVdMdGlMY2tNUHFvNVl5eWlSWU1IcG1ad3JxSnNkYkFWb2dWaElnZll4NTNPSkloYmxJIn1dfQ==', - 'x-amz-signature': - '9e861ee405f4930c8fd992e631fa202563b50b23c2f505cbfcbd407198cd594d', + 'x-amz-security-token': 'xxxxxxxxxxxxxxxx', + policy: 'xxxxxxxxx====', + 'x-amz-signature': 'xxxxxxxxx', }, }, }); @@ -383,14 +412,14 @@ Object.values(formTypes).forEach((type) => { }); }); - selectForm(type).selectFile(uploadedImagesPathNames); + selectForm(type).selectFile(uploadedFilePathNames[type][multiFileUSecaseIndex]); clickUploadButton(); cy.get('#upload-summary-header').should('be.visible'); - cy.get('#failed-uploads').should('contain', '6 of 11 files failed to upload'); - cy.get('#failed-uploads tbody tr').should('have.length', 6); - cy.get('#successful-uploads tbody tr').should('have.length', 5); + cy.get('#failed-uploads').should('contain', '1 of 2 files failed to upload'); + cy.get('#failed-uploads tbody tr').should('have.length', 1); + cy.get('#successful-uploads tbody tr').should('have.length', 1); cy.get('#close-page-warning').should('be.visible'); testStartAgainButton(); diff --git a/app/cypress/fixtures/lg-files/1of1_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf b/app/cypress/fixtures/lg-files/1of1_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf new file mode 100644 index 000000000..e69de29bb diff --git a/app/cypress/fixtures/lg-files/1of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf b/app/cypress/fixtures/lg-files/1of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf new file mode 100644 index 000000000..e69de29bb diff --git a/app/cypress/fixtures/lg-files/2of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf b/app/cypress/fixtures/lg-files/2of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf new file mode 100644 index 000000000..e69de29bb diff --git a/app/cypress/fixtures/test-images/test_image.jpg b/app/cypress/fixtures/test-images/test_image.jpg deleted file mode 100644 index 152d9abee..000000000 Binary files a/app/cypress/fixtures/test-images/test_image.jpg and /dev/null differ diff --git a/app/cypress/fixtures/test-images/test_image_eight.jpg b/app/cypress/fixtures/test-images/test_image_eight.jpg deleted file mode 100644 index bfb6cc835..000000000 Binary files a/app/cypress/fixtures/test-images/test_image_eight.jpg and /dev/null differ diff --git a/app/cypress/fixtures/test-images/test_image_eleven.jpg b/app/cypress/fixtures/test-images/test_image_eleven.jpg deleted file mode 100644 index 70c22b425..000000000 Binary files a/app/cypress/fixtures/test-images/test_image_eleven.jpg and /dev/null differ diff --git a/app/cypress/fixtures/test-images/test_image_five.jpg b/app/cypress/fixtures/test-images/test_image_five.jpg deleted file mode 100644 index 032021bd3..000000000 Binary files a/app/cypress/fixtures/test-images/test_image_five.jpg and /dev/null differ diff --git a/app/cypress/fixtures/test-images/test_image_four.jpg b/app/cypress/fixtures/test-images/test_image_four.jpg deleted file mode 100644 index e08bf57ad..000000000 Binary files a/app/cypress/fixtures/test-images/test_image_four.jpg and /dev/null differ diff --git a/app/cypress/fixtures/test-images/test_image_nine.jpg b/app/cypress/fixtures/test-images/test_image_nine.jpg deleted file mode 100644 index fd4973a24..000000000 Binary files a/app/cypress/fixtures/test-images/test_image_nine.jpg and /dev/null differ diff --git a/app/cypress/fixtures/test-images/test_image_seven.jpg b/app/cypress/fixtures/test-images/test_image_seven.jpg deleted file mode 100644 index cec209c65..000000000 Binary files a/app/cypress/fixtures/test-images/test_image_seven.jpg and /dev/null differ diff --git a/app/cypress/fixtures/test-images/test_image_six.jpg b/app/cypress/fixtures/test-images/test_image_six.jpg deleted file mode 100644 index 374f2a94c..000000000 Binary files a/app/cypress/fixtures/test-images/test_image_six.jpg and /dev/null differ diff --git a/app/cypress/fixtures/test-images/test_image_ten.jpg b/app/cypress/fixtures/test-images/test_image_ten.jpg deleted file mode 100644 index 7f6c8bf5a..000000000 Binary files a/app/cypress/fixtures/test-images/test_image_ten.jpg and /dev/null differ diff --git a/app/cypress/fixtures/test-images/test_image_three.jpg b/app/cypress/fixtures/test-images/test_image_three.jpg deleted file mode 100644 index a878ae5f3..000000000 Binary files a/app/cypress/fixtures/test-images/test_image_three.jpg and /dev/null differ diff --git a/app/cypress/fixtures/test-images/test_image_two.jpg b/app/cypress/fixtures/test-images/test_image_two.jpg deleted file mode 100644 index fd4973a24..000000000 Binary files a/app/cypress/fixtures/test-images/test_image_two.jpg and /dev/null differ diff --git a/app/src/components/blocks/documentInputForm/DocumentInputForm.tsx b/app/src/components/blocks/documentInputForm/DocumentInputForm.tsx index 348044def..25d381759 100644 --- a/app/src/components/blocks/documentInputForm/DocumentInputForm.tsx +++ b/app/src/components/blocks/documentInputForm/DocumentInputForm.tsx @@ -75,12 +75,23 @@ const DocumentInputForm = ({ . )} + {formType === DOCUMENT_TYPE.LLOYD_GEORGE && ( + <> +
  • + Each Lloyd George file uploaded must match the following format: + [PDFnumber]_Lloyd_George_Record_[Patient Name]_[NHS + Number]_[D.O.B]. For example: 1of2_Lloyd_George_Record_[Joe + Bloggs]_[123456789]_[25-12-2019] +
  • +
  • You can only upload PDF files
  • + + )} } />
    {documents && documents.length > 0 && ( - +
    Filename @@ -111,7 +122,7 @@ const DocumentInputForm = ({
    )} - {hasDuplicateFiles && ( + {hasDuplicateFiles && formType === DOCUMENT_TYPE.ARF && ( Possible duplicate file

    There are two or more documents with the same name.

    diff --git a/app/src/components/blocks/selectStage/SelectStage.test.tsx b/app/src/components/blocks/selectStage/SelectStage.test.tsx index b59bde1b5..9c06681a6 100644 --- a/app/src/components/blocks/selectStage/SelectStage.test.tsx +++ b/app/src/components/blocks/selectStage/SelectStage.test.tsx @@ -1,7 +1,11 @@ /* eslint-disable testing-library/no-unnecessary-act */ import { render, screen, waitFor } from '@testing-library/react'; import SelectStage from './SelectStage'; -import { buildPatientDetails, buildTextFile } from '../../../helpers/test/testBuilders'; +import { + buildPatientDetails, + buildTextFile, + buildLgFile, +} from '../../../helpers/test/testBuilders'; import userEvent from '@testing-library/user-event'; import { DOCUMENT_UPLOAD_STATE as documentUploadStates } from '../../../types/pages/UploadDocumentsPage/types'; import { act } from 'react-dom/test-utils'; @@ -19,6 +23,9 @@ describe('', () => { const documentOne = buildTextFile('one', 100); const documentTwo = buildTextFile('two', 200); const documentThree = buildTextFile('three', 100); + const lgDocumentOne = buildLgFile(1, 2); + const lgDocumentTwo = buildLgFile(2, 2); + const arfDocuments = [documentOne, documentTwo, documentThree]; const setDocumentMock = jest.fn(); setDocumentMock.mockImplementation((document) => { @@ -58,16 +65,14 @@ describe('', () => { }); act(() => { - userEvent.upload(screen.getByTestId('LG-input'), [ - documentOne, - documentTwo, - documentThree, - ]); + userEvent.upload(screen.getByTestId('LG-input'), [lgDocumentOne, lgDocumentTwo]); }); - expect(await screen.findAllByText(documentOne.name)).toHaveLength(2); - expect(await screen.findAllByText(documentTwo.name)).toHaveLength(2); - expect(await screen.findAllByText(documentThree.name)).toHaveLength(2); + expect(await screen.findAllByText(documentOne.name)).toHaveLength(1); + expect(await screen.findAllByText(documentTwo.name)).toHaveLength(1); + expect(await screen.findAllByText(documentThree.name)).toHaveLength(1); + expect(await screen.findAllByText(lgDocumentOne.name)).toHaveLength(1); + expect(await screen.findAllByText(lgDocumentTwo.name)).toHaveLength(1); expect(screen.getByRole('button', { name: 'Upload' })).toBeEnabled(); }); @@ -101,20 +106,25 @@ describe('', () => { }, ); - it.each([['ARF'], ['LG']])( - "does not upload either forms if selected file is less than 5GB for '%s' input", + it.each([ + { name: 'ARF', documents: arfDocuments }, + { name: 'LG', documents: [buildLgFile(1, 2)] }, + ])( + "does not upload either forms if selected file is more than 5GB for '%s' input", async (inputType) => { renderSelectStage(setDocumentMock); - const documentBig = buildTextFile('four', 6 * Math.pow(1024, 3)); + const documentBig = + inputType.name === 'ARF' + ? buildTextFile('four', 6 * Math.pow(1024, 3)) + : buildLgFile(3, 2, 6 * Math.pow(1024, 3)); + inputType.documents.push(documentBig); act(() => { - userEvent.upload(screen.getByTestId(`${inputType}-input`), [ - documentOne, - documentTwo, - documentThree, - documentBig, - ]); + userEvent.upload( + screen.getByTestId(`${inputType.name}-input`), + inputType.documents, + ); }); expect(screen.getByText(documentBig.name)).toBeInTheDocument(); @@ -131,8 +141,153 @@ describe('', () => { }, ); - it.each([['ARF'], ['LG']])( - "shows a duplicate file warning if two or more files match name/size for '%s' input", + it('does not upload LG form if selected file is not PDF', async () => { + renderSelectStage(setDocumentMock); + const lgFileWithBadType = new File( + ['test'], + `1of2000_Lloyd_George_Record_[Joe Bloggs]_[1234567890]_[25-12-2019].pdf`, + { + type: 'text/plain', + }, + ); + + act(() => { + userEvent.upload(screen.getByTestId(`LG-input`), lgFileWithBadType); + }); + + expect(screen.getByText(lgFileWithBadType.name)).toBeInTheDocument(); + + act(() => { + userEvent.click(screen.getByText('Upload')); + }); + + expect( + await screen.findByText( + 'One or more of the files do not match the required file type. Please check the file(s) and try again', + ), + ).toBeInTheDocument(); + }); + + it('does not upload LG form if total number of file does not match file name', async () => { + renderSelectStage(setDocumentMock); + const lgExtraFile = buildLgFile(3, 3); + + act(() => { + userEvent.upload(screen.getByTestId(`LG-input`), lgExtraFile); + }); + + expect(screen.getByText(lgExtraFile.name)).toBeInTheDocument(); + + act(() => { + userEvent.click(screen.getByText('Upload')); + }); + + expect( + await screen.findByText( + 'One or more of the files do not match the required filename format. Please check the file(s) and try again', + ), + ).toBeInTheDocument(); + }); + + it('does not upload LG form if selected file does not match naming conventions', async () => { + renderSelectStage(setDocumentMock); + const pdfFileWithBadName = new File(['test'], `test_not_up_to_naming_conventions.pdf`, { + type: 'application/pdf', + }); + act(() => { + userEvent.upload(screen.getByTestId(`LG-input`), pdfFileWithBadName); + }); + + expect(screen.getByText(pdfFileWithBadName.name)).toBeInTheDocument(); + + act(() => { + userEvent.click(screen.getByText('Upload')); + }); + + expect( + await screen.findByText( + 'One or more of the files do not match the required filename format. Please check the file(s) and try again', + ), + ).toBeInTheDocument(); + }); + + it('does not upload LG form if selected file number is bigger than number of total files', async () => { + renderSelectStage(setDocumentMock); + const pdfFileWithBadNumber = buildLgFile(2, 1); + act(() => { + userEvent.upload(screen.getByTestId(`LG-input`), pdfFileWithBadNumber); + }); + + expect(screen.getByText(pdfFileWithBadNumber.name)).toBeInTheDocument(); + + act(() => { + userEvent.click(screen.getByText('Upload')); + }); + + expect( + await screen.findByText( + 'One or more of the files do not match the required filename format. Please check the file(s) and try again', + ), + ).toBeInTheDocument(); + }); + + it('does not upload LG form if files do not match each other', async () => { + renderSelectStage(setDocumentMock); + const joeBloggsFile = new File( + ['test'], + `1of2_Lloyd_George_Record_[Joe Bloggs]_[1234567890]_[25-12-2019].pdf`, + { + type: 'application/pdf', + }, + ); + const johnSmithFile = new File( + ['test'], + `2of2_Lloyd_George_Record_[John Smith]_[9876543210]_[25-12-2019].pdf`, + { + type: 'application/pdf', + }, + ); + act(() => { + userEvent.upload(screen.getByTestId(`LG-input`), [joeBloggsFile, johnSmithFile]); + }); + + expect(screen.getByText(joeBloggsFile.name)).toBeInTheDocument(); + expect(screen.getByText(johnSmithFile.name)).toBeInTheDocument(); + + act(() => { + userEvent.click(screen.getByText('Upload')); + }); + + expect( + await screen.findByText( + 'One or more of the files do not match the required filename format. Please check the file(s) and try again', + ), + ).toBeInTheDocument(); + }); + + it('does not upload LG form if two or more files match name/size', async () => { + renderSelectStage(setDocumentMock); + const duplicateFileWarning = 'There are two or more documents with the same name.'; + act(() => { + userEvent.upload(screen.getByTestId(`LG-input`), [lgDocumentTwo, lgDocumentTwo]); + }); + + expect(screen.getAllByText(lgDocumentTwo.name)).toHaveLength(2); + + act(() => { + userEvent.click(screen.getByText('Upload')); + }); + + expect( + await screen.findByText( + 'There are documents chosen that have the same name, a record with duplicate file names can not be uploaded because it does not match the required file format. Please check the files(s) and try again.', + ), + ).toBeInTheDocument(); + expect(screen.queryByText(duplicateFileWarning)).not.toBeInTheDocument(); + }); + + it.each([['ARF']])( + 'shows a duplicate file warning if two or more files match name/size for ARF input only', async (inputType) => { const duplicateFileWarning = 'There are two or more documents with the same name.'; @@ -165,7 +320,7 @@ describe('', () => { async (inputType) => { renderSelectStage(setDocumentMock); - const selectFilesLabel = screen.getByTestId('ARF-input'); + const selectFilesLabel = screen.getByTestId(`${inputType}-input`); act(() => { userEvent.upload(selectFilesLabel, documentOne); diff --git a/app/src/components/blocks/selectStage/SelectStage.tsx b/app/src/components/blocks/selectStage/SelectStage.tsx index 8d2011339..f2a2fb452 100644 --- a/app/src/components/blocks/selectStage/SelectStage.tsx +++ b/app/src/components/blocks/selectStage/SelectStage.tsx @@ -28,7 +28,9 @@ function SelectStage({ uploadDocuments, setDocuments, patientDetails }: Props) { const mergedDocuments = [...arfDocuments, ...lgDocuments]; const hasFileInput = mergedDocuments.length; - + const lgRegex = + /[0-9]+of[0-9]+_Lloyd_George_Record_\[[A-Za-z]+\s[A-Za-z]+]_\[[0-9]{10}]_\[\d\d-\d\d-\d\d\d\d].pdf/; // eslint-disable-line + const lgFilesNumber = /of[0-9]+/; const FIVEGB = 5 * Math.pow(1024, 3); const { handleSubmit, control, formState } = useForm(); const formConfig = (name: string) => ({ @@ -39,18 +41,63 @@ function SelectStage({ uploadDocuments, setDocuments, patientDetails }: Props) { isFile: () => { return !!hasFileInput || 'Please select a file'; }, - isLessThan5GB: (value?: Array) => { + perFileValidation: (value?: Array) => { if (Array.isArray(value)) { for (let i = 0; i < value.length; i++) { - if (value[i].file.size > FIVEGB) { + const currentFile = value[i].file; + if (currentFile.size > FIVEGB) { return 'Please ensure that all files are less than 5GB in size'; } + if (name === 'lg-documents') { + if (currentFile.type !== 'application/pdf') { + return 'One or more of the files do not match the required file type. Please check the file(s) and try again'; + } + const expectedNumberOfFiles = currentFile.name.match(lgFilesNumber); + const doesPassRegex = lgRegex.exec(currentFile.name); + const doFilesTotalMatch = + expectedNumberOfFiles && + value.length === parseInt(expectedNumberOfFiles[0].slice(2)); + const isFileNumberBiggerThanTotal = + expectedNumberOfFiles && + parseInt(currentFile.name.split(lgFilesNumber)[0]) > + parseInt(expectedNumberOfFiles[0].slice(2)); + const isFileNumberZero = + currentFile.name.split(lgFilesNumber)[0] === '0'; + const doesFileNameMatchEachOther = + currentFile.name.split(lgFilesNumber)[1] === + value[0].file.name.split(lgFilesNumber)[1]; + if ( + !doesPassRegex || + !doFilesTotalMatch || + isFileNumberBiggerThanTotal || + isFileNumberZero || + !doesFileNameMatchEachOther + ) { + return 'One or more of the files do not match the required filename format. Please check the file(s) and try again'; + } + } } } }, + hasDuplicateFile: (value?: Array) => { + if ( + name === 'lg-documents' && + value?.some((doc: UploadDocument) => { + return value?.some( + (compare: UploadDocument) => + doc.file.name === compare.file.name && + doc.file.size === compare.file.size && + doc.id !== compare.id, + ); + }) + ) { + return 'There are documents chosen that have the same name, a record with duplicate file names can not be uploaded because it does not match the required file format. Please check the files(s) and try again.'; + } + }, }, }, }); + const lgController = useController(formConfig('lg-documents')); const arfController = useController(formConfig('arf-documents')); @@ -87,11 +134,13 @@ function SelectStage({ uploadDocuments, setDocuments, patientDetails }: Props) { setArfDocuments(updatedDocList); if (arfInputRef.current) { arfInputRef.current.files = toFileList(updatedDocList); + arfController.field.onChange(updatedDocList); } } else { setLgDocuments(updatedDocList); if (lgInputRef.current) { lgInputRef.current.files = toFileList(updatedDocList); + lgController.field.onChange(updatedDocList); } } @@ -106,11 +155,12 @@ function SelectStage({ uploadDocuments, setDocuments, patientDetails }: Props) { noValidate data-testid="upload-document-form" > + + Upload documents + + +
    - - Upload documents - -

    Electronic health records

    -
    -
    +
    +

    Lloyd George records

    { return file; }; +const buildLgFile = (name: number, numberOfFiles: number, size?: number) => { + const file = new File( + ['test'], + `${name}of${numberOfFiles}_Lloyd_George_Record_[Joe Bloggs]_[1234567890]_[25-12-2019].pdf`, + { + type: 'application/pdf', + }, + ); + + if (size) { + Object.defineProperty(file, 'size', { + value: size, + }); + } + + return file; +}; + const buildDocument = ( file: File, uploadStatus: DOCUMENT_UPLOAD_STATE, @@ -77,4 +95,11 @@ const buildSearchResult = (searchResultOverride?: Partial) => { return result; }; -export { buildUserAuth, buildPatientDetails, buildTextFile, buildDocument, buildSearchResult }; +export { + buildUserAuth, + buildPatientDetails, + buildTextFile, + buildDocument, + buildSearchResult, + buildLgFile, +};