Skip to content

Commit

Permalink
Hide network requests from cypress test runner (#1643)
Browse files Browse the repository at this point in the history
* hide requests from the test runner window

* add extra steps for test reliability

Co-authored-by: Michael Yankelev <12774278+FSM1@users.noreply.github.com>
  • Loading branch information
asnaith and FSM1 authored Oct 19, 2021
1 parent d23d305 commit 548de6a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
14 changes: 14 additions & 0 deletions packages/files-ui/cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,19 @@ Cypress.on("uncaught:exception", (err) => {
}
})

// Hide fetch/XHR requests
// interim solution until cypress adds configuration support
// source https://gist.github.com/simenbrekken/3d2248f9e50c1143bf9dbe02e67f5399
const app = window.top

if(app != null && !app.document.head.querySelector("[data-hide-command-log-request]")) {
const style = app.document.createElement("style")
style.innerHTML =
".command-name-request, .command-name-xhr { display: none }"
style.setAttribute("data-hide-command-log-request", "")

app.document.head.appendChild(style)
}

// Alternatively you can use CommonJS syntax:
// require('./commands')
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const recoverSuccessToast = {
body: () => cy.get("[data-testId=toast-recover-success]", { timeout: 10000 }),
closeButton: () => cy.get("[data-testid=button-close-toast-recover-success]")
}
15 changes: 12 additions & 3 deletions packages/files-ui/cypress/tests/file-management-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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 { recoverSuccessToast } from "../support/page-objects/toasts/recoverSuccessToast"
import { uploadCompleteToast } from "../support/page-objects/toasts/uploadCompleteToast"

describe("File management", () => {
Expand Down Expand Up @@ -89,12 +90,16 @@ describe("File management", () => {

// ensure the home root now has the folder and file
navigationMenu.homeNavButton().click()
homePage.fileItemRow().should("have.length", 2)
homePage.fileItemRow()
.should("be.visible")
.should("have.length", 2)
homePage.fileItemName().should("contain.text", folderName)
homePage.fileItemName().should("contain.text", $fileName)

// ensure folder already in the root cannot be moved to Home
homePage.fileItemName().contains(`${$fileName}`).click()
// ensure file already in the root cannot be moved to Home
homePage.fileItemName().contains(`${$fileName}`)
.should("be.visible")
.click()
homePage.moveSelectedButton().click()
moveItemModal.folderList().contains("Home").click()
moveItemModal.errorLabel().should("be.visible")
Expand All @@ -112,8 +117,10 @@ describe("File management", () => {
// select a parent folder and initiate move action
homePage.fileItemName().contains("Parent").click()
homePage.moveSelectedButton().click()
moveItemModal.body().should("be.visible")

// ensure folder already in the root cannot be moved to Home
moveItemModal.folderList().should("be.visible")
moveItemModal.folderList().contains("Home").click()
moveItemModal.body().should("be.visible")
moveItemModal.errorLabel().should("be.visible")
Expand Down Expand Up @@ -259,6 +266,8 @@ describe("File management", () => {
recoverItemModal.folderList().contains("Home").click()
recoverItemModal.recoverButton().safeClick()
binPage.fileItemRow().should("not.exist")
recoverSuccessToast.body().should("be.visible")
recoverSuccessToast.closeButton().click()

// ensure recovered file is correct
navigationMenu.homeNavButton().click()
Expand Down
1 change: 1 addition & 0 deletions packages/files-ui/cypress/tests/file-preview-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe("File Preview", () => {
// add files
homePage.uploadFile("../fixtures/uploadedFiles/logo.png")
homePage.uploadFile("../fixtures/uploadedFiles/text-file.txt")
homePage.fileItemRow().should("have.length", 2)

// store their file names as cypress aliases for later comparison
homePage.fileItemName().eq(0).invoke("text").as("fileNameA")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ const BinFileBrowser: React.FC<IFileBrowserModuleProps> = ({ controls = false }:
).then(() => {
addToast({
title: t`Data restored successfully`,
type: "success"
type: "success",
testId: "recover-success"
})
}).catch((error) => {
console.error("Error recovering:", error)
Expand Down

0 comments on commit 548de6a

Please sign in to comment.