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

Detect and dismiss toasts in ui tests #1610

Merged
merged 10 commits into from
Oct 6, 2021
1 change: 1 addition & 0 deletions packages/common-components/src/Toasts/ToastContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const ToastContent = ({ toast, onClose }: ToastContentProps) => {
}
{isClosable &&
<div
data-testid={`button-close-toast-${toast.testId}`}
className={classes.closeIcon}
onClick={onClose}
>
Expand Down
1 change: 0 additions & 1 deletion packages/files-ui/cypress/support/page-objects/binPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const binPage = {
// bin page specific file browser elements
recoverSelectedButton: () => cy.get("[data-testId=button-recover-selected-file]"),
deleteSelectedButton: () => cy.get("[data-testId=button-delete-selected-file]"),
permanentDeleteSuccessToast: () => cy.get("[data-testId=toast-deletion-success]", { timeout: 10000 }),
selectAllCheckbox: () => cy.get("[data-testId=checkbox-select-all]"),

// kebab menu elements
Expand Down
7 changes: 3 additions & 4 deletions packages/files-ui/cypress/support/page-objects/homePage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { basePage } from "./basePage"
import { fileBrowser } from "./fileBrowser"
import { fileUploadModal } from "./modals/fileUploadModal"
import { uploadCompleteToast } from "./toasts/uploadCompleteToast"

export const homePage = {
...basePage,
Expand All @@ -12,9 +13,6 @@ export const homePage = {
moveSelectedButton: () => cy.get("[data-testId=button-move-selected-file]"),
deleteSelectedButton: () => cy.get("[data-testId=button-delete-selected-file]"),
selectAllCheckbox: () => cy.get("[data-testId=checkbox-select-all]"),
uploadStatusToast: () => cy.get("[data-testId=toast-upload-status]", { timeout: 10000 }),
deleteSuccessToast: () => cy.get("[data-testId=toast-deletion-success]", { timeout: 10000 }),
moveSuccessToast: () => cy.get("[data-testId=toast-move-success]", { timeout: 10000 }),
fileRenameInput: () => cy.get("[data-cy=rename-form] input"),
fileRenameSubmitButton: () => cy.get("[data-cy=rename-submit-button]"),
fileRenameErrorLabel: () => cy.get("[data-cy=rename-form] span.minimal.error"),
Expand All @@ -37,7 +35,8 @@ export const homePage = {

// ensure upload is complete before proceeding
fileUploadModal.body().should("not.exist")
this.uploadStatusToast().should("not.exist")
uploadCompleteToast.body().should("be.visible")
uploadCompleteToast.closeButton().click()
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const deleteSuccessToast = {
body: () => cy.get("[data-testId=toast-deletion-success]", { timeout: 10000 }),
closeButton: () => cy.get("[data-testid=button-close-toast-deletion-success]")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const moveSuccessToast = {
body: () => cy.get("[data-testId=toast-move-success]", { timeout: 10000 }),
closeButton: () => cy.get("[data-testid=button-close-toast-move-success]")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const uploadCompleteToast = {
body: () => cy.get("[data-testId=toast-upload-complete]", { timeout: 10000 }),
closeButton: () => cy.get("[data-testid=button-close-toast-upload-complete]")
}
30 changes: 26 additions & 4 deletions packages/files-ui/cypress/tests/file-management-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { deleteFileModal } from "../support/page-objects/modals/deleteFileModal"
import { fileUploadModal } from "../support/page-objects/modals/fileUploadModal"
import { moveItemModal } from "../support/page-objects/modals/moveItemModal"
import { recoverItemModal } from "../support/page-objects/modals/recoverItemModal"
import { deleteSuccessToast } from "../support/page-objects/toasts/deleteSuccessToast"
import { moveSuccessToast } from "../support/page-objects/toasts/moveSuccessToast"
import { uploadCompleteToast } from "../support/page-objects/toasts/uploadCompleteToast"

describe("File management", () => {

Expand Down Expand Up @@ -81,7 +84,8 @@ describe("File management", () => {
homePage.moveSelectedButton().click()
moveItemModal.folderList().contains("Home").click()
moveItemModal.moveButton().safeClick()
homePage.moveSuccessToast().should("not.exist")
moveSuccessToast.body().should("be.visible")
moveSuccessToast.closeButton().click()

// ensure the home root now has the folder and file
navigationMenu.homeNavButton().click()
Expand Down Expand Up @@ -175,6 +179,8 @@ describe("File management", () => {
fileUploadModal.removeFileButton().should("have.length", 2)
fileUploadModal.uploadButton().safeClick()
fileUploadModal.body().should("not.exist")
uploadCompleteToast.body().should("be.visible")
uploadCompleteToast.closeButton().click()
homePage.fileItemRow().should("have.length", 2)
})

Expand Down Expand Up @@ -230,6 +236,8 @@ describe("File management", () => {
deleteFileModal.body().should("be.visible")
deleteFileModal.confirmButton().safeClick()
deleteFileModal.body().should("not.exist")
deleteSuccessToast.body().should("be.visible")
deleteSuccessToast.closeButton().click()
homePage.fileItemRow().should("not.exist")

// confirm the deleted file is moved to the bin
Expand Down Expand Up @@ -268,10 +276,14 @@ describe("File management", () => {
homePage.fileItemKebabButton().first().click()
homePage.deleteMenuOption().click()
deleteFileModal.confirmButton().safeClick()
deleteSuccessToast.body().should("be.visible")
deleteSuccessToast.closeButton().click()
navigationMenu.binNavButton().click()
binPage.fileItemKebabButton().first().click()
binPage.deleteMenuOption().click()
deleteFileModal.confirmButton().safeClick()
deleteSuccessToast.body().should("be.visible")
deleteSuccessToast.closeButton().click()
binPage.fileItemRow().should("not.exist")
navigationMenu.homeNavButton().click()
homePage.fileItemRow().should("not.exist")
Expand All @@ -289,6 +301,8 @@ describe("File management", () => {
deleteFileModal.body().should("be.visible")
deleteFileModal.confirmButton().safeClick()
deleteFileModal.body().should("not.exist")
deleteSuccessToast.body().should("be.visible")
deleteSuccessToast.closeButton().click()
homePage.fileItemRow().should("not.exist")

// confirm the deleted folder is moved to the bin
Expand All @@ -313,10 +327,14 @@ describe("File management", () => {
homePage.fileItemKebabButton().first().click()
homePage.deleteMenuOption().click()
deleteFileModal.confirmButton().safeClick()
deleteSuccessToast.body().should("be.visible")
deleteSuccessToast.closeButton().click()
navigationMenu.binNavButton().click()
binPage.fileItemKebabButton().first().click()
binPage.deleteMenuOption().click()
deleteFileModal.confirmButton().safeClick()
deleteSuccessToast.body().should("be.visible")
deleteSuccessToast.closeButton().click()
binPage.fileItemRow().should("not.exist")
navigationMenu.homeNavButton().click()
homePage.fileItemRow().should("not.exist")
Expand Down Expand Up @@ -367,12 +385,15 @@ describe("File management", () => {
homePage.fileItemKebabButton().click()
homePage.deleteMenuOption().click()
deleteFileModal.confirmButton().safeClick()
homePage.deleteSuccessToast().should("not.exist")
deleteSuccessToast.body().should("be.visible")
deleteSuccessToast.closeButton().click()

navigationMenu.binNavButton().click()
binPage.fileItemKebabButton().click()
binPage.deleteMenuOption().click()
deleteFileModal.confirmButton().safeClick()
binPage.permanentDeleteSuccessToast().should("not.exist")
deleteSuccessToast.body().should("be.visible")
deleteSuccessToast.closeButton().click()
navigationMenu.spaceUsedLabel().should("contain.text", "0 Bytes")
})

Expand All @@ -392,7 +413,8 @@ describe("File management", () => {
homePage.selectAllCheckbox().click()
homePage.deleteSelectedButton().click()
deleteFileModal.confirmButton().safeClick()
homePage.deleteSuccessToast().should("not.exist")
deleteSuccessToast.body().should("be.visible")
deleteSuccessToast.closeButton().click()
homePage.fileItemRow().should("have.length", 0)

// recover both of the files in the same action
Expand Down
6 changes: 3 additions & 3 deletions packages/files-ui/src/Contexts/FilesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ const FilesProvider = ({ children }: FilesContextProps) => {
type: "success",
progress: 0,
onProgressCancel: cancelSource.cancel,
isClosable: false,
testId: "upload-status"
isClosable: false
}

const toastId = addToast(toastParams)
Expand Down Expand Up @@ -411,7 +410,8 @@ const FilesProvider = ({ children }: FilesContextProps) => {
title: "Upload complete",
progress: undefined,
onProgressCancel: undefined,
isClosable: true
isClosable: true,
testId: "upload-complete"
}, true)
return Promise.resolve()
} catch (error: any) {
Expand Down