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]")
}
48 changes: 43 additions & 5 deletions packages/files-ui/cypress/tests/file-management-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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<string>("@fileNameA").then((fileNameA) => {
Expand All @@ -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")
Tbaut marked this conversation as resolved.
Show resolved Hide resolved
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<string>("@fileContent").then((fileContent) => {
cy.readFile(`${downloadsFolder}/${fileName}`)
.should("exist")
.should("eq", fileContent)
})

})
})
})
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 @@ -633,6 +633,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 @@ -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)
Expand Down