Skip to content

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

Fix flaky caching test in data studio metrics e2e (#75199)

Andrei Chernykh6864d60beaf7
diff --git a/e2e/support/helpers/e2e-data-studio-helpers.ts b/e2e/support/helpers/e2e-data-studio-helpers.ts
index 9b86b4208e5..e97bba44a00 100644
--- a/e2e/support/helpers/e2e-data-studio-helpers.ts
+++ b/e2e/support/helpers/e2e-data-studio-helpers.ts
@@ -147,14 +147,6 @@ export const DataStudio = {
noResults: () =>
libraryPage().findByText("No tables, metrics, or snippets yet"),
libraryPage,
- metricItem: (name: string) =>
- // The library page lists items as they come back from /api/ee/library;
- // on fetch (microtask resolution) the initial render can land before
- // a freshly-created metric is indexed into the library response. The
- // outer findAllByTestId retries with its default timeout, but it can
- // resolve while the named metric is still missing; give `contains`
- // its own longer timeout to keep retrying for that specific name.
- cy.findAllByTestId("metric-name").contains(name, { timeout: 10000 }),
allTableItems: () => libraryPage().findAllByTestId("table-name"),
tableItem: (name: string) =>
DataStudio.Library.allTableItems().contains(name),
diff --git a/e2e/support/helpers/e2e-metric-page-helpers.ts b/e2e/support/helpers/e2e-metric-page-helpers.ts
index e5a05f0f4da..4c8cc18527d 100644
--- a/e2e/support/helpers/e2e-metric-page-helpers.ts
+++ b/e2e/support/helpers/e2e-metric-page-helpers.ts
@@ -16,7 +16,6 @@ export const MetricPage = {
overviewTab: () => MetricPage.header().findByText("Overview"),
definitionTab: () => MetricPage.header().findByText("Definition"),
dependenciesTab: () => MetricPage.header().findByText("Dependencies"),
- cachingTab: () => MetricPage.header().findByText("Caching"),
historyTab: () => MetricPage.header().findByText("History"),
aboutPageDescriptionSidebar: () =>
metricAboutPage().findByTestId("metric-description-sidebar"),
diff --git a/e2e/support/test-library-data.ts b/e2e/support/test-library-data.ts
index 65e3bd276ce..453d486e504 100644
--- a/e2e/support/test-library-data.ts
+++ b/e2e/support/test-library-data.ts
@@ -37,6 +37,10 @@ export function createLibraryWithItems() {
cy.request("PUT", `/api/card/${card.id}`, {
collection_id: metricsCollection?.id,
});
+ // Expose ids so specs can navigate/verify directly instead of clicking
+ // through the lazily-rendered library tree, which is a flake source.
+ cy.wrap(card.id).as("trustedMetricId");
+ cy.wrap(metricsCollection?.id).as("metricsCollectionId");
});
});
}
diff --git a/e2e/test/scenarios/data-studio/data-studio-metrics.cy.spec.ts b/e2e/test/scenarios/data-studio/data-studio-metrics.cy.spec.ts
index 34761272c1a..50854ef479e 100644
--- a/e2e/test/scenarios/data-studio/data-studio-metrics.cy.spec.ts
+++ b/e2e/test/scenarios/data-studio/data-studio-metrics.cy.spec.ts
@@ -17,6 +17,13 @@ describe("scenarios > data studio > library > metrics", () => {
createLibraryWithItems();
});
+ // Navigate straight to the metric's page by id. Clicking it out of the
+ // library tree is flaky because rows lazy-load per subcollection.
+ const visitMetricPage = () =>
+ cy
+ .get<number>("@trustedMetricId")
+ .then((id) => cy.visit(`/data-studio/library/metrics/${id}`));
+
it("should create a new metric with proper validation and save to collection", () => {
H.DataStudio.Library.visit();
@@ -112,14 +119,8 @@ describe("scenarios > data studio > library > metrics", () => {
});
});
- it("should edit metric definition and save changes", function () {
- cy.log("Navigate to Data Studio Library");
- cy.visit("/data-studio/library");
-
- cy.log("Click on the metric from the collection view");
- H.DataStudio.Library.libraryPage()
- .findByText("Trusted Orders Metric")
- .click();
+ it("should edit metric definition and save changes", () => {
+ visitMetricPage();
cy.log("Verify metric overview page displays correct data");
H.DataStudio.Metrics.aboutPage()
@@ -139,21 +140,17 @@ describe("scenarios > data studio > library > metrics", () => {
.findByDisplayValue("Updated Orders Metric")
.should("be.visible");
- cy.log("Verify updated name appears in collection view");
- cy.visit("/data-studio/library");
- H.DataStudio.Library.metricItem("Updated Orders Metric").should(
- "be.visible",
+ cy.log("Verify the new name persisted");
+ cy.get<number>("@trustedMetricId").then((id) =>
+ cy
+ .request("GET", `/api/card/${id}`)
+ .its("body.name")
+ .should("eq", "Updated Orders Metric"),
);
});
it("should cancel editing and revert changes", () => {
- cy.log("Navigate to Data Studio Library");
- cy.visit("/data-studio/library");
-
- cy.log("Click on the metric from the collection view");
- H.DataStudio.Library.libraryPage()
- .findByText("Trusted Orders Metric")
- .click();
+ visitMetricPage();
cy.log("Navigate to definition tab");
H.DataStudio.Metrics.definitionTab().click();
@@ -172,13 +169,7 @@ describe("scenarios > data studio > library > metrics", () => {
});
it("should show unsaved changes warning when navigating away", () => {
- cy.log("Navigate to Data Studio Library");
- cy.visit("/data-studio/library");
-
- cy.log("Click on the metric from the collection view");
- H.DataStudio.Library.libraryPage()
- .findByText("Trusted Orders Metric")
- .click();
+ visitMetricPage();
cy.log("Navigate to definition tab");
H.DataStudio.Metrics.definitionTab().click();
@@ -203,13 +194,7 @@ describe("scenarios > data studio > library > metrics", () => {
});
it("should archive and restore a metric", () => {
- cy.log("Navigate to Data Studio Library");
- cy.visit("/data-studio/library");
-
- cy.log("Click on the metric from the collection view");
- H.DataStudio.Library.libraryPage()
- .findByText("Trusted Orders Metric")
- .click();
+ visitMetricPage();
cy.log("Verify metric is loaded before archiving");
H.DataStudio.Metrics.aboutPage()
@@ -225,14 +210,16 @@ describe("scenarios > data studio > library > metrics", () => {
cy.wait("@updateCard");
- cy.log("Verify redirected to library page");
+ cy.log("Verify redirected to the library");
cy.url().should("include", "/data-studio/library");
- cy.log("Verify metric is removed from collection view");
- cy.visit("/data-studio/library");
- H.DataStudio.Library.libraryPage()
- .findByText("Trusted Orders Metric")
- .should("not.exist");
+ cy.log("Verify the metric is archived");
+ cy.get<number>("@trustedMetricId").then((id) =>
+ cy
+ .request("GET", `/api/card/${id}`)
+ .its("body.archived")
+ .should("eq", true),
+ );
cy.log("Navigate to trash");
cy.visit("/trash");
@@ -248,21 +235,17 @@ describe("scenarios > data studio > library > metrics", () => {
cy.findByTestId("archive-banner").findByText("Restore").click();
cy.wait("@updateCard");
- cy.log("Verify metric is restored in collection view");
- cy.visit("/data-studio/library");
- H.DataStudio.Library.libraryPage()
- .findByText("Trusted Orders Metric")
- .should("be.visible");
+ cy.log("Verify the metric is restored");
+ cy.get<number>("@trustedMetricId").then((id) =>
+ cy
+ .request("GET", `/api/card/${id}`)
+ .its("body.archived")
+ .should("eq", false),
+ );
});
it("should view metric in the metrics explorer view via the Explore button", () => {
- cy.log("Navigate to Data Studio Library");
- cy.visit("/data-studio/library");
-
- cy.log("Click on the metric from the collection view");
- H.DataStudio.Library.libraryPage()
- .findByText("Trusted Orders Metric")
- .click();
+ visitMetricPage();
cy.log("Verify metric is loaded");
H.DataStudio.Metrics.aboutPage()
@@ -276,17 +259,7 @@ describe("scenarios > data studio > library > metrics", () => {
});
it("should duplicate metric via more menu", () => {
- cy.log("Navigate to Data Studio Library");
- cy.visit("/data-studio/library");
-
- cy.log("Click on the metric from the collection view");
- // The library page lists items as they come back from /api/ee/library;
- // on fetch (microtask resolution) the initial render can land before
- // the metric we created in `createLibraryWithItems` has been indexed
- // into the library response. Allow more time than the default 4s retry.
- H.DataStudio.Library.libraryPage()
- .findByText("Trusted Orders Metric", { timeout: 10000 })
- .click();
+ visitMetricPage();
cy.log("Verify metric is loaded");
H.DataStudio.Metrics.aboutPage()
@@ -323,22 +296,21 @@ describe("scenarios > data studio > library > metrics", () => {
.findAllByText("Trusted Orders Metric - Duplicate")
.should("have.length", 2); // breadcrumbs + header
- cy.log("Verify both metrics appear in collection view");
- H.DataStudio.nav().findByRole("link", { name: "Library" }).click();
- H.DataStudio.Library.libraryPage().within(() => {
- cy.findByText("Trusted Orders Metric").should("be.visible");
- cy.findByText("Trusted Orders Metric - Duplicate").should("be.visible");
- });
+ cy.log("Verify both metrics live in the Metrics collection");
+ cy.get<number>("@metricsCollectionId").then((collectionId) =>
+ cy
+ .request("GET", `/api/collection/${collectionId}/items`)
+ .its("body.data")
+ .then((items: { name: string }[]) => {
+ const names = items.map((item) => item.name);
+ expect(names).to.include("Trusted Orders Metric");
+ expect(names).to.include("Trusted Orders Metric - Duplicate");
+ }),
+ );
});
it("should move metric to different collection via more menu", () => {
- cy.log("Navigate to Data Studio Library");
- cy.visit("/data-studio/library");
-
- cy.log("Click on the metric from the collection view");
- H.DataStudio.Library.libraryPage()
- .findByText("Trusted Orders Metric")
- .click();
+ visitMetricPage();
cy.log("Verify metric is loaded");
H.DataStudio.Metrics.aboutPage()
@@ -357,11 +329,17 @@ describe("scenarios > data studio > library > metrics", () => {
cy.log("Verify metric is in First collection");
cy.findByTestId("move-card-toast").findByText("First collection").click();
- cy.log("Verify metric is no longer in Metrics collection");
- cy.visit("/data-studio/library");
- H.DataStudio.Library.libraryPage()
- .findByText("Trusted Orders Metric")
- .should("not.exist");
+ cy.log("Verify the metric left the Metrics collection");
+ cy.get<number>("@trustedMetricId").then((id) =>
+ cy
+ .get<number>("@metricsCollectionId")
+ .then((metricsCollectionId) =>
+ cy
+ .request("GET", `/api/card/${id}`)
+ .its("body.collection_id")
+ .should("not.eq", metricsCollectionId),
+ ),
+ );
});
describe("analytics events", () => {
@@ -418,30 +396,36 @@ describe("scenarios > data studio > library > metrics", () => {
describe("caching", () => {
it("should allow changing metric caching settings", () => {
- cy.log("Navigate to Data Studio Library");
- cy.visit("/data-studio/library");
+ cy.intercept("PUT", "/api/cache").as("updateCacheConfig");
- cy.log("Click on the metric from the collection view");
- H.DataStudio.Library.metricItem("Trusted Orders Metric").click();
+ visitMetricPage();
- cy.log("Navigate to caching tab");
- H.DataStudio.Metrics.cachingTab().click();
+ cy.log("Open the caching settings from the overflow menu");
+ H.DataStudio.Metrics.moreMenu().click();
+ H.popover().findByText("Caching").click();
- cy.log("Change the setting and save");
- cy.findByTestId("cache-strategy-select").should("have.value", "Default");
- cy.findByTestId("cache-strategy-select").click();
- cy.findByRole("option", { name: /Duration/ }).click();
- cy.findByRole("button", { name: "Save" }).click();
- cy.findByRole("button", { name: /Saved/ }).should("exist");
+ cy.log("Change the strategy to Duration and save");
+ H.modal()
+ .findByTestId("cache-strategy-select")
+ .should("have.value", "Default")
+ .click();
+ // The Select dropdown renders in a portal; wait for it to open, then pick.
+ H.selectDropdown()
+ .findByRole("option", { name: /Duration/ })
+ .click();
+ H.modal().findByTestId("strategy-form-submit-button").click();
+
+ cy.wait("@updateCacheConfig");
- // wait for the save button to disappear - that means the form is no longer dirty
- // and navigating away won't show the confirmation modal that was causing flakes
- cy.findByRole("button", { name: /Saved/ }).should("not.exist");
+ cy.log("Saving persists the change and closes the modal");
+ H.modal().should("not.exist");
- cy.log("Navigate away and come back to verify the change is persisted");
- H.DataStudio.Metrics.overviewTab().click();
- H.DataStudio.Metrics.cachingTab().click();
- cy.findByTestId("cache-strategy-select").should("have.value", "Duration");
+ cy.log("Re-open the caching settings to verify the change is persisted");
+ H.DataStudio.Metrics.moreMenu().click();
+ H.popover().findByText("Caching").click();
+ H.modal()
+ .findByTestId("cache-strategy-select")
+ .should("have.value", "Duration");
});
});
});