Skip to content

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

Consolidate documents e2e tests (#83532)

Nemanja Glumacbaaf3ef3f899
diff --git a/e2e/support/helpers/e2e-comment-helpers.ts b/e2e/support/helpers/e2e-comment-helpers.ts
index 7f7234f8634..d6e920367d2 100644
--- a/e2e/support/helpers/e2e-comment-helpers.ts
+++ b/e2e/support/helpers/e2e-comment-helpers.ts
@@ -117,7 +117,7 @@ function getSidebar() {
}
function closeSidebar() {
- cy.icon("close").click();
+ getSidebar().icon("close").click();
}
function getMentionDialog() {
diff --git a/e2e/support/helpers/e2e-document-helpers.ts b/e2e/support/helpers/e2e-document-helpers.ts
index d7b857cb9fd..118cba50979 100644
--- a/e2e/support/helpers/e2e-document-helpers.ts
+++ b/e2e/support/helpers/e2e-document-helpers.ts
@@ -216,23 +216,28 @@ export function documentDoDrag(
const { x: deltaX = 0, y: deltaY = 0 } = diff;
const rect = handle[0].getBoundingClientRect();
+ const { scrollX, scrollY } = handle[0].ownerDocument.defaultView ?? {
+ scrollX: 0,
+ scrollY: 0,
+ };
+ const point = (x: number, y: number) => ({
+ clientX: x,
+ clientY: y,
+ pageX: x + scrollX,
+ pageY: y + scrollY,
+ });
+ const end = point(rect.x + deltaX, rect.y + deltaY);
cy.log(`x: ${rect.x}, y: ${rect.y}, diff: ${diff}`);
cy.wrap(handle).trigger("mousedown", {
button: 0,
- clientX: rect.x,
- clientY: rect.y,
+ ...point(rect.x, rect.y),
force: true,
});
cy.get("body")
- .trigger("mousemove", {
- button: 0,
- clientX: rect.x + deltaX,
- clientY: rect.y + deltaY,
- force: true,
- })
- .trigger("mouseup");
+ .trigger("mousemove", { button: 0, ...end, force: true })
+ .trigger("mouseup", { button: 0, ...end });
});
}
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 b5de313a60c..ad5b720f26f 100644
--- a/e2e/test/scenarios/documents/card-embed-node.cy.spec.ts
+++ b/e2e/test/scenarios/documents/card-embed-node.cy.spec.ts
@@ -18,14 +18,13 @@ describe("documents card embed node custom logic", () => {
name: "DnD Test Document",
document: DOCUMENT_WITH_TWO_CARDS,
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
H.visitDocument("@documentId");
});
- it("should create a flexContainer when dropping one cardEmbed onto another standalone cardEmbed", () => {
+ it("should not group a card dropped onto itself, group a card dropped onto another, and add supporting text to the group", () => {
// Wait for cards to load
H.getDocumentCard("Orders")
.should("be.visible")
@@ -41,6 +40,18 @@ describe("documents card embed node custom logic", () => {
.find('[data-type="flexContainer"]')
.should("not.exist");
+ cy.log("dropping a card onto itself does nothing");
+ H.dragAndDropCardOnAnotherCard("Orders", "Orders");
+
+ // Verify no flexContainer was created
+ H.documentContent()
+ .find('[data-type="flexContainer"]')
+ .should("not.exist");
+
+ // Verify the card is still standalone
+ H.getDocumentCard("Orders").should("exist");
+
+ cy.log("dropping a card onto another card creates a flexContainer");
H.dragAndDropCardOnAnotherCard("Orders", "Orders, Count");
// Verify flexContainer was created
@@ -61,12 +72,43 @@ describe("documents card embed node custom logic", () => {
cy.get('[data-type="flexContainer"]').should("exist");
});
- // Verify that originally separate cards are now side by side
+ cy.log("add supporting text to a card in the flexContainer");
+ H.documentContent()
+ .findByTestId("document-card-supporting-text")
+ .should("not.exist");
+
+ H.openDocumentCardMenu("Orders");
+ H.popover()
+ .findByText("Add supporting text")
+ .closest("button")
+ .should("be.enabled")
+ .click();
+
+ H.documentContent()
+ .findByTestId("document-card-supporting-text")
+ .should("exist");
+
+ // Verify the supporting text has the placeholder text
+ H.documentContent()
+ .findByTestId("document-card-supporting-text")
+ .should("contain.text", "Write whatever you'd like to");
+
+ // Verify the flexContainer now contains supporting text and both cards
H.documentContent()
.find('[data-type="flexContainer"]')
.within(() => {
+ cy.findByTestId("document-card-supporting-text").should("exist");
cy.findAllByTestId("document-card-embed").should("have.length", 2);
});
+
+ // Verify supporting text was added at the beginning of the flexContainer
+ H.documentContent()
+ .find('[data-type="flexContainer"]')
+ .find(
+ '[data-testid="document-card-supporting-text"], [data-testid="document-card-embed"]',
+ )
+ .first()
+ .should("have.attr", "data-testid", "document-card-supporting-text");
});
it("should handle drag and drop with proper drop side positioning", () => {
@@ -93,30 +135,6 @@ describe("documents card embed node custom logic", () => {
assertFlexContainerCardsOrder(["Orders, Count", "Orders"]);
});
});
-
- it("should prevent dropping a card onto itself", () => {
- // Wait for cards to load
- H.getDocumentCard("Orders")
- .should("be.visible")
- .findByTestId("table-root")
- .should("exist");
-
- // Verify initial state - no flexContainer
- H.documentContent()
- .find('[data-type="flexContainer"]')
- .should("not.exist");
-
- // Attempt to drag and drop the card onto itself
- H.dragAndDropCardOnAnotherCard("Orders", "Orders");
-
- // Verify no flexContainer was created
- H.documentContent()
- .find('[data-type="flexContainer"]')
- .should("not.exist");
-
- // Verify the card is still standalone
- H.getDocumentCard("Orders").should("exist");
- });
});
describe("advanced flexContainer scenarios", () => {
@@ -125,47 +143,12 @@ describe("documents card embed node custom logic", () => {
name: "Advanced DnD Test Document",
document: DOCUMENT_WITH_THREE_CARDS_AND_COLUMNS,
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
H.visitDocument("@documentId");
});
- it("should allow you to resize the cards inside a flex container", () => {
- getCardWidths(["Orders", "Orders, Count"], (first, second) => {
- cy.wrap(first).as("ogWidth1");
- cy.wrap(second).as("ogWidth2");
- expect(first).to.be.closeTo(second, 3);
- });
-
- H.getDocumentCard("Orders").as("ORDERS_CARD");
- H.getDocumentCard("Orders, Count").as("ORDERS_COUNT_CARD");
-
- const flexContainer = H.getFlexContainerForCard("Orders");
-
- const handles = H.getResizeHandlesForFlexContianer(flexContainer);
-
- H.documentDoDrag(handles.eq(0), { x: 100 });
-
- getCardWidths(["Orders", "Orders, Count"], (first, second) => {
- cy.get("@ogWidth1").then((_first) => {
- cy.get("@ogWidth2").then((_second) => {
- cy.log("compare that changes are close to the drag distance");
- // Unjustified type cast. FIXME
- expect((_first as unknown as number) + 100).to.be.closeTo(first, 3);
- // Unjustified type cast. FIXME
- expect((_second as unknown as number) - 100).to.be.closeTo(
- second,
- 3,
- );
-
- expect(first).to.be.closeTo(second + 200, 3);
- });
- });
- });
- });
-
it("should add a third card to an existing flexContainer with 2 cards", () => {
// Wait for all cards to load
H.getDocumentCard("Orders")
@@ -211,6 +194,17 @@ describe("documents card embed node custom logic", () => {
H.documentUndo();
+ H.documentContent()
+ .find('[data-type="flexContainer"]')
+ .should("have.length", 1)
+ .within(() => {
+ assertFlexContainerCardsOrder(["Orders", "Orders, Count"]);
+ });
+ H.getDocumentCard("Orders, Count, Grouped by Created At (year)")
+ .should("be.visible")
+ .closest('[data-type="flexContainer"]')
+ .should("not.exist");
+
// Drag the standalone card (Orders by Year) onto one of the cards in the flexContainer
H.dragAndDropCardOnAnotherCard(
"Orders, Count, Grouped by Created At (year)",
@@ -231,6 +225,17 @@ describe("documents card embed node custom logic", () => {
H.documentUndo();
+ H.documentContent()
+ .find('[data-type="flexContainer"]')
+ .should("have.length", 1)
+ .within(() => {
+ assertFlexContainerCardsOrder(["Orders", "Orders, Count"]);
+ });
+ H.getDocumentCard("Orders, Count, Grouped by Created At (year)")
+ .should("be.visible")
+ .closest('[data-type="flexContainer"]')
+ .should("not.exist");
+
// Drag the standalone card (Orders by Year) onto one of the cards in the flexContainer
H.dragAndDropCardOnAnotherCard(
"Orders, Count, Grouped by Created At (year)",
@@ -288,7 +293,7 @@ describe("documents card embed node custom logic", () => {
});
});
- it("should prevent adding a fourth card to a flexContainer with 3 cards", () => {
+ it("should disable 'Add supporting text', prevent adding a fourth card, and delete cards with Backspace when a flexContainer has 3 cards", () => {
// Wait for all cards to load
H.getDocumentCard("Orders")
.should("be.visible")
@@ -299,47 +304,108 @@ describe("documents card embed node custom logic", () => {
.findByTestId("table-root")
.should("exist");
- // First, add the third card to reach the limit
+ cy.log("'Add supporting text' is enabled with 2 cards");
+ H.openDocumentCardMenu("Orders");
+ H.popover()
+ .findByText("Add supporting text")
+ .closest("button")
+ .should("be.enabled");
+ cy.realPress("Escape");
+ cy.get(H.POPOVER_ELEMENT).should("not.exist");
+
+ cy.log("a standalone card dropped onto a 2-card flexContainer joins it");
+ H.getDocumentCard("Orders, Count, Grouped by Created At (year)")
+ .should("be.visible")
+ .closest('[data-type="flexContainer"]')
+ .should("not.exist");
H.dragAndDropCardOnAnotherCard(
"Orders, Count, Grouped by Created At (year)",
"Orders",
{ side: "right" },
);
- // Verify we have 3 cards in the flexContainer
H.documentContent()
.find('[data-type="flexContainer"]')
+ .should("have.length", 1)
.within(() => {
- cy.findAllByTestId("document-card-embed").should("have.length", 3);
+ assertFlexContainerCardsOrder([
+ "Orders",
+ "Orders, Count, Grouped by Created At (year)",
+ "Orders, Count",
+ ]);
});
- // Add another card to try to exceed the limit
+ cy.log("a fourth card is rejected");
addNewStandaloneCard("Orders Model");
+ H.getDocumentCard("Orders Model")
+ .should("be.visible")
+ .findByTestId("table-root")
+ .should("exist");
+ H.getDocumentCard("Orders Model")
+ .closest('[data-type="flexContainer"]')
+ .should("not.exist");
- // Wait for the new card to be added
- H.documentContent()
- .findAllByTestId("document-card-embed")
- .should("have.length", 4); // 3 in flexContainer + 1 new standalone
-
- // Try to drag the new standalone card onto the flexContainer
- H.dragAndDropCardOnAnotherCard("Orders", "Orders, Count", {
+ H.dragAndDropCardOnAnotherCard("Orders Model", "Orders", {
side: "left",
});
- // Verify the flexContainer still has only 3 cards (drop should be rejected)
H.documentContent()
.find('[data-type="flexContainer"]')
+ .should("have.length", 1)
.within(() => {
- cy.findAllByTestId("document-card-embed").should("have.length", 3);
+ assertFlexContainerCardsOrder([
+ "Orders",
+ "Orders, Count, Grouped by Created At (year)",
+ "Orders, Count",
+ ]);
});
+ H.getDocumentCard("Orders Model")
+ .should("be.visible")
+ .closest('[data-type="flexContainer"]')
+ .should("not.exist");
+ H.documentContent()
+ .findAllByTestId("document-card-embed")
+ .should("have.length", 4);
- // Verify the standalone card is still separate
+ cy.log("'Add supporting text' is disabled with 3 cards");
+ H.openDocumentCardMenu("Orders");
+ H.popover()
+ .findByText("Add supporting text")
+ .closest("button")
+ .should("have.attr", "data-disabled");
+ cy.realPress("Escape");
+ cy.get(H.POPOVER_ELEMENT).should("not.exist");
+
+ cy.log("Backspace deletes a selected card from the flexContainer");
+ H.getDocumentCard("Orders").realClick({ position: "top" });
+ cy.realPress("Backspace");
+
+ H.documentContent()
+ .findAllByTestId("card-embed-title")
+ .filter((_index, element) => element.innerText === "Orders")
+ .should("not.exist");
H.documentContent()
.findAllByTestId("document-card-embed")
- .should("have.length", 4); // Still 4 total, with 1 standalone
+ .should("have.length", 3);
+ H.documentContent().find('[data-type="flexContainer"]').should("exist");
+
+ cy.log("deleting down to 1 card unwraps the flexContainer");
+ H.getDocumentCard("Orders, Count").realClick({ position: "top" });
+ cy.realPress("Backspace");
+
+ H.documentContent()
+ .find('[data-type="flexContainer"]')
+ .should("not.exist");
+ H.documentContent()
+ .findAllByTestId("document-card-embed")
+ .should("have.length", 2);
+ H.getDocumentCard("Orders, Count, Grouped by Created At (year)").should(
+ "exist",
+ );
+ H.getDocumentCard("Orders Model").should("exist");
});
- it("should reorder cards within the same flexContainer", () => {
+ it("should reorder cards within the same flexContainer and preserve resized widths when swapping", () => {
// Wait for all cards to load
H.getDocumentCard("Orders")
.should("be.visible")
@@ -381,10 +447,8 @@ describe("documents card embed node custom logic", () => {
.within(() => {
assertFlexContainerCardsOrder(["Orders", "Orders, Count"]);
});
- });
- it("should preserve card widths when swapping cards within the same flexContainer", () => {
- // Wait for all cards to load
+ cy.log("resized widths are preserved when swapping cards");
H.getDocumentCard("Orders")
.should("be.visible")
.findByTestId("table-root")
@@ -394,16 +458,10 @@ describe("documents card embed node custom logic", () => {
.findByTestId("table-root")
.should("exist");
- // Verify initial order: Orders | Orders, Count
- H.documentContent()
- .find('[data-type="flexContainer"]')
- .should("exist")
- .within(() => {
- assertFlexContainerCardsOrder(["Orders", "Orders, Count"]);
- });
-
// Verify both cards start with equal widths
getCardWidths(["Orders", "Orders, Count"], (first, second) => {
+ cy.wrap(first).as("ogWidth1");
+ cy.wrap(second).as("ogWidth2");
expect(first).to.be.closeTo(second, 3);
});
@@ -420,6 +478,15 @@ describe("documents card embed node custom logic", () => {
cy.wrap(ordersCountWidth).as("ordersCountWidth");
// Verify the widths are now different
expect(ordersWidth).to.be.greaterThan(ordersCountWidth);
+ expect(ordersWidth).to.be.closeTo(ordersCountWidth + 300, 3);
+
+ cy.get<number>("@ogWidth1").then((ogWidth1) => {
+ cy.get<number>("@ogWidth2").then((ogWidth2) => {
+ cy.log("compare that changes are close to the drag distance");
+ expect(ordersWidth).to.be.closeTo(ogWidth1 + 150, 3);
+ expect(ordersCountWidth).to.be.closeTo(ogWidth2 - 150, 3);
+ });
+ });
},
);
@@ -509,8 +576,8 @@ describe("documents card embed node custom logic", () => {
});
});
- describe("text wrapping in table cards", () => {
- it("should support text wrapping with proper row heights", () => {
+ describe("cardEmbed on a new document", () => {
+ it("should remove a card that is the first item in a document (UXW-2169) and support text wrapping with proper row heights", () => {
H.createQuestion({
name: "reviews",
type: "model",
@@ -529,6 +596,18 @@ describe("documents card embed node custom logic", () => {
cy.visit("/document/new");
+ cy.log("a card that is the first item in a document can be removed");
+ H.documentContent().click();
+ H.addToDocument("/ord", false);
+ H.commandSuggestionItem(/Orders, Count$/).click();
+
+ H.openDocumentCardMenu("Orders, Count");
+ H.popover().findByText("Remove Chart").click();
+
+ cy.findAllByTestId("document-card-embed").should("have.length", 0);
+ cy.get(H.POPOVER_ELEMENT).should("not.exist");
+
+ cy.log("text wrapping in table cards");
H.documentContent().click();
H.addToDocument("/reviews", false);
H.commandSuggestionItem(/reviews/).click();
@@ -548,13 +627,12 @@ describe("documents card embed node custom logic", () => {
});
});
- describe("navigating from cardEmbed", () => {
- it("should open a question in a new tab when clicking title with ctrl/meta key", () => {
+ describe("navigating from and deleting a cardEmbed", () => {
+ it("should open a question and a drill-through action in a new tab when clicking with ctrl/meta key, and delete a selected card with Backspace", () => {
H.createDocument({
name: "Test Document",
document: DOCUMENT_WITH_TWO_CARDS,
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
@@ -572,31 +650,27 @@ describe("documents card embed node custom logic", () => {
.false;
});
- H.onNextAnchorClick((anchor) => {
- expect(anchor)
- .to.have.attr("href")
- .match(/\/question\//);
- expect(anchor).to.have.attr("rel", "noopener");
- expect(anchor).to.have.attr("target", "_blank");
- });
+ H.onNextAnchorClick(
+ cy
+ .spy((anchor: HTMLAnchorElement) => {
+ expect(anchor)
+ .to.have.attr("href")
+ .match(/\/question\//);
+ expect(anchor).to.have.attr("rel", "noopener");
+ expect(anchor).to.have.attr("target", "_blank");
+ })
+ .as("titleAnchorClick"),
+ );
// Click on the card title with ctrl/meta key
H.getDocumentCard("Orders")
.findByTestId("card-embed-title")
.click(H.holdMetaKey);
- });
- it("should open drill-through action in a new tab when clicking with ctrl/meta key", () => {
- H.createDocument({
- name: "Test Document",
- document: DOCUMENT_WITH_TWO_CARDS,
- collection_id: null,
- alias: "document",
- idAlias: "documentId",
- });
-
- H.visitDocument("@documentId");
+ cy.get("@titleAnchorClick").should("have.been.calledOnce");
+ cy.location("pathname").should("match", /^\/document\//);
+ cy.log("drill-through action");
// Wait for cards to load
H.getDocumentCard("Orders, Count")
.should("be.visible")
@@ -610,54 +684,31 @@ describe("documents card embed node custom logic", () => {
.first()
.click();
- // Verify window.open was called
- cy.on("uncaught:exception", (error) => {
- expect(error.message.includes("expected '<a>' to have attribute")).to.be
- .false;
- });
-
- H.onNextAnchorClick((anchor) => {
- expect(anchor)
- .to.have.attr("href")
- .match(/\/question/);
- expect(anchor).to.have.attr("rel", "noopener");
- expect(anchor).to.have.attr("target", "_blank");
- });
+ H.onNextAnchorClick(
+ cy
+ .spy((anchor: HTMLAnchorElement) => {
+ expect(anchor)
+ .to.have.attr("href")
+ .match(/\/question/);
+ expect(anchor).to.have.attr("rel", "noopener");
+ expect(anchor).to.have.attr("target", "_blank");
+ })
+ .as("drillAnchorClick"),
+ );
// Wait for the popover to appear and click the first action with ctrl/meta key
H.popover()
.findByText("See these Orders")
.should("be.visible")
.click(H.holdMetaKey);
- });
- });
-
- describe("deleting a cardEmbed", () => {
- it("should allow you to remove a card if it is the first item in a docuemnt (UXW-2169)", () => {
- cy.visit("/document/new");
-
- H.documentContent().click();
- H.addToDocument("/ord", false);
- H.commandSuggestionItem(/Orders, Count$/).click();
-
- H.openDocumentCardMenu("Orders, Count");
- H.popover().findByText("Remove Chart").click();
-
- cy.findAllByTestId("document-card-embed").should("have.length", 0);
- });
- it("should delete a cardEmbed when selected and Backspace is pressed", () => {
- H.createDocument({
- name: "DnD Test Document",
- document: DOCUMENT_WITH_TWO_CARDS,
- collection_id: null,
- alias: "document",
- idAlias: "documentId",
- });
+ cy.get("@drillAnchorClick").should("have.been.calledOnce");
+ cy.location("pathname").should("match", /^\/document\//);
- H.visitDocument("@documentId");
+ cy.log("Backspace deletes a selected cardEmbed");
+ cy.realPress("Escape");
+ cy.get(H.POPOVER_ELEMENT).should("not.exist");
- // Wait for cards to load
H.getDocumentCard("Orders")
.should("be.visible")
.findByTestId("table-root")
@@ -667,7 +718,7 @@ describe("documents card embed node custom logic", () => {
.findByTestId("table-root")
.should("exist");
- // Verify initial state - we have 2 standalone cards
+ // The ctrl/meta-clicks leave the document with its 2 standalone cards
H.documentContent()
.findAllByTestId("document-card-embed")
.should("have.length", 2);
@@ -692,80 +743,6 @@ describe("documents card embed node custom logic", () => {
// Verify the remaining card is Orders, Count
H.getDocumentCard("Orders, Count").should("exist").and("be.visible");
});
-
- it("should delete a cardEmbed from a flexContainer when selected and Backspace is pressed", () => {
- H.createDocument({
- name: "DnD Test Document",
- document: DOCUMENT_WITH_THREE_CARDS_AND_COLUMNS,
- collection_id: null,
- alias: "document",
- idAlias: "documentId",
- });
-
- H.visitDocument("@documentId");
-
- // First create a flexContainer by dropping one card onto another
- H.getDocumentCard("Orders")
- .should("be.visible")
- .findByTestId("table-root")
- .should("exist");
- H.getDocumentCard("Orders, Count")
- .should("be.visible")
- .findByTestId("table-root")
- .should("exist");
-
- // Create flexContainer
- H.dragAndDropCardOnAnotherCard(
- "Orders, Count, Grouped by Created At (year)",
- "Orders",
- { side: "right" },
- );
-
- // Verify flexContainer was created with 2 cards
- H.documentContent()
- .find('[data-type="flexContainer"]')
- .should("exist")
- .within(() => {
- cy.findAllByTestId("document-card-embed").should("have.length", 3);
- });
-
- // Click on one of the cards in the flexContainer to select it
- H.getDocumentCard("Orders").realClick({ position: "top" });
-
- // Press Backspace to delete the selected card
- cy.realPress("Backspace");
-
- // Verify the Orders card has been deleted from the flexContainer
- H.documentContent()
- .findAllByTestId("card-embed-title")
- .filter((_index, element) => element.innerText === "Orders")
- .should("not.exist");
-
- H.documentContent()
- .findAllByTestId("document-card-embed")
- .should("have.length", 2);
-
- H.documentContent().get('[data-type="flexContainer"]').should("exist");
-
- // Click on one of the cards in the flexContainer to select it
- H.getDocumentCard("Orders, Count").realClick({ position: "top" });
-
- // Press Backspace to delete the selected card
- cy.realPress("Backspace");
-
- // Verify the flexContainer now has only 1 card and should be unwrapped back to standalone
- H.documentContent()
- .get('[data-type="flexContainer"]')
- .should("not.exist"); // FlexContainer should be unwrapped when only 1 card remains
-
- // Verify only the Orders, Count card remains as a standalone card
- H.documentContent()
- .findAllByTestId("document-card-embed")
- .should("have.length", 1);
- H.getDocumentCard("Orders, Count, Grouped by Created At (year)").should(
- "exist",
- );
- });
});
});
@@ -780,7 +757,12 @@ function assertFlexContainerCardsOrder(expectedCardTitles: string[]) {
}
function addNewStandaloneCard(cardName: string) {
- cy.get(".node-paragraph.is-empty").click();
+ // Move the cursor to the document's trailing empty paragraph
+ H.documentContent().findByText("Advanced drag and drop scenarios").click();
+ cy.realPress([
+ H.metaKey,
+ Cypress.platform === "darwin" ? "ArrowDown" : "End",
+ ]);
H.addToDocument("/", false);
H.commandSuggestionItem("Chart").click();
H.commandSuggestionItem(/Browse all/).click();
diff --git a/e2e/test/scenarios/documents/comments.cy.spec.ts b/e2e/test/scenarios/documents/comments.cy.spec.ts
index fcad09e8fdb..9f6aae5e0e0 100644
--- a/e2e/test/scenarios/documents/comments.cy.spec.ts
+++ b/e2e/test/scenarios/documents/comments.cy.spec.ts
@@ -28,20 +28,25 @@ describe("document comments", () => {
beforeEach(() => {
H.restore();
cy.signInAsAdmin();
- H.resetSnowplow();
});
it("allows to comment on every type of node", () => {
+ cy.intercept("GET", "/api/comment?*").as("comments");
createAndVisitLoremIpsumDocument();
+ cy.wait("@comments");
cy.log("does not need schema adjustments by default");
+ H.getHeading1().should("be.visible");
cy.findByRole("button", { name: "Save" }).should("not.exist");
cy.log("does not have any comments by default");
- cy.findByRole("link", { name: "All comments" }).should("not.exist");
+ cy.findByRole("link", { name: "Show all comments" }).should("not.exist");
cy.get<DocumentId>("@documentId").then((documentId) => {
testCommentingOnNode(documentId, HEADING_1_ID, H.getHeading1);
+ cy.findByRole("link", { name: "Show all comments" })
+ .scrollIntoView()
+ .should("be.visible");
testCommentingOnNode(documentId, HEADING_2_ID, H.getHeading2);
testCommentingOnNode(documentId, HEADING_3_ID, H.getHeading3);
testCommentingOnNode(documentId, PARAGRAPH_ID, H.getParagraph);
@@ -174,8 +179,22 @@ describe("document comments", () => {
cy.findByRole("heading", { name: "Comments about this" }).should(
"be.visible",
);
+ Comments.getNewThreadInput().click();
+ cy.realType("World");
+ cy.realPress([META_KEY, "Enter"]);
+ Comments.getCommentByText("World").should("be.visible");
cy.findByText("Hello").should("not.exist");
});
+
+ Comments.closeSidebar();
+ Comments.getSidebar().should("not.exist");
+ Comments.getDocumentNodeButtons()
+ .filter(":visible")
+ .should("have.length", 2)
+ .and(($buttons) => {
+ expect($buttons.eq(0)).to.have.text("1");
+ expect($buttons.eq(1)).to.have.text("1");
+ });
});
});
@@ -217,6 +236,7 @@ describe("document comments", () => {
cy.findByRole("textbox", { name: "Document Title" })
.should("be.visible")
.and("have.value", "Lorem ipsum");
+ H.getParagraph().should("be.visible");
cy.findByRole("button", { name: "Save" }).should("not.exist");
});
@@ -500,6 +520,8 @@ describe("document comments", () => {
.should("be.visible")
.and("have.value", "Lorem ipsum");
+ cy.findByRole("link", { name: "Show all comments" }).should("be.visible");
+
cy.get<DocumentId>("@documentId").then((targetId) => {
cy.findByPlaceholderText("New document").realClick();
Comments.getDocumentNodeButton({
@@ -513,7 +535,9 @@ describe("document comments", () => {
createLoremIpsumDocument();
cy.get<DocumentId>("@documentId").then((documentId) => {
- cy.log("resolved 3-comments thread");
+ cy.log(
+ "a thread with comments from two users, and a comment on another node",
+ );
createComment(documentId, HEADING_1_ID, "Test X");
@@ -558,6 +582,7 @@ describe("document comments", () => {
});
cy.log("does not allow to edit or delete other people's comments");
+ H.popover().findByText("Copy link").should("be.visible");
H.popover().findByText(/edit/i).should("not.exist");
H.popover()
.findByText(/delete|remove/i)
@@ -582,7 +607,7 @@ describe("document comments", () => {
});
});
- it("allows editing the document when comments are open", () => {
+ it("allows editing the document with comments open, and opening comments with unsaved changes", () => {
create1ParagraphDocument();
cy.get<DocumentId>("@documentId").then((documentId) => {
@@ -601,65 +626,53 @@ describe("document comments", () => {
cy.findByRole("button", { name: "Save" }).should("exist");
H.documentContent()
- .get('[contenteditable="true"]')
+ .find('[contenteditable="true"]')
.should("be.visible");
H.documentFormattingMenu().should("not.exist");
});
- });
- });
- it("allows opening comments when document has changes", () => {
- create1ParagraphDocument();
+ Comments.getNewThreadInput().click();
+ Comments.getNewThreadInput().find(".ProseMirror-focused").should("exist");
+ cy.realType("Test comment");
+ cy.realPress([META_KEY, "Enter"]);
+ Comments.getCommentByText("Test comment").should("be.visible");
+ cy.findByRole("button", { name: "Save" }).should("be.visible");
+ H.getParagraph("Lorem ipsum dolor sit amet.test").should("be.visible");
- cy.get<DocumentId>("@documentId").then((documentId) => {
- createParagraphComment(documentId, "Test");
- H.visitDocument("@documentId");
- cy.findByRole("textbox", { name: "Document Title" })
- .should("be.visible")
- .and("have.value", "Lorem ipsum");
+ cy.findByRole("button", { name: "Save" }).click();
+ cy.findByRole("button", { name: "Save" }).should("not.exist");
- H.getParagraph().realHover();
+ cy.log("allows opening comments when document has changes");
+ H.visitDocument(documentId);
+ Comments.getSidebar().should("not.exist");
+
+ H.documentContent().click();
+ cy.realType("xyz");
+ cy.findByRole("button", { name: "Save" }).should("be.visible");
+
+ H.getParagraph("Lorem ipsum dolor sit amet.testxyz").realHover();
Comments.getDocumentNodeButton({
targetId: documentId,
childTargetId: PARAGRAPH_ID,
hasComments: true,
})
.should("be.visible")
- .and("not.be.disabled");
-
- H.documentContent().click();
- cy.realType("xyz");
-
- H.getParagraph("Lorem ipsum dolor sit amet.xyz").realHover();
-
- cy.findByLabelText("Comments").should("not.be.disabled").click();
+ .and("contain.text", "1")
+ .click();
Comments.getSidebar().should("be.visible");
+ cy.findByRole("button", { name: "Save" }).should("be.visible");
- cy.findByLabelText("Show all comments").should("not.be.disabled").click();
- Comments.getSidebar().should("be.visible");
+ Comments.openAllComments();
+ Comments.getCommentByText("Test comment").should("be.visible");
+ cy.findByRole("button", { name: "Save" }).should("be.visible");
});
});
describe("comment editor", () => {
- it("supports basic formatting with markdown", () => {
- startNewCommentIn1ParagraphDocument();
-
- cy.realType("**bold** *italic* ~~strike~~ `code`");
- cy.realPress([META_KEY, "Enter"]);
-
- Comments.getCommentInputs()
- .first()
- .within(() => {
- cy.get("strong").should("have.text", "bold");
- cy.get("em").should("have.text", "italic");
- cy.get("s").should("have.text", "strike");
- cy.get("code").should("have.text", "code");
- });
- });
-
- it("supports basic formatting with keyboard shortcuts", () => {
+ it("supports formatting via keyboard shortcuts, markdown, and the formatting menu, and emojis", () => {
startNewCommentIn1ParagraphDocument();
+ cy.log("supports basic formatting with keyboard shortcuts");
cy.realType("bold italic strike code");
selectCharactersLeft("code".length);
@@ -682,19 +695,33 @@ describe("document comments", () => {
cy.findByRole("button", { name: "Send" }).click();
- Comments.getCommentInputs()
- .first()
+ Comments.getAllComments()
+ .should("have.length", 1)
+ .eq(0)
.within(() => {
cy.get("strong").should("have.text", "bold");
cy.get("em").should("have.text", "italic");
cy.get("s").should("have.text", "strike");
cy.get("code").should("have.text", "code");
});
- });
- it("supports basic formatting with formatting menu", () => {
- startNewCommentIn1ParagraphDocument();
+ cy.log("supports basic formatting with markdown");
+ Comments.getNewThreadInput().click();
+ cy.realType("**bold** *italic* ~~strike~~ `code`");
+ cy.realPress([META_KEY, "Enter"]);
+
+ Comments.getAllComments()
+ .should("have.length", 2)
+ .eq(1)
+ .within(() => {
+ cy.get("strong").should("have.text", "bold");
+ cy.get("em").should("have.text", "italic");
+ cy.get("s").should("have.text", "strike");
+ cy.get("code").should("have.text", "code");
+ });
+ cy.log("supports basic formatting with formatting menu");
+ Comments.getNewThreadInput().click();
cy.realType("bold italic strike code");
selectCharactersLeft("code".length);
@@ -729,17 +756,73 @@ describe("document comments", () => {
cy.realPress([META_KEY, "Enter"]);
- Comments.getCommentInputs()
- .first()
+ Comments.getAllComments()
+ .should("have.length", 3)
+ .eq(2)
.within(() => {
cy.get("strong").should("have.text", "bold");
cy.get("em").should("have.text", "italic");
cy.get("s").should("have.text", "strike");
cy.get("code").should("have.text", "code");
});
+
+ cy.log("supports emojis");
+ Comments.getNewThreadInput().click();
+ cy.realType(":s");
+ Comments.getEmojiPicker()
+ .should("be.visible")
+ .and("contain.text", "😄")
+ .and("contain.text", "💦");
+
+ cy.log("can filter emojis");
+ cy.realType("mile");
+ Comments.getEmojiPicker()
+ .should("be.visible")
+ .and("contain.text", "😄")
+ .and("not.contain.text", "💦");
+
+ cy.log("can use arrow keys for navigation within the emoji picker");
+ cy.realPress("ArrowDown");
+ cy.realPress("ArrowRight");
+ cy.realPress("Enter");
+
+ Comments.getEmojiPicker().should("not.exist");
+
+ cy.log("can submit first suggestion with Enter");
+ cy.realType(":eggplant{enter}");
+
+ cy.log("closes suggestion dialog but not the comments modal on Esc");
+ cy.realType(":eg");
+ Comments.getEmojiPicker().should("be.visible");
+ cy.realPress("Escape");
+ Comments.getEmojiPicker().should("not.exist");
+ Comments.getSidebar().should("be.visible");
+
+ cy.log("can use mouse to select emoji");
+ cy.realType("{backspace}{backspace}{backspace}:egg");
+ Comments.getEmojiPicker().findByText("🥚").click();
+
+ Comments.getSidebar().within(() => {
+ Comments.getNewThreadInput()
+ .should("contain.text", "😊")
+ .and("contain.text", "🍆")
+ .and("contain.text", "🥚");
+
+ cy.realPress([META_KEY, "Enter"]);
+ });
+
+ Comments.getAllComments()
+ .should("have.length", 4)
+ .eq(3)
+ .within(() => {
+ cy.contains("😊").should("be.visible");
+ cy.contains("🍆").should("be.visible");
+ cy.contains("🥚").should("be.visible");
+ });
});
- it("supports mentions and can mention yourself", () => {
+ it("supports mentions, including yourself and users without first and last names", () => {
+ cy.request("post", "/api/user", { email: "[email protected]" });
cy.intercept({
method: "GET",
pathname: "/api/search",
@@ -776,7 +859,7 @@ describe("document comments", () => {
cy.realPress("Enter");
H.documentMentionDialog().should("not.exist");
- cy.log("closes suggestion dialog but not the comments modal on Esc");
+ cy.log("closes mention dialog but not the comments modal on Esc");
cy.realType(" @no");
H.documentMentionDialog().should("be.visible");
cy.realPress("Escape");
@@ -795,66 +878,32 @@ describe("document comments", () => {
.should("be.visible");
cy.realPress([META_KEY, "Enter"]);
-
- cy.findByText("a few seconds ago").should("be.visible");
- cy.findByText("@Bobby Tables").should("be.visible");
- cy.findByText("@None Tableton").should("be.visible");
});
- });
-
- it("supports emojis", () => {
- startNewCommentIn1ParagraphDocument();
-
- cy.realType(":s");
- Comments.getEmojiPicker()
- .should("be.visible")
- .and("contain.text", "😄")
- .and("contain.text", "💦");
- cy.log("can filter emojis");
- cy.realType("mile");
- Comments.getEmojiPicker()
- .should("be.visible")
- .and("contain.text", "😄")
- .and("not.contain.text", "💦");
-
- cy.log("can use arrow keys for navigation within the emoji picker");
- cy.realPress("ArrowDown");
- cy.realPress("ArrowRight");
- cy.realPress("Enter");
-
- Comments.getEmojiPicker().should("not.exist");
-
- cy.log("can submit first suggestion with Enter");
- cy.realType(":eggplant{enter}");
-
- cy.log("closes suggestion dialog but not the comments modal on Esc");
- cy.realType(":eg");
- cy.realPress("Escape");
- Comments.getEmojiPicker().should("not.exist");
- Comments.getSidebar().should("be.visible");
-
- cy.log("can use mouse to select emoji");
- cy.realType("{backspace}{backspace}{backspace}:egg");
- Comments.getEmojiPicker().findByText("🥚").click();
-
- Comments.getSidebar().within(() => {
- Comments.getNewThreadInput()
- .should("contain.text", "😊")
- .and("contain.text", "🍆")
- .and("contain.text", "🥚");
+ Comments.getAllComments()
+ .should("have.length", 1)
+ .eq(0)
+ .within(() => {
+ cy.findByText("a few seconds ago").should("be.visible");
+ cy.findByText("@Bobby Tables").should("be.visible");
+ cy.findByText("@None Tableton").should("be.visible");
+ });
- cy.realPress([META_KEY, "Enter"]);
+ cy.log("handles mentioning users without first and last names");
+ Comments.getNewThreadInput().type("@No");
+ Comments.getMentionDialog().findByText("[email protected]").click();
+ Comments.getNewThreadInput().type("needs to see this");
+ cy.realPress([META_KEY, "Enter"]);
- cy.contains("😊").should("be.visible");
- cy.contains("🍆").should("be.visible");
- cy.contains("🥚").should("be.visible");
- });
+ Comments.getAllComments().should("have.length", 2);
+ // mention is it's own span, so we need to search for the pieces individually
+ Comments.getCommentByText("@[email protected]").should("exist");
+ Comments.getCommentByText("needs to see this").should("exist");
});
});
describe("resolve / unresolve", () => {
- it("should resolve / unresolve basic discussion", () => {
+ it("should resolve and unresolve a discussion, show the resolved tab only when needed, block replies to resolved threads, and let another user resolve a thread", () => {
startNewCommentIn1ParagraphDocument();
const commentText = "Test resolving";
@@ -862,20 +911,47 @@ describe("document comments", () => {
cy.realType(commentText);
cy.realPress([META_KEY, "Enter"]);
+ cy.log("does not show resolved tab when there are no resolved comments");
+ Comments.getCommentByText(commentText).should("be.visible");
+ cy.findByTestId("comments-resolved-tab").should("not.exist");
+
Comments.resolveCommentByText(commentText);
- cy.findByTestId("discussion").should("not.exist");
+ Comments.getSidebar().findByText(commentText).should("not.exist");
cy.findByTestId("comments-resolved-tab").should("be.visible");
cy.findByTestId("comments-resolved-tab")
.should("contain.text", "Resolved (1)")
.click();
+ cy.log("does not allow replies for resolved threads");
+ Comments.getCommentInputs().should("have.length", 1); // only the comment content
+
Comments.reopenCommentByText(commentText);
cy.findByTestId("comments-resolved-tab").should("not.exist");
+
+ cy.log("should be possible to resolve a thread created by another user");
+ Comments.getSidebar().within(() => {
+ Comments.getNewThreadInput().click();
+ });
+ cy.realType("Main comment");
+ cy.realPress([META_KEY, "Enter"]);
+ Comments.getCommentByText("Main comment").should("be.visible");
+
+ cy.signInAsNormalUser();
+ H.visitDocument("@documentId");
+ cy.findByLabelText("Show all comments").click();
+ Comments.getCommentByText("Main comment").should("be.visible");
+ Comments.resolveCommentByText("Main comment");
+
+ cy.findByTestId("comments-resolved-tab").should("be.visible");
+ Comments.getSidebar().findByText("Main comment").should("not.exist");
+ Comments.getAllComments()
+ .should("have.length", 1)
+ .and("contain.text", commentText);
});
- it("only first comment in a thread can be resolved", () => {
+ it("allows resolving only via the first comment, shows all comments of a resolved thread, and resolves and unresolves a thread whose first comment is deleted", () => {
startNewCommentIn1ParagraphDocument();
cy.realType("Main comment");
@@ -885,6 +961,7 @@ describe("document comments", () => {
cy.realType("Reply 1");
cy.realPress([META_KEY, "Enter"]);
+ cy.log("only first comment in a thread can be resolved");
Comments.getCommentByText("Reply 1")
.realHover()
.within(() => {
@@ -898,43 +975,20 @@ describe("document comments", () => {
cy.findByTestId("comment-action-panel").should("be.visible");
cy.findByTestId("comment-action-panel-resolve").should("be.visible");
});
- });
-
- it("does not show resolved tab when there are no resolved comments", () => {
- startNewCommentIn1ParagraphDocument();
-
- cy.realType("Main comment");
- cy.realPress([META_KEY, "Enter"]);
-
- cy.findByTestId("comments-resolved-tab").should("not.exist");
- });
-
- it("resolved threads show all comments in them", () => {
- startNewCommentIn1ParagraphDocument();
-
- cy.realType("Main comment");
- cy.realPress([META_KEY, "Enter"]);
-
- Comments.getCommentInputs().should("have.length", 2).last().click();
- cy.realType("Reply 1");
- cy.realPress([META_KEY, "Enter"]);
+ cy.log("resolved threads show all comments in them");
Comments.resolveCommentByText("Main comment");
cy.findByTestId("comments-resolved-tab").should("be.visible").click();
Comments.getCommentByText("Main comment").should("be.visible");
Comments.getCommentByText("Reply 1").should("be.visible");
- });
-
- it("should be possible to resolve and unresolve a thread when the first comment is deleted", () => {
- startNewCommentIn1ParagraphDocument();
- cy.realType("Main comment");
- cy.realPress([META_KEY, "Enter"]);
+ Comments.reopenCommentByText("Main comment");
+ cy.findByTestId("comments-resolved-tab").should("not.exist");
+ Comments.getCommentByText("Main comment").should("be.visible");
+ Comments.getCommentByText("Reply 1").should("be.visible");
- Comments.getCommentInputs().should("have.length", 2).last().click();
- cy.realType("Reply 1");
- cy.realPress([META_KEY, "Enter"]);
+ cy.log("resolving a thread when the first comment is deleted");
Comments.getCommentByText("Main comment")
.realHover()
@@ -970,35 +1024,6 @@ describe("document comments", () => {
cy.findAllByRole("tab").should("have.length", 0);
Comments.getNewThreadInput().should("be.visible");
});
-
- it("should be possible to resolve a thread created by another user", () => {
- startNewCommentIn1ParagraphDocument();
-
- cy.realType("Main comment");
- cy.realPress([META_KEY, "Enter"]);
- Comments.getCommentByText("Main comment").should("be.visible");
-
- cy.signInAsNormalUser();
- H.visitDocument("@documentId");
- cy.findByLabelText("Show all comments").click();
- Comments.getCommentByText("Main comment").should("be.visible");
- Comments.resolveCommentByText("Main comment");
-
- cy.findByTestId("comments-resolved-tab").should("be.visible");
- cy.findByTestId("discussion-comment").should("not.exist");
- });
-
- it("should not allow replies for resolved threads", () => {
- startNewCommentIn1ParagraphDocument();
-
- cy.realType("Main comment");
- cy.realPress([META_KEY, "Enter"]);
-
- Comments.resolveCommentByText("Main comment");
- cy.findByTestId("comments-resolved-tab").should("be.visible").click();
-
- Comments.getCommentInputs().should("have.length", 1); // only the comment content
- });
});
describe("links", () => {
@@ -1019,7 +1044,7 @@ describe("document comments", () => {
});
});
- it("copies and opens a link to a comment", () => {
+ it("copies and opens a comment link, switching between open and resolved tabs as its thread is resolved and unresolved, and opens a link to a resolved comment", () => {
H.visitDocument("@documentId");
cy.get<number>("@documentId").then((documentId) => {
@@ -1055,13 +1080,10 @@ describe("document comments", () => {
"aria-current",
"location",
);
- });
-
- it("opens a comment link in its thread vs. 'All comments'", () => {
- cy.get<number>("@headingCommentId").then((commentId) => {
- H.visitDocumentComment("@documentId", HEADING_1_ID, commentId);
- });
+ cy.log("opens a comment link in its thread vs. 'All comments'");
+ // Visiting the copied link only changes the hash, so reload to open it cold
+ cy.reload();
Comments.getSidebar().within(() => {
cy.findByRole("heading", { name: "All comments" }).should("not.exist");
cy.findByRole("heading", { name: "Comments about this" }).should(
@@ -1074,15 +1096,39 @@ describe("document comments", () => {
"location",
);
});
- });
- it("opens a link to a resolved comment correctly", () => {
+ cy.log(
+ "changes between open/resolved tabs when resolving/unresolving a linked comment",
+ );
+ Comments.getSidebar()
+ .findByTestId("comments-resolved-tab")
+ .should("not.exist");
+ Comments.resolveCommentByText("Foo");
+
+ Comments.getSidebar()
+ .findByTestId("comments-resolved-tab")
+ .should("be.visible");
+
+ Comments.reopenCommentByText("Foo");
+ Comments.getSidebar()
+ .findByTestId("comments-resolved-tab")
+ .should("not.exist");
+
+ cy.log("opens a link to a resolved comment correctly");
cy.get<number>("@headingCommentId").then((commentId) => {
cy.request("PUT", `/api/comment/${commentId}`, {
is_resolved: true,
});
- H.visitDocumentComment("@documentId", HEADING_1_ID, commentId);
+ cy.location("hash").should("eq", `#comment-${commentId}`);
+ });
+ cy.get<DocumentId>("@documentId").then((documentId) => {
+ cy.intercept("GET", `/api/document/${documentId}`).as(
+ "resolvedLinkDocument",
+ );
});
+ // The page is still on the copied link, so a reload opens it cold
+ cy.reload();
+ cy.wait("@resolvedLinkDocument");
Comments.getSidebar().within(() => {
cy.findByTestId("comments-resolved-tab").should("be.visible");
@@ -1094,30 +1140,10 @@ describe("document comments", () => {
);
});
});
-
- it("changes between open/resolved tabs when resolving/unresolving a linked comment", () => {
- cy.get<number>("@headingCommentId").then((commentId) => {
- H.visitDocumentComment("@documentId", HEADING_1_ID, commentId);
- });
-
- Comments.getSidebar()
- .findByTestId("comments-resolved-tab")
- .should("not.exist");
- Comments.resolveCommentByText("Foo");
-
- Comments.getSidebar()
- .findByTestId("comments-resolved-tab")
- .should("be.visible");
-
- Comments.reopenCommentByText("Foo");
- Comments.getSidebar()
- .findByTestId("comments-resolved-tab")
- .should("not.exist");
- });
});
describe("all comments sidebar", () => {
- it("should all threads new to old", () => {
+ it("should show all threads newest first and not allow creating new threads", () => {
startNewCommentIn1ParagraphDocument();
cy.realType("thread 1");
cy.realPress([META_KEY, "Enter"]);
@@ -1133,40 +1159,43 @@ describe("document comments", () => {
expect(comments.eq(0)).to.contain.text("thread 2");
expect(comments.eq(1)).to.contain.text("thread 1");
});
- });
-
- it("does not allow to create new threads", () => {
- startNewCommentIn1ParagraphDocument();
- cy.realType("thread 1");
- cy.realPress([META_KEY, "Enter"]);
-
- Comments.openAllComments();
+ cy.log("does not allow to create new threads");
Comments.getNewThreadInput().should("not.exist");
});
- it("should render placeholder when no comments", () => {
+ it("should render a placeholder when there are no comments and when all comments are resolved", () => {
create1ParagraphDocument();
- H.visitDocument("@documentId");
+ H.visitDocumentComment("@documentId", "all");
+
+ Comments.getSidebar()
+ .should("contain", "All comments")
+ .should("contain", "No comments");
- cy.location().then((loc) => {
- cy.visit(`${loc.pathname}/comments/all`);
+ cy.log("no open comments, but resolved");
+ Comments.closeSidebar();
+ Comments.getSidebar().should("not.exist");
- Comments.getSidebar()
- .should("contain", "All comments")
- .should("contain", "No comments");
+ H.getParagraph().realHover();
+ cy.get<DocumentId>("@documentId").then((targetId) => {
+ Comments.getDocumentNodeButton({
+ targetId,
+ childTargetId: PARAGRAPH_ID,
+ })
+ .should("be.visible")
+ .click();
});
- });
- it("should render placeholder when no open comments, but resolved", () => {
- create1ParagraphDocument();
- cy.get<DocumentId>("@documentId").then((documentId) => {
- createParagraphComment(documentId, "Test 1");
+ Comments.getSidebar().within(() => {
+ cy.findByRole("heading", { name: "Comments about this" }).should(
+ "be.visible",
+ );
+ Comments.getNewThreadInput().click();
});
+ cy.realType("Test 1");
+ cy.realPress([META_KEY, "Enter"]);
+ Comments.getCommentByText("Test 1").should("be.visible");
- H.visitDocument("@documentId");
-
- Comments.getDocumentNodeButtons().eq(0).click();
Comments.resolveCommentByText("Test 1");
Comments.openAllComments();
@@ -1177,7 +1206,7 @@ describe("document comments", () => {
});
describe("comment reactions", () => {
- it("should allow to add multiple reactions to a comment", () => {
+ it("should allow adding multiple reactions to a comment, removing own reactions, and reacting on resolved but not on deleted comments", () => {
create1ParagraphDocument();
cy.get<DocumentId>("@documentId").then((documentId) => {
createParagraphComment(documentId, "Test 1");
@@ -1192,90 +1221,60 @@ describe("document comments", () => {
cy.wrap(el).should("contain", `${FIRST_REACTION_EMOJI}1`);
cy.wrap(el).should("contain", `${SECOND_REACTION_EMOJI}1`);
});
- });
- });
-
- it("should allow to remove own reactions from a comment", () => {
- create1ParagraphDocument();
- cy.get<DocumentId>("@documentId").then((documentId) => {
- createParagraphComment(documentId, "Test 1");
- });
- H.visitDocumentComment("@documentId", PARAGRAPH_ID);
-
- Comments.reactToComment("Test 1", FIRST_REACTION_EMOJI);
- Comments.reactToComment("Test 1", SECOND_REACTION_EMOJI);
- Comments.getSidebar().within(() => {
+ cy.log("removes own reactions");
cy.findByTestId("discussion-reactions").within(() => {
cy.findByText(`${FIRST_REACTION_EMOJI}`).should("exist");
cy.findByText(`${FIRST_REACTION_EMOJI}`).click();
cy.findByText(`${FIRST_REACTION_EMOJI}`).should("not.exist");
});
});
- });
-
- it("should allow to react on other people's reactions", () => {
- create1ParagraphDocument();
- cy.get<DocumentId>("@documentId").then((documentId) => {
- createParagraphComment(documentId, "Test 1").then((comment) => {
- const { id } = comment.body;
- H.createReaction({ comment_id: id, emoji: FIRST_REACTION_EMOJI });
- H.createReaction({ comment_id: id, emoji: SECOND_REACTION_EMOJI });
- });
- });
-
- cy.signInAsNormalUser();
- H.visitDocumentComment("@documentId", PARAGRAPH_ID);
-
- Comments.reactToComment("Test 1", FIRST_REACTION_EMOJI);
- Comments.reactToComment("Test 1", SECOND_REACTION_EMOJI);
-
- Comments.getSidebar().within(() => {
- cy.findByTestId("discussion-reactions").within((el) => {
- cy.wrap(el).should("contain", `${FIRST_REACTION_EMOJI}2`);
- cy.wrap(el).should("contain", `${SECOND_REACTION_EMOJI}2`);
- cy.findByText(`${FIRST_REACTION_EMOJI}`).click();
- cy.wrap(el).should("contain", `${FIRST_REACTION_EMOJI}1`);
- });
- });
- });
- it("should allow to react on resolved comments", () => {
- create1ParagraphDocument();
+ cy.log("should allow to react on resolved comments");
cy.get<DocumentId>("@documentId").then((documentId) => {
- createParagraphComment(documentId, "Test 1").then((comment) => {
- H.updateComment({ id: comment.body.id, is_resolved: true });
- });
+ createParagraphComment(documentId, "Resolved comment").then(
+ (comment) => {
+ H.updateComment({ id: comment.body.id, is_resolved: true });
+ },
+ );
});
H.visitDocumentComment("@documentId", PARAGRAPH_ID);
cy.findByRole("tab", { name: "Resolved (1)" }).click();
- Comments.reactToComment("Test 1", FIRST_REACTION_EMOJI);
- Comments.reactToComment("Test 1", SECOND_REACTION_EMOJI);
+ Comments.reactToComment("Resolved comment", FIRST_REACTION_EMOJI);
+ Comments.reactToComment("Resolved comment", SECOND_REACTION_EMOJI);
Comments.getSidebar().within(() => {
- cy.findByTestId("discussion-reactions").within((el) => {
- cy.wrap(el).should("contain", `${FIRST_REACTION_EMOJI}1`);
- cy.wrap(el).should("contain", `${SECOND_REACTION_EMOJI}1`);
- });
+ Comments.getCommentByText("Resolved comment")
+ .findByTestId("discussion-reactions")
+ .within((el) => {
+ cy.wrap(el).should("contain", `${FIRST_REACTION_EMOJI}1`);
+ cy.wrap(el).should("contain", `${SECOND_REACTION_EMOJI}1`);
+ });
});
- });
- it("should not allow to react on deleted comments", () => {
- create1ParagraphDocument();
+ cy.log("should not allow to react on deleted comments");
cy.get<DocumentId>("@documentId").then((documentId) => {
- createParagraphComment(documentId, "Test 1").then((comment) => {
- createParagraphComment(documentId, "Test II", comment.body.id);
- deleteComment(comment.body.id);
- });
+ createParagraphComment(documentId, "Deleted comment").then(
+ (comment) => {
+ createParagraphComment(documentId, "Test II", comment.body.id);
+ deleteComment(comment.body.id);
+ },
+ );
});
H.visitDocumentComment("@documentId", PARAGRAPH_ID);
Comments.getSidebar().within(() => {
+ Comments.getCommentByText("Test II").scrollIntoView().realHover();
+ Comments.getCommentByText("Test II")
+ .findByRole("button", { name: "Add reaction" })
+ .should("be.visible");
+
cy.findByTestId("discussion-comment-deleted")
+ .scrollIntoView()
.realHover()
.within(() => {
cy.findByTestId("comment-action-panel").should("be.visible");
@@ -1285,151 +1284,183 @@ describe("document comments", () => {
});
});
});
- });
-
- describe("top level blocks", () => {
- describe("with markdown", () => {
- it("should support blockquotes", () => {
- startNewCommentIn1ParagraphDocument();
-
- cy.log("verify blockquote is rendered during typing");
- cy.realType("> blockquote");
- H.getBlockquote("blockquote", Comments.getSidebar()).should(
- "be.visible",
- );
-
- cy.log("verify blockquote is rendered after submitting");
- cy.realPress([META_KEY, "Enter"]);
- H.getBlockquote("blockquote", Comments.getSidebar()).should(
- "be.visible",
- );
- });
-
- it("should support ordered lists", () => {
- startNewCommentIn1ParagraphDocument();
- cy.realType("1. one");
- cy.realPress("Enter");
- cy.realType("two");
- cy.log("verify ordered list is rendered during typing");
- H.getOrderedList("one", Comments.getSidebar()).should("be.visible");
- H.getOrderedList("two", Comments.getSidebar()).should("be.visible");
-
- cy.log("verify ordered list is rendered after submitting");
- cy.realPress([META_KEY, "Enter"]);
-
- H.getOrderedList("one", Comments.getSidebar()).should("be.visible");
- H.getOrderedList("two", Comments.getSidebar()).should("be.visible");
- });
-
- it("should support unordered lists", () => {
- startNewCommentIn1ParagraphDocument();
-
- cy.realType("- a");
- cy.realPress("Enter");
- cy.realType("b");
- cy.log("verify bullet list is rendered during typing");
- H.getBulletList("a", Comments.getSidebar()).should("be.visible");
- H.getBulletList("b", Comments.getSidebar()).should("be.visible");
-
- cy.log("verify bullet list is rendered after submitting");
- cy.realPress([META_KEY, "Enter"]);
-
- H.getBulletList("a", Comments.getSidebar()).should("be.visible");
- H.getBulletList("b", Comments.getSidebar()).should("be.visible");
- });
-
- it("should support code blocks", () => {
- startNewCommentIn1ParagraphDocument();
-
- cy.realType("```");
- cy.realPress("Enter");
- cy.log("verify code block is rendered during typing");
- cy.realType("code");
- H.getCodeBlock("code", Comments.getSidebar()).should("be.visible");
-
- cy.log("verify code block is rendered after submitting");
- cy.realPress([META_KEY, "Enter"]);
-
- H.getCodeBlock("code", Comments.getSidebar()).should("be.visible");
- });
- });
-
- describe("with shortcuts", () => {
- it("should support ordered list", () => {
- startNewCommentIn1ParagraphDocument();
-
- cy.realType("ol");
- cy.realPress([META_KEY, "Shift", "7"]);
-
- H.getOrderedList("ol", Comments.getSidebar()).should("be.visible");
- });
-
- it("should support bullet list", () => {
- startNewCommentIn1ParagraphDocument();
-
- cy.realType("ul");
- cy.realPress([META_KEY, "Shift", "8"]);
-
- H.getBulletList("ul", Comments.getSidebar()).should("be.visible");
- });
-
- it("should support code block", () => {
- startNewCommentIn1ParagraphDocument();
-
- cy.realType("code");
- cy.realPress([META_KEY, "Alt", "c"]);
-
- H.getCodeBlock("code", Comments.getSidebar()).should("be.visible");
+ it("should allow to react on other people's reactions", () => {
+ create1ParagraphDocument();
+ cy.get<DocumentId>("@documentId").then((documentId) => {
+ createParagraphComment(documentId, "Test 1").then((comment) => {
+ const { id } = comment.body;
+ H.createReaction({ comment_id: id, emoji: FIRST_REACTION_EMOJI });
+ H.createReaction({ comment_id: id, emoji: SECOND_REACTION_EMOJI });
+ });
});
- // explicitly disabled in CustomStarterKit to keep default browser behavior
- it.skip("should support blockquote", () => {
- startNewCommentIn1ParagraphDocument();
+ cy.signInAsNormalUser();
+ H.visitDocumentComment("@documentId", PARAGRAPH_ID);
- cy.realType("blockquote");
- cy.realPress([META_KEY, "Shift", "k"]);
+ Comments.reactToComment("Test 1", FIRST_REACTION_EMOJI);
+ Comments.reactToComment("Test 1", SECOND_REACTION_EMOJI);
- H.getBlockquote("blockquote", Comments.getSidebar()).should(
- "be.visible",
- );
+ Comments.getSidebar().within(() => {
+ cy.findByTestId("discussion-reactions").within((el) => {
+ cy.wrap(el).should("contain", `${FIRST_REACTION_EMOJI}2`);
+ cy.wrap(el).should("contain", `${SECOND_REACTION_EMOJI}2`);
+ cy.findByText(`${FIRST_REACTION_EMOJI}`).click();
+ cy.wrap(el).should("contain", `${FIRST_REACTION_EMOJI}1`);
+ });
});
});
+ });
- it("should render saved top level blocks", () => {
+ describe("top level blocks", () => {
+ it("should support top level blocks with markdown and shortcuts and render them after submitting and reloading", () => {
startNewCommentIn1ParagraphDocument();
+ cy.log("blockquote");
cy.realType("> blockquote");
+ H.getBlockquote("blockquote", Comments.getNewThreadInput()).should(
+ "be.visible",
+ );
cy.realPress([META_KEY, "Enter"]);
Comments.getAllComments().should("have.length", 1);
+ H.getBlockquote("blockquote", Comments.getAllComments().eq(0)).should(
+ "be.visible",
+ );
- Comments.getNewThreadInput().type("1. ol");
+ cy.log("ordered list");
+ Comments.getNewThreadInput().click();
+ cy.realType("1. ol");
cy.realPress("Enter");
cy.realType("two");
+ H.getOrderedList("ol", Comments.getNewThreadInput()).should("be.visible");
+ H.getOrderedList("two", Comments.getNewThreadInput()).should(
+ "be.visible",
+ );
cy.realPress([META_KEY, "Enter"]);
Comments.getAllComments().should("have.length", 2);
+ H.getOrderedList("ol", Comments.getAllComments().eq(1)).should(
+ "be.visible",
+ );
+ H.getOrderedList("two", Comments.getAllComments().eq(1)).should(
+ "be.visible",
+ );
- Comments.getNewThreadInput().type("- ul");
+ cy.log("bullet list");
+ Comments.getNewThreadInput().click();
+ cy.realType("- ul");
cy.realPress("Enter");
cy.realType("b");
+ H.getBulletList("ul", Comments.getNewThreadInput()).should("be.visible");
+ H.getBulletList("b", Comments.getNewThreadInput()).should("be.visible");
cy.realPress([META_KEY, "Enter"]);
Comments.getAllComments().should("have.length", 3);
+ H.getBulletList("ul", Comments.getAllComments().eq(2)).should(
+ "be.visible",
+ );
+ H.getBulletList("b", Comments.getAllComments().eq(2)).should(
+ "be.visible",
+ );
- Comments.getNewThreadInput().type("```");
+ cy.log("code block");
+ Comments.getNewThreadInput().click();
+ cy.realType("```");
cy.realPress("Enter");
cy.realType("code");
+ H.getCodeBlock("code", Comments.getNewThreadInput()).should("be.visible");
cy.realPress([META_KEY, "Enter"]);
Comments.getAllComments().should("have.length", 4);
+ H.getCodeBlock("code", Comments.getAllComments().eq(3)).should(
+ "be.visible",
+ );
+
+ cy.log("ordered list shortcut");
+ Comments.getNewThreadInput().click();
+ cy.realType("ol shortcut");
+ cy.realPress([META_KEY, "Shift", "7"]);
+
+ H.getOrderedList("ol shortcut", Comments.getNewThreadInput()).should(
+ "be.visible",
+ );
+ cy.realPress([META_KEY, "Enter"]);
+ Comments.getAllComments().should("have.length", 5);
+ H.getOrderedList("ol shortcut", Comments.getAllComments().eq(4)).should(
+ "be.visible",
+ );
+
+ cy.log("bullet list shortcut");
+ Comments.getNewThreadInput().click();
+ cy.realType("ul shortcut");
+ cy.realPress([META_KEY, "Shift", "8"]);
+
+ H.getBulletList("ul shortcut", Comments.getNewThreadInput()).should(
+ "be.visible",
+ );
+ cy.realPress([META_KEY, "Enter"]);
+ Comments.getAllComments().should("have.length", 6);
+ H.getBulletList("ul shortcut", Comments.getAllComments().eq(5)).should(
+ "be.visible",
+ );
+
+ cy.log("blockquote shortcut is disabled");
+ // CustomBlockquote and CustomBold leave Mod-Shift-b to the browser.
+ // Shift+b is sent as key "B", like a real keyboard: a lowercase "b" with
+ // shiftKey makes ProseMirror fall back to the Mod-b (bold) binding.
+ Comments.getNewThreadInput().click();
+ cy.realType("not a quote");
+ cy.realPress([META_KEY, "Shift", "B"]);
+ cy.realType(" after shortcut");
+ Comments.getNewThreadInput()
+ .find("p")
+ .should("have.text", "not a quote after shortcut");
+ Comments.getNewThreadInput().find("blockquote").should("not.exist");
+ Comments.getNewThreadInput().find("strong").should("not.exist");
+ cy.realPress([META_KEY, "Enter"]);
+ Comments.getAllComments().should("have.length", 7);
+ Comments.getCommentByText("not a quote after shortcut")
+ .find("blockquote")
+ .should("not.exist");
+
+ cy.log("code block shortcut");
+ Comments.getNewThreadInput().click();
+ cy.realType("code shortcut");
+ cy.realPress([META_KEY, "Alt", "c"]);
+
+ H.getCodeBlock("code shortcut", Comments.getNewThreadInput()).should(
+ "be.visible",
+ );
+ cy.realPress([META_KEY, "Enter"]);
+ Comments.getAllComments().should("have.length", 8);
+ H.getCodeBlock("code shortcut", Comments.getAllComments().eq(7)).should(
+ "be.visible",
+ );
cy.intercept("GET", "/api/document/*").as("reloadedDocument");
cy.intercept("GET", "/api/comment?*").as("reloadedComments");
cy.reload();
cy.wait(["@reloadedDocument", "@reloadedComments"]);
- H.getBlockquote("blockquote", Comments.getSidebar()).should("be.visible");
- H.getOrderedList("ol", Comments.getSidebar()).should("be.visible");
- H.getBulletList("ul", Comments.getSidebar()).should("be.visible");
- H.getCodeBlock("code", Comments.getSidebar()).should("be.visible");
+ // The thread is taller than the sidebar, so scroll each block into view
+ H.getBlockquote("blockquote", Comments.getSidebar())
+ .scrollIntoView()
+ .should("be.visible");
+ H.getOrderedList("ol", Comments.getSidebar())
+ .scrollIntoView()
+ .should("be.visible");
+ H.getBulletList("ul", Comments.getSidebar())
+ .scrollIntoView()
+ .should("be.visible");
+ H.getCodeBlock("code", Comments.getSidebar())
+ .scrollIntoView()
+ .should("be.visible");
+ H.getOrderedList("ol shortcut", Comments.getSidebar())
+ .scrollIntoView()
+ .should("be.visible");
+ H.getBulletList("ul shortcut", Comments.getSidebar())
+ .scrollIntoView()
+ .should("be.visible");
+ H.getCodeBlock("code shortcut", Comments.getSidebar())
+ .scrollIntoView()
+ .should("be.visible");
});
});
@@ -1438,7 +1469,7 @@ describe("document comments", () => {
H.setupSMTP();
});
- it("a new thread group notifies the owner of the document", () => {
+ it("notifies the document owner of a new thread, thread participants of a reply, and an @mentioned user", () => {
create1ParagraphDocument();
cy.get<DocumentId>("@documentId").then((documentId) => {
@@ -1464,85 +1495,97 @@ describe("document comments", () => {
},
);
});
- });
- it("a new reply in a thread notifies anyone in the thread", () => {
+ cy.log("a new reply in a thread notifies anyone in the thread");
+ cy.signInAsAdmin();
+ H.clearInbox();
create1ParagraphDocument();
cy.get<DocumentId>("@documentId").then((documentId) => {
- createParagraphComment(documentId, "Test 1").then((comment) => {
- cy.signInAsNormalUser();
-
- createParagraphComment(documentId, "Test 2", comment.body.id).then(
- ({ body: comment }) => {
- H.getInbox(1).then((response: any) => {
- const emails = response.body;
- cy.log("you should not get notified about your own comments");
- expect(emails).to.have.length(1);
-
- verifyEmail({
- email: emails[0],
- expected: {
- address: "[email protected]",
- subject: "Comment on Lorem ipsum",
- heading: "Robert Tableton replied to a thread",
- documentTitle: "Lorem ipsum",
- documentHref: `http://localhost:4000/document/${documentId}`,
- commentHref: `http://localhost:4000/document/${documentId}/comments/${PARAGRAPH_ID}#comment-${comment.id}`,
- },
- });
- });
- },
- );
-
- H.clearInbox();
-
- cy.signInAsImpersonatedUser();
- createParagraphComment(documentId, "Test 3", comment.body.id).then(
- ({ body: comment }) => {
- H.getInbox(2).then((response: any) => {
- const emails = response.body;
- expect(emails).to.have.length(2);
-
- const emailToAdmin = emails.find(
- (email: any) => email.to[0].address === "[email protected]",
- );
- const emailToNormalUser = emails.find(
- (email: any) =>
- email.to[0].address === "[email protected]",
- );
-
- verifyEmail({
- email: emailToAdmin,
- expected: {
- address: "[email protected]",
- subject: "Comment on Lorem ipsum",
- heading: "User Impersonated replied to a thread",
- documentTitle: "Lorem ipsum",
- documentHref: `http://localhost:4000/document/${documentId}`,
- commentHref: `http://localhost:4000/document/${documentId}/comments/${PARAGRAPH_ID}#comment-${comment.id}`,
- },
- });
-
- verifyEmail({
- email: emailToNormalUser,
- expected: {
- address: "[email protected]",
- subject: "Comment on Lorem ipsum",
- heading: "User Impersonated replied to a thread",
- documentTitle: "Lorem ipsum",
- documentHref: `http://localhost:4000/document/${documentId}`,
- commentHref: `http://localhost:4000/document/${documentId}/comments/${PARAGRAPH_ID}#comment-${comment.id}`,
- },
+ createParagraphComment(documentId, "Test 1").then(
+ ({ body: threadComment }) => {
+ cy.signInAsNormalUser();
+ createParagraphComment(documentId, "Test 2", threadComment.id).then(
+ ({ body: normalUserReply }) => {
+ cy.signInAsImpersonatedUser();
+ createParagraphComment(
+ documentId,
+ "Test 3",
+ threadComment.id,
+ ).then(({ body: impersonatedUserReply }) => {
+ H.getInbox(3).then((response: any) => {
+ const emails = response.body;
+ cy.log(
+ "you should not get notified about your own comments",
+ );
+ expect(emails).to.have.length(3);
+
+ const getHeading = (email: any) =>
+ new DOMParser()
+ .parseFromString(email.html, "text/html")
+ .querySelector("h1")?.textContent ?? "";
+ const findEmail = (address: string, heading: string) =>
+ emails.find(
+ (email: any) =>
+ email.to[0].address === address &&
+ getHeading(email).includes(heading),
+ );
+
+ verifyEmail({
+ email: findEmail(
+ "Robert Tableton replied to a thread",
+ ),
+ expected: {
+ address: "[email protected]",
+ subject: "Comment on Lorem ipsum",
+ heading: "Robert Tableton replied to a thread",
+ documentTitle: "Lorem ipsum",
+ documentHref: `http://localhost:4000/document/${documentId}`,
+ commentHref: `http://localhost:4000/document/${documentId}/comments/${PARAGRAPH_ID}#comment-${normalUserReply.id}`,
+ },
+ });
+
+ verifyEmail({
+ email: findEmail(
+ "User Impersonated replied to a thread",
+ ),
+ expected: {
+ address: "[email protected]",
+ subject: "Comment on Lorem ipsum",
+ heading: "User Impersonated replied to a thread",
+ documentTitle: "Lorem ipsum",
+ documentHref: `http://localhost:4000/document/${documentId}`,
+ commentHref: `http://localhost:4000/document/${documentId}/comments/${PARAGRAPH_ID}#comment-${impersonatedUserReply.id}`,
+ },
+ });
+
+ verifyEmail({
+ email: findEmail(
+ "User Impersonated replied to a thread",
+ ),
+ expected: {
+ address: "[email protected]",
+ subject: "Comment on Lorem ipsum",
+ heading: "User Impersonated replied to a thread",
+ documentTitle: "Lorem ipsum",
+ documentHref: `http://localhost:4000/document/${documentId}`,
+ commentHref: `http://localhost:4000/document/${documentId}/comments/${PARAGRAPH_ID}#comment-${impersonatedUserReply.id}`,
+ },
+ });
+ });
});
- });
- },
- );
- });
+ },
+ );
+ },
+ );
});
- });
- it("an explicit @mention notifies that person", () => {
+ cy.log("an explicit @mention notifies that person");
+ cy.signInAsAdmin();
+ H.clearInbox();
create1ParagraphDocument();
cy.get<DocumentId>("@documentId").then((documentId) => {
@@ -1594,21 +1637,6 @@ describe("document comments", () => {
});
});
});
-
- it("handles commenting with users without first and last names", () => {
- cy.request("post", "/api/user", { email: "[email protected]" });
- startNewCommentIn1ParagraphDocument();
- Comments.getNewThreadInput().type("@No");
- Comments.getMentionDialog().findByText("[email protected]").click();
- Comments.getNewThreadInput().type("needs to see this");
- cy.realPress([META_KEY, "Enter"]);
-
- // assert that the comment was created
- Comments.getAllComments().should("have.length", 1);
- // mention is it's own span, so we need to search for the pieces individually
- Comments.getCommentByText("@[email protected]").should("exist");
- Comments.getCommentByText("needs to see this").should("exist");
- });
});
function selectCharactersLeft(count: number) {
diff --git a/e2e/test/scenarios/documents/document-downloads.cy.spec.ts b/e2e/test/scenarios/documents/document-downloads.cy.spec.ts
index fa23a80eb50..c8a2ccb9ba4 100644
--- a/e2e/test/scenarios/documents/document-downloads.cy.spec.ts
+++ b/e2e/test/scenarios/documents/document-downloads.cy.spec.ts
@@ -10,15 +10,15 @@ describe("scenarios > documents > downloads", () => {
cy.signInAsAdmin();
});
- it("shows Download results for read-only document access", () => {
+ it("shows the full card menu for write access, only Download results for read-only access, no document without collection access, and no Download results without download permission", () => {
H.createDocument({
name: "Download Test Document",
document: DOCUMENT_WITH_TWO_CARDS,
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
+ cy.log("Write access shows the full menu including Download results");
H.visitDocument("@documentId");
// Wait for card to load
@@ -27,33 +27,20 @@ describe("scenarios > documents > downloads", () => {
.findByTestId("table-root")
.should("exist");
- // Sign in as read-only user
- cy.signIn("readonly");
- H.visitDocument("@documentId");
-
- // Wait for card to load as readonly user
- H.getDocumentCard("Orders")
- .should("be.visible")
- .findByTestId("table-root")
- .should("exist");
-
// Open card menu
H.openDocumentCardMenu("Orders");
- // Verify menu shows only "Download results" and it's enabled
+ // Verify menu shows all options with Download results
H.popover().within(() => {
+ cy.findByRole("menuitem", { name: /Edit Query/i }).should("be.visible");
+ cy.findByRole("menuitem", { name: /Edit Visualization/i }).should(
+ "be.visible",
+ );
+ cy.findByRole("menuitem", { name: /Replace/i }).should("be.visible");
cy.findByRole("menuitem", { name: /Download results/i }).should(
"be.visible",
);
- // Verify all menu items: only Download results should be enabled
- cy.findAllByRole("menuitem").each(($item) => {
- const text = $item.text();
- if (text.includes("Download results")) {
- cy.wrap($item).should("not.be.disabled");
- } else {
- cy.wrap($item).should("be.disabled");
- }
- });
+ cy.findByRole("menuitem", { name: /Remove Chart/i }).should("be.visible");
});
// Click Download results
@@ -65,20 +52,16 @@ describe("scenarios > documents > downloads", () => {
cy.findByText(".xlsx").should("be.visible");
cy.findByText(".json").should("be.visible");
});
- });
-
- it("shows full menu including Download results for write access", () => {
- H.createDocument({
- name: "Admin Download Test Document",
- document: DOCUMENT_WITH_TWO_CARDS,
- collection_id: null,
- alias: "document",
- idAlias: "documentId",
- });
+ cy.log("Read-only access shows only Download results");
+ cy.signIn("readonly");
H.visitDocument("@documentId");
- // Wait for card to load
+ H.documentContent()
+ .findByRole("textbox")
+ .should("have.attr", "contenteditable", "false");
+
+ // Wait for card to load as readonly user
H.getDocumentCard("Orders")
.should("be.visible")
.findByTestId("table-root")
@@ -87,17 +70,21 @@ describe("scenarios > documents > downloads", () => {
// Open card menu
H.openDocumentCardMenu("Orders");
- // Verify menu shows all options with Download results
+ // Verify only "Download results" is enabled
H.popover().within(() => {
- cy.findByRole("menuitem", { name: /Edit Query/i }).should("be.visible");
- cy.findByRole("menuitem", { name: /Edit Visualization/i }).should(
- "be.visible",
- );
- cy.findByRole("menuitem", { name: /Replace/i }).should("be.visible");
- cy.findByRole("menuitem", { name: /Download results/i }).should(
- "be.visible",
- );
- cy.findByRole("menuitem", { name: /Remove Chart/i }).should("be.visible");
+ cy.findByRole("menuitem", { name: /Download results/i })
+ .should("be.visible")
+ .and("be.enabled");
+ [
+ /Add supporting text/,
+ /Edit Visualization/,
+ /Edit Query/,
+ /Replace/,
+ /Remove Chart/,
+ ].forEach((name) => {
+ cy.findByRole("menuitem", { name }).should("be.disabled");
+ });
+ cy.findAllByRole("menuitem").should("have.length", 6);
});
// Click Download results
@@ -109,26 +96,8 @@ describe("scenarios > documents > downloads", () => {
cy.findByText(".xlsx").should("be.visible");
cy.findByText(".json").should("be.visible");
});
- });
-
- it("does not show download when permissions are 'none'", () => {
- H.createDocument({
- name: "No Access Document",
- document: DOCUMENT_WITH_TWO_CARDS,
- collection_id: null,
- alias: "document",
- idAlias: "documentId",
- });
-
- H.visitDocument("@documentId");
- // Wait for card to load
- H.getDocumentCard("Orders")
- .should("be.visible")
- .findByTestId("table-root")
- .should("exist");
-
- // Sign in as user with no collection access
+ cy.log("No collection access shows a permission error");
cy.signIn("nocollection");
H.visitDocument("@documentId");
@@ -141,19 +110,12 @@ describe("scenarios > documents > downloads", () => {
// Document content should not render and no card menu should be visible
H.documentContent().should("not.exist");
cy.findByRole("button", { name: /ellipsis/ }).should("not.exist");
- });
- it("hides Download results when the person lacks download permission but can view the collection", () => {
+ cy.log(
+ "No download permission hides Download results while the collection stays viewable",
+ );
+ cy.signInAsAdmin();
H.activateToken("pro-self-hosted");
-
- H.createDocument({
- name: "No Download Permission Document",
- document: DOCUMENT_WITH_TWO_CARDS,
- collection_id: null,
- alias: "document",
- idAlias: "documentId",
- });
-
H.visitDocument("@documentId");
// Wait for card to load
@@ -193,6 +155,7 @@ describe("scenarios > documents > downloads", () => {
// Verify that Download results is not shown
H.popover().within(() => {
+ cy.findByRole("menuitem", { name: /Edit Query/ }).should("be.disabled");
cy.findByRole("menuitem", { name: /Download results/i }).should(
"not.exist",
);
diff --git a/e2e/test/scenarios/documents/document-links.cy.spec.ts b/e2e/test/scenarios/documents/document-links.cy.spec.ts
index c96371b6dfe..c61836f1bcb 100644
--- a/e2e/test/scenarios/documents/document-links.cy.spec.ts
+++ b/e2e/test/scenarios/documents/document-links.cy.spec.ts
@@ -10,66 +10,12 @@ describe("Links in documents", () => {
cy.signInAsAdmin();
});
- describe("plain links", () => {
- it("should support adding, editing, and removing links via floating menu", () => {
- cy.visit("/document/new");
- H.documentContent().click();
-
- cy.log("Add text and make a link");
- H.addToDocument("Click here", false);
- times("here".length, () => cy.realPress(["Shift", "{leftarrow}"]));
- H.documentFormattingMenu().findByRole("button", { name: /link/ }).click();
- cy.realType("test.com{enter}");
-
- cy.log("Assert link exists with correct href");
- H.documentContent()
- .findByRole("link", { name: "here" })
- .invoke("attr", "href")
- .then((href) => expect(href).to.equal("https://test.com"));
-
- cy.log("Edit link url");
- H.documentContent().findByRole("link", { name: "here" }).realHover();
- cy.icon("pencil").click();
- cy.findByTestId("document-formatting-menu")
- .get("input")
- .should("be.focused");
- cy.realType("url.com/a/1?k=v");
- cy.icon("check").click();
-
- cy.log("Assert link still exists, has updated href");
- H.documentContent()
- .findByRole("link", { name: "here" })
- .invoke("attr", "href")
- .then((href) => expect(href).to.equal("https://url.com/a/1?k=v"));
-
- cy.log("Remove link");
- H.documentContent().findByRole("link", { name: "here" }).realHover();
- cy.icon("pencil").click();
- cy.findByTestId("document-formatting-menu").icon("trash").click();
-
- cy.log("Assert link is unlinked");
- H.documentContent()
- .findByRole("paragraph")
- .should("contain.text", "Click here")
- .findByRole("link", { name: "here" })
- .should("not.exist");
- });
-
- it("should convert markdown links to real links", () => {
- cy.visit("/document/new");
- H.documentContent().click();
- H.addToDocument("Click [here](url.com).", false);
- H.documentContent()
- .findByRole("paragraph")
- .should("contain.text", "Click here.")
- .findByRole("link", { name: "here" })
- .should("exist");
- });
- });
-
describe("smart links", () => {
beforeEach(() => {
H.createQuestion(PRODUCTS_AVERAGE_BY_CATEGORY, { wrapId: true });
+ });
+
+ it("should display the most up-to-date title or 'No access' for smart links, convert markdown links, add, edit and remove links via the floating menu, and add smart links via the suggestion and mention menus", () => {
cy.get("@questionId").then((questionId) => {
H.createDocument({
name: "Document with SmartLinks",
@@ -96,9 +42,7 @@ describe("Links in documents", () => {
idAlias: "documentId",
});
});
- });
- it("should display the most up-to-date title for the entity it references", () => {
H.visitDocument("@documentId");
H.documentContent().should(
@@ -115,9 +59,8 @@ describe("Links in documents", () => {
H.documentContent()
.findByRole("link", { name: /cached name/ })
.should("not.exist");
- });
- it("should display 'No access' if the user doesn't have permission to see the link", () => {
+ cy.log("Display 'No access' without permission to the linked entity");
cy.get("@questionId").then((questionId) => {
cy.intercept("GET", `/api/card/${questionId}`, {
statusCode: 403,
@@ -131,12 +74,65 @@ describe("Links in documents", () => {
.should("exist")
.icon("eye_crossed_out")
.should("exist");
- });
- it("should allow adding a smart link using the suggestion menu", () => {
+ cy.log(
+ "Convert markdown links, edit links via the floating menu, and add smart links via the suggestion and mention menus",
+ );
+ // Takes precedence over the 403 stub so smart links to the question load again
+ cy.get("@questionId").then((questionId) => {
+ cy.intercept("GET", `/api/card/${questionId}`, (req) => req.continue());
+ });
cy.visit("/document/new");
H.documentContent().click();
+ cy.log("Convert a markdown link to a real link");
+ H.addToDocument("Read [there](url.com).", false);
+ H.documentContent()
+ .findByRole("paragraph")
+ .should("contain.text", "Read there.")
+ .findByRole("link", { name: "there" })
+ .should("exist");
+ H.addToDocument("", true);
+
+ cy.log("Add text and make a link");
+ H.addToDocument("Click here", false);
+ times("here".length, () => cy.realPress(["Shift", "{leftarrow}"]));
+ H.documentFormattingMenu().findByRole("button", { name: /link/ }).click();
+ cy.realType("test.com{enter}");
+
+ cy.log("Assert link exists with correct href");
+ H.documentContent()
+ .findByRole("link", { name: "here" })
+ .invoke("attr", "href")
+ .then((href) => expect(href).to.equal("https://test.com"));
+
+ cy.log("Edit link url");
+ H.documentContent().findByRole("link", { name: "here" }).realHover();
+ cy.icon("pencil").click();
+ H.documentFormattingMenu().find("input").should("be.focused");
+ cy.realType("url.com/a/1?k=v");
+ H.documentFormattingMenu().icon("check").click();
+
+ cy.log("Assert link still exists, has updated href");
+ H.documentContent()
+ .findByRole("link", { name: "here" })
+ .invoke("attr", "href")
+ .then((href) => expect(href).to.equal("https://url.com/a/1?k=v"));
+
+ cy.log("Remove link");
+ H.documentContent().findByRole("link", { name: "here" }).realHover();
+ cy.icon("pencil").click();
+ cy.findByTestId("document-formatting-menu").icon("trash").click();
+
+ cy.log("Assert link is unlinked");
+ H.documentContent()
+ .contains("p", "Click here")
+ .findByRole("link", { name: "here" })
+ .should("not.exist");
+
+ cy.log("Add a smart link from the suggestion menu");
+ moveCursorToDocumentEnd();
+ H.addToDocument("", true);
cy.log("Trigger suggestion menu with /");
H.addToDocument("/", false);
@@ -154,11 +150,9 @@ describe("Links in documents", () => {
name: new RegExp(PRODUCTS_AVERAGE_BY_CATEGORY.name),
})
.should("exist");
- });
-
- it("should allow adding a smart link using 'Browse all' option in suggestion menu", () => {
- cy.visit("/document/new");
+ cy.log("Add a smart link using 'Browse all' option in suggestion menu");
+ H.addToDocument("", true);
openLinkSuggestionBrowseAllPicker();
H.modal().within(() => {
@@ -201,11 +195,9 @@ describe("Links in documents", () => {
name: new RegExp("Bobby Tables's Personal Collection"),
})
.should("exist");
- });
-
- it("should allow adding a smart link using 'Browse all' option in mention menu", () => {
- cy.visit("/document/new");
+ cy.log("Add a smart link using 'Browse all' option in mention menu");
+ H.addToDocument("", true);
openLinkMentionMenuBrowseAllPicker();
H.modal().within(() => {
@@ -218,7 +210,7 @@ describe("Links in documents", () => {
cy.log("Verify table smart link was added");
H.documentContent()
.findByRole("link", {
- name: new RegExp("Products"),
+ name: /Products$/,
})
.should("exist");
});
@@ -226,7 +218,7 @@ describe("Links in documents", () => {
});
function openLinkSuggestionBrowseAllPicker() {
- H.documentContent().click();
+ moveCursorToDocumentEnd();
cy.log("Trigger suggestion menu with /");
H.addToDocument("/", false);
@@ -238,10 +230,18 @@ function openLinkSuggestionBrowseAllPicker() {
}
function openLinkMentionMenuBrowseAllPicker() {
- H.documentContent().click();
+ moveCursorToDocumentEnd();
cy.log("Trigger mention menu with @");
H.addToDocument("@", false);
H.documentMentionItem(/Browse all/).click();
}
+
+function moveCursorToDocumentEnd() {
+ H.documentContent().click();
+ cy.realPress([
+ H.metaKey,
+ Cypress.platform === "darwin" ? "ArrowDown" : "End",
+ ]);
+}
diff --git a/e2e/test/scenarios/documents/document-permissions.cy.spec.ts b/e2e/test/scenarios/documents/document-permissions.cy.spec.ts
index c91ef8d8b75..72b08f59d9c 100644
--- a/e2e/test/scenarios/documents/document-permissions.cy.spec.ts
+++ b/e2e/test/scenarios/documents/document-permissions.cy.spec.ts
@@ -6,13 +6,11 @@ const { ALL_USERS_GROUP } = USER_GROUPS;
describe("document permissions", () => {
beforeEach(() => {
H.restore();
- cy.signInAsAdmin();
- H.resetSnowplow();
- cy.signOut();
});
it("should allow a non-admin user to create a new document and save it", () => {
cy.signInAsAdmin();
+ H.resetSnowplow();
cy.updateCollectionGraph({
[ALL_USERS_GROUP]: { root: "none" },
@@ -35,8 +33,8 @@ describe("document permissions", () => {
cy.findByRole("button", { name: "Save" }).click();
- H.entityPickerModalLevel(0).findByText("Our analytics").should("not.exist");
H.entityPickerModalItem(0, "Collections").should("exist");
+ H.entityPickerModalLevel(0).findByText("Our analytics").should("not.exist");
H.entityPickerModalItem(0, /Personal Collection/).click();
H.entityPickerModal().findByRole("button", { name: "Select" }).click();
@@ -78,7 +76,6 @@ describe("document permissions", () => {
type: "doc",
},
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
diff --git a/e2e/test/scenarios/documents/documents.cy.spec.ts b/e2e/test/scenarios/documents/documents.cy.spec.ts
index 79db80fda67..1dde0947335 100644
--- a/e2e/test/scenarios/documents/documents.cy.spec.ts
+++ b/e2e/test/scenarios/documents/documents.cy.spec.ts
@@ -13,11 +13,8 @@ import {
ACCOUNTS_COUNT_BY_CREATED_AT,
ORDERS_COUNT_BY_CREATED_AT,
ORDERS_COUNT_BY_PRODUCT_CATEGORY,
- PIVOT_TABLE_CARD,
PRODUCTS_AVERAGE_BY_CATEGORY,
PRODUCTS_COUNT_BY_CATEGORY_PIE,
- SCALAR_CARD,
- STEP_COLUMN_CARD,
} from "e2e/support/test-visualization-data";
import type { Document } from "metabase-types/api";
@@ -31,9 +28,11 @@ describe("documents", () => {
});
describe("duplicating documents", () => {
- it("should warn about unsaved changes when duplicating an existing document", () => {
+ it("should warn about unsaved changes on duplicate, keep them on cancel, and save, copy and redirect on confirm", () => {
+ cy.intercept("POST", "/api/document/*/copy").as("copyDoc");
+
H.createDocument({
- name: "Unsaved Duplicate Doc",
+ name: "Save Duplicate Doc",
document: {
content: [
{
@@ -45,16 +44,15 @@ describe("documents", () => {
type: "doc",
},
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
H.visitDocument("@documentId");
cy.findByRole("textbox", { name: "Document Title" })
- .should("have.value", "Unsaved Duplicate Doc")
+ .should("have.value", "Save Duplicate Doc")
.clear()
- .type("Unsaved title");
+ .type("Saved title");
H.documentContent().click();
H.addToDocument(" changed", false);
@@ -66,47 +64,14 @@ describe("documents", () => {
cy.findByTestId("save-confirmation").should("be.visible");
+ cy.log("cancelling the warning keeps the changes unsaved");
cy.findByRole("button", { name: "Cancel" }).click();
cy.findByTestId("save-confirmation").should("not.exist");
cy.findByRole("heading", { name: /Duplicate "/ }).should("not.exist");
-
- // still unsaved
- H.documentSaveButton().should("be.visible");
- });
-
- it("should save changes when duplicating, then copy and redirect to the new document", () => {
- cy.intercept("POST", "/api/document/*/copy").as("copyDoc");
-
- H.createDocument({
- name: "Save Duplicate Doc",
- document: {
- content: [
- {
- type: "paragraph",
- content: [{ type: "text", text: "Original content" }],
- attrs: { _id: "1" },
- },
- ],
- type: "doc",
- },
- collection_id: null,
- alias: "document",
- idAlias: "documentId",
- });
-
- H.visitDocument("@documentId");
-
- cy.findByRole("textbox", { name: "Document Title" })
- .should("have.value", "Save Duplicate Doc")
- .clear()
- .type("Saved title");
-
- H.documentContent().click();
- H.addToDocument(" changed", false);
-
H.documentSaveButton().should("be.visible");
+ cy.log("saving from the warning opens the duplicate modal");
cy.findByLabelText("More options").click();
H.popover().findByText("Duplicate").click();
@@ -121,6 +86,9 @@ describe("documents", () => {
);
// duplicate modal
+ cy.findByRole("heading", { name: 'Duplicate "Saved title"' }).should(
+ "be.visible",
+ );
cy.findByRole("button", { name: "Duplicate" }).should("be.visible");
cy.findByRole("textbox", { name: "Name" }).then(($input) => {
// Snapshot the value now; aliasing a command chain here can become flaky after navigation.
@@ -167,7 +135,6 @@ describe("documents", () => {
type: "doc",
},
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
@@ -375,28 +342,8 @@ describe("documents", () => {
);
});
- it("should focus the start of the document body when pressing Enter on the title input", () => {
- cy.visit("/document/new");
-
- cy.log("Type a title");
- cy.findByRole("textbox", { name: "Document Title" })
- .should("be.focused")
- .type("Doc Title{enter}");
-
- cy.log("Add some content to the document body");
- H.addToDocument("One{enter}Two");
-
- cy.log("Click back on the title to focus it and hit Enter");
- cy.findByRole("textbox", { name: "Document Title" })
- .click()
- .type("{enter}");
-
- cy.log("Focus should be placed at the beginning of the document body");
- cy.realType("NEW: ");
- H.documentContent().should("have.text", "NEW: OneTwo");
- });
-
- it("should handle navigating from /new to /new gracefully", () => {
+ it("should handle navigating from /new to /new gracefully, focus the start of the body when pressing Enter on the title, and show an error toast when creating a document fails", () => {
+ cy.log("navigating from /new to /new");
cy.visit("/");
H.newButton("Document").click();
cy.title().should("eq", "New document · Metabase");
@@ -431,6 +378,49 @@ describe("documents", () => {
.click();
H.documentContent().should("have.text", "");
H.documentSaveButton().should("not.exist");
+
+ cy.log("Enter on the title focuses the start of the body");
+ // A fresh page load, so the title input gets the initial focus
+ cy.visit("/document/new");
+
+ cy.log("Type a title");
+ cy.findByRole("textbox", { name: "Document Title" })
+ .should("be.focused")
+ .type("Doc Title{enter}");
+
+ cy.log("Add some content to the document body");
+ H.addToDocument("One{enter}Two");
+
+ cy.log("Click back on the title to focus it and hit Enter");
+ cy.findByRole("textbox", { name: "Document Title" })
+ .click()
+ .type("{enter}");
+
+ cy.log("Focus should be placed at the beginning of the document body");
+ cy.realType("NEW: ");
+ H.documentContent().should("have.text", "NEW: OneTwo");
+
+ cy.log("error toast when creating a new document fails");
+ cy.intercept("POST", "/api/document", { statusCode: 500 }).as(
+ "createDocumentError",
+ );
+ cy.intercept("GET", "/api/collection/*").as("getCollection");
+ // A fresh page load discards the unsaved document above
+ cy.visit("/document/new");
+
+ // make changes and attempt to save
+ cy.findByRole("textbox", { name: "Document Title" }).type("Title");
+ H.documentSaveButton().click();
+ cy.wait("@getCollection");
+ H.entityPickerModalItem(0, "Our analytics").click();
+ H.entityPickerModal().findByRole("button", { name: "Select" }).click();
+ cy.wait("@createDocumentError");
+
+ // assert error toast is visible and user can reattempt save
+ cy.findByTestId("toast-undo")
+ .should("be.visible")
+ .and("contain.text", "Error saving document");
+ H.documentSaveButton().should("be.visible");
});
describe("document editing", () => {
@@ -479,60 +469,18 @@ describe("documents", () => {
type: "doc",
},
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
});
- it("renders a 'not found' message if the copied card has been permanently deleted", () => {
- cy.get<Document>("@document").then(({ id, document: { content } }) => {
- const resizeNode = content?.find((n) => n.type === "resizeNode");
- const cardEmbed = resizeNode?.content?.[0];
- const clonedCardId = cardEmbed?.attrs?.id;
- cy.request("DELETE", `/api/card/${clonedCardId}`);
- H.visitDocument(id);
- });
- cy.findByTestId("document-card-embed").should(
- "have.text",
- "Couldn't find this chart.",
- );
- });
-
- it("read only access", () => {
- cy.signIn("readonly");
-
- H.visitDocument("@documentId");
-
- H.documentContent()
- .findByRole("textbox")
- .should("have.attr", "contenteditable", "false");
-
- H.openDocumentCardMenu("Orders");
- H.popover().findAllByRole("menuitem").should("be.disabled");
- });
-
- it("no access", () => {
- cy.signIn("nocollection");
-
+ it("should print and handle undo/redo, resetting the history when a different document is viewed and keeping it on save, and render 'not found' messages for a permanently deleted card and a nonexistent document", () => {
+ const originalText = "Lorem Ipsum and some more words";
+ const originalExact = new RegExp(`^${originalText}$`);
+ const modification = " etc.";
+ const modifiedExact = new RegExp(`^${originalText}${modification}$`);
H.visitDocument("@documentId");
- cy.findByRole("status").should(
- "contain.text",
- "Sorry, you don’t have permission to see that.",
- );
- });
-
- it("not found", () => {
- H.visitDocument(9999);
- H.main().within(() => {
- 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", () => {
- H.visitDocument("@documentId");
+ cy.log("print");
cy.findByRole("button", { name: "More options" }).click();
// This needs to be *after* the page load to work
@@ -550,20 +498,14 @@ describe("documents", () => {
target_id: id,
});
});
- });
- it("should handle undo/redo properly, resetting the history whenever a different document is viewed", () => {
- H.visitDocument("@documentId");
+ cy.log("undo/redo");
H.getDocumentCard("Orders").should("exist");
H.documentContent().within(() => {
- const originalText = "Lorem Ipsum and some more words";
- const originalExact = new RegExp(`^${originalText}$`);
cy.contains(originalExact).click();
cy.realPress([H.metaKey, "z"]);
cy.contains(originalExact);
- const modification = " etc.";
- const modifiedExact = new RegExp(`^${originalText}${modification}$`);
H.addToDocument(modification, false);
cy.contains(modifiedExact);
cy.realPress([H.metaKey, "z"]);
@@ -576,17 +518,11 @@ describe("documents", () => {
H.documentContent().should("have.text", "");
cy.realPress([H.metaKey, "z"]);
H.documentContent().should("have.text", "");
- });
- it("should not clear undo history on save", () => {
- const originalText = "Lorem Ipsum and some more words";
- const originalExact = new RegExp(`^${originalText}$`);
+ cy.log("undo history survives save");
H.visitDocument("@documentId");
cy.findByTestId("document-card-embed").should("contain", "37.65"); // wait for data loading
H.documentContent().contains(originalExact).click();
-
- const modification = " etc.";
- const modifiedExact = new RegExp(`^${originalText}${modification}$`);
H.addToDocument(modification, false);
H.documentContent().contains(modifiedExact);
@@ -598,6 +534,34 @@ describe("documents", () => {
cy.realPress([H.metaKey, "z"]);
cy.realPress([H.metaKey, "z"]);
H.documentContent().contains(originalExact);
+
+ cy.log("permanently deleted card");
+ cy.get<number>("@documentId").then((id) => {
+ cy.request<Document>("GET", `/api/document/${id}`).then(
+ ({ body: { document } }) => {
+ const resizeNode = document.content?.find(
+ (n) => n.type === "resizeNode",
+ );
+ const cardEmbed = resizeNode?.content?.[0];
+ const clonedCardId = cardEmbed?.attrs?.id;
+ cy.request("DELETE", `/api/card/${clonedCardId}`);
+ H.visitDocument(id);
+ },
+ );
+ });
+ cy.findByTestId("document-card-embed").should(
+ "have.text",
+ "Couldn't find this chart.",
+ );
+
+ cy.log("nonexistent document");
+ H.visitDocument(9999);
+ H.main().within(() => {
+ cy.findByText("We're a little lost...").should("be.visible");
+ cy.findByText("The page you asked for couldn't be found.").should(
+ "be.visible",
+ );
+ });
});
});
});
@@ -611,15 +575,98 @@ describe("documents", () => {
type: "doc",
},
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
-
- H.addPostgresDatabase();
});
- it("should support typing with a markdown syntax", () => {
+ it("should support formatting via floating menu and typing with a markdown syntax, and show an error toast when saving fails", () => {
H.visitDocument("@documentId");
+
+ cy.log("floating menu formatting");
+ const content = "Some text to play with";
+
+ const formatTests: ({ button: RegExp; revert?: boolean } & (
+ | { role: string }
+ | { selector: string }
+ ))[] = [
+ {
+ button: /text_bold/,
+ role: "strong",
+ },
+ {
+ button: /text_italic/,
+ role: "emphasis",
+ },
+ {
+ button: /text_strike/,
+ selector: "s",
+ },
+ {
+ button: /format_code/,
+ role: "code",
+ },
+ {
+ button: /H1/,
+ role: "heading",
+ },
+ {
+ button: /H2/,
+ role: "heading",
+ },
+ {
+ button: /^list/,
+ role: "list",
+ },
+ {
+ button: /ordered_list/,
+ role: "list",
+ },
+ {
+ button: /quote/,
+ role: "blockquote",
+ },
+ {
+ button: /code_block/,
+ role: "code",
+ revert: false,
+ },
+ ];
+
+ const assertUnformatted = () =>
+ H.documentContent()
+ // Converting to a heading currently adds a newline, which generates a new paragraph
+ .findAllByRole("paragraph")
+ .eq(0)
+ .should("contain.text", content);
+
+ H.documentContent().click();
+
+ H.addToDocument(content, false);
+ cy.realPress(["Shift", "{home}"]);
+
+ H.documentFormattingMenu().should("exist");
+
+ formatTests.forEach((formatTest) => {
+ const { button, revert = true } = formatTest;
+ H.documentFormattingMenu()
+ .findByRole("button", { name: button })
+ .click();
+ ("selector" in formatTest
+ ? H.documentContent().find(formatTest.selector)
+ : H.documentContent().findByRole(formatTest.role)
+ ).should("contain.text", content);
+ if (revert) {
+ H.documentFormattingMenu()
+ .findByRole("button", { name: button })
+ .click();
+ assertUnformatted();
+ }
+ });
+
+ cy.log("markdown syntax");
+ H.clearDocumentContent();
+ // Clearing keeps the code block; backspace turns it back into a paragraph
+ H.documentContent().type("{backspace}");
H.documentContent().click();
H.addToDocument("# This is a heading level 1");
@@ -681,89 +728,25 @@ describe("documents", () => {
.should("exist");
});
- it("should support formatting via floating menu", () => {
- const content = "Some text to play with";
-
- const formatTests = [
- {
- button: /text_bold/,
- role: "strong",
- },
- {
- button: /text_italic/,
- role: "emphasis",
- },
- {
- button: /text_strike/,
- role: "paragraph", // figure out what to do here
- },
- {
- button: /format_code/,
- role: "code",
- },
- {
- button: /H1/,
- role: "heading",
- },
- {
- button: /H2/,
- role: "heading",
- },
- {
- button: /^list/,
- role: "list",
- },
- {
- button: /ordered_list/,
- role: "list",
- },
- {
- button: /quote/,
- role: "blockquote",
- },
- {
- button: /code_block/,
- role: "code",
- revert: false,
- },
- ];
-
- const assertUnformatted = () =>
- H.documentContent()
- // Converting to a heading currently adds a newline, which generates a new paragraph
- .findAllByRole("paragraph")
- .eq(0)
- .should("contain.text", content);
-
- H.documentContent().click();
-
- H.addToDocument(content, false);
- cy.realPress(["Shift", "{home}"]);
-
- H.documentFormattingMenu().should("exist");
+ cy.log("error toast when updating the document fails");
+ cy.intercept("PUT", "/api/document/*", { statusCode: 500 }).as(
+ "updateDocumentError",
+ );
+ H.addToDocument("aaa");
+ H.documentSaveButton().scrollIntoView().click();
+ cy.wait("@updateDocumentError");
- formatTests.forEach(({ button, role, revert = true }) => {
- H.documentFormattingMenu()
- .findByRole("button", { name: button })
- .click();
- H.documentContent().findByRole(role).should("contain.text", content);
- if (revert) {
- H.documentFormattingMenu()
- .findByRole("button", { name: button })
- .click();
- assertUnformatted();
- }
- });
- });
+ // assert error toast is visible and user can reattempt save
+ cy.findByTestId("toast-undo")
+ .should("be.visible")
+ .and("contain.text", "Error saving document");
+ H.documentSaveButton().scrollIntoView().should("be.visible");
});
describe("Card Embeds", () => {
beforeEach(() => {
H.createQuestion(PRODUCTS_AVERAGE_BY_CATEGORY);
H.createQuestion(ACCOUNTS_COUNT_BY_CREATED_AT);
- H.createQuestion(PIVOT_TABLE_CARD);
- H.createNativeQuestion(STEP_COLUMN_CARD);
- H.createNativeQuestion(SCALAR_CARD.LANDING_PAGE_VIEWS);
// Need to get this one to simulate recent activity
H.createQuestion(PRODUCTS_COUNT_BY_CATEGORY_PIE).then(
({ body: { id } }) => cy.request("POST", `/api/card/${id}/query`),
@@ -780,6 +763,7 @@ describe("documents", () => {
});
it("should support keyboard and mouse selection in suggestions without double highlight", () => {
+ H.addPostgresDatabase();
H.activateToken("pro-self-hosted");
H.setupAnthropicLlmProvider();
H.visitDocument("@documentId");
@@ -800,8 +784,19 @@ describe("documents", () => {
assertOnlyOneOptionActive(/Quote/);
+ cy.intercept({
+ method: "GET",
+ pathname: "/api/search",
+ query: { q: "pro" },
+ }).as("searchPro");
H.addToDocument("pro", false);
+ // Results for the partial queries render first, and a change in their
+ // count resets the active option
+ cy.wait("@searchPro");
+ H.commandSuggestionDialog()
+ .findAllByRole("option")
+ .should("have.length", 2);
assertOnlyOneOptionActive(/Products by Category/);
cy.realPress("{downarrow}");
@@ -843,7 +838,7 @@ describe("documents", () => {
assertOnlyOneOptionActive(/QA Postgres/, "metabot");
});
- it("should support adding cards and updating viz settings", () => {
+ it("should support adding, renaming, replacing and resizing cards and updating viz settings", () => {
H.documentContent().click();
H.addToDocument("/", false);
@@ -866,6 +861,25 @@ describe("documents", () => {
H.getDocumentCard(ACCOUNTS_COUNT_BY_CREATED_AT.name).should("exist");
+ cy.log("resize a card");
+ H.getDocumentCard(ACCOUNTS_COUNT_BY_CREATED_AT.name).then(($card) => {
+ // Unjustified type cast. FIXME
+ const ogHeight = $card.height() as number;
+ const resizeNode = H.getDocumentCardResizeContainer(
+ ACCOUNTS_COUNT_BY_CREATED_AT.name,
+ );
+
+ H.documentDoDrag(H.getDragHandleForDocumentResizeNode(resizeNode), {
+ y: 200,
+ });
+
+ H.getDocumentCard(ACCOUNTS_COUNT_BY_CREATED_AT.name).should(
+ ($resized) => {
+ expect($resized.height()).to.be.closeTo(ogHeight + 200, 3);
+ },
+ );
+ });
+
cy.realPress("{downarrow}");
cy.log("via recents");
@@ -907,7 +921,7 @@ describe("documents", () => {
);
H.getDocumentSidebar().findByRole("button", { name: /close/ }).click();
- // Edit the Query. Assert on the number of breakouts
+ cy.log("edit the query of an unnamed card");
H.openDocumentCardMenu(PRODUCTS_COUNT_BY_CATEGORY_PIE.name);
H.getDocumentCard(PRODUCTS_COUNT_BY_CATEGORY_PIE.name)
.findByRole("list")
@@ -924,8 +938,33 @@ describe("documents", () => {
.findAllByRole("listitem")
.should("have.length", 7);
+ cy.log("rename a card");
+ H.getDocumentCard(PRODUCTS_COUNT_BY_CATEGORY_PIE.name).realHover();
+ H.getDocumentCard(PRODUCTS_COUNT_BY_CATEGORY_PIE.name)
+ .find(".Icon-pencil")
+ .click();
+ cy.realType("New name{enter}");
+
+ cy.log("edit the query of a renamed card");
+ H.openDocumentCardMenu("New name");
+ H.getDocumentCard("New name")
+ .findByRole("list")
+ .findAllByRole("listitem")
+ .should("have.length", 7);
+ H.popover().findByText("Edit Query").click();
+
+ H.removeSummaryGroupingField({ field: "Price: Auto binned" });
+ H.addSummaryGroupingField({ field: "Category" });
+ H.modal().findByRole("button", { name: "Save and use" }).click();
+
+ cy.log("the new name is preserved after editing the query");
+ H.getDocumentCard("New name")
+ .findByRole("list")
+ .findAllByRole("listitem")
+ .should("have.length", 4);
+
//Replace Card
- H.openDocumentCardMenu(PRODUCTS_COUNT_BY_CATEGORY_PIE.name);
+ H.openDocumentCardMenu("New name");
H.popover().findByText("Replace").click();
H.modal().within(() => {
@@ -947,258 +986,12 @@ describe("documents", () => {
H.documentContent()
.findAllByTestId("card-embed-title")
- .contains(ORDERS_COUNT_BY_PRODUCT_CATEGORY.name)
+ .contains("New name")
.should("not.exist");
H.getDocumentCard("Orders").should("exist");
});
- it("should support renaming cards", () => {
- cy.log("Add card");
- H.documentContent().click();
- H.addToDocument("/", false);
- H.commandSuggestionItem("Chart").click();
- H.commandSuggestionDialog()
- .findByText(PRODUCTS_COUNT_BY_CATEGORY_PIE.name)
- .click();
-
- cy.log("Rename card");
- cy.findByTestId("card-embed-title").realHover();
- cy.icon("pencil").click();
- cy.realType("New name{enter}");
-
- cy.log("Edit query");
- H.openDocumentCardMenu("New name");
- H.popover().findByText("Edit Query").click();
- H.removeSummaryGroupingField({ field: "Category" });
- H.addSummaryGroupingField({ field: "Price" });
- H.modal().findByRole("button", { name: "Save and use" }).click();
-
- cy.log("Assert new name is preserved");
- H.getDocumentCard("New name").should("exist");
- });
-
- it("should support resizing cards", () => {
- H.documentContent().click();
- H.addToDocument("/", false);
-
- cy.log("search via type");
- H.addToDocument("Accounts", false);
- H.commandSuggestionDialog().should(
- "contain.text",
- ACCOUNTS_COUNT_BY_CREATED_AT.name,
- );
-
- cy.realPress("{downarrow}");
- H.addToDocument("\n", false);
-
- H.getDocumentCard(ACCOUNTS_COUNT_BY_CREATED_AT.name).then((el) => {
- const ogHeight = el.height();
- const resizeNode = H.getDocumentCardResizeContainer(
- ACCOUNTS_COUNT_BY_CREATED_AT.name,
- );
-
- H.documentDoDrag(H.getDragHandleForDocumentResizeNode(resizeNode), {
- y: 200,
- });
-
- H.getDocumentCard(ACCOUNTS_COUNT_BY_CREATED_AT.name).then((el) => {
- const newHeight = el.height();
-
- cy.log(`${ogHeight}, ${newHeight}`);
-
- // Unjustified type cast. FIXME
- expect(newHeight).to.be.lessThan(ogHeight as number);
- });
- });
- });
-
- const PADDING_CARD = 1;
- type ChartCard =
- | (StructuredQuestionDetails & { name: string })
- | (NativeQuestionDetails & { name: string });
- type ChartSpec = {
- label: string;
- card: ChartCard;
- paddingX: number;
- selector: string;
- };
-
- const isNativeQuestion = (
- question: ChartCard,
- ): question is NativeQuestionDetails & { name: string } =>
- "native" in question;
-
- const createQuestionForCard = (
- question: ChartCard,
- nameOverride?: string,
- ) => {
- const details = nameOverride
- ? { ...question, name: nameOverride }
- : question;
- return isNativeQuestion(details)
- ? H.createNativeQuestion(details)
- : H.createQuestion(details);
- };
-
- const chartTypes: ChartSpec[] = [
- {
- label: "line",
- card: ACCOUNTS_COUNT_BY_CREATED_AT,
- paddingX: 16 + PADDING_CARD,
- selector: "[data-testid='chart-container'] > :first-child",
- },
- {
- label: "pie",
- card: PRODUCTS_COUNT_BY_CATEGORY_PIE,
- paddingX: 14 + PADDING_CARD,
- selector: "[data-testid='chart-with-legend']",
- },
- ];
-
- const assertChartMatchesContainerWidth = (
- cardName: string,
- paddingX: number,
- selector: string,
- ) => {
- H.getDocumentCard(cardName).then(($card) => {
- const cardWidth = $card.width()!;
- cy.wrap($card).find(selector).as("chart");
-
- cy.get("@chart")
- .should("exist")
- .then(($chart) => {
- const width = $chart.width()!;
- expect(width + paddingX * 2).to.equal(cardWidth);
- });
- });
- };
-
- it("keeps chart widths in sync during flex resize", () => {
- const cardIds: Record<string, { firstId: number; secondId: number }> =
- {};
-
- // Create all questions first
- chartTypes.forEach(({ label, card }) => {
- const secondCardName = `${card.name} (copy)`;
-
- cy.then(() =>
- createQuestionForCard(card).then(({ body }) => {
- cardIds[label] = { firstId: body.id, secondId: 0 };
- }),
- );
-
- cy.then(() =>
- createQuestionForCard(card, secondCardName).then(({ body }) => {
- cardIds[label].secondId = body.id;
- }),
- );
- });
-
- cy.then(() => {
- const content = chartTypes.map(({ label }) => ({
- type: "resizeNode",
- attrs: {
- height: 350,
- minHeight: 280,
- _id: `flex-${label}`,
- },
- content: [
- {
- type: "flexContainer",
- attrs: {
- _id: `flex-${label}-container`,
- columnWidths: [50, 50],
- },
- content: [
- {
- type: "cardEmbed",
- attrs: {
- id: cardIds[label].firstId,
- name: null,
- _id: `flex-${label}-card-1`,
- },
- },
- {
- type: "cardEmbed",
- attrs: {
- id: cardIds[label].secondId,
- name: null,
- _id: `flex-${label}-card-2`,
- },
- },
- ],
- },
- ],
- }));
-
- return H.createDocument({
- name: "Flex chart width document",
- document: {
- type: "doc",
- content,
- },
- collection_id: null,
- idAlias: "flexDocumentId",
- });
- });
-
- cy.intercept("POST", "/api/card/*/query").as("cardQuery");
-
- H.visitDocument("@flexDocumentId");
-
- // Wait for all cards to load (16 chart types × 2 cards each = 32 queries)
- for (let i = 0; i < chartTypes.length * 2; i++) {
- cy.wait("@cardQuery", { timeout: 15000 });
- }
-
- chartTypes.forEach(({ card, paddingX, selector }) => {
- const firstCardName = card.name;
- const secondCardName = `${card.name} (copy)`;
-
- const firstCardChart =
- H.getDocumentCard(firstCardName).find(selector);
- const secondCardChart =
- H.getDocumentCard(secondCardName).find(selector);
-
- firstCardChart.should("exist");
- secondCardChart.should("exist");
-
- const flexContainer = H.getFlexContainerForCard(firstCardName);
- const handles = H.getResizeHandlesForFlexContianer(flexContainer);
-
- handles.eq(0).then(($handle) => {
- cy.wrap($handle).realMouseDown({
- button: "left",
- position: "center",
- });
-
- const steps = [10, 40, 60, -100, -10, -40, -60];
- steps.forEach((deltaX) => {
- cy.wrap($handle).realMouseMove(deltaX, 0, {
- position: "center",
- });
-
- assertChartMatchesContainerWidth(
- firstCardName,
- paddingX,
- selector,
- );
- assertChartMatchesContainerWidth(
- secondCardName,
- paddingX,
- selector,
- );
- });
-
- cy.wrap($handle).realMouseUp({
- button: "left",
- position: "center",
- });
- });
- });
- });
-
it("should copy an added card on save", () => {
cy.intercept({
method: "PUT",
@@ -1274,10 +1067,12 @@ describe("documents", () => {
.findByText("Orders, Count, Grouped by Created At (year)")
.click();
- cy.location("pathname").should(
- "not.include",
- ORDERS_BY_YEAR_QUESTION_ID.toString(),
- );
+ cy.location("pathname")
+ .should("match", /^\/question\/\d+/)
+ .then((pathname) => {
+ const [, questionId] = pathname.match(/^\/question\/(\d+)/)!;
+ expect(Number(questionId)).not.to.equal(ORDERS_BY_YEAR_QUESTION_ID);
+ });
// Navigating to a question from a document should result in a back button
cy.findByLabelText("Back to Foo Document").click();
@@ -1303,6 +1098,200 @@ describe("documents", () => {
});
});
+ describe("flex chart widths", () => {
+ const PADDING_CARD = 1;
+ type ChartCard =
+ | (StructuredQuestionDetails & { name: string })
+ | (NativeQuestionDetails & { name: string });
+ type ChartSpec = {
+ label: string;
+ card: ChartCard;
+ paddingX: number;
+ selector: string;
+ };
+
+ const isNativeQuestion = (
+ question: ChartCard,
+ ): question is NativeQuestionDetails & { name: string } =>
+ "native" in question;
+
+ const createQuestionForCard = (
+ question: ChartCard,
+ nameOverride?: string,
+ ) => {
+ const details = nameOverride
+ ? { ...question, name: nameOverride }
+ : question;
+ return isNativeQuestion(details)
+ ? H.createNativeQuestion(details)
+ : H.createQuestion(details);
+ };
+
+ const chartTypes: ChartSpec[] = [
+ {
+ label: "line",
+ card: ACCOUNTS_COUNT_BY_CREATED_AT,
+ paddingX: 16 + PADDING_CARD,
+ selector: "[data-testid='chart-container'] > :first-child",
+ },
+ {
+ label: "pie",
+ card: PRODUCTS_COUNT_BY_CATEGORY_PIE,
+ paddingX: 14 + PADDING_CARD,
+ selector: "[data-testid='chart-with-legend']",
+ },
+ ];
+
+ const assertChartMatchesContainerWidth = (
+ cardName: string,
+ paddingX: number,
+ selector: string,
+ ) => {
+ H.getDocumentCard(cardName).then(($card) => {
+ const cardWidth = $card.width()!;
+ cy.wrap($card).find(selector).as("chart");
+
+ cy.get("@chart")
+ .should("exist")
+ .then(($chart) => {
+ const width = $chart.width()!;
+ expect(width + paddingX * 2).to.equal(cardWidth);
+ });
+ });
+ };
+
+ it("keeps chart widths in sync during flex resize", () => {
+ const cardIds: Record<string, { firstId: number; secondId: number }> = {};
+
+ // Create all questions first
+ chartTypes.forEach(({ label, card }) => {
+ const secondCardName = `${card.name} (copy)`;
+
+ cy.then(() =>
+ createQuestionForCard(card).then(({ body }) => {
+ cardIds[label] = { firstId: body.id, secondId: 0 };
+ }),
+ );
+
+ cy.then(() =>
+ createQuestionForCard(card, secondCardName).then(({ body }) => {
+ cardIds[label].secondId = body.id;
+ }),
+ );
+ });
+
+ cy.then(() => {
+ const content = chartTypes.map(({ label }) => ({
+ type: "resizeNode",
+ attrs: {
+ height: 350,
+ minHeight: 280,
+ _id: `flex-${label}`,
+ },
+ content: [
+ {
+ type: "flexContainer",
+ attrs: {
+ _id: `flex-${label}-container`,
+ columnWidths: [50, 50],
+ },
+ content: [
+ {
+ type: "cardEmbed",
+ attrs: {
+ id: cardIds[label].firstId,
+ name: null,
+ _id: `flex-${label}-card-1`,
+ },
+ },
+ {
+ type: "cardEmbed",
+ attrs: {
+ id: cardIds[label].secondId,
+ name: null,
+ _id: `flex-${label}-card-2`,
+ },
+ },
+ ],
+ },
+ ],
+ }));
+
+ return H.createDocument({
+ name: "Flex chart width document",
+ document: {
+ type: "doc",
+ content,
+ },
+ collection_id: null,
+ idAlias: "flexDocumentId",
+ });
+ });
+
+ cy.intercept("POST", "/api/card/*/query").as("cardQuery");
+
+ H.visitDocument("@flexDocumentId");
+
+ // Wait for all cards to load (2 cards per chart type)
+ for (let i = 0; i < chartTypes.length * 2; i++) {
+ cy.wait("@cardQuery", { timeout: 15000 });
+ }
+
+ chartTypes.forEach(({ card, paddingX, selector }) => {
+ const firstCardName = card.name;
+ const secondCardName = `${card.name} (copy)`;
+
+ const firstCardChart = H.getDocumentCard(firstCardName).find(selector);
+ const secondCardChart =
+ H.getDocumentCard(secondCardName).find(selector);
+
+ firstCardChart.should("exist");
+ secondCardChart.should("exist");
+
+ const flexContainer = H.getFlexContainerForCard(firstCardName);
+ const handles = H.getResizeHandlesForFlexContianer(flexContainer);
+
+ H.getDocumentCard(firstCardName).then(($card) => {
+ cy.wrap($card.width()).as("initialCardWidth");
+ });
+
+ handles.eq(0).then(($handle) => {
+ cy.wrap($handle).realMouseDown({
+ button: "left",
+ position: "center",
+ });
+
+ const steps = [10, 40, 60, -100, -10, -40, -60];
+ steps.forEach((deltaX, index) => {
+ cy.wrap($handle).realMouseMove(deltaX, 0, {
+ position: "center",
+ });
+
+ if (index === 0) {
+ cy.get<number>("@initialCardWidth").then((initialWidth) => {
+ H.getDocumentCard(firstCardName).should(($card) => {
+ expect($card.width()).not.to.equal(initialWidth);
+ });
+ });
+ }
+
+ assertChartMatchesContainerWidth(firstCardName, paddingX, selector);
+ assertChartMatchesContainerWidth(
+ secondCardName,
+ paddingX,
+ selector,
+ );
+ });
+
+ cy.wrap($handle).realMouseUp({
+ button: "left",
+ position: "center",
+ });
+ });
+ });
+ });
+ });
+
describe("creating new questions", () => {
beforeEach(() => {
H.createDocument({
@@ -1312,14 +1301,14 @@ describe("documents", () => {
type: "doc",
},
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
cy.intercept("POST", "/api/dataset").as("dataset");
});
- it("should allow creating a new notebook question and embedding it in the document", () => {
+ it("should create notebook questions, including a time series line chart, and a native SQL question, embed them in the document and save it", () => {
+ cy.intercept("GET", "/api/database").as("database");
H.visitDocument("@documentId");
H.documentContent().click();
@@ -1353,17 +1342,51 @@ describe("documents", () => {
});
});
- cy.log("Verify document can be saved with a new question");
- cy.findByRole("button", { name: "Save" }).should("be.visible").click();
- cy.findByRole("button", { name: "Save" }).should("not.exist");
+ cy.log("time series aggregation gets a line chart");
+ H.documentContent()
+ .find(".node-paragraph")
+ .should("have.length.at.least", 1)
+ .last()
+ .click();
- H.undoToast().findByText("Document saved").should("exist");
- });
+ cy.log("Trigger command menu and create a new question");
+ H.addToDocument("/", false);
+ H.commandSuggestionItem("Chart").click();
+ H.commandSuggestionItem(/New chart/).click();
+ H.commandSuggestionItem(/New Question/).click();
- it("should allow creating a new native SQL question and embedding it in the document", () => {
- cy.intercept("GET", "/api/database").as("database");
- H.visitDocument("@documentId");
- H.documentContent().click();
+ cy.log("Create a time series query with Orders table");
+ H.miniPicker().within(() => {
+ cy.findByText("Our analytics").click();
+ cy.findByText("Orders").click();
+ });
+
+ H.addSummaryField({ metric: "Sum of ...", field: "Total" });
+ H.addSummaryGroupingField({ field: "Created At" });
+
+ cy.findByRole("dialog", { name: "Create new question" })
+ .findByRole("button", { name: "Save and use" })
+ .click();
+
+ cy.log("Verify the question is embedded with a line chart visualization");
+ H.getDocumentCard("Orders, Sum of Total, Grouped by Created At: Month")
+ .should("exist")
+ .within(() => {
+ cy.log("Verify it has a line chart visualization (not a table)");
+ cy.findByTestId("chart-container").should("exist");
+ cy.get("svg").should("exist");
+ H.cartesianChartCircle().should("have.length.at.least", 1);
+ });
+
+ cy.log("native SQL question");
+ // The `document_add_card` assertion below counts only the native card
+ H.resetSnowplow();
+ cy.intercept("POST", "/api/dataset").as("nativeDataset");
+ H.documentContent()
+ .find(".node-paragraph")
+ .should("have.length.at.least", 1)
+ .last()
+ .click();
cy.log("Trigger command menu and select Chart");
H.addToDocument("/", false);
@@ -1385,11 +1408,18 @@ describe("documents", () => {
.findByRole("button", { name: "Save and use" })
.click();
- cy.wait("@dataset");
+ cy.wait("@nativeDataset");
cy.log("Verify the SQL query is embedded in the document");
H.getDocumentCard("New question").should("exist");
- cy.findByRole("button", { name: "Save" }).should("be.visible").click();
+
+ cy.log("Verify document can be saved with new questions");
+ cy.findByRole("button", { name: "Save" })
+ .scrollIntoView()
+ .should("be.visible")
+ .click();
+ cy.findByRole("button", { name: "Save" }).should("not.exist");
+ H.undoToast().findByText("Document saved").should("exist");
cy.get("@documentId").then((id) => {
H.expectUnstructuredSnowplowEvent({
@@ -1399,24 +1429,26 @@ describe("documents", () => {
});
cy.log("Change native question title");
- H.documentContent().within(() => {
+ H.getDocumentCard("New question").within(() => {
cy.findByText("New question").realHover();
cy.icon("pencil").click();
-
- cy.realType("New native question");
});
+ cy.realType("New native question");
cy.get(".node-paragraph").first().click(); // unfocus cardEmbed
H.getDocumentCard("New native question").should("be.visible");
- cy.log("Verify document can be saved with a new question");
- cy.findByRole("button", { name: "Save" }).should("be.visible").click();
+ cy.log("Verify document can be saved with a renamed question");
+ cy.findByRole("button", { name: "Save" })
+ .scrollIntoView()
+ .should("be.visible")
+ .click();
cy.findByRole("button", { name: "Save" }).should("not.exist");
H.undoToast().findByText("Document saved").should("exist");
});
- it("should support keyboard navigation when creating a new question", () => {
+ it("should support keyboard navigation when creating a new question and show the 'Create new question' footer for empty search results", () => {
H.visitDocument("@documentId");
H.documentContent().click();
@@ -1465,11 +1497,9 @@ describe("documents", () => {
cy.log("Verify modal is closed");
cy.findByRole("dialog", { name: "Edit SQL Query" }).should("not.exist");
- });
- it("should show 'Create new question' footer when no search results are found", () => {
- H.visitDocument("@documentId");
- H.documentContent().click();
+ cy.log("'Create new question' footer for empty search results");
+ H.clearDocumentContent();
cy.log("Trigger command menu and select Chart");
H.addToDocument("/", false);
@@ -1488,45 +1518,12 @@ describe("documents", () => {
cy.log("Verify 'Browse all' footer is also visible");
H.commandSuggestionItem(/Browse all/).should("be.visible");
- });
- it("should automatically assign appropriate visualization type for time series aggregation", () => {
- H.visitDocument("@documentId");
- H.documentContent().click();
-
- cy.log("Trigger command menu and create a new question");
- H.addToDocument("/", false);
- H.commandSuggestionItem("Chart").click();
- H.commandSuggestionItem(/New chart/).click();
- H.commandSuggestionItem(/New Question/).click();
-
- cy.log("Create a time series query with Orders table");
- H.miniPicker().within(() => {
- cy.findByText("Our analytics").click();
- cy.findByText("Orders").click();
- });
-
- H.addSummaryField({ metric: "Sum of ...", field: "Total" });
- H.addSummaryGroupingField({ field: "Created At" });
-
- cy.findByRole("dialog", { name: "Create new question" })
- .findByRole("button", { name: "Save and use" })
- .click();
-
- cy.log("Verify the question is embedded with a line chart visualization");
- H.getDocumentCard("Orders, Sum of Total, Grouped by Created At: Month")
- .should("exist")
- .within(() => {
- cy.log("Verify it has a line chart visualization (not a table)");
- cy.findByTestId("chart-container").should("exist");
- cy.get("svg").should("exist");
- H.cartesianChartCircle().should("have.length.at.least", 1);
- });
- });
-
- it("should trigger new question type suggestion menu when typing non-matching search and hitting Enter", () => {
- H.visitDocument("@documentId");
- H.documentContent().click();
+ cy.log(
+ "hitting Enter on a non-matching search opens the new question menu",
+ );
+ cy.realPress("Escape");
+ H.clearDocumentContent();
cy.log("Type a non-matching search term");
H.addToDocument("/asdfsdaf", false);
@@ -1558,7 +1555,6 @@ describe("documents", () => {
type: "doc",
},
collection_id: READ_ONLY_PERSONAL_COLLECTION_ID,
- alias: "document",
idAlias: "documentId",
});
@@ -1570,9 +1566,8 @@ describe("documents", () => {
H.commandSuggestionItem("Chart").click();
cy.log("Verify 'Create new question' footer is not visible");
- H.commandSuggestionDialog()
- .findByRole("button", { name: /New chart/ })
- .should("not.exist");
+ H.commandSuggestionItem(/Browse all/).should("be.visible");
+ H.commandSuggestionItem(/New chart/).should("not.exist");
cy.log("Search for something to verify footer doesn't appear");
H.addToDocument("xyznonexistent", false);
@@ -1583,12 +1578,8 @@ describe("documents", () => {
cy.log(
"Verify 'Create new question' footer is still not visible for no-permission user",
);
- H.commandSuggestionDialog()
- .findByRole("button", { name: /New chart/ })
- .should("not.exist");
-
- cy.log("Verify 'Browse all' footer is still available");
H.commandSuggestionItem(/Browse all/).should("be.visible");
+ H.commandSuggestionItem(/New chart/).should("not.exist");
});
it("should not show native SQL question option for users without native query editing permissions", () => {
@@ -1601,7 +1592,6 @@ describe("documents", () => {
type: "doc",
},
collection_id: NO_SQL_PERSONAL_COLLECTION_ID,
- alias: "document",
idAlias: "documentId",
});
@@ -1615,13 +1605,14 @@ describe("documents", () => {
cy.log("Click 'New chart' to open question type menu");
H.commandSuggestionItem(/New chart/).click();
- cy.log("Verify only notebook option is available, not SQL");
- H.commandSuggestionItem(/New SQL query/).should("not.exist");
-
cy.log("Verify notebook modal opens automatically");
cy.findByRole("dialog", { name: "Create new question" }).should(
"be.visible",
);
+
+ cy.log("Verify only notebook option is available, not SQL");
+ H.commandSuggestionItem(/New Question/).should("exist");
+ H.commandSuggestionItem(/New SQL query/).should("not.exist");
});
});
@@ -1683,29 +1674,44 @@ describe("documents", () => {
type: "doc",
},
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
});
- it("should show anchor link icon on left side when hovering over a heading", () => {
- H.visitDocument("@documentId");
+ it("should scroll to the anchor hash block, show the anchor and comments menus, and copy the anchor URL", () => {
+ cy.log("navigating with an anchor hash scrolls to the block");
+ cy.get("@documentId").then((documentId) => {
+ cy.visit(`/document/${documentId}#heading-block-2`);
+
+ H.documentContent()
+ .findByRole("heading", { name: "Second Heading" })
+ .should("be.visible");
+ H.documentContent()
+ .findByRole("heading", { name: "First Heading" })
+ .should("not.be.visible");
+ });
+
+ cy.log("hovering a block shows the copy link and comments menus");
H.documentContent()
.findByRole("heading", { name: "First Heading" })
.realHover();
- // Filter to visible one since all blocks have hidden buttons
+ // Filter to visible one since all blocks have hidden menus
cy.get('[data-testid="anchor-link-menu"]')
.filter(":visible")
.first()
.findByRole("button", { name: /copy link/i })
.should("be.visible");
- });
- it("should copy anchor URL to clipboard when clicking anchor link", () => {
- H.visitDocument("@documentId");
+ // Comments button uses ForwardRefLink, so it's a link role not button
+ cy.get('[data-testid="comments-menu"]')
+ .filter(":visible")
+ .first()
+ .findByRole("link", { name: /comments/i })
+ .should("be.visible");
+ cy.log("clicking the anchor link copies the anchor URL");
cy.wrap(
Cypress.automation("remote:debugger:protocol", {
command: "Browser.grantPermissions",
@@ -1716,11 +1722,6 @@ describe("documents", () => {
}),
);
- H.documentContent()
- .findByRole("heading", { name: "First Heading" })
- .realHover();
-
- // Filter to visible one since all blocks have hidden buttons
cy.get('[data-testid="anchor-link-menu"]')
.filter(":visible")
.first()
@@ -1733,89 +1734,10 @@ describe("documents", () => {
win.navigator.clipboard.readText().then((text) => {
expect(text).to.include("/document/");
expect(text).to.include("#heading-block-1");
+ expect(text).not.to.include("#heading-block-2");
});
});
});
-
- it("should scroll to the correct block when navigating with anchor hash", () => {
- cy.get("@documentId").then((documentId) => {
- cy.visit(`/document/${documentId}#heading-block-2`);
-
- H.documentContent()
- .findByRole("heading", { name: "Second Heading" })
- .should("be.visible");
-
- H.documentContent()
- .findByRole("heading", { name: "First Heading" })
- .should("not.be.visible");
- });
- });
-
- it("should still show comments menu on right side (regression check)", () => {
- H.visitDocument("@documentId");
-
- H.documentContent()
- .findByRole("heading", { name: "First Heading" })
- .realHover();
-
- // Filter to visible one since all blocks have hidden menus
- cy.get('[data-testid="anchor-link-menu"]')
- .filter(":visible")
- .first()
- .findByRole("button", { name: /copy link/i })
- .should("be.visible");
-
- // Comments button uses ForwardRefLink, so it's a link role not button
- cy.get('[data-testid="comments-menu"]')
- .filter(":visible")
- .first()
- .findByRole("link", { name: /comments/i })
- .should("be.visible");
- });
- });
-
- describe("error handling", () => {
- it("should display an error toast when creating a new document fails", () => {
- // setup
- cy.intercept("POST", "/api/document", { statusCode: 500 });
- cy.intercept("GET", "/api/collection/*").as("getCollection");
- cy.visit("/document/new");
-
- // make changes and attempt to save
- cy.findByRole("textbox", { name: "Document Title" }).type("Title");
- H.documentSaveButton().click();
- cy.wait("@getCollection");
- H.entityPickerModalItem(0, "Our analytics").click();
- H.entityPickerModal().findByRole("button", { name: "Select" }).click();
-
- // assert error toast is visible and user can reattempt save
- cy.findByTestId("toast-undo")
- .should("be.visible")
- .and("contain.text", "Error saving document");
- H.documentSaveButton().should("be.visible");
- });
-
- it("should display an error toast when updating a document fails", () => {
- // setup
- cy.intercept("PUT", "/api/document/*", { statusCode: 500 });
- H.createDocument({
- name: "Test Document",
- document: { type: "doc", content: [] },
- idAlias: "documentId",
- });
- H.visitDocument("@documentId");
-
- // make changes and attempt to save
- H.documentContent().click();
- H.addToDocument("aaa");
- H.documentSaveButton().click();
-
- // assert error toast is visible and user can reattempt save
- cy.findByTestId("toast-undo")
- .should("be.visible")
- .and("contain.text", "Error saving document");
- H.documentSaveButton().should("be.visible");
- });
});
describe("revision history", () => {
diff --git a/e2e/test/scenarios/documents/public-documents.cy.spec.ts b/e2e/test/scenarios/documents/public-documents.cy.spec.ts
index 697b75fdd16..d8c7738d2c0 100644
--- a/e2e/test/scenarios/documents/public-documents.cy.spec.ts
+++ b/e2e/test/scenarios/documents/public-documents.cy.spec.ts
@@ -1,4 +1,5 @@
import { ORDERS_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";
+import type { DocumentId } from "metabase-types/api";
const { H } = cy;
@@ -32,40 +33,15 @@ function createTestDocumentWithCard(name = "Test Document") {
});
}
-// Helper function to create a test document with custom content
-function createTestDocument(name: string, content: string) {
- return H.createDocument({
- name,
- document: {
- content: [
- {
- type: "paragraph",
- content: [{ type: "text", text: content }],
- attrs: { _id: "1" },
- },
- ],
- type: "doc",
- },
- collection_id: null,
- idAlias: "documentId",
- });
+// Helper function to visit a public document
+function createPublicLink() {
+ cy.get("@documentId")
+ .then((documentId) => H.createPublicDocumentLink(documentId))
+ .then(({ body: { uuid } }) => cy.wrap(uuid).as("publicUuid"));
}
-// Helper function to visit a public document
-function visitPublicDocument(
- documentIdAlias = "@documentId",
- options?: { signOut?: boolean },
-) {
- cy.get(documentIdAlias)
- .then((documentId) => {
- return H.createPublicDocumentLink(documentId);
- })
- .then(({ body: { uuid } }) => {
- if (options?.signOut) {
- cy.signOut();
- }
- cy.visit(`/public/document/${uuid}`);
- });
+function visitPublicDocument() {
+ cy.get("@publicUuid").then((uuid) => cy.visit(`/public/document/${uuid}`));
}
// Helper function to verify document is read-only
@@ -79,7 +55,6 @@ function verifyDocumentIsReadOnly() {
// Helper function to verify comments are hidden
function verifyCommentsAreHidden() {
H.Comments.getDocumentNodeButtons().should("not.exist");
- cy.findByTestId("comments-sidebar").should("not.exist");
cy.findByRole("link", { name: "Show all comments" }).should("not.exist");
}
@@ -97,11 +72,46 @@ describe("scenarios > documents > public", () => {
H.updateSetting("enable-public-sharing", true);
});
- it("should not show comments in public documents", () => {
- // Create a document with content and an embedded card
- createTestDocument("Test Public Document", "This is a test paragraph");
+ it("should restrict comments, header menu, editing, metabot blocks and the card menu in public view, and show an error after the document is trashed", () => {
+ const metabotPrompt = "Some metabot prompt";
+ H.createDocument({
+ name: "Test Public Document",
+ document: {
+ content: [
+ {
+ type: "paragraph",
+ content: [{ type: "text", text: "This is a test paragraph" }],
+ attrs: { _id: "1" },
+ },
+ {
+ type: "metabot",
+ content: [{ type: "text", text: metabotPrompt }],
+ },
+ ],
+ type: "doc",
+ },
+ collection_id: null,
+ idAlias: "documentId",
+ });
+
+ cy.get<DocumentId>("@documentId").then((documentId) => {
+ H.createComment({
+ target_type: "document",
+ target_id: documentId,
+ child_target_id: "1",
+ content: {
+ type: "doc",
+ content: [
+ {
+ type: "paragraph",
+ content: [{ type: "text", text: "A test comment" }],
+ },
+ ],
+ },
+ });
+ });
- cy.log("Visit the document as admin to verify comments exist");
+ cy.log("Visit the document as admin");
H.visitDocument("@documentId");
// Verify the document content loaded
@@ -110,71 +120,6 @@ describe("scenarios > documents > public", () => {
// Verify comment buttons exist for authenticated users
H.Comments.getDocumentNodeButtons().should("exist");
- cy.log("Create public link and visit public document");
- visitPublicDocument();
-
- cy.log("Verify document content is visible");
- H.documentContent().should("contain", "This is a test paragraph");
-
- cy.log("Verify comment buttons do not exist in public view");
- verifyCommentsAreHidden();
- });
-
- it("should only show 'Download results' in card menu for public documents", () => {
- // Create a document with an embedded card
- createTestDocumentWithCard("Test Document with Card");
-
- cy.log("Visit document as admin to verify full menu exists");
- H.visitDocument("@documentId");
-
- // Wait for card to load
- H.getDocumentCard("Orders").should("exist");
-
- // Open card menu as admin and verify multiple options exist
- H.openDocumentCardMenu("Orders");
- H.popover().within(() => {
- cy.findByText("Edit Visualization").should("exist");
- cy.findByText("Edit Query").should("exist");
- cy.findByText("Replace").should("exist");
- });
-
- // Close the popover by clicking outside
- H.documentContent().click();
-
- cy.log("Create public link and visit public document");
- visitPublicDocument();
-
- cy.log("Verify card is visible in public view");
- H.getDocumentCard("Orders").should("exist");
-
- cy.log("Open card menu in public view");
- H.openDocumentCardMenu("Orders");
-
- cy.log("Verify only 'Download results' option is present");
- H.popover().within(() => {
- cy.findByText("Download results").should("exist");
- cy.findByText("Edit Visualization").should("not.exist");
- cy.findByText("Edit Query").should("not.exist");
- cy.findByText("Replace").should("not.exist");
-
- // Verify there's only one menu item
- cy.findAllByRole("menuitem").should("have.length", 1);
- });
- });
-
- it("should restrict document header menu in public view", () => {
- // Create a document
- createTestDocument(
- "Test Document Header",
- "Testing header menu restrictions",
- );
-
- cy.log("Visit document as admin to verify full menu exists");
- H.visitDocument("@documentId");
-
- // Verify the document content loaded
- H.documentContent().should("contain", "Testing header menu restrictions");
-
// Check that "More options" menu exists with admin options
cy.findByRole("button", { name: "More options" }).click();
H.popover().within(() => {
@@ -186,88 +131,68 @@ describe("scenarios > documents > public", () => {
// Close the popover
H.documentContent().click();
- cy.log("Create public link and visit public document");
- visitPublicDocument();
-
- cy.log("Verify document content is visible in public view");
- H.documentContent().should("contain", "Testing header menu restrictions");
-
- cy.log("Verify 'More options' menu is either hidden or restricted");
- // In public view, the "More options" button should not exist or should have limited options
- cy.findByRole("button", { name: "More options" }).should("not.exist");
- });
-
- it("should be read-only in public view", () => {
- // Create a document
- createTestDocument(
- "Read-only Test Document",
- "This content should not be editable",
- );
-
- cy.log("Visit document as admin to verify it's editable");
- H.visitDocument("@documentId");
-
// Verify the document content is editable
H.documentContent()
.findByRole("textbox")
.should("have.attr", "contenteditable", "true");
+ // Verify the metabot block shows its Run button
+ H.documentContent().findByRole("button", { name: "Run" }).should("exist");
+
+ // Verify the comments link and sidebar are available
+ cy.findByRole("link", { name: "Show all comments" }).should("be.visible");
+ H.Comments.openAllComments();
+ H.Comments.getSidebar().should("be.visible");
+
cy.log("Create public link and visit public document");
+ createPublicLink();
visitPublicDocument();
cy.log("Verify document content is visible");
- H.documentContent().should(
- "contain",
- "This content should not be editable",
- );
+ H.documentContent().should("contain", "This is a test paragraph");
+
+ cy.log("Verify comment buttons do not exist in public view");
+ verifyCommentsAreHidden();
+
+ cy.log("Verify 'More options' menu is hidden");
+ cy.findByRole("button", { name: "More options" }).should("not.exist");
cy.log("Verify document is read-only");
verifyDocumentIsReadOnly();
- });
- it("should display metabot blocks in a read-only state", () => {
- const text = "Some metabot prompt";
- H.createDocument({
- name: "Document with metabot block",
- document: {
- content: [
- {
- type: "metabot",
- content: [{ type: "text", text }],
- },
- ],
- type: "doc",
- },
- collection_id: null,
- idAlias: "documentId",
- });
- visitPublicDocument();
-
- cy.log("Click the metabot block and enter text");
- H.documentContent().findByText(text).click();
+ cy.log("Metabot block is read-only");
+ H.documentContent().findByText(metabotPrompt).click();
cy.realType("a");
cy.log("Verify the text wasn't updated");
- H.documentContent().findByText(text).should("exist");
+ H.documentContent().findByText(metabotPrompt).should("exist");
cy.log("Verify that run/close buttons don't exist");
H.documentContent().find("button").should("not.exist");
- });
- it("should allow downloading results from embedded cards", () => {
- // Create a document with an embedded card
- createTestDocumentWithCard("Download Test Document");
+ cy.log(
+ "Public card menu only offers downloads; trashing the document breaks its public link",
+ );
+ // Re-points @documentId and @publicUuid at the document with a card
+ createTestDocumentWithCard("Test Document with Card");
cy.log("Create public link and visit public document");
+ createPublicLink();
visitPublicDocument();
- cy.log("Verify card is visible");
+ cy.log("Verify document and card are visible in public view");
+ H.documentContent().should("contain", "Test content");
H.getDocumentCard("Orders").should("exist");
- cy.log("Open card menu and verify download option");
+ cy.log("Open card menu in public view");
H.openDocumentCardMenu("Orders");
+
+ cy.log("Verify only 'Download results' option is present");
H.popover().within(() => {
cy.findByText("Download results").should("exist");
+
+ // Verify there's only one menu item
+ cy.findAllByRole("menuitem").should("have.length", 1);
});
cy.log("Click 'Download results' to show format options");
@@ -280,109 +205,38 @@ describe("scenarios > documents > public", () => {
cy.findByText(".json").should("exist");
cy.findByTestId("download-results-button").should("exist");
});
- });
-
- it("should be accessible without authentication", () => {
- // Create a document with public link
- createTestDocumentWithCard("Public Anonymous Document");
- cy.log("Sign out and visit public document as anonymous user");
- visitPublicDocument("@documentId", { signOut: true });
-
- cy.log("Verify document content is visible without authentication");
- H.documentContent().should("contain", "Test content");
- H.getDocumentCard("Orders").should("exist");
+ cy.log("Move the document to trash");
+ cy.intercept("PUT", "/api/document/*").as("updateDocument");
+ H.visitDocument("@documentId");
+ cy.findByRole("button", { name: "More options" }).click();
+ H.popover().findByText("Move to trash").click();
+ cy.wait("@updateDocument");
- cy.log("Verify document is read-only");
- verifyDocumentIsReadOnly();
+ cy.log("Try to access public link after document deletion");
+ visitPublicDocument();
- cy.log("Verify no authentication UI is shown");
- cy.findByRole("button", { name: "Sign in" }).should("not.exist");
+ cy.log("Verify error message is shown");
+ verifyErrorMessage("Not found");
});
- it("should become inaccessible when public sharing is disabled", () => {
+ it("should be accessible anonymously with branding, inaccessible once public sharing is disabled, and unbranded on premium", () => {
// Create a document with public link
createTestDocumentWithCard("Document for Disabling Test");
cy.log("Create public link while sharing is enabled");
- cy.get("@documentId")
- .then((documentId) => {
- return H.createPublicDocumentLink(documentId);
- })
- .then(({ body: { uuid } }) => {
- cy.wrap(uuid).as("publicUuid");
-
- cy.log("Verify document is accessible with sharing enabled");
- cy.signOut();
- cy.visit(`/public/document/${uuid}`);
- H.documentContent().should("contain", "Test content");
- });
+ createPublicLink();
- cy.log("Disable public sharing");
- cy.signInAsAdmin();
- H.updateSetting("enable-public-sharing", false);
+ cy.log("Verify document is accessible with sharing enabled");
cy.signOut();
+ visitPublicDocument();
+ H.documentContent().should("contain", "Test content");
- cy.log("Try to access public document after disabling sharing");
- cy.get("@publicUuid").then((uuid) => {
- cy.visit(`/public/document/${uuid}`);
-
- cy.log("Verify document is no longer accessible");
- verifyErrorMessage("An error occurred.");
- });
-
- // Cleanup: Re-enable public sharing for subsequent tests
- cy.signInAsAdmin();
- H.updateSetting("enable-public-sharing", true);
- });
-
- it("should show error when accessing public link of deleted document", () => {
- // Create a document with public link
- createTestDocumentWithCard("Document to be Deleted");
-
- cy.log("Create public link");
- cy.get("@documentId")
- .then((documentId) => {
- return H.createPublicDocumentLink(documentId);
- })
- .then(({ body: { uuid } }) => {
- cy.wrap(uuid).as("publicUuid");
-
- cy.log("Verify document is accessible before deletion");
- cy.visit(`/public/document/${uuid}`);
- H.documentContent().should("contain", "Test content");
- });
-
- cy.log("Delete the document");
- cy.get("@documentId").then((documentId) => {
- H.visitDocument(documentId);
- });
-
- // Move document to trash
- cy.findByRole("button", { name: "More options" }).click();
- H.popover().findByText("Move to trash").click();
-
- cy.log("Try to access public link after document deletion");
- cy.get("@publicUuid").then((uuid) => {
- cy.visit(`/public/document/${uuid}`);
-
- cy.log("Verify error message is shown");
- verifyErrorMessage("Not found");
- });
- });
-
- it("should display 'Powered by Metabase' link in footer", () => {
- // Create a document
- createTestDocument(
- "Test Document with Footer",
- "Testing footer branding link",
- );
-
- cy.log("Create public link and visit public document");
- visitPublicDocument("@documentId", { signOut: true });
-
- cy.log("Verify document content is visible");
- H.documentContent().should("contain", "Testing footer branding link");
+ cy.log("Verify the document is read-only without authentication");
+ H.getDocumentCard("Orders").should("exist");
+ verifyDocumentIsReadOnly();
+ cy.location("pathname").should("match", /^\/public\/document\//);
+ cy.findByRole("button", { name: "Sign in" }).should("not.exist");
cy.log("Verify 'Powered by Metabase' link exists in footer");
cy.findByRole("link", { name: "Powered by Metabase" })
@@ -390,23 +244,28 @@ describe("scenarios > documents > public", () => {
.should("be.visible")
.should("have.attr", "href")
.and("contain", "https://www.metabase.com?");
- });
- it("should not display footer for premium", () => {
- H.activateToken("pro-self-hosted");
+ cy.log("Disable public sharing");
+ cy.signInAsAdmin();
+ H.updateSetting("enable-public-sharing", false);
+ cy.signOut();
- // Create a document
- createTestDocument(
- "Test Document with Footer",
- "Testing footer branding link",
- );
+ cy.log("Try to access public document after disabling sharing");
+ visitPublicDocument();
- cy.log("Create public link and visit public document");
- visitPublicDocument("@documentId", { signOut: true });
+ cy.log("Verify document is no longer accessible");
+ verifyErrorMessage("An error occurred.");
- cy.log("Verify document content is visible");
- H.documentContent().should("contain", "Testing footer branding link");
+ cy.log("Re-enable public sharing with a premium token");
+ cy.signInAsAdmin();
+ H.updateSetting("enable-public-sharing", true);
+ H.activateToken("pro-self-hosted");
+ cy.signOut();
+
+ visitPublicDocument();
+ H.documentContent().should("contain", "Test content");
- cy.findByTestId("embed-frame-footer").should("not.exist");
+ cy.log("Verify 'Powered by Metabase' link is hidden for premium");
+ cy.findByRole("link", { name: "Powered by Metabase" }).should("not.exist");
});
});
diff --git a/e2e/test/scenarios/documents/supporting-text.cy.spec.ts b/e2e/test/scenarios/documents/supporting-text.cy.spec.ts
index 165164a5643..e0dda9986a3 100644
--- a/e2e/test/scenarios/documents/supporting-text.cy.spec.ts
+++ b/e2e/test/scenarios/documents/supporting-text.cy.spec.ts
@@ -18,7 +18,6 @@ describe("documents supporting text", () => {
name: "Supporting Text Test Document",
document: DOCUMENT_WITH_TWO_LIGHTWEIGHT_CARDS,
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
@@ -79,108 +78,11 @@ describe("documents supporting text", () => {
H.getDocumentCard(ORDERS_BY_YEAR_CARD_TITLE).should("exist");
});
- it("should add supporting text to a cardEmbed in a flexContainer", () => {
+ it("should add, remove, edit and resize supporting text, disable adding more to its group, and persist width after save", () => {
H.createDocument({
- name: "Supporting Text Flex Test Document",
- document: DOCUMENT_WITH_TWO_CARDS,
- collection_id: null,
- alias: "document",
- idAlias: "documentId",
- });
-
- H.visitDocument("@documentId");
-
- // Wait for cards to load
- H.getDocumentCard("Orders")
- .should("be.visible")
- .findByTestId("table-root")
- .should("exist");
- H.getDocumentCard("Orders, Count")
- .should("be.visible")
- .findByTestId("table-root")
- .should("exist");
-
- // Create a flexContainer by dropping one card onto another
- H.dragAndDropCardOnAnotherCard("Orders", "Orders, Count");
-
- // Verify flexContainer was created
- H.documentContent().find('[data-type="flexContainer"]').should("exist");
-
- // Verify no supporting text exists yet
- H.documentContent()
- .findByTestId("document-card-supporting-text")
- .should("not.exist");
-
- // Open the card menu and click "Add supporting text"
- H.openDocumentCardMenu("Orders");
- H.popover().findByText("Add supporting text").click();
-
- // Verify supporting text was added at the beginning of the flexContainer
- H.documentContent()
- .findByTestId("document-card-supporting-text")
- .should("exist");
-
- // Verify the supporting text has the placeholder text
- H.documentContent()
- .findByTestId("document-card-supporting-text")
- .should("contain.text", "Write whatever you'd like to");
-
- // Verify the flexContainer now contains supporting text and both cards
- H.documentContent()
- .find('[data-type="flexContainer"]')
- .within(() => {
- cy.findByTestId("document-card-supporting-text").should("exist");
- cy.findAllByTestId("document-card-embed").should("have.length", 2);
- });
- });
-
- it("should allow editing supporting text content", () => {
- H.createDocument({
- name: "Edit Supporting Text Test Document",
- document: DOCUMENT_WITH_TWO_CARDS,
- collection_id: null,
- alias: "document",
- idAlias: "documentId",
- });
-
- H.visitDocument("@documentId");
-
- // Wait for cards to load
- H.getDocumentCard("Orders")
- .should("be.visible")
- .findByTestId("table-root")
- .should("exist");
-
- // Add supporting text
- H.openDocumentCardMenu("Orders");
- H.popover().findByText("Add supporting text").click();
-
- // Verify supporting text was added
- H.documentContent()
- .findByTestId("document-card-supporting-text")
- .should("exist");
-
- // Type some content
- const testText = "# Hdg{enter}Lorem ipsum";
- cy.realType(testText);
-
- // Verify the text was added
- H.documentContent()
- .findByTestId("document-card-supporting-text")
- .contains("h1", "Hdg")
- .should("exist");
- H.documentContent()
- .findByTestId("document-card-supporting-text")
- .contains("p", "Lorem ipsum")
- .should("exist");
- });
-
- it("should disable 'Add supporting text' when supporting text already exists in flexContainer", () => {
- H.createDocument({
- name: "Disable Supporting Text Test Document",
+ name: "Resize Supporting Text Test Document",
document: DOCUMENT_WITH_TWO_CARDS,
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
@@ -192,96 +94,31 @@ describe("documents supporting text", () => {
.findByTestId("table-root")
.should("exist");
- // Add supporting text to the first card
- H.openDocumentCardMenu("Orders");
- H.popover().findByText("Add supporting text").click();
-
- // Verify supporting text was added
- H.documentContent()
- .findByTestId("document-card-supporting-text")
- .should("exist");
-
- // Try to add another supporting text to the same flexContainer
+ cy.log("add supporting text");
H.openDocumentCardMenu("Orders");
-
- // Verify the "Add supporting text" option is disabled
H.popover()
.findByText("Add supporting text")
.closest("button")
- .should("have.attr", "data-disabled");
- });
-
- it("should disable 'Add supporting text' when flexContainer has 3 cards", () => {
- H.createDocument({
- name: "Max Cards Supporting Text Test Document",
- document: DOCUMENT_WITH_THREE_CARDS_AND_COLUMNS,
- collection_id: null,
- alias: "document",
- idAlias: "documentId",
- });
-
- H.visitDocument("@documentId");
+ .should("be.enabled")
+ .click();
- // Wait for all cards to load
- H.getDocumentCard("Orders")
- .should("be.visible")
- .findByTestId("table-root")
- .should("exist");
- H.getDocumentCard("Orders, Count")
- .should("be.visible")
- .findByTestId("table-root")
+ // Verify supporting text was added
+ H.documentContent()
+ .findByTestId("document-card-supporting-text")
.should("exist");
- // Add the third card to reach MAX_GROUP_SIZE
- H.dragAndDropCardOnAnotherCard(
- "Orders, Count, Grouped by Created At (year)",
- "Orders",
- { side: "right" },
+ cy.log(
+ "'Add supporting text' is disabled when the group has supporting text",
);
-
- // Verify flexContainer has 3 cards
- H.documentContent()
- .find('[data-type="flexContainer"]')
- .within(() => {
- cy.findAllByTestId("document-card-embed").should("have.length", 3);
- });
-
- // Open the card menu
H.openDocumentCardMenu("Orders");
-
- // Verify the "Add supporting text" option is disabled
H.popover()
.findByText("Add supporting text")
.closest("button")
.should("have.attr", "data-disabled");
- });
-
- it("should remove supporting text when it becomes empty and Backspace is pressed", () => {
- H.createDocument({
- name: "Remove Empty Supporting Text Test Document",
- document: DOCUMENT_WITH_TWO_CARDS,
- collection_id: null,
- alias: "document",
- idAlias: "documentId",
- });
-
- H.visitDocument("@documentId");
-
- // Wait for cards to load
- H.getDocumentCard("Orders")
- .should("be.visible")
- .findByTestId("table-root")
- .should("exist");
-
- // Add supporting text
- H.openDocumentCardMenu("Orders");
- H.popover().findByText("Add supporting text").click();
-
- // Verify supporting text was added
- H.documentContent()
- .findByTestId("document-card-supporting-text")
- .should("exist");
+ cy.realPress("Escape");
+ cy.get(H.POPOVER_ELEMENT).should("not.exist");
+ cy.log("empty supporting text is removed on Backspace");
// Click into the supporting text
H.documentContent()
.findByTestId("document-card-supporting-text")
@@ -300,33 +137,14 @@ describe("documents supporting text", () => {
// Verify the card is still there as a standalone card
H.getDocumentCard("Orders").should("exist");
- });
-
- it("should allow resizing supporting text and persist width after save", () => {
- cy.intercept({
- method: "GET",
- path: "/api/document/*",
- }).as("documentGet");
-
- H.createDocument({
- name: "Resize Supporting Text Test Document",
- document: DOCUMENT_WITH_TWO_CARDS,
- collection_id: null,
- alias: "document",
- idAlias: "documentId",
- });
-
- H.visitDocument("@documentId");
- // Wait for cards to load
- H.getDocumentCard("Orders")
- .should("be.visible")
- .findByTestId("table-root")
- .should("exist");
-
- // Add supporting text to create a flexContainer
+ cy.log("add supporting text again and edit it");
H.openDocumentCardMenu("Orders");
- H.popover().findByText("Add supporting text").click();
+ H.popover()
+ .findByText("Add supporting text")
+ .closest("button")
+ .should("be.enabled")
+ .click();
// Verify flexContainer and supporting text were created
H.documentContent().find('[data-type="flexContainer"]').should("exist");
@@ -334,6 +152,20 @@ describe("documents supporting text", () => {
.findByTestId("document-card-supporting-text")
.should("exist");
+ // Type some content
+ cy.realType("# Hdg{enter}Lorem ipsum");
+
+ // Verify the text was added
+ H.documentContent()
+ .findByTestId("document-card-supporting-text")
+ .contains("h1", "Hdg")
+ .should("exist");
+ H.documentContent()
+ .findByTestId("document-card-supporting-text")
+ .contains("p", "Lorem ipsum")
+ .should("exist");
+
+ cy.log("resize supporting text and persist width after save");
// Get initial widths of supporting text and card
H.documentContent()
.findByTestId("document-card-supporting-text")
@@ -405,10 +237,6 @@ describe("documents supporting text", () => {
.findByTestId("document-card-supporting-text")
.should("contain.text", testText);
- H.documentContent()
- .findByTestId("document-card-supporting-text")
- .should("contain.text", testText);
-
// Save the document
H.documentSaveButton().should("not.be.disabled").click();
@@ -418,6 +246,10 @@ describe("documents supporting text", () => {
.and("contain.text", "Document saved");
// Reload the page to verify persistence
+ cy.intercept({
+ method: "GET",
+ path: "/api/document/*",
+ }).as("documentGet");
cy.reload();
cy.wait("@documentGet");
@@ -457,13 +289,16 @@ describe("documents supporting text", () => {
name: "Supporting Text auto-cleanup",
document: DOCUMENT_WITH_THREE_CARDS_AND_COLUMNS,
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
H.visitDocument("@documentId");
H.openDocumentCardMenu("Orders");
- H.popover().findByText("Add supporting text").click();
+ H.popover()
+ .findByText("Add supporting text")
+ .closest("button")
+ .should("be.enabled")
+ .click();
cy.realType("Lorem ipsum");
const targetCardTitle = "Orders, Count, Grouped by Created At (year)";
@@ -483,7 +318,6 @@ describe("documents supporting text", () => {
name: "DnD Test Document",
document: DOCUMENT_WITH_SUPPORTING_TEXT,
collection_id: null,
- alias: "document",
idAlias: "documentId",
});
H.visitDocument("@documentId");
@@ -525,7 +359,20 @@ describe("documents supporting text", () => {
});
};
- it("should reorder when dropping a supporting text block onto a card", () => {
+ it("should do nothing when dropping a supporting text block outside of a group, and reorder when dropping it onto a card", () => {
+ H.getDocumentCard("Orders").should("exist");
+ H.documentsDragAndDrop({
+ getSource: () => getSupportingText().find("[data-drag-handle]"),
+ getTarget: () => H.getDocumentCard("Orders, Count"),
+ });
+
+ assertHorizontalLayout(getSupportingText(), H.getDocumentCard("Orders"));
+ assertVerticalLayout(
+ getSupportingText(),
+ H.getDocumentCard("Orders, Count"),
+ );
+
+ cy.log("drop supporting text onto a card");
H.getDocumentCard("Orders").should("exist");
H.documentsDragAndDrop({
getSource: () => getSupportingText().find("[data-drag-handle]"),
@@ -569,19 +416,5 @@ describe("documents supporting text", () => {
);
assertHorizontalLayout(getSupportingText(), H.getDocumentCard("Orders"));
});
-
- it("should do nothing if dragging a supporting text block outside of a group", () => {
- H.getDocumentCard("Orders").should("exist");
- H.documentsDragAndDrop({
- getSource: () => getSupportingText().find("[data-drag-handle]"),
- getTarget: () => H.getDocumentCard("Orders, Count"),
- });
-
- assertHorizontalLayout(getSupportingText(), H.getDocumentCard("Orders"));
- assertVerticalLayout(
- getSupportingText(),
- H.getDocumentCard("Orders, Count"),
- );
- });
});
});