Skip to content

Commit

Permalink
add cypress testing for file download
Browse files Browse the repository at this point in the history
  • Loading branch information
AshrafMd-1 committed Feb 17, 2024
1 parent 916e2bf commit 4df976e
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 6 deletions.
65 changes: 61 additions & 4 deletions cypress/e2e/patient_spec/patient_detailpage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("Patient Details", () => {
it("Edit file name", () => {
patientPage.visitPatient("Dummy Patient 4");
patientFileUploadPage.visitPatientDetailsPage();
patientFileUploadPage.clickEditFileName(
patientFileUploadPage.editFileName(
`Cypress File ${new Date().getTime().toString().slice(9)}`
);
patientFileUploadPage.clickSaveFileName();
Expand All @@ -54,17 +54,74 @@ describe("Patient Details", () => {
it("Archive file", () => {
patientPage.visitPatient("Dummy Patient 4");
patientFileUploadPage.visitPatientDetailsPage();
patientFileUploadPage.clickArchiveFile();
patientFileUploadPage.archiveFile();
patientFileUploadPage.clickSaveArchiveFile();
patientFileUploadPage.verifySuccessNotification(
"File archived successfully"
);
patientFileUploadPage.verifyArchiveFile();
});

//TODO : Verify the uploaded file can only be modified by the author, district admin, and above users.
it("Verify the uploaded file be edited by author", () => {
loginPage.login("dummynurse1", "Coronasafe@123");
patientPage.visitPatient("Dummy Patient 5");
patientFileUploadPage.visitPatientDetailsPage();
patientFileUploadPage.uploadFile();
patientFileUploadPage.clickUploadFile();
patientFileUploadPage.verifyFileEditOption(true);
patientFileUploadPage.editFileName(
`Cypress File ${new Date().getTime().toString().slice(9)}`
);
patientFileUploadPage.clickSaveFileName();
patientFileUploadPage.verifySuccessNotification(
"File name changed successfully"
);
});

it("Verify the uploaded file be cannot edited by other users below district admin", () => {
loginPage.login("dummynurse2", "Coronasafe@123");
patientPage.visitPatient("Dummy Patient 5");
patientFileUploadPage.visitPatientDetailsPage();
patientFileUploadPage.verifyFileEditOption(false);
});

it("Verify the uploaded file be can edited by district admin and above", () => {
loginPage.loginAsDisctrictAdmin();
patientPage.visitPatient("Dummy Patient 5");
patientFileUploadPage.visitPatientDetailsPage();
patientFileUploadPage.verifyFileEditOption(true);
patientFileUploadPage.editFileName(
`Cypress File ${new Date().getTime().toString().slice(9)}`
);
patientFileUploadPage.clickSaveFileName();
patientFileUploadPage.verifySuccessNotification(
"File name changed successfully"
);
});

it("Verify that file download is possible for author.", () => {
loginPage.login("dummynurse1", "Coronasafe@123");
patientPage.visitPatient("Dummy Patient 5");
patientFileUploadPage.visitPatientDetailsPage();
patientFileUploadPage.verifyFileDownloadOption(true);
patientFileUploadPage.downloadFile();
});

it("Verify that file download is possible for users below district admin.", () => {
loginPage.login("dummynurse2", "Coronasafe@123");
patientPage.visitPatient("Dummy Patient 5");
patientFileUploadPage.visitPatientDetailsPage();
patientFileUploadPage.verifyFileDownloadOption(true);
patientFileUploadPage.downloadFile();
});

//TODO : Verify file download is possible for all users.
it("Verify that file download is possible for district admin and above.", () => {
loginPage.loginAsDisctrictAdmin();
patientPage.visitPatient("Dummy Patient 5");
patientFileUploadPage.visitPatientDetailsPage();
patientFileUploadPage.verifyFileDownloadOption(true);
patientFileUploadPage.downloadFile();
});

afterEach(() => {
cy.saveLocalStorage();
Expand Down
20 changes: 18 additions & 2 deletions cypress/pageobject/Patient/PatientFileupload.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { cy } from "local-cypress";

let fileName = "";

export class PatientFileUploadPage {
Expand Down Expand Up @@ -31,7 +33,7 @@ export class PatientFileUploadPage {
cy.wait("@uploadFile").its("response.statusCode").should("eq", 201);
}

clickEditFileName(newFileName: string) {
editFileName(newFileName: string) {
cy.get("#edit-file-name").click().scrollIntoView();
cy.get("#editFileName").clear().type(newFileName);
}
Expand All @@ -42,7 +44,7 @@ export class PatientFileUploadPage {
cy.wait("@saveFileName").its("response.statusCode").should("eq", 200);
}

clickArchiveFile() {
archiveFile() {
cy.wait(2000);
cy.get("#file-name").then(($el: string) => {
fileName = $el.text().split(":")[1].trim();
Expand All @@ -65,6 +67,20 @@ export class PatientFileUploadPage {
});
}

verifyFileEditOption(status: boolean) {
cy.get("#edit-file-name").should(status ? "be.visible" : "not.exist");
}

verifyFileDownloadOption(status: boolean) {
cy.get("#preview-file").should(status ? "be.visible" : "not.be.visible");
}

downloadFile() {
cy.intercept("GET", "**/api/v1/files/**").as("downloadFile");
cy.get("#preview-file").click();
cy.wait("@downloadFile").its("response.statusCode").should("eq", 200);
}

verifySuccessNotification(msg: string) {
cy.verifyNotification(msg);
}
Expand Down
1 change: 1 addition & 0 deletions src/Components/Patient/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ export const FileUpload = (props: FileUploadProps) => {
onClick={() => {
loadFile(item.id);
}}
id="preview-file"
className="m-1 w-full sm:w-auto"
>
{" "}
Expand Down

0 comments on commit 4df976e

Please sign in to comment.