Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix flaky documents test (#64711)

Kamil Mielnikf67961423a6d
diff --git a/e2e/support/helpers/e2e-document-helpers.ts b/e2e/support/helpers/e2e-document-helpers.ts
index 0a1640c6c85..441561c202c 100644
--- a/e2e/support/helpers/e2e-document-helpers.ts
+++ b/e2e/support/helpers/e2e-document-helpers.ts
@@ -37,18 +37,12 @@ export const documentMetabotSuggestionItem = (name: RegExp | string) =>
export const commandSuggestionItem = (name: RegExp | string) =>
commandSuggestionDialog().findByRole("option", { name });
-export const getDocumentCard = (name: string, expectCardExists = true) => {
- const cardsResult = documentContent()
+export const getDocumentCard = (name: string) => {
+ return documentContent()
.findAllByTestId("card-embed-title")
- .filter((index, el) => {
- // Filter elements based on custom logic, e.g., text content, class, etc.
- return el.innerText === name;
- })
- .should("have.length", expectCardExists ? 1 : 0);
-
- return expectCardExists
- ? cardsResult.closest('[data-testid="document-card-embed"]')
- : cardsResult;
+ .filter((_index, element) => element.innerText === name)
+ .should("have.length", 1)
+ .closest('[data-testid="document-card-embed"]');
};
export const getDocumentCardResizeContainer = (name: string) =>
diff --git a/e2e/test/scenarios/documents/card-embed-node.cy.spec.ts b/e2e/test/scenarios/documents/card-embed-node.cy.spec.ts
index 1c925f0b8cc..8e47197556a 100644
--- a/e2e/test/scenarios/documents/card-embed-node.cy.spec.ts
+++ b/e2e/test/scenarios/documents/card-embed-node.cy.spec.ts
@@ -22,7 +22,7 @@ describe("documents card embed node custom logic", () => {
idAlias: "documentId",
});
- cy.get("@documentId").then((id) => cy.visit(`/document/${id}`));
+ H.visitDocument("@documentId");
});
it("should create a flexContainer when dropping one cardEmbed onto another standalone cardEmbed", () => {
@@ -129,7 +129,7 @@ describe("documents card embed node custom logic", () => {
idAlias: "documentId",
});
- cy.get("@documentId").then((id) => cy.visit(`/document/${id}`));
+ H.visitDocument("@documentId");
});
it("should allow you to resize the cards inside a flex container", () => {
@@ -439,7 +439,7 @@ describe("documents card embed node custom logic", () => {
idAlias: "documentId",
});
- cy.get("@documentId").then((id) => cy.visit(`/document/${id}`));
+ H.visitDocument("@documentId");
// Wait for cards to load
H.getDocumentCard("Orders")
@@ -463,7 +463,10 @@ describe("documents card embed node custom logic", () => {
cy.realPress("Backspace");
// Verify the Orders card has been deleted
- H.getDocumentCard("Orders", false).should("not.exist");
+ H.documentContent()
+ .findAllByTestId("card-embed-title")
+ .filter((_index, element) => element.innerText === "Orders")
+ .should("not.exist");
// Verify only one card remains
H.documentContent()
@@ -483,7 +486,7 @@ describe("documents card embed node custom logic", () => {
idAlias: "documentId",
});
- cy.get("@documentId").then((id) => cy.visit(`/document/${id}`));
+ H.visitDocument("@documentId");
// First create a flexContainer by dropping one card onto another
H.getDocumentCard("Orders")
@@ -517,7 +520,10 @@ describe("documents card embed node custom logic", () => {
cy.realPress("Backspace");
// Verify the Orders card has been deleted from the flexContainer
- H.getDocumentCard("Orders", false).should("not.exist");
+ H.documentContent()
+ .findAllByTestId("card-embed-title")
+ .filter((_index, element) => element.innerText === "Orders")
+ .should("not.exist");
H.documentContent()
.findAllByTestId("document-card-embed")
diff --git a/e2e/test/scenarios/documents/documents.cy.spec.ts b/e2e/test/scenarios/documents/documents.cy.spec.ts
index 3d16359e536..7aedde92c4c 100644
--- a/e2e/test/scenarios/documents/documents.cy.spec.ts
+++ b/e2e/test/scenarios/documents/documents.cy.spec.ts
@@ -230,7 +230,7 @@ H.describeWithSnowplowEE("documents", () => {
const cardEmbed = resizeNode?.content?.[0];
const clonedCardId = cardEmbed?.attrs?.id;
cy.request("DELETE", `/api/card/${clonedCardId}`);
- cy.visit(`/document/${id}`);
+ H.visitDocument(id);
});
cy.findByTestId("document-card-embed").should(
"have.text",
@@ -241,7 +241,7 @@ H.describeWithSnowplowEE("documents", () => {
it("read only access", () => {
cy.signIn("readonly");
- cy.get("@documentId").then((id) => cy.visit(`/document/${id}`));
+ H.visitDocument("@documentId");
H.documentContent()
.findByRole("textbox")
@@ -254,7 +254,7 @@ H.describeWithSnowplowEE("documents", () => {
it("no access", () => {
cy.signIn("nocollection");
- cy.get("@documentId").then((id) => cy.visit(`/document/${id}`));
+ H.visitDocument("@documentId");
cy.findByRole("status").should(
"contain.text",
"Sorry, you don’t have permission to see that.",
@@ -262,17 +262,17 @@ H.describeWithSnowplowEE("documents", () => {
});
it("not found", () => {
- cy.get("@documentId").then((id) =>
- cy.visit(`/document/${(id as unknown as number) + 1}`),
- );
+ H.visitDocument(9999);
H.main().within(() => {
- cy.findByText("We're a little lost...").should("exist");
- cy.findByText("The page you asked for couldn't be found.");
+ cy.findByText("We're a little lost...").should("be.visible");
+ cy.findByText("The page you asked for couldn't be found.").should(
+ "be.visible",
+ );
});
});
it("should allow you to print", () => {
- cy.get("@documentId").then((id) => cy.visit(`/document/${id}`));
+ H.visitDocument("@documentId");
cy.findByRole("button", { name: "More options" }).click();
// This needs to be *after* the page load to work
@@ -295,7 +295,7 @@ H.describeWithSnowplowEE("documents", () => {
it("should handle undo/redo properly, resetting the history whenever a different document is viewed", () => {
const isMac = Cypress.platform === "darwin";
const metaKey = isMac ? "Meta" : "Control";
- cy.get("@documentId").then((id) => cy.visit(`/document/${id}`));
+ H.visitDocument("@documentId");
H.getDocumentCard("Orders").should("exist");
H.documentContent().within(() => {
const originalText = "Lorem Ipsum and some more words";
@@ -326,7 +326,7 @@ H.describeWithSnowplowEE("documents", () => {
const originalText = "Lorem Ipsum and some more words";
const originalExact = new RegExp(`^${originalText}$`);
- cy.get("@documentId").then((id) => cy.visit(`/document/${id}`));
+ H.visitDocument("@documentId");
cy.findByTestId("document-card-embed").should("contain", "37.65"); // wait for data loading
H.documentContent().contains(originalExact).click();
@@ -364,7 +364,7 @@ H.describeWithSnowplowEE("documents", () => {
});
it("should support typing with a markdown syntax", () => {
- cy.get("@documentId").then((id) => cy.visit(`/document/${id}`));
+ H.visitDocument("@documentId");
H.documentContent().click();
H.addToDocument("# This is a heading level 1");
@@ -518,7 +518,7 @@ H.describeWithSnowplowEE("documents", () => {
dashboard_id: id,
});
});
- cy.get("@documentId").then((id) => cy.visit(`/document/${id}`));
+ H.visitDocument("@documentId");
});
it("should support keyboard and mouse selection in suggestions without double highlight", () => {
@@ -827,11 +827,10 @@ H.describeWithSnowplowEE("documents", () => {
cy.location("pathname").should("equal", `/document/${id}`),
);
- H.getDocumentCard("Orders, Count, Grouped by Created At (year)").within(
- () => {
- H.cartesianChartCircle().eq(1).click();
- },
+ H.getDocumentCard("Orders, Count, Grouped by Created At (year)").should(
+ "be.visible",
);
+ H.cartesianChartCircle().eq(1).click();
H.popover().findByText("See these Orders").click();
@@ -874,7 +873,7 @@ H.describeWithSnowplowEE("documents", () => {
document: { type: "doc", content: [] },
idAlias: "documentId",
});
- cy.get("@documentId").then((id) => cy.visit(`/document/${id}`));
+ H.visitDocument("@documentId");
// make changes and attempt to save
H.documentContent().click();