From 378e61fcbe838720a2b3249d08606e6e007a42e0 Mon Sep 17 00:00:00 2001 From: Juan Manuel Spoleti Date: Wed, 18 May 2022 15:27:30 -0300 Subject: [PATCH 1/6] files - download file from file browser TEST done --- .../toasts/downloadCompleteToast.ts | 4 +++ .../cypress/tests/file-management-spec.ts | 32 +++++++++++++++++++ .../files-ui/src/Contexts/FilesContext.tsx | 4 ++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 packages/files-ui/cypress/support/page-objects/toasts/downloadCompleteToast.ts 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..c69bdbb899 100644 --- a/packages/files-ui/cypress/tests/file-management-spec.ts +++ b/packages/files-ui/cypress/tests/file-management-spec.ts @@ -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" import { apiTestHelper } from "../support/utils/apiTestHelper" import { createFolderModal } from "../support/page-objects/modals/createFolderModal" import { deleteFileModal } from "../support/page-objects/modals/deleteFileModal" @@ -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", () => { @@ -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") + + cy.web3Login({ clearCSFBucket: true }) + + // upload a file + homePage.uploadFile(`../fixtures/uploadedFiles/${fileName}`) + 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 + downloadCompleteToast.body().should("be.visible") + downloadCompleteToast.closeButton().click() + cy.readFile(path.join(downloadsFolder, fileName)).should("exist") + }) }) }) diff --git a/packages/files-ui/src/Contexts/FilesContext.tsx b/packages/files-ui/src/Contexts/FilesContext.tsx index b76d65c1dc..dca6ddc221 100644 --- a/packages/files-ui/src/Contexts/FilesContext.tsx +++ b/packages/files-ui/src/Contexts/FilesContext.tsx @@ -622,6 +622,7 @@ const FilesProvider = ({ children }: FilesContextProps) => { type: "success", progress: 0, isClosable: false, + testId: "downloading-file", onProgressCancel: cancelSource.cancel } const toastId = addToast(toastParams) @@ -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) From d9df801e3a2c0045621e7d6a99dfe53f90dbf17e Mon Sep 17 00:00:00 2001 From: Juan Manuel Spoleti Date: Thu, 19 May 2022 10:35:33 -0300 Subject: [PATCH 2/6] remove ; --- packages/files-ui/cypress/tests/file-management-spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/files-ui/cypress/tests/file-management-spec.ts b/packages/files-ui/cypress/tests/file-management-spec.ts index c69bdbb899..8596508f4c 100644 --- a/packages/files-ui/cypress/tests/file-management-spec.ts +++ b/packages/files-ui/cypress/tests/file-management-spec.ts @@ -526,8 +526,8 @@ describe("File management", () => { cy.wait("@downloadRequest").should((download) => { expect(download.response).to.have.property("statusCode", 200); - }); - }); + }) + }) // ensure the file was download downloadCompleteToast.body().should("be.visible") From 85f2996b1e838864e05dd3bcf6093015dcf145e2 Mon Sep 17 00:00:00 2001 From: Juan Manuel Spoleti Date: Fri, 20 May 2022 09:30:00 -0300 Subject: [PATCH 3/6] add file content validation --- .../files-ui/cypress/tests/file-management-spec.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/files-ui/cypress/tests/file-management-spec.ts b/packages/files-ui/cypress/tests/file-management-spec.ts index 8596508f4c..9a629fccc2 100644 --- a/packages/files-ui/cypress/tests/file-management-spec.ts +++ b/packages/files-ui/cypress/tests/file-management-spec.ts @@ -511,8 +511,9 @@ describe("File management", () => { cy.web3Login({ clearCSFBucket: true }) - // upload a file + // upload a file and store file content homePage.uploadFile(`../fixtures/uploadedFiles/${fileName}`) + cy.readFile(`cypress/fixtures/uploadedFiles/${fileName}`).as("fileContent") homePage.fileItemRow().should("have.length", 1) // download file from kebab menu @@ -529,10 +530,15 @@ describe("File management", () => { }) }) - // ensure the file was download + // ensure the file was downloaded downloadCompleteToast.body().should("be.visible") downloadCompleteToast.closeButton().click() - cy.readFile(path.join(downloadsFolder, fileName)).should("exist") + cy.get("@fileContent").then((fileContent) => { + cy.readFile(path.join(downloadsFolder, fileName)) + .should("exist") + .should("eq", fileContent); + }); + }) }) }) From 8b1c3c0285639c0b95b89081597d863613db1b8b Mon Sep 17 00:00:00 2001 From: Juan Manuel Spoleti Date: Fri, 20 May 2022 09:57:04 -0300 Subject: [PATCH 4/6] remove ; --- packages/files-ui/cypress/tests/file-management-spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/files-ui/cypress/tests/file-management-spec.ts b/packages/files-ui/cypress/tests/file-management-spec.ts index 9a629fccc2..31d76b1067 100644 --- a/packages/files-ui/cypress/tests/file-management-spec.ts +++ b/packages/files-ui/cypress/tests/file-management-spec.ts @@ -523,10 +523,10 @@ describe("File management", () => { cy.intercept("POST", "**/bucket/*/download") .as("downloadRequest") .then(() => { - homePage.downloadMenuOption().eq(0).click(); + homePage.downloadMenuOption().eq(0).click() cy.wait("@downloadRequest").should((download) => { - expect(download.response).to.have.property("statusCode", 200); + expect(download.response).to.have.property("statusCode", 200) }) }) @@ -536,8 +536,8 @@ describe("File management", () => { cy.get("@fileContent").then((fileContent) => { cy.readFile(path.join(downloadsFolder, fileName)) .should("exist") - .should("eq", fileContent); - }); + .should("eq", fileContent) + }) }) }) From b211f4bcaff6f4b5ec0534354301173646b52c68 Mon Sep 17 00:00:00 2001 From: Juan Manuel Spoleti Date: Fri, 20 May 2022 12:53:58 -0300 Subject: [PATCH 5/6] fixes from PR comment --- .../files-ui/cypress/tests/file-management-spec.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/files-ui/cypress/tests/file-management-spec.ts b/packages/files-ui/cypress/tests/file-management-spec.ts index 31d76b1067..788bc6d9ff 100644 --- a/packages/files-ui/cypress/tests/file-management-spec.ts +++ b/packages/files-ui/cypress/tests/file-management-spec.ts @@ -3,7 +3,6 @@ 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" import { apiTestHelper } from "../support/utils/apiTestHelper" import { createFolderModal } from "../support/page-objects/modals/createFolderModal" import { deleteFileModal } from "../support/page-objects/modals/deleteFileModal" @@ -505,15 +504,16 @@ describe("File management", () => { fileInfoModal.body().should("not.exist") }) - it("can download a file from file browser", () => { + it.only("can download a file from file browser", () => { const fileName = "text-file.txt" const downloadsFolder = Cypress.config("downloadsFolder") + const fileRelativePath = `uploadedFiles/${fileName}` cy.web3Login({ clearCSFBucket: true }) // upload a file and store file content - homePage.uploadFile(`../fixtures/uploadedFiles/${fileName}`) - cy.readFile(`cypress/fixtures/uploadedFiles/${fileName}`).as("fileContent") + homePage.uploadFile(`../fixtures/${fileRelativePath}`) + cy.fixture(fileRelativePath).as("fileContent") homePage.fileItemRow().should("have.length", 1) // download file from kebab menu @@ -534,7 +534,7 @@ describe("File management", () => { downloadCompleteToast.body().should("be.visible") downloadCompleteToast.closeButton().click() cy.get("@fileContent").then((fileContent) => { - cy.readFile(path.join(downloadsFolder, fileName)) + cy.readFile(`${downloadsFolder}/${fileName}`) .should("exist") .should("eq", fileContent) }) From d0aadc1436673e22d73a8744ade5bf7e6b5cdf8c Mon Sep 17 00:00:00 2001 From: Thibaut Sardan Date: Mon, 23 May 2022 15:21:57 +0200 Subject: [PATCH 6/6] simplifying remove only and lint --- .../cypress/tests/file-management-spec.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/files-ui/cypress/tests/file-management-spec.ts b/packages/files-ui/cypress/tests/file-management-spec.ts index 788bc6d9ff..499f575862 100644 --- a/packages/files-ui/cypress/tests/file-management-spec.ts +++ b/packages/files-ui/cypress/tests/file-management-spec.ts @@ -468,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) => { @@ -504,21 +504,21 @@ describe("File management", () => { fileInfoModal.body().should("not.exist") }) - it.only("can download a file from file browser", () => { + it("can download a file from file browser", () => { const fileName = "text-file.txt" const downloadsFolder = Cypress.config("downloadsFolder") - const fileRelativePath = `uploadedFiles/${fileName}` + const fileFixturePath = `uploadedFiles/${fileName}` cy.web3Login({ clearCSFBucket: true }) - + // upload a file and store file content - homePage.uploadFile(`../fixtures/${fileRelativePath}`) - cy.fixture(fileRelativePath).as("fileContent") + 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") @@ -529,7 +529,7 @@ describe("File management", () => { expect(download.response).to.have.property("statusCode", 200) }) }) - + // ensure the file was downloaded downloadCompleteToast.body().should("be.visible") downloadCompleteToast.closeButton().click()