Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Files] Add download file test #2139

Merged
merged 10 commits into from
May 23, 2022
Original file line number Diff line number Diff line change
@@ -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]")
}
32 changes: 32 additions & 0 deletions packages/files-ui/cypress/tests/file-management-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { homePage } from "../support/page-objects/homePage"
import { navigationMenu } from "../support/page-objects/navigationMenu"
import { folderName, folderPath } from "../fixtures/filesTestData"
import "cypress-pipe"
import path from "path"
juans-chainsafe marked this conversation as resolved.
Show resolved Hide resolved
import { apiTestHelper } from "../support/utils/apiTestHelper"
import { createFolderModal } from "../support/page-objects/modals/createFolderModal"
import { deleteFileModal } from "../support/page-objects/modals/deleteFileModal"
Expand All @@ -13,6 +14,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", () => {
Expand Down Expand Up @@ -502,5 +504,35 @@ 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")
Tbaut marked this conversation as resolved.
Show resolved Hide resolved

cy.web3Login({ clearCSFBucket: true })

// upload a file
homePage.uploadFile(`../fixtures/uploadedFiles/${fileName}`)
Tbaut marked this conversation as resolved.
Show resolved Hide resolved
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 download
Tbaut marked this conversation as resolved.
Show resolved Hide resolved
downloadCompleteToast.body().should("be.visible")
downloadCompleteToast.closeButton().click()
cy.readFile(path.join(downloadsFolder, fileName)).should("exist")
})
})
})
4 changes: 3 additions & 1 deletion packages/files-ui/src/Contexts/FilesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ const FilesProvider = ({ children }: FilesContextProps) => {
type: "success",
progress: 0,
isClosable: false,
testId: "downloading-file",
onProgressCancel: cancelSource.cancel
}
const toastId = addToast(toastParams)
Expand Down Expand Up @@ -652,7 +653,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)
Expand Down