Skip to content
Snippets Groups Projects
Unverified Commit df2b2589 authored by Alexander Polyankin's avatar Alexander Polyankin Committed by GitHub
Browse files

Refactor pinned items e2e tests (#23462)

parent d284f41e
No related branches found
No related tags found
No related merge requests found
import { popover, restore } from "__support__/e2e/cypress"; import { popover, restore } from "__support__/e2e/cypress";
const DASHBOARD_ITEM_NAME = "Orders in a dashboard"; const DASHBOARD_NAME = "Orders in a dashboard";
const CARD_ITEM_NAME = "Orders, Count"; const QUESTION_NAME = "Orders, Count";
const MODE_ITEM_NAME = "Orders"; const MODEL_NAME = "Orders";
describe("scenarios > collection pinned items overview", () => { describe("scenarios > collection pinned items overview", () => {
beforeEach(() => { beforeEach(() => {
restore(); restore();
cy.signInAsAdmin(); cy.signInAsAdmin();
cy.intercept("POST", `/api/card/*/query`).as("cardQuery"); cy.intercept("POST", `/api/card/*/query`).as("getCardQuery");
cy.intercept( cy.intercept("GET", "/api/collection/*/items?pinned_state=is_pinned*").as(
"GET", "getPinnedItems",
"/api/collection/root/items?pinned_state=is_pinned*", );
).as("pinnedItemsGET");
}); });
it("should let the user pin items", () => { it("should be able to pin a dashboard", () => {
// Turn question 1 into a model openRootCollection();
cy.request("PUT", "/api/card/1", { dataset: true }); openUnpinnedItemMenu(DASHBOARD_NAME);
popover().within(() => cy.findByText("Pin this").click());
cy.visit("/collection/root"); cy.wait("@getPinnedItems");
cy.wait("@pinnedItemsGET");
// pin a dashboard getPinnedSection().within(() => {
pinItem(DASHBOARD_ITEM_NAME); cy.icon("dashboard").should("be.visible");
cy.wait("@pinnedItemsGET"); cy.findByText("A dashboard").should("be.visible");
cy.findByText(DASHBOARD_NAME).click();
// ensure the dashboard card is showing in the pinned section
cy.findByTestId("pinned-items").within(() => {
cy.icon("dashboard");
cy.findByText("A dashboard");
// click on the card to navigate to the dashboard
cy.findByText(DASHBOARD_ITEM_NAME).click();
cy.url().should("include", "/dashboard/1"); cy.url().should("include", "/dashboard/1");
}); });
});
cy.visit("/collection/root"); it("should be able to pin a question", () => {
cy.wait("@pinnedItemsGET"); openRootCollection();
openUnpinnedItemMenu(QUESTION_NAME);
// pin a card popover().within(() => cy.findByText("Pin this").click());
pinItem(CARD_ITEM_NAME); cy.wait(["@getPinnedItems", "@getCardQuery"]);
cy.wait(["@pinnedItemsGET", "@cardQuery"]);
// ensure the card visualization is showing in the pinned section getPinnedSection().within(() => {
cy.findByTestId("pinned-items").within(() => { cy.findByText("18,760").should("be.visible");
cy.findByText("18,760"); cy.findByText(QUESTION_NAME).click();
cy.findByText(CARD_ITEM_NAME).click();
cy.url().should("include", "/question/2"); cy.url().should("include", "/question/2");
}); });
});
it("should be able to pin a model", () => {
cy.request("PUT", "/api/card/1", { dataset: true });
cy.visit("/collection/root"); openRootCollection();
cy.wait(["@pinnedItemsGET", "@cardQuery"]); openUnpinnedItemMenu(MODEL_NAME);
popover().within(() => cy.findByText("Pin this").click());
cy.wait("@getPinnedItems");
// pin a model getPinnedSection().within(() => {
pinItem(MODE_ITEM_NAME); cy.icon("model").should("be.visible");
cy.wait("@pinnedItemsGET"); cy.findByText(MODEL_NAME).should("be.visible");
// ensure the model card is showing in the pinned section
cy.findByTestId("pinned-items").within(() => {
cy.findByText(MODE_ITEM_NAME);
cy.icon("model");
cy.findByText("A model").click(); cy.findByText("A model").click();
cy.url().should("include", "/model/1"); cy.url().should("include", "/model/1");
}); });
}); });
describe("pinned item actions", () => { it("should be able to unpin a pinned dashboard", () => {
beforeEach(() => { cy.request("PUT", "/api/dashboard/1", { collection_position: 1 });
// pin a dashboard using the API
cy.request("PUT", "/api/dashboard/1", {
collection_position: 1,
});
cy.visit("/collection/root");
cy.wait("@pinnedItemsGET");
// open the action menu
cy.findByTestId("pinned-items").within(() => {
cy.icon("dashboard");
// the menu icon is hidden until the user hovers their mouse over the card
cy.icon("ellipsis").click({ force: true });
});
});
it("should be able to unpin a pinned item", () => { openRootCollection();
popover().within(() => { openPinnedItemMenu(DASHBOARD_NAME);
cy.findByText("Unpin").click(); popover().within(() => cy.findByText("Unpin").click());
}); cy.wait("@getPinnedItems");
// verify that the item is no longer in the pinned section getPinnedSection().should("not.exist");
cy.wait("@pinnedItemsGET"); });
cy.findByTestId("pinned-items").should("not.exist");
});
it("should be able to move a pinned item", () => { it("should be able to move a pinned dashboard", () => {
popover().within(() => { cy.request("PUT", "/api/dashboard/1", { collection_position: 1 });
cy.findByText("Move").click();
});
// verify that the move modal is showing openRootCollection();
cy.findByText(`Move "${DASHBOARD_ITEM_NAME}"?`); openPinnedItemMenu(DASHBOARD_NAME);
}); popover().within(() => cy.findByText("Move").click());
it("should be able to duplicate a pinned item", () => { cy.findByText(`Move "${DASHBOARD_NAME}"?`).should("be.visible");
popover().within(() => { });
cy.findByText("Duplicate").click();
});
// verify that the duplicate modal is showing it("should be able to duplicate a pinned dashboard", () => {
cy.findByText(`Duplicate "${DASHBOARD_ITEM_NAME}"`); cy.request("PUT", "/api/dashboard/1", { collection_position: 1 });
});
it("should be able to archive a pinned item", () => { openRootCollection();
popover().within(() => { openPinnedItemMenu(DASHBOARD_NAME);
cy.findByText("Archive").click(); popover().within(() => cy.findByText("Duplicate").click());
});
// verify that the item is no longer on the page cy.findByText(`Duplicate "${DASHBOARD_NAME}"`).should("be.visible");
cy.wait("@pinnedItemsGET"); });
cy.findByTestId("pinned-items").should("not.exist");
cy.findByText(DASHBOARD_ITEM_NAME).should("not.exist"); it("should be able to archive a pinned dashboard", () => {
}); cy.request("PUT", "/api/dashboard/1", { collection_position: 1 });
openRootCollection();
openPinnedItemMenu(DASHBOARD_NAME);
popover().within(() => cy.findByText("Archive").click());
cy.wait("@getPinnedItems");
getPinnedSection().should("not.exist");
cy.findByText(DASHBOARD_NAME).should("not.exist");
}); });
}); });
const pinItem = name => { const getPinnedSection = () => {
cy.findByText(name) return cy.findByTestId("pinned-items");
.closest("tr") };
.within(() => cy.icon("ellipsis").click());
const getUnpinnedSection = () => {
return cy.findByRole("table");
};
const openRootCollection = () => {
cy.visit("/collection/root");
cy.wait("@getPinnedItems");
};
popover().within(() => cy.icon("pin").click()); const openPinnedItemMenu = name => {
getPinnedSection().within(() => {
cy.findByText(name)
.closest("a")
.within(() => cy.icon("ellipsis").click({ force: true }));
});
};
const openUnpinnedItemMenu = name => {
getUnpinnedSection().within(() => {
cy.findByText(name)
.closest("tr")
.within(() => cy.icon("ellipsis").click());
});
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment