diff --git a/packages/files-ui/cypress/support/page-objects/toasts/downloadCompleteToast.ts b/packages/files-ui/cypress/support/page-objects/toasts/downloadCompleteToast.ts new file mode 100644 index 0000000000..b60227f978 --- /dev/null +++ b/packages/files-ui/cypress/support/page-objects/toasts/downloadCompleteToast.ts @@ -0,0 +1,4 @@ +export const downloadCompleteToast = { + body: () => cy.get("[data-testid=toast-download-complete]", { timeout: 10000 }), + closeButton: () => cy.get("[data-testid=button-close-toast-download-complete]") +} diff --git a/packages/files-ui/cypress/tests/file-management-spec.ts b/packages/files-ui/cypress/tests/file-management-spec.ts index a95a153c73..499f575862 100644 --- a/packages/files-ui/cypress/tests/file-management-spec.ts +++ b/packages/files-ui/cypress/tests/file-management-spec.ts @@ -13,6 +13,7 @@ import { deleteSuccessToast } from "../support/page-objects/toasts/deleteSuccess import { moveSuccessToast } from "../support/page-objects/toasts/moveSuccessToast" import { recoverSuccessToast } from "../support/page-objects/toasts/recoverSuccessToast" import { uploadCompleteToast } from "../support/page-objects/toasts/uploadCompleteToast" +import { downloadCompleteToast } from "../support/page-objects/toasts/downloadCompleteToast" import { fileInfoModal } from "../support/page-objects/modals/fileInfoModal" describe("File management", () => { @@ -467,25 +468,25 @@ describe("File management", () => { it("can view file information via modal option", () => { cy.web3Login({ clearCSFBucket: true }) - + // upload a file homePage.uploadFile("../fixtures/uploadedFiles/text-file.txt") homePage.fileItemRow().should("have.length", 1) - + // store file name as cypress aliases for later comparison homePage.fileItemName().eq(0).invoke("text").as("fileNameA") - + // navigate to the info modal for the file homePage.fileItemKebabButton().first().click() homePage.infoMenuOption().eq(0).click() - + // ensure all labels on the modal are visible fileInfoModal.nameLabel().should("be.visible") fileInfoModal.fileSizeLabel().should("be.visible") fileInfoModal.dateUploadedLabel().should("be.visible") fileInfoModal.cidLabel().should("be.visible") fileInfoModal.decryptionKeyLabel().should("be.visible") - + // ensure the correct file name is being displayed fileInfoModal.body().should("be.visible") cy.get("@fileNameA").then((fileNameA) => { @@ -502,5 +503,42 @@ describe("File management", () => { fileInfoModal.closeButton().click() fileInfoModal.body().should("not.exist") }) + + it("can download a file from file browser", () => { + const fileName = "text-file.txt" + const downloadsFolder = Cypress.config("downloadsFolder") + const fileFixturePath = `uploadedFiles/${fileName}` + + cy.web3Login({ clearCSFBucket: true }) + + // upload a file and store file content + homePage.uploadFile(fileFixturePath) + cy.fixture(fileFixturePath).as("fileContent") + homePage.fileItemRow().should("have.length", 1) + + // download file from kebab menu + homePage.fileItemKebabButton().first().click() + + // intercept POST to ensure the request was successful + cy.intercept("POST", "**/bucket/*/download") + .as("downloadRequest") + .then(() => { + homePage.downloadMenuOption().eq(0).click() + + cy.wait("@downloadRequest").should((download) => { + expect(download.response).to.have.property("statusCode", 200) + }) + }) + + // ensure the file was downloaded + downloadCompleteToast.body().should("be.visible") + downloadCompleteToast.closeButton().click() + cy.get("@fileContent").then((fileContent) => { + cy.readFile(`${downloadsFolder}/${fileName}`) + .should("exist") + .should("eq", fileContent) + }) + + }) }) }) diff --git a/packages/files-ui/src/Contexts/FilesContext.tsx b/packages/files-ui/src/Contexts/FilesContext.tsx index 58f6dbb9ba..e2722bdf5f 100644 --- a/packages/files-ui/src/Contexts/FilesContext.tsx +++ b/packages/files-ui/src/Contexts/FilesContext.tsx @@ -633,6 +633,7 @@ const FilesProvider = ({ children }: FilesContextProps) => { type: "success", progress: 0, isClosable: false, + testId: "downloading-file", onProgressCancel: cancelSource.cancel } const toastId = addToast(toastParams) @@ -663,7 +664,8 @@ const FilesProvider = ({ children }: FilesContextProps) => { type: "success", progress: undefined, onProgressCancel: undefined, - isClosable: true + isClosable: true, + testId: "download-complete" }, true) URL.revokeObjectURL(link.href) setDownloadsInProgress(false)