Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const confirmationUrl = '/patient/document-upload/confirmation';
dbItem.FileLocation = dbItem.FileLocation.replace('{env}', workspace);

const uploadedFilePathNames = [
'cypress/fixtures/lg-files/simple_pages/6.pdf',
'cypress/fixtures/lg-files/simple_pages/7.pdf',
'cypress/fixtures/lg-files/simple_pdf_pages/6.pdf',
'cypress/fixtures/lg-files/simple_pdf_pages/7.pdf',
];
const uploadedFileNames = ['6', '7'];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { pdsPatients } from '../../../support/patients';
import dbItem from '../../../fixtures/dynamo-db-items/active-patient-h81109.json';
import { Roles } from '../../../support/roles';

const workspace = Cypress.env('WORKSPACE');
const lgTableName = `${workspace}_LloydGeorgeReferenceMetadata`;
const bucketName = `${workspace}-lloyd-george-store`;
const activePatient = pdsPatients.activeUpload;
const filePath = `${activePatient}/`;

const patientVerifyUrl = '/patient/verify';
const lloydGeorgeRecordUrl = '/patient/documents';
const documentUploadUrl = '/patient/document-upload';
const selectFilesUrl = '/patient/document-upload/select-files';
const confirmationUrl = '/patient/document-upload/confirmation';

dbItem.FileLocation = dbItem.FileLocation.replace('{env}', workspace);

const uploadedEhrFilePathName = 'cypress/fixtures/lg-files/simple_pdf_pages/6.pdf';
const uploadedEhrFileName = '6.pdf';

const uploadedEhrAttachmentsFilePathNames = [
'cypress/fixtures/non-pdf-files/1.csv',
'cypress/fixtures/non-pdf-files/2.txt',
];
const uploadedEhrAttachmentsFileNames = ['1.csv', '2.txt'];

const expectedRows = [
{
type: 'Electronic health record',
filename: uploadedEhrFileName,
},
{
type: 'Electronic health record attachments',
filename: 'EHR_Attachments_(2).zip',
},
];

describe('GP Workflow: Upload EHR with attachments and view them successfully as data controller', () => {
context('Upload EHR with attachments and view them successfully as data controller', () => {
beforeEach(() => {
cy.deleteItemsBySecondaryKeyFromDynamoDb(
lgTableName,
'NhsNumberIndex',
'NhsNumber',
activePatient.toString(),
);
});

afterEach(() => {
cy.deleteItemsBySecondaryKeyFromDynamoDb(
lgTableName,
'NhsNumberIndex',
'NhsNumber',
activePatient.toString(),
);
cy.deleteAllFilesFromS3Prefix(bucketName, filePath);
});

const roles = [Roles.SMOKE_GP_ADMIN, Roles.SMOKE_GP_CLINICAL];

roles.forEach((role) => {
it(
`[Smoke] ${role} can upload EHR with attachments and view them successfully`,
{ tags: 'smoke', defaultCommandTimeout: 20000 },
() => {
cy.smokeLogin(role);
cy.navigateToPatientSearchPage();

cy.get('#nhs-number-input').should('exist');
cy.get('#nhs-number-input').click();
cy.get('#nhs-number-input').type(activePatient);
cy.getByTestId('search-submit-btn').should('exist');
cy.getByTestId('search-submit-btn').click();
cy.url({ timeout: 15000 }).should('contain', patientVerifyUrl);

cy.get('#verify-submit').should('exist');
cy.get('#verify-submit').click();
cy.url().should('contain', lloydGeorgeRecordUrl);

cy.getByTestId('upload-button').click();
cy.url().should('contain', documentUploadUrl);

cy.getByTestId('upload-717301000000104-link').should('exist');
cy.getByTestId('upload-717301000000104-link').click();
cy.url().should('contain', selectFilesUrl);

cy.getByTestId('button-input').selectFile(uploadedEhrFilePathName, {
force: true,
});
cy.get('#selected-documents-table').should('contain', uploadedEhrFileName);

cy.get('#continue-button').should('exist');
cy.get('#continue-button').click();
cy.url().should('contain', selectFilesUrl);

uploadedEhrAttachmentsFilePathNames.forEach((file) => {
cy.getByTestId('button-input').selectFile(file, { force: true });
var index = uploadedEhrAttachmentsFilePathNames.indexOf(file);
cy.get('#selected-documents-table').should(
'contain',
uploadedEhrAttachmentsFileNames[index],
);
});

cy.get('#continue-button').should('exist');
cy.get('#continue-button').click();
cy.url().should('contain', confirmationUrl);
cy.get('#selected-717301000000104-table').should(
'contain',
uploadedEhrFileName,
);
uploadedEhrAttachmentsFileNames.forEach((file) => {
var index = uploadedEhrAttachmentsFileNames.indexOf(file);
cy.get('#selected-24511000000107-table').should(
'contain',
uploadedEhrAttachmentsFileNames[index],
);
});
cy.getByTestId('confirm-button').should('exist').click();

cy.getByTestId('upload-complete-page').should('exist');
cy.getByTestId('upload-complete-card').should('be.visible');

cy.getByTestId('home-btn').should('exist');
cy.getByTestId('home-btn').eq(1).click();
cy.navigateToPatientSearchPage();

cy.get('#nhs-number-input').type(activePatient);
cy.get('#search-submit').click();
cy.get('.patient-results-form').should('exist');
cy.get('.patient-results-form').submit();

cy.getByTestId('available-files-table-title').should('exist');

cy.get('[data-testid="search-result"]').should(
'have.length',
expectedRows.length,
);

expectedRows.forEach((row, index) => {
cy.get('[data-testid="search-result"]')
.eq(index)
.within(() => {
cy.get('[data-testid="doctype"]').should('contain.text', row.type);
cy.get('[data-testid="filename"]').should(
'contain.text',
row.filename,
);
cy.get('[data-testid^="view-"]')
.should('exist')
.and('be.visible')
.and('contain.text', 'View');
});
});
},
);
});
});
});
1 change: 1 addition & 0 deletions app/cypress/fixtures/non-pdf-files/1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions app/cypress/fixtures/non-pdf-files/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
26 changes: 26 additions & 0 deletions app/cypress/support/aws.commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
DeleteObjectCommand,
PutObjectCommandInput,
DeleteObjectCommandInput,
ListObjectsV2Command,
ListObjectsV2CommandOutput,
} from '@aws-sdk/client-s3';

import {
Expand Down Expand Up @@ -91,6 +93,30 @@ Cypress.Commands.add('deleteFileFromS3', (bucketName: string, fileName: string)
);
});

Cypress.Commands.add('deleteAllFilesFromS3Prefix', (bucketName: string, prefix: string): void => {
const deleteAllFilesFromS3Prefix = async (): Promise<void> => {
const listResponse: ListObjectsV2CommandOutput = await s3.send(
new ListObjectsV2Command({
Bucket: bucketName,
Prefix: prefix,
}),
);

const keys: string[] = (listResponse.Contents || []).map((obj) => obj.Key!);

for (const key of keys) {
await s3.send(
new DeleteObjectCommand({
Bucket: bucketName,
Key: key,
}),
);
}
};

cy.then(() => deleteAllFilesFromS3Prefix());
});

Cypress.Commands.add(
'deleteItemFromDynamoDb',
(tableName: string, itemId: string, version?: number) => {
Expand Down
11 changes: 10 additions & 1 deletion app/cypress/support/commands.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// cypress/support/commands.d.ts
/// <reference types="cypress" />

import type { PutObjectCommandOutput, DeleteObjectCommandOutput } from '@aws-sdk/client-s3';
import type {
PutObjectCommandOutput,
DeleteObjectCommandOutput,
ListObjectsCommandOutput,
} from '@aws-sdk/client-s3';
import type { PutItemCommandOutput, DeleteItemCommandOutput } from '@aws-sdk/client-dynamodb';

declare global {
Expand All @@ -25,6 +29,11 @@ declare global {
fileName: string,
): Chainable<DeleteObjectCommandOutput>;

deleteAllFilesFromS3Prefix(
bucketName: string,
prefix: string,
): Chainable<ListObjectsCommandOutput>;

deleteItemFromDynamoDb(
tableName: string,
itemId: string,
Expand Down
Loading