Skip to content

Commit

Permalink
PRMDR-679 added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NogaNHS committed Feb 21, 2024
1 parent 884263f commit 96e76ac
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const searchPatientUrl = '/search/patient';
const viewLloydGeorgeRecordUrl = '/patient/view/lloyd-george-record';
const clickUploadButton = () => {
cy.get('#upload-button').click();
cy.wait(20);
};

const testSearchPatientButton = () => {
Expand All @@ -20,6 +19,12 @@ const testViewRecordButton = () => {
cy.url().should('eq', baseUrl + viewLloydGeorgeRecordUrl);
};

const testUploadCompletePageContent = () => {
cy.getByTestId('upload-complete-card').should('be.visible');
cy.getByTestId('view-record-btn').should('be.visible');
cy.getByTestId('search-patient-btn').should('be.visible');
};

const uploadedFilePathNames = {
LG: [
'cypress/fixtures/lg-files/1of1_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf',
Expand All @@ -40,10 +45,37 @@ const uploadedFileNames = {
],
};
const bucketUrlIdentifer = 'document-store.s3.amazonaws.com';
const selectForm = () => cy.getByTestId(`upload-document-form`);
const singleFileUsecaseIndex = 0;
const multiFileUSecaseIndex = 1;
const multiFileUsecaseIndex = 1;
const fileNames = uploadedFileNames.LG[multiFileUsecaseIndex];

const stubbedResponseMulti = {
statusCode: 200,
body: {
[fileNames[0]]: {
url: 'http://' + bucketUrlIdentifer,
fields: {
key: 'test key',
'x-amz-algorithm': 'xxxx-xxxx-SHA256',
'x-amz-credential': 'xxxxxxxxxxx/20230904/eu-west-2/s3/aws4_request',
'x-amz-date': '20230904T125954Z',
'x-amz-security-token': 'xxxxxxxxx',
'x-amz-signature': '9xxxxxxxx',
},
},
[fileNames[1]]: {
url: 'http://' + bucketUrlIdentifer,
fields: {
key: 'test key',
'x-amz-algorithm': 'xxxx-xxxx-SHA256',
'x-amz-credential': 'xxxxxxxxxxx/20230904/eu-west-2/s3/aws4_request',
'x-amz-date': '20230904T125954Z',
'x-amz-security-token': 'xxxxxxxxx',
'x-amz-signature': '9xxxxxxxx',
},
},
},
};
describe('GP Workflow: Upload Lloyd George record when user is GP admin BSOL and patient has no record', () => {
const beforeEachConfiguration = () => {
cy.login(Roles.GP_ADMIN);
Expand All @@ -63,6 +95,8 @@ describe('GP Workflow: Upload Lloyd George record when user is GP admin BSOL and
cy.get('#verify-submit').click();
cy.wait('@stitch');
cy.getByTestId('upload-patient-record-button').click();
cy.url().should('include', 'upload');
cy.url().should('eq', baseUrl + '/patient/upload/lloyd-george-record');
};

beforeEach(() => {
Expand All @@ -71,10 +105,10 @@ describe('GP Workflow: Upload Lloyd George record when user is GP admin BSOL and

context('Upload Lloyd George document for an active patient', () => {
it(
`User can upload a single Lloyd George file using the "Select files" button and can then view LG record`,
`User can upload a single LG file using the "Select files" button and can then view LG record`,
{ tags: 'regression' },
() => {
const fileName = uploadedFileNames.LG[0];
const fileName = uploadedFileNames.LG[singleFileUsecaseIndex];

const stubbedResponse = {
statusCode: 200,
Expand All @@ -94,9 +128,6 @@ describe('GP Workflow: Upload Lloyd George record when user is GP admin BSOL and
},
};

cy.url().should('include', 'upload');
cy.url().should('eq', baseUrl + '/patient/upload/lloyd-george-record');

cy.intercept('POST', '**/DocumentReference**', stubbedResponse);
cy.intercept('POST', '**/' + bucketUrlIdentifer + '**', {
statusCode: 204,
Expand All @@ -108,17 +139,82 @@ describe('GP Workflow: Upload Lloyd George record when user is GP admin BSOL and
);
clickUploadButton();

cy.getByTestId('upload-documents-table').should(
'contain',
uploadedFileNames.LG[singleFileUsecaseIndex],
);
cy.wait(20);

cy.getByTestId('upload-complete-page')
.should('include.text', 'Record uploaded for')
.should('include.text', 'You have successfully uploaded 1 file')
.should('include.text', 'Hide files')
.should('contain', uploadedFileNames.LG[singleFileUsecaseIndex]);
cy.getByTestId('upload-complete-card').should('be.visible');
cy.getByTestId('view-record-btn').should('be.visible');
cy.getByTestId('search-patient-btn').should('be.visible');

testUploadCompletePageContent();

testViewRecordButton();
},
);
it(
`User can upload a multiple LG file using the "Select files" button and can then view LG record`,
{ tags: 'regression' },
() => {
cy.intercept('POST', '**/DocumentReference**', stubbedResponseMulti);
cy.intercept('POST', '**/' + bucketUrlIdentifer + '**', {
statusCode: 204,
});

cy.getByTestId('button-input').selectFile(
uploadedFilePathNames.LG[multiFileUsecaseIndex],
{ force: true },
);
clickUploadButton();
cy.getByTestId('upload-documents-table')
.should('contain', uploadedFileNames.LG[multiFileUsecaseIndex][0])
.should('contain', uploadedFileNames.LG[multiFileUsecaseIndex][1]);
cy.wait(20);

cy.getByTestId('upload-complete-page')
.should('include.text', 'Record uploaded for')
.should('include.text', 'You have successfully uploaded 2 files')
.should('include.text', 'Hide files');

testUploadCompletePageContent();

testSearchPatientButton();
},
);

it(
`User can upload a multiple LG file using drag and drop and can then view LG record`,
{ tags: 'regression' },
() => {
cy.intercept('POST', '**/DocumentReference**', stubbedResponseMulti);
cy.intercept('POST', '**/' + bucketUrlIdentifer + '**', {
statusCode: 204,
});

cy.getByTestId('dropzone').selectFile(
uploadedFilePathNames.LG[multiFileUsecaseIndex],
{ force: true, action: 'drag-drop' },
);
clickUploadButton();
cy.getByTestId('upload-documents-table')
.should('contain', uploadedFileNames.LG[multiFileUsecaseIndex][0])
.should('contain', uploadedFileNames.LG[multiFileUsecaseIndex][1]);
cy.wait(20);

cy.getByTestId('upload-complete-page')
.should('include.text', 'Record uploaded for')
.should('include.text', 'You have successfully uploaded 2 files')
.should('include.text', 'Hide files')
.should('contain', uploadedFileNames.LG[multiFileUsecaseIndex][0])
.should('contain', uploadedFileNames.LG[multiFileUsecaseIndex][1]);
testUploadCompletePageContent();

testSearchPatientButton();
},
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function LloydGeorgeUploadStage({ documents, setStage }: Props) {
captionProps={{
className: 'nhsuk-u-visually-hidden',
}}
data-testid="upload-documents-table"
>
<Table.Head>
<Table.Row>
Expand Down

0 comments on commit 96e76ac

Please sign in to comment.