Skip to content

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

Consolidate explorations e2e tests (#83654)

Chris Vandoodewaard94ef260096aa
diff --git a/e2e/support/helpers/e2e-explorations-helpers.ts b/e2e/support/helpers/e2e-explorations-helpers.ts
index b00737202d9..245cfdad60a 100644
--- a/e2e/support/helpers/e2e-explorations-helpers.ts
+++ b/e2e/support/helpers/e2e-explorations-helpers.ts
@@ -52,25 +52,6 @@ export function selectAllMetricsTab(): void {
cy.findByRole("dialog").findByRole("tab", { name: "All" }).click();
}
-export interface AddMetricsToExplorationOptions {
- metrics: string[];
-}
-
-/**
- * Pick metrics through the "+ Metrics" picker.
- */
-export function addMetricsToExploration({
- metrics,
-}: AddMetricsToExplorationOptions): void {
- cy.findByRole("button", { name: /Metrics/ }).click();
- cy.wait("@getDimensions");
- selectAllMetricsTab();
- for (const name of metrics) {
- cy.findByRole("checkbox", { name }).check({ force: true });
- }
- cy.findByRole("button", { name: "Add" }).click();
-}
-
/**
* Pick the named timelines (one or many) through the "+ Events" modal.
*/
diff --git a/e2e/test/scenarios/explorations/explorations.cy.spec.ts b/e2e/test/scenarios/explorations/explorations.cy.spec.ts
index 081e1574a88..b3c62d284cc 100644
--- a/e2e/test/scenarios/explorations/explorations.cy.spec.ts
+++ b/e2e/test/scenarios/explorations/explorations.cy.spec.ts
@@ -89,371 +89,6 @@ function createTimelineWithSentinelEvent(
});
}
-describe("scenarios > explorations > new research > manual flow", () => {
- beforeEach(() => {
- cy.task("stopMockLlmServer");
- H.restore();
- cy.signInAsAdmin();
- H.enableExplorations();
- seedMetrics();
- H.resetSnowplow();
- H.enableTracking();
- });
-
- afterEach(() => {
- H.expectNoBadSnowplowEvents();
- });
-
- it("picks Our analytics + metrics + timelines, creates an exploration, and lands on the detail page", () => {
- createTimelineWithSentinelEvent("Releases", "star").then((releasesId) => {
- createTimelineWithSentinelEvent("Marketing campaigns", "bell").then(
- (marketingId) => {
- H.visitNewExploration();
-
- // Root is a FE-only id (`"root"`); the create POST must send
- // `collection_id: null` or the BE schema rejects it.
- cy.findByRole("button", { name: /Personal collection/i }).click();
- H.pickEntity({ path: ["Our analytics"], select: true });
- cy.findByRole("button", { name: /Our analytics/i }).should(
- "be.visible",
- );
-
- H.startManualExploration();
-
- // Manual setup is its own location, so browser back returns here
- // instead of leaving the research flow (UXW-4832).
- cy.location("pathname").should("eq", "/question/research/plan");
-
- H.addMetricsToExploration({
- metrics: [ORDERS_COUNT_METRIC_NAME],
- });
-
- cy.findByTestId("research-content")
- .should("be.visible")
- .and("contain", ORDERS_COUNT_METRIC_NAME);
-
- // Pick two timelines via the "+ Events" modal.
- H.addTimelinesToExploration(["Marketing campaigns", "Releases"]);
-
- // The first picked timeline shows as a pill next to the Events
- // button; the rest collapse into a "+N" overflow pill.
- cy.findByTestId("selected-timelines-container").within(() => {
- cy.findByText("Marketing campaigns").should("be.visible");
- cy.findByText("+1").should("be.visible");
- });
-
- H.beginResearch().then((id) => {
- // `beginResearch` consumed the create request; re-read it off its
- // alias to assert timeline ids + root collection were forwarded.
- cy.get("@createExploration")
- .its("request.body")
- .should((body) => {
- expect(body.timeline_ids).to.deep.eq([marketingId, releasesId]);
- expect(body.collection_id).to.eq(null);
- });
-
- H.expectUnstructuredSnowplowEvent({
- event: "exploration_plan_edited",
- triggered_from: "manual",
- event_detail: "metrics",
- });
- H.expectUnstructuredSnowplowEvent({
- event: "exploration_plan_edited",
- triggered_from: "manual",
- event_detail: "timelines",
- });
- H.expectUnstructuredSnowplowEvent({
- event: "exploration_created",
- target_id: id,
- });
-
- // `beginResearch` already asserted the detail-page URL.
- // No new-exploration CTA on the detail page.
- cy.findByRole("button", { name: /Start research/i }).should(
- "not.exist",
- );
- });
- },
- );
- });
- });
-
- it("filters Exploration data pickers by typing into their search inputs", () => {
- // Both timelines need an event so the picker surfaces them — the
- // empty-state case is still exercised by the "no match" search at
- // the bottom of this test.
- createTimelineWithSentinelEvent("Releases", "star");
- createTimelineWithSentinelEvent("Marketing campaigns", "bell");
-
- H.visitNewExploration();
- H.startManualExploration();
-
- // --- "+ Metrics" modal search ---
- cy.findByRole("button", { name: /Metrics/ }).click();
- // Seeded names are "Count of orders" + "Count of orders over time".
- cy.wait("@getDimensions");
- // Seeded metrics aren't in the library; switch off the default Library tab.
- H.selectAllMetricsTab();
- cy.findByRole("checkbox", { name: ORDERS_COUNT_METRIC_NAME }).should(
- "exist",
- );
- cy.findByRole("checkbox", { name: ORDERS_TIMESERIES_METRIC_NAME }).should(
- "exist",
- );
-
- // Type a substring that only matches the timeseries metric.
- cy.findByPlaceholderText("Search for a metric").type("over time");
- cy.wait("@getDimensions");
- cy.findByRole("checkbox", { name: ORDERS_TIMESERIES_METRIC_NAME }).should(
- "exist",
- );
- cy.findByRole("checkbox", { name: ORDERS_COUNT_METRIC_NAME }).should(
- "not.exist",
- );
-
- // Clear the input → both rows return.
- cy.findByPlaceholderText("Search for a metric").clear();
- cy.findByRole("checkbox", { name: ORDERS_COUNT_METRIC_NAME }).should(
- "exist",
- );
- cy.findByRole("checkbox", { name: ORDERS_TIMESERIES_METRIC_NAME }).should(
- "exist",
- );
-
- // Search for something that matches no metric → empty-state copy.
- cy.findByPlaceholderText("Search for a metric").type("zzz");
- cy.wait("@getDimensions");
- cy.findByRole("dialog").should("contain", "No results");
-
- // Close the metrics modal before opening the events one.
- cy.get("body").type("{esc}");
-
- // --- "+ Events" modal search ---
- cy.findByRole("button", { name: /Events/ }).click();
- cy.findByRole("checkbox", { name: "Releases" }).should("exist");
- cy.findByRole("checkbox", { name: "Marketing campaigns" }).should("exist");
-
- // Filter to just one timeline by name fragment.
- cy.findByPlaceholderText("Search for a timeline").type("release");
- cy.findByRole("checkbox", { name: "Releases" }).should("exist");
- cy.findByRole("checkbox", { name: "Marketing campaigns" }).should(
- "not.exist",
- );
-
- // Clear → both return.
- cy.findByPlaceholderText("Search for a timeline").clear();
- cy.findByRole("checkbox", { name: "Releases" }).should("exist");
- cy.findByRole("checkbox", { name: "Marketing campaigns" }).should("exist");
- });
-});
-
-describe("scenarios > explorations > new research > metabot flow", () => {
- beforeEach(() => {
- cy.task("stopMockLlmServer");
- H.restore();
- cy.signInAsAdmin();
- H.enableExplorations();
- seedMetrics();
- H.resetSnowplow();
- H.enableTracking();
- });
-
- afterEach(() => {
- H.expectNoBadSnowplowEvents();
- });
-
- it("auto-populates metrics + dimensions + name from agent tool calls, then Start research succeeds", () => {
- cy.request("GET", "/api/exploration/dimensions").then(({ body }) => {
- // Unjustified type cast. FIXME
- const data = body as {
- metrics: Array<{ id: number; name: string; dimension_ids: string[] }>;
- dimension_groups: Array<{
- name: string;
- dimension_interestingness: number | null;
- dimensions: Array<{
- id: string;
- name: string;
- display_name: string;
- dimension_interestingness: number | null;
- }>;
- }>;
- };
-
- const firstMetric = data.metrics[0];
- const interestingGroup =
- data.dimension_groups.find((g) =>
- g.dimensions.some((d) => (d.dimension_interestingness ?? 0) >= 0.7),
- ) ?? data.dimension_groups[0];
- expect(
- firstMetric,
- "seeded metric is exposed by /api/exploration/dimensions",
- ).to.exist;
- expect(interestingGroup, "at least one dimension group is exposed").to
- .exist;
-
- const agentName = "New exploration";
- H.mockExplorationsAgentToolCalls([
- {
- toolCallId: "groups-1",
- toolName: "add_research_groups",
- // The tool result is only the LLM's summary of the edit; the picker
- // hydration rides a `research_plan_update` data part.
- result: `Added 1 group(s) to the research plan:\n- ${firstMetric.name}, by the automatically-selected dimensions`,
- dataParts: [
- {
- dataType: "research_plan_update",
- data: {
- metrics: [firstMetric],
- dimension_groups: [interestingGroup],
- groups: [{ metric_id: firstMetric.id }],
- },
- },
- ],
- },
- {
- toolCallId: "name-1",
- toolName: "set_research_name",
- result: { name: agentName },
- },
- ]);
-
- H.visitNewExploration();
-
- H.explorationsMetabotPromptInput().type("Why are signups down?");
- cy.findByRole("button", { name: /Create plan/i }).click();
-
- // The chat dispatch went through with the `explorations`
- // profile, confirming we wired the new-exploration page to
- // the right agent.
- cy.wait("@metabotAgent")
- .its("request.body.profile_id")
- .should("eq", "explorations");
-
- // Right panel hydrated from the tool-call result — the agent's
- // metric now heads a research-plan block.
- cy.findByRole("main").findByText(firstMetric.name).should("be.visible");
-
- // Click Start research; the create-exploration POST body
- // should carry the name the agent picked.
- cy.intercept("POST", "/api/exploration").as("createExploration");
- cy.findByRole("button", { name: /Start research/i }).click();
- cy.wait("@createExploration").then(({ request, response }) => {
- expect(request.body.name).to.eq(agentName);
- // Unjustified type cast. FIXME
- const id = response?.body?.id as number;
- H.expectUnstructuredSnowplowEvent({
- event: "exploration_agent_message_sent",
- });
- H.expectUnstructuredSnowplowEvent({
- event: "exploration_plan_edited",
- triggered_from: "agent",
- event_detail: "metrics",
- });
- H.expectUnstructuredSnowplowEvent({
- event: "exploration_created",
- target_id: id,
- });
- });
- });
- });
-});
-
-describe("scenarios > explorations > detail page", () => {
- beforeEach(() => {
- cy.task("stopMockLlmServer");
- H.restore();
- cy.signInAsAdmin();
- H.enableExplorations();
- seedMetrics();
- H.resetSnowplow();
- H.enableTracking();
- });
-
- afterEach(() => {
- H.expectNoBadSnowplowEvents();
- });
-
- it("changes sidebar selection on click and shows the corresponding visualization area", () => {
- H.createExplorationViaApi({ name: "Click selection fixture" }).then(
- (id) => {
- visitExplorationUntilSettled(id, 2);
-
- // The page auto-selects a row on load, so clicking the first (already
- // selected) row would pass even with click-to-select broken. Click a
- // row that is NOT selected and assert the selection moves to it.
- cy.findAllByRole("treeitem")
- .filter('[aria-selected="false"]')
- .eq(1) // first treeitem is the summary document
- .invoke("attr", "href")
- .then((href) => {
- cy.get(`[role="treeitem"][href="${href}"]`).click();
- cy.get(`[role="treeitem"][href="${href}"]`).should(
- "have.attr",
- "aria-selected",
- "true",
- );
- });
-
- // The clicked page's chart renders in the main area — assert a real
- // visualization anchor, not just "main is not empty" (a spinner
- // satisfies that).
- cy.location("pathname").should("match", /\/page\/\d+$/);
- cy.findByRole("main")
- .findByTestId("visualization-root", { timeout: 15000 })
- .should("be.visible");
- },
- );
- });
-
- it("preserves the URL `timeline` param across navigation and reload", () => {
- createTimelineWithSentinelEvent("Releases", "star").then((timelineId) => {
- cy.request("GET", "/api/exploration/dimensions").then(({ body }) => {
- // Unjustified type cast. FIXME
- const data = body as GetExplorationDataResponse;
- const temporalDimension = data.dimension_groups
- .flatMap((group) => group.dimensions)
- .find((dim) => dim.effective_type.includes("Date"));
- expect(temporalDimension, "sample DB exposes a temporal dimension").to
- .exist;
-
- H.createExplorationViaApi({
- name: "Timeline persistence fixture",
- timelineIds: [timelineId],
- dimensionIds: [temporalDimension!.id],
- }).then((id) => {
- cy.visit(`/question/research/${id}?timeline=${timelineId}`);
- // Sidebar treeitems appear once the BE returns query rows.
- cy.findAllByRole("treeitem", { timeout: 15000 })
- .first()
- .should("be.visible");
-
- cy.findByRole("treeitem", {
- name: new RegExp(`${temporalDimension!.display_name}$`), // anchor at end so we don't match day of week or hour of day
- }).click();
-
- cy.findByTestId("exploration-chart-grid").within(() => {
- H.timelineEventChip("Releases event").should("be.visible");
- });
-
- cy.location("search").should("include", `timeline=${timelineId}`);
-
- // Reload — the URL param is the source of truth and the
- // router shouldn't rewrite it away on hydration.
- cy.reload();
- cy.findAllByRole("treeitem", { timeout: 15000 })
- .first()
- .should("be.visible");
- cy.location("search").should("include", `timeline=${timelineId}`);
-
- cy.findByTestId("exploration-chart-grid").within(() => {
- H.timelineEventChip("Releases event").should("be.visible");
- });
- });
- });
- });
- });
-});
-
/**
* Resolve the "Count of orders" metric plus its first two dimensions and
* create an exploration with them — yielding one metric-group heading with
@@ -550,18 +185,7 @@ function openExploreFurtherToast(threadName: string): void {
cy.findByRole("button", { name: "View" }).click();
});
}
-
-describe("scenarios > explorations > sidebar triage", () => {
- const sidebar = () => cy.findByTestId("exploration-page-sidebar");
- const filterToggle = () => cy.findByTestId("exploration-show-hidden-toggle");
- const selectedRows = () =>
- cy.findAllByRole("treeitem").filter('[aria-selected="true"]');
- const toggleShowHiddenItems = () => {
- filterToggle().click();
- H.menu().findByText("Show hidden items").click();
- cy.get("body").type("{esc}");
- };
-
+describe("scenarios > explorations", () => {
beforeEach(() => {
cy.task("stopMockLlmServer");
H.restore();
@@ -576,256 +200,739 @@ describe("scenarios > explorations > sidebar triage", () => {
H.expectNoBadSnowplowEvents();
});
- it("filters pages with the Stars and Discussions tabs and persists the sort preference across reloads", () => {
- createTwoPageExploration("Sidebar tabs fixture").then(
- ({ explorationId, pageNames }) => {
- visitExplorationUntilSettled(explorationId, 2);
-
- cy.log("Stars tab is empty until something is starred");
- cy.findByRole("radio", { name: "Stars" }).click({ force: true });
- cy.location("search").should("include", "tab=stars");
- H.main().findByText("Nothing's been starred yet.").should("be.visible");
- cy.findAllByRole("treeitem").should("not.exist");
-
- cy.log("Discussions tab shows its own empty message");
- cy.findByRole("radio", { name: "Discussions" }).click({ force: true });
- H.main().findByText("No discussions yet.").should("be.visible");
- cy.findAllByRole("treeitem").should("not.exist");
-
- cy.log("Star the selected page with the s shortcut");
- cy.findByRole("radio", { name: "All" }).click({ force: true });
- cy.findAllByRole("treeitem").should("have.length", 3); // summary document + 2 pages
- sidebar().findByText(pageNames[0]).click();
- selectedRows().should("contain.text", pageNames[0]);
- cy.intercept("PUT", "/api/exploration/page/*/starred").as("setStarred");
- cy.get("body").type("s");
- cy.wait("@setStarred").its("request.body.starred").should("eq", true);
- H.main()
- .findByRole("button", { name: "Remove star" })
- .should("be.visible");
-
- cy.log("The c shortcut opens the comment editor");
- cy.get("body").type("c");
- // The editor's placeholder is CSS-rendered by TipTap (not real text),
- // so anchor on the editor's Send button instead. The popover is
- // portaled outside <main>.
- H.popover().findByRole("button", { name: "Send" }).should("be.visible");
- H.main().findByRole("button", { name: "Add comment" }).click();
- cy.findByRole("button", { name: "Send" }).should("not.exist");
-
- cy.log("The l shortcut copies a link to the selected page");
- // Headless Chrome denies real clipboard access here (NotAllowedError),
- // so stub the write and assert the call instead of reading it back.
- cy.window().then((win) => {
- cy.stub(win.navigator.clipboard, "writeText")
- .as("copyToClipboard")
- .resolves();
+ describe("new research", () => {
+ it("picks Our analytics + metrics + timelines, filters the data pickers by search, creates an exploration, and lands on the detail page", () => {
+ createTimelineWithSentinelEvent("Releases", "star").then((releasesId) => {
+ createTimelineWithSentinelEvent("Marketing campaigns", "bell").then(
+ (marketingId) => {
+ H.visitNewExploration();
+
+ // Root is a FE-only id (`"root"`); the create POST must send
+ // `collection_id: null` or the BE schema rejects it.
+ cy.findByRole("button", { name: /Personal collection/i }).click();
+ H.pickEntity({ path: ["Our analytics"], select: true });
+ cy.findByRole("button", { name: /Our analytics/i }).should(
+ "be.visible",
+ );
+
+ H.startManualExploration();
+
+ // Manual setup is its own location, so browser back returns here
+ // instead of leaving the research flow (UXW-4832).
+ cy.location("pathname").should("eq", "/question/research/plan");
+
+ cy.log("Search inside the + Metrics modal");
+ cy.intercept({
+ method: "GET",
+ pathname: "/api/exploration/dimensions",
+ query: { q: "over time" },
+ }).as("searchOverTime");
+ cy.intercept({
+ method: "GET",
+ pathname: "/api/exploration/dimensions",
+ query: { q: "zzz" },
+ }).as("searchNoMatch");
+ cy.findByRole("button", { name: /Metrics/ }).click();
+ // Seeded names are "Count of orders" + "Count of orders over time".
+ // Seeded metrics aren't in the library; switch off the default Library tab.
+ H.selectAllMetricsTab();
+ cy.findByRole("checkbox", {
+ name: ORDERS_COUNT_METRIC_NAME,
+ }).should("exist");
+ cy.findByRole("checkbox", {
+ name: ORDERS_TIMESERIES_METRIC_NAME,
+ }).should("exist");
+
+ // Type a substring that only matches the timeseries metric.
+ cy.findByPlaceholderText("Search for a metric").type("over time");
+ cy.wait("@searchOverTime");
+ cy.findByRole("checkbox", {
+ name: ORDERS_TIMESERIES_METRIC_NAME,
+ }).should("exist");
+ cy.findByRole("checkbox", {
+ name: ORDERS_COUNT_METRIC_NAME,
+ }).should("not.exist");
+
+ // Clear the input → both rows return.
+ cy.findByPlaceholderText("Search for a metric").clear();
+ cy.findByRole("checkbox", {
+ name: ORDERS_COUNT_METRIC_NAME,
+ }).should("exist");
+ cy.findByRole("checkbox", {
+ name: ORDERS_TIMESERIES_METRIC_NAME,
+ }).should("exist");
+
+ // Search for something that matches no metric → empty-state copy.
+ cy.findByPlaceholderText("Search for a metric").type("zzz");
+ cy.wait("@searchNoMatch");
+ cy.findByRole("dialog").should("contain", "No results");
+
+ cy.findByPlaceholderText("Search for a metric").clear();
+ cy.findByRole("checkbox", {
+ name: ORDERS_COUNT_METRIC_NAME,
+ }).should("exist");
+ cy.get("body").type("{esc}");
+
+ cy.log("Search inside the + Events modal");
+ cy.findByRole("button", { name: /Events/ }).click();
+ cy.findByRole("checkbox", { name: "Releases" }).should("exist");
+ cy.findByRole("checkbox", { name: "Marketing campaigns" }).should(
+ "exist",
+ );
+
+ // Filter to just one timeline by name fragment.
+ cy.findByPlaceholderText("Search for a timeline").type("release");
+ cy.findByRole("checkbox", { name: "Releases" }).should("exist");
+ cy.findByRole("checkbox", { name: "Marketing campaigns" }).should(
+ "not.exist",
+ );
+
+ // Clear → both return.
+ cy.findByPlaceholderText("Search for a timeline").clear();
+ cy.findByRole("checkbox", { name: "Releases" }).should("exist");
+ cy.findByRole("checkbox", { name: "Marketing campaigns" }).should(
+ "exist",
+ );
+ cy.get("body").type("{esc}");
+
+ cy.log("Add a metric");
+ cy.findByRole("button", { name: /Metrics/ }).click();
+ H.selectAllMetricsTab();
+ cy.findByRole("checkbox", { name: ORDERS_COUNT_METRIC_NAME }).check(
+ {
+ force: true,
+ },
+ );
+ cy.findByRole("button", { name: "Add" }).click();
+
+ cy.findByTestId("research-content")
+ .should("be.visible")
+ .and("contain", ORDERS_COUNT_METRIC_NAME);
+
+ // Pick two timelines via the "+ Events" modal.
+ H.addTimelinesToExploration(["Marketing campaigns", "Releases"]);
+
+ // The first picked timeline shows as a pill next to the Events
+ // button; the rest collapse into a "+N" overflow pill.
+ cy.findByTestId("selected-timelines-container").within(() => {
+ cy.findByText("Marketing campaigns").should("be.visible");
+ cy.findByText("+1").should("be.visible");
+ });
+
+ H.beginResearch().then((id) => {
+ // `beginResearch` consumed the create request; re-read it off its
+ // alias to assert timeline ids + root collection were forwarded.
+ cy.get("@createExploration")
+ .its("request.body")
+ .should((body) => {
+ expect(body.timeline_ids).to.deep.eq([
+ marketingId,
+ releasesId,
+ ]);
+ expect(body.collection_id).to.eq(null);
+ });
+
+ H.expectUnstructuredSnowplowEvent({
+ event: "exploration_plan_edited",
+ triggered_from: "manual",
+ event_detail: "metrics",
+ });
+ H.expectUnstructuredSnowplowEvent({
+ event: "exploration_plan_edited",
+ triggered_from: "manual",
+ event_detail: "timelines",
+ });
+ H.expectUnstructuredSnowplowEvent({
+ event: "exploration_created",
+ target_id: id,
+ });
+
+ // `beginResearch` already asserted the detail-page URL.
+ // No new-exploration CTA on the detail page.
+ cy.findAllByRole("treeitem", { timeout: 15000 })
+ .first()
+ .should("be.visible");
+ cy.findByRole("button", { name: /Start research/i }).should(
+ "not.exist",
+ );
+ });
+ },
+ );
+ });
+ });
+
+ it("auto-populates metrics + dimensions + name from agent tool calls, then Start research succeeds", () => {
+ cy.request("GET", "/api/exploration/dimensions").then(({ body }) => {
+ // Unjustified type cast. FIXME
+ const data = body as {
+ metrics: Array<{ id: number; name: string; dimension_ids: string[] }>;
+ dimension_groups: Array<{
+ name: string;
+ dimension_interestingness: number | null;
+ dimensions: Array<{
+ id: string;
+ name: string;
+ display_name: string;
+ dimension_interestingness: number | null;
+ }>;
+ }>;
+ };
+
+ const firstMetric = data.metrics[0];
+ const interestingGroup =
+ data.dimension_groups.find((g) =>
+ g.dimensions.some((d) => (d.dimension_interestingness ?? 0) >= 0.7),
+ ) ?? data.dimension_groups[0];
+ expect(
+ firstMetric,
+ "seeded metric is exposed by /api/exploration/dimensions",
+ ).to.exist;
+ expect(interestingGroup, "at least one dimension group is exposed").to
+ .exist;
+
+ const agentName = "New exploration";
+ H.mockExplorationsAgentToolCalls([
+ {
+ toolCallId: "groups-1",
+ toolName: "add_research_groups",
+ // The tool result is only the LLM's summary of the edit; the picker
+ // hydration rides a `research_plan_update` data part.
+ result: `Added 1 group(s) to the research plan:\n- ${firstMetric.name}, by the automatically-selected dimensions`,
+ dataParts: [
+ {
+ dataType: "research_plan_update",
+ data: {
+ metrics: [firstMetric],
+ dimension_groups: [interestingGroup],
+ groups: [{ metric_id: firstMetric.id }],
+ },
+ },
+ ],
+ },
+ {
+ toolCallId: "name-1",
+ toolName: "set_research_name",
+ result: { name: agentName },
+ },
+ ]);
+
+ H.visitNewExploration();
+
+ H.explorationsMetabotPromptInput().type("Why are signups down?");
+ cy.findByRole("button", { name: /Create plan/i }).click();
+
+ // The chat dispatch went through with the `explorations`
+ // profile, confirming we wired the new-exploration page to
+ // the right agent.
+ cy.wait("@metabotAgent")
+ .its("request.body.profile_id")
+ .should("eq", "explorations");
+
+ // Right panel hydrated from the tool-call result — the agent's
+ // metric now heads a research-plan block.
+ cy.findByRole("main").findByText(firstMetric.name).should("be.visible");
+
+ // Click Start research; the create-exploration POST body
+ // should carry the name the agent picked.
+ cy.intercept("POST", "/api/exploration").as("createExploration");
+ cy.findByRole("button", { name: /Start research/i }).click();
+ cy.wait("@createExploration").then(({ request, response }) => {
+ expect(request.body.name).to.eq(agentName);
+ // Unjustified type cast. FIXME
+ const id = response?.body?.id as number;
+ H.expectUnstructuredSnowplowEvent({
+ event: "exploration_agent_message_sent",
+ });
+ H.expectUnstructuredSnowplowEvent({
+ event: "exploration_plan_edited",
+ triggered_from: "agent",
+ event_detail: "metrics",
+ });
+ H.expectUnstructuredSnowplowEvent({
+ event: "exploration_created",
+ target_id: id,
+ });
});
- cy.get("body").type("l");
- H.undoToastListContainer()
- .findByText("Copied link")
- .should("be.visible");
- cy.location("href").then((href) => {
- cy.get("@copyToClipboard").should("have.been.calledWith", href);
+ });
+ });
+ });
+
+ describe("detail page", () => {
+ it("preserves the URL `timeline` param across navigation and reload", () => {
+ createTimelineWithSentinelEvent("Releases", "star").then((timelineId) => {
+ cy.request("GET", "/api/exploration/dimensions").then(({ body }) => {
+ // Unjustified type cast. FIXME
+ const data = body as GetExplorationDataResponse;
+ const temporalDimension = data.dimension_groups
+ .flatMap((group) => group.dimensions)
+ .find((dim) => dim.effective_type.includes("Date"));
+ expect(temporalDimension, "sample DB exposes a temporal dimension").to
+ .exist;
+
+ H.createExplorationViaApi({
+ name: "Timeline persistence fixture",
+ timelineIds: [timelineId],
+ dimensionIds: [temporalDimension!.id],
+ }).then((id) => {
+ cy.visit(`/question/research/${id}?timeline=${timelineId}`);
+ // Sidebar treeitems appear once the BE returns query rows.
+ cy.findAllByRole("treeitem", { timeout: 15000 })
+ .first()
+ .should("be.visible");
+
+ cy.findByRole("treeitem", {
+ name: new RegExp(`${temporalDimension!.display_name}$`), // anchor at end so we don't match day of week or hour of day
+ }).click();
+
+ cy.findByTestId("exploration-chart-grid").within(() => {
+ H.timelineEventChip("Releases event").should("be.visible");
+ });
+
+ cy.location("search").should("include", `timeline=${timelineId}`);
+
+ // Reload — the URL param is the source of truth and the
+ // router shouldn't rewrite it away on hydration.
+ cy.reload();
+ cy.findAllByRole("treeitem", { timeout: 15000 })
+ .first()
+ .should("be.visible");
+ cy.location("search").should("include", `timeline=${timelineId}`);
+
+ cy.findByTestId("exploration-chart-grid").within(() => {
+ H.timelineEventChip("Releases event").should("be.visible");
+ });
+ });
});
+ });
+ });
+ });
- cy.log("Stars tab now shows only the starred page");
- cy.findByRole("radio", { name: "Stars" }).click({ force: true });
- cy.findAllByRole("treeitem")
- .should("have.length", 1)
- .first()
- .should("contain.text", pageNames[0]);
-
- cy.log("Alphabetical sort is remembered per exploration");
- cy.findByRole("radio", { name: "All" }).click({ force: true });
- // Assert and click through separate queries — chaining `.click()` off
- // the assertion can act on a node a poll-driven re-render detached.
- filterToggle().should("have.attr", "aria-pressed", "false");
- filterToggle().click();
- H.menu().findByText("Alphabetical").click();
- H.menu()
- .findByRole("menuitem", { name: /Alphabetical/ })
- .should("have.attr", "data-checked", "true");
- cy.get("body").type("{esc}");
- cy.log("Sorting is not a filter, so the toggle stays unfilled");
- filterToggle().should("have.attr", "aria-pressed", "false");
-
- cy.reload();
- cy.findAllByRole("treeitem", { timeout: 15000 })
- .first()
- .should("be.visible");
- filterToggle().should("have.attr", "aria-pressed", "false");
- filterToggle().click();
- H.menu()
- .findByRole("menuitem", { name: /Alphabetical/ })
- .should("have.attr", "data-checked", "true");
- },
- );
+ describe("sidebar triage", () => {
+ const sidebar = () => cy.findByTestId("exploration-page-sidebar");
+ const filterToggle = () =>
+ cy.findByTestId("exploration-show-hidden-toggle");
+ const selectedRows = () =>
+ cy.findAllByRole("treeitem").filter('[aria-selected="true"]');
+ const toggleShowHiddenItems = () => {
+ filterToggle().click();
+ H.menu().findByText("Show hidden items").click();
+ cy.get("body").type("{esc}");
+ };
+
+ it("selects a page on click, filters pages with the Stars and Discussions tabs, persists the sort preference across reloads, and hides and reveals pages from the toolbar and group menus", () => {
+ createTwoPageExploration("Sidebar triage fixture").then(
+ ({ explorationId, metricName, pageNames }) => {
+ visitExplorationUntilSettled(explorationId, 2);
+
+ cy.log("Clicking an unselected page selects it and shows its chart");
+ // The page auto-selects a row on load, so clicking the first (already
+ // selected) row would pass even with click-to-select broken. Click a
+ // row that is NOT selected and assert the selection moves to it.
+ cy.findAllByRole("treeitem").should("have.length", 3); // summary document + 2 pages
+ cy.findAllByRole("treeitem")
+ .filter('[aria-selected="false"]')
+ .eq(1) // first treeitem is the summary document
+ .invoke("attr", "href")
+ .then((href) => {
+ cy.get(`[role="treeitem"][href="${href}"]`).click();
+ cy.get(`[role="treeitem"][href="${href}"]`)
+ .should("have.attr", "aria-selected", "true")
+ .invoke("text")
+ .then((text) => text.trim())
+ .as("clickedPageName");
+ });
+
+ // The clicked page's chart renders in the main area — assert a real
+ // visualization anchor, not just "main is not empty" (a spinner
+ // satisfies that).
+ cy.location("pathname").should("match", /\/page\/\d+$/);
+ cy.findByRole("main")
+ .findByTestId("visualization-root", { timeout: 15000 })
+ .should("be.visible");
+
+ cy.log("Stars tab is empty until something is starred");
+ cy.findByRole("radio", { name: "Stars" }).click({ force: true });
+ cy.location("search").should("include", "tab=stars");
+ H.main()
+ .findByText("Nothing's been starred yet.")
+ .should("be.visible");
+ cy.findAllByRole("treeitem").should("not.exist");
+
+ cy.log("Discussions tab shows its own empty message");
+ cy.findByRole("radio", { name: "Discussions" }).click({
+ force: true,
+ });
+ H.main().findByText("No discussions yet.").should("be.visible");
+ cy.findAllByRole("treeitem").should("not.exist");
+
+ cy.log("Star the selected page with the s shortcut");
+ cy.findByRole("radio", { name: "All" }).click({ force: true });
+ cy.findAllByRole("treeitem").should("have.length", 3); // summary document + 2 pages
+ cy.get<string>("@clickedPageName").then((name) => {
+ sidebar().findByText(name).click();
+ selectedRows().should("contain.text", name);
+ });
+ cy.intercept("PUT", "/api/exploration/page/*/starred").as(
+ "setStarred",
+ );
+ cy.get("body").type("s");
+ cy.wait("@setStarred").its("request.body.starred").should("eq", true);
+ H.main()
+ .findByRole("button", { name: "Remove star" })
+ .should("be.visible");
+
+ cy.log("The c shortcut opens the comment editor");
+ cy.get("body").type("c");
+ // The editor's placeholder is CSS-rendered by TipTap (not real text),
+ // so anchor on the editor's Send button instead. The popover is
+ // portaled outside <main>.
+ H.popover()
+ .findByRole("button", { name: "Send" })
+ .should("be.visible");
+ H.main().findByRole("button", { name: "Add comment" }).click();
+ cy.findByRole("button", { name: "Send" }).should("not.exist");
+
+ cy.log("The l shortcut copies a link to the selected page");
+ // Headless Chrome denies real clipboard access here (NotAllowedError),
+ // so stub the write and assert the call instead of reading it back.
+ cy.window().then((win) => {
+ cy.stub(win.navigator.clipboard, "writeText")
+ .as("copyToClipboard")
+ .resolves();
+ });
+ cy.get("body").type("l");
+ H.undoToastListContainer()
+ .findByText("Copied link")
+ .should("be.visible");
+ cy.location("href").then((href) => {
+ cy.get("@copyToClipboard").should("have.been.calledWith", href);
+ });
+
+ cy.log("Stars tab now shows only the starred page");
+ cy.findByRole("radio", { name: "Stars" }).click({ force: true });
+ cy.get<string>("@clickedPageName").then((name) => {
+ cy.findAllByRole("treeitem")
+ .should("have.length", 1)
+ .first()
+ .should("contain.text", name);
+ });
+
+ cy.log("Alphabetical sort is remembered per exploration");
+ cy.findByRole("radio", { name: "All" }).click({ force: true });
+ // Assert and click through separate queries — chaining `.click()` off
+ // the assertion can act on a node a poll-driven re-render detached.
+ filterToggle().should("have.attr", "aria-pressed", "false");
+ filterToggle().click();
+ H.menu().findByText("Alphabetical").click();
+ H.menu()
+ .findByRole("menuitem", { name: /Alphabetical/ })
+ .should("have.attr", "data-checked", "true");
+ cy.get("body").type("{esc}");
+ cy.log("Sorting is not a filter, so the toggle stays unfilled");
+ filterToggle().should("have.attr", "aria-pressed", "false");
+
+ cy.reload();
+ cy.findAllByRole("treeitem", { timeout: 15000 })
+ .first()
+ .should("be.visible");
+ filterToggle().should("have.attr", "aria-pressed", "false");
+ filterToggle().click();
+ H.menu()
+ .findByRole("menuitem", { name: /Alphabetical/ })
+ .should("have.attr", "data-checked", "true");
+ cy.get("body").type("{esc}");
+
+ cy.intercept("PUT", "/api/exploration/pages/hidden").as(
+ "setPagesHidden",
+ );
+ // Which of the two dimension-named pages is selected is
+ // data-dependent; derive it from the DOM instead of assuming.
+ cy.findAllByRole("treeitem").should("have.length", 3); // summary document + 2 pages
+ selectedRows().should("have.length", 1);
+ selectedRows()
+ .first()
+ .invoke("text")
+ .then((text) => {
+ const firstPageName = text.trim();
+ const secondPageName = pageNames.find(
+ (name) => name !== firstPageName,
+ )!;
+
+ cy.log("Triage arrows step between pages");
+ cy.findByRole("button", { name: "Next" }).click();
+ selectedRows().should("contain.text", secondPageName);
+ cy.findByRole("button", { name: "Previous" }).click();
+ selectedRows().should("contain.text", firstPageName);
+
+ cy.log("Hide the selected page with the h shortcut");
+ cy.get("body").type("h");
+ cy.wait("@setPagesHidden").then(({ request }) => {
+ expect(request.body.hidden).to.eq(true);
+ expect(request.body.page_ids).to.have.length(1);
+ });
+ H.undoToastListContainer()
+ .findByText(`"${firstPageName}" hidden`)
+ .should("be.visible");
+
+ cy.log("Auto-advance moves the selection to the remaining page");
+ selectedRows().should("contain.text", secondPageName);
+ cy.findAllByRole("treeitem").should("have.length", 2); // summary document + 1 non-hidden page
+ sidebar().findByText(firstPageName).should("not.exist");
+
+ cy.log("Show hidden items reveals the page with a Hidden marker");
+ toggleShowHiddenItems();
+ filterToggle().should("have.attr", "aria-pressed", "true");
+ sidebar().findByText(firstPageName).should("be.visible");
+ sidebar().findAllByLabelText("Hidden").should("have.length", 1);
+ toggleShowHiddenItems();
+ cy.findAllByRole("treeitem").should("have.length", 2);
+ sidebar().findByText(firstPageName).should("not.exist");
+ });
+
+ cy.log("Hide the whole group from its actions menu");
+ sidebar()
+ .findByRole("group", { name: metricName })
+ .findByRole("button", { name: "Group actions" })
+ .click({ force: true });
+ H.menu().findByText("Hide").click();
+ cy.wait("@setPagesHidden")
+ .its("request.body.hidden")
+ .should("eq", true);
+ H.undoToastListContainer()
+ .findByText(`${metricName} hidden`)
+ .should("be.visible");
+
+ cy.log("Everything but the summary document is hidden");
+ cy.findAllByRole("treeitem").should("have.length", 1);
+
+ cy.log("Hidden state is persisted server-side across a reload");
+ cy.reload();
+ cy.findAllByRole("treeitem").should("have.length", 1);
+
+ cy.log("Show hidden items + the group Show action restore the pages");
+ toggleShowHiddenItems();
+ cy.findAllByRole("treeitem").should("have.length", 3);
+ sidebar().findAllByLabelText("Hidden").should("have.length", 2);
+ sidebar()
+ .findByRole("group", { name: metricName })
+ .findByRole("button", { name: "Group actions" })
+ .click({ force: true });
+ H.menu().findByText("Show").click();
+ cy.wait("@setPagesHidden")
+ .its("request.body.hidden")
+ .should("eq", false);
+ cy.findAllByRole("treeitem").should("have.length", 3);
+ sidebar().findAllByLabelText("Hidden").should("not.exist");
+
+ cy.log(
+ "Hiding the group with every page visible sends both page ids",
+ );
+ toggleShowHiddenItems();
+ cy.findAllByRole("treeitem").should("have.length", 3);
+ sidebar()
+ .findByRole("group", { name: metricName })
+ .findByRole("button", { name: "Group actions" })
+ .click({ force: true });
+ H.menu().findByText("Hide").click();
+ cy.wait("@setPagesHidden").then(({ request }) => {
+ expect(request.body.hidden).to.eq(true);
+ expect(request.body.page_ids).to.have.length(2);
+ });
+ cy.findAllByRole("treeitem").should("have.length", 1);
+
+ cy.log("Undo on the group-hidden toast restores the whole group");
+ H.undoToastListContainer()
+ .findByText(`${metricName} hidden`)
+ .should("be.visible");
+ H.undoToastListContainer()
+ .findByRole("button", { name: "Undo" })
+ .click();
+ cy.wait("@setPagesHidden")
+ .its("request.body.hidden")
+ .should("eq", false);
+ cy.findAllByRole("treeitem").should("have.length", 3);
+ },
+ );
+ });
});
- it("hides pages from the toolbar and group menus and reveals them via Show hidden items", () => {
- createTwoPageExploration("Sidebar hide fixture").then(
- ({ explorationId, metricName, pageNames }) => {
- cy.intercept("PUT", "/api/exploration/pages/hidden").as(
- "setPagesHidden",
- );
- visitExplorationUntilSettled(explorationId, 2);
-
- // The page auto-selects the tree's first page on load, and the tree
- // orders pages by interestingness — so which of the two
- // dimension-named pages is selected is data-dependent; derive it
- // from the DOM instead of assuming.
- cy.findAllByRole("treeitem").should("have.length", 3); // summary document + 2 pages
- selectedRows().should("have.length", 1);
- selectedRows()
- .first()
- .invoke("text")
- .then((text) => {
- const firstPageName = text.trim();
- const secondPageName = pageNames.find(
- (name) => name !== firstPageName,
- )!;
-
- cy.log("Triage arrows step between pages");
- cy.findByRole("button", { name: "Next" }).click();
- selectedRows().should("contain.text", secondPageName);
- cy.findByRole("button", { name: "Previous" }).click();
- selectedRows().should("contain.text", firstPageName);
-
- cy.log("Hide the selected page with the h shortcut");
- cy.get("body").type("h");
- cy.wait("@setPagesHidden").then(({ request }) => {
- expect(request.body.hidden).to.eq(true);
- expect(request.body.page_ids).to.have.length(1);
+ describe("chart click-through", () => {
+ it("clicking a cartesian point opens Explore further + Add comment, posts explore-further filters, and navigates from the new-thread toast", () => {
+ createTimelineWithSentinelEvent("Releases", "star").then((timelineId) => {
+ cy.request("GET", "/api/exploration/dimensions").then(({ body }) => {
+ // manual typecast for BE data
+ const seeded = body as GetExplorationDataResponse;
+ const seededMetric = seeded.metrics.find(
+ (metric) => metric.name === ORDERS_COUNT_METRIC_NAME,
+ );
+ expect(
+ seededMetric,
+ `"${ORDERS_COUNT_METRIC_NAME}" metric is exposed by /api/exploration/dimensions`,
+ ).to.exist;
+ cy.request("POST", `/api/metric/${seededMetric!.id}/dimension/add`, {
+ dimensions: [
+ {
+ id: "e2e00000-cafe-4bb8-9d8a-0123456789ab",
+ mapping_target: [
+ "field",
+ { "source-field": ORDERS.PRODUCT_ID },
+ PRODUCTS.CATEGORY,
+ ],
+ },
+ ],
+ });
+ });
+
+ cy.request("GET", "/api/exploration/dimensions").then(({ body }) => {
+ // Unjustified type cast. FIXME
+ const data = body as GetExplorationDataResponse;
+ const ordersMetric = data.metrics.find(
+ (metric) => metric.name === ORDERS_COUNT_METRIC_NAME,
+ );
+ expect(
+ ordersMetric,
+ `"${ORDERS_COUNT_METRIC_NAME}" metric is exposed by /api/exploration/dimensions`,
+ ).to.exist;
+ const dimsById = new Map(
+ data.dimension_groups.flatMap((group) =>
+ group.dimensions.map((dim) => [dim.id, dim] as const),
+ ),
+ );
+ const dimension = ordersMetric!.dimension_ids
+ .map((id) => dimsById.get(id))
+ .find((dim) => dim != null && dim.display_name === "Category");
+ expect(
+ dimension,
+ 'orders metric exposes the curated "Category" dimension',
+ ).to.exist;
+
+ H.createExplorationViaApi({
+ name: "Chart click-through fixture",
+ metricCardIds: [ordersMetric!.id],
+ dimensionIds: [dimension!.id],
+ timelineIds: [timelineId],
+ }).then((explorationId) => {
+ let initialThreadIds: number[] = [];
+
+ cy.intercept(
+ "POST",
+ `/api/exploration/${explorationId}/explore-further`,
+ ).as("exploreFurther");
+
+ cy.visit(
+ `/question/research/${explorationId}?timeline=${timelineId}`,
+ );
+ cy.findAllByRole("treeitem", { timeout: 30000 })
+ .first()
+ .should("be.visible");
+
+ cy.request("GET", `/api/exploration/${explorationId}`).then(
+ ({ body }) => {
+ // Unjustified type cast. FIXME
+ const exploration = body as Exploration;
+ initialThreadIds = (exploration.threads ?? []).map(
+ (thread) => thread.id,
+ );
+ // Navigate straight to the dimension's page. Driving the
+ // sidebar here would depend on which group happens to be
+ // auto-expanded — a state this test doesn't control.
+ const pages = (exploration.threads ?? []).flatMap((thread) =>
+ (thread.blocks ?? []).flatMap((block) => block.pages ?? []),
+ );
+ const page = pages.find((p) =>
+ (p.name ?? "").includes(dimension!.display_name),
+ );
+ expect(page, "the dimension's page exists on the exploration")
+ .to.exist;
+ cy.wrap(page!.id).as("pageId");
+ cy.visit(
+ `/question/research/${explorationId}/page/${page!.id}?timeline=${timelineId}`,
+ );
+ },
+ );
+
+ cy.location("pathname").should("include", "/page/");
+
+ // Wait for the selected page's queries to settle before clicking
+ // the chart — `Ready` is the settled-state icon label.
+ cy.findAllByLabelText("Ready", { timeout: 30000 })
+ .first()
+ .should("be.visible");
+
+ H.chartPathWithFillColor("#509EE3").first().click({ force: true });
+
+ cy.findByTestId("click-actions-view").within(() => {
+ cy.findByRole("button", { name: /Explore further/i }).should(
+ "be.visible",
+ );
+ cy.findByRole("button", { name: /Add comment/i }).should(
+ "be.visible",
+ );
});
- H.undoToastListContainer()
- .findByText(`"${firstPageName}" hidden`)
- .should("be.visible");
- cy.log("Auto-advance moves the selection to the remaining page");
- selectedRows().should("contain.text", secondPageName);
- cy.findAllByRole("treeitem").should("have.length", 2); // summary document + 1 non-hidden page
- sidebar().findByText(firstPageName).should("not.exist");
-
- cy.log("Show hidden items reveals the page with a Hidden marker");
- toggleShowHiddenItems();
- filterToggle().should("have.attr", "aria-pressed", "true");
- sidebar().findByText(firstPageName).should("be.visible");
- sidebar().findAllByLabelText("Hidden").should("have.length", 1);
- toggleShowHiddenItems();
- cy.findAllByRole("treeitem").should("have.length", 2);
- sidebar().findByText(firstPageName).should("not.exist");
- });
+ cy.findByTestId("click-actions-view")
+ .findByRole("button", { name: /Explore further/i })
+ .click();
- cy.log("Hide the whole group from its actions menu");
- sidebar()
- .findByRole("group", { name: metricName })
- .findByRole("button", { name: "Group actions" })
- .click({ force: true });
- H.menu().findByText("Hide").click();
- cy.wait("@setPagesHidden")
- .its("request.body.hidden")
- .should("eq", true);
- H.undoToastListContainer()
- .findByText(`${metricName} hidden`)
- .should("be.visible");
-
- cy.log("Everything but the summary document is hidden");
- cy.findAllByRole("treeitem").should("have.length", 1);
-
- cy.log("Hidden state is persisted server-side across a reload");
- cy.reload();
- cy.findAllByRole("treeitem").should("have.length", 1);
-
- cy.log("Show hidden items + the group Show action restore the pages");
- toggleShowHiddenItems();
- cy.findAllByRole("treeitem").should("have.length", 3);
- sidebar().findAllByLabelText("Hidden").should("have.length", 2);
- sidebar()
- .findByRole("group", { name: metricName })
- .findByRole("button", { name: "Group actions" })
- .click({ force: true });
- H.menu().findByText("Show").click();
- cy.wait("@setPagesHidden")
- .its("request.body.hidden")
- .should("eq", false);
- cy.findAllByRole("treeitem").should("have.length", 3);
- sidebar().findAllByLabelText("Hidden").should("not.exist");
-
- cy.log("Hiding the group with every page visible sends both page ids");
- toggleShowHiddenItems();
- cy.findAllByRole("treeitem").should("have.length", 3);
- sidebar()
- .findByRole("group", { name: metricName })
- .findByRole("button", { name: "Group actions" })
- .click({ force: true });
- H.menu().findByText("Hide").click();
- cy.wait("@setPagesHidden").then(({ request }) => {
- expect(request.body.hidden).to.eq(true);
- expect(request.body.page_ids).to.have.length(2);
- });
- cy.findAllByRole("treeitem").should("have.length", 1);
-
- cy.log("Undo on the group-hidden toast restores the whole group");
- H.undoToastListContainer()
- .findByText(`${metricName} hidden`)
- .should("be.visible");
- H.undoToastListContainer()
- .findByRole("button", { name: "Undo" })
- .click();
- cy.wait("@setPagesHidden")
- .its("request.body.hidden")
- .should("eq", false);
- cy.findAllByRole("treeitem").should("have.length", 3);
- },
- );
- });
-});
+ cy.wait("@exploreFurther").then(({ request, response }) => {
+ cy.get("@pageId").then((pageId) => {
+ expect(request.body.page_id).to.eq(pageId);
+ });
+ expect(request.body.explore_filters).to.be.an("array").and.not.be
+ .empty;
+ expect(request.body.explore_filters[0]).to.include.keys(
+ "operator",
+ "field_ref",
+ "value",
+ "display_value",
+ );
+ expect(request.body.explore_filters[0].operator).to.eq("=");
-describe("scenarios > explorations > chart click-through", () => {
- beforeEach(() => {
- cy.task("stopMockLlmServer");
- H.restore();
- cy.signInAsAdmin();
- H.enableExplorations();
- seedMetrics();
- H.resetSnowplow();
- H.enableTracking();
- });
+ // Unjustified type cast. FIXME
+ const threads = (response?.body as Exploration).threads ?? [];
+ const newThread = threads.find(
+ (thread) => !initialThreadIds.includes(thread.id),
+ );
+ expect(newThread, "explore-further adds a new thread").to.exist;
+ cy.wrap(newThread!.name).as("newThreadName");
+ });
- afterEach(() => {
- H.expectNoBadSnowplowEvents();
- });
+ cy.get<string>("@newThreadName").then((name) => {
+ openExploreFurtherToast(name);
+ });
- it("clicking a cartesian point opens Explore further + Add comment, posts explore-further filters, and navigates from the new-thread toast", () => {
- createTimelineWithSentinelEvent("Releases", "star").then((timelineId) => {
- cy.request("GET", "/api/exploration/dimensions").then(({ body }) => {
- // manual typecast for BE data
- const seeded = body as GetExplorationDataResponse;
- const seededMetric = seeded.metrics.find(
- (metric) => metric.name === ORDERS_COUNT_METRIC_NAME,
- );
- expect(
- seededMetric,
- `"${ORDERS_COUNT_METRIC_NAME}" metric is exposed by /api/exploration/dimensions`,
- ).to.exist;
- cy.request("POST", `/api/metric/${seededMetric!.id}/dimension/add`, {
- dimensions: [
- {
- id: "e2e00000-cafe-4bb8-9d8a-0123456789ab",
- mapping_target: [
- "field",
- { "source-field": ORDERS.PRODUCT_ID },
- PRODUCTS.CATEGORY,
- ],
- },
- ],
+ cy.get("@pageId").then((pageId) => {
+ cy.location("pathname")
+ .should("include", `/question/research/${explorationId}/page/`)
+ .and(
+ "not.eq",
+ `/question/research/${explorationId}/page/${pageId}`,
+ );
+ });
+ cy.findByRole("main")
+ .findAllByTestId("visualization-root", { timeout: 15000 })
+ .first()
+ .should("be.visible");
+ cy.location("search").should("include", "tab=all");
+ cy.location("search").should("include", `timeline=${timelineId}`);
+
+ cy.get("@newThreadName").then((name) => {
+ cy.findByRole("group", { name: String(name) }).should(
+ "have.attr",
+ "aria-expanded",
+ "true",
+ );
+ });
+ });
});
});
+ });
- cy.request("GET", "/api/exploration/dimensions").then(({ body }) => {
- // Unjustified type cast. FIXME
- const data = body as GetExplorationDataResponse;
+ it("brushing a timeseries cartesian chart opens Explore further only, posts between explore_filters, navigates from the new-thread toast, and Add to Summary flips the placeholder Summary, preserves filter pills, and mirrors page comments", () => {
+ cy.request<GetExplorationDataResponse>(
+ "GET",
+ "/api/exploration/dimensions",
+ ).then(({ body: data }) => {
const ordersMetric = data.metrics.find(
(metric) => metric.name === ORDERS_COUNT_METRIC_NAME,
);
@@ -838,19 +945,18 @@ describe("scenarios > explorations > chart click-through", () => {
group.dimensions.map((dim) => [dim.id, dim] as const),
),
);
- const dimension = ordersMetric!.dimension_ids
+ const temporalDimension = ordersMetric!.dimension_ids
.map((id) => dimsById.get(id))
- .find((dim) => dim != null && dim.display_name === "Category");
+ .find((dim) => dim != null && dim.effective_type.includes("Date"));
expect(
- dimension,
- 'orders metric exposes the curated "Category" dimension',
+ temporalDimension,
+ "orders metric exposes at least one temporal dimension",
).to.exist;
H.createExplorationViaApi({
- name: "Chart click-through fixture",
+ name: "Chart brush explore-further fixture",
metricCardIds: [ordersMetric!.id],
- dimensionIds: [dimension!.id],
- timelineIds: [timelineId],
+ dimensionIds: [temporalDimension!.id],
}).then((explorationId) => {
let initialThreadIds: number[] = [];
@@ -859,54 +965,75 @@ describe("scenarios > explorations > chart click-through", () => {
`/api/exploration/${explorationId}/explore-further`,
).as("exploreFurther");
- cy.visit(
- `/question/research/${explorationId}?timeline=${timelineId}`,
- );
- cy.findAllByRole("treeitem", { timeout: 30000 })
+ visitExplorationUntilSettled(explorationId, 1);
+
+ // Summary is pinned at the top of the tree but not initially selected
+ // while it is still a placeholder.
+ cy.findAllByRole("treeitem")
.first()
- .should("be.visible");
+ .should("contain.text", "Summary")
+ .and("have.attr", "aria-selected", "false");
+ cy.findAllByRole("treeitem")
+ .filter('[aria-selected="true"]')
+ .should("have.length", 1)
+ .and("not.contain.text", "Summary")
+ .invoke("attr", "href")
+ .should("match", /\/page\/\d+/);
+
+ cy.request<Exploration>(
+ "GET",
+ `/api/exploration/${explorationId}`,
+ ).then(({ body: exploration }) => {
+ expect(exploration.document, "BE auto-creates a Summary document")
+ .to.exist;
+ expect(exploration.document?.name).to.eq("Summary");
+ expect(exploration.document?.is_placeholder).to.eq(true);
+ initialThreadIds = (exploration.threads ?? []).map(
+ (thread) => thread.id,
+ );
+ });
- cy.request("GET", `/api/exploration/${explorationId}`).then(
- ({ body }) => {
- // Unjustified type cast. FIXME
- const exploration = body as Exploration;
- initialThreadIds = (exploration.threads ?? []).map(
- (thread) => thread.id,
- );
- // Navigate straight to the dimension's page. Driving the
- // sidebar here would depend on which group happens to be
- // auto-expanded — a state this test doesn't control.
- const pages = (exploration.threads ?? []).flatMap((thread) =>
- (thread.blocks ?? []).flatMap((block) => block.pages ?? []),
- );
- const page = pages.find((p) =>
- (p.name ?? "").includes(dimension!.display_name),
- );
- expect(page, "the dimension's page exists on the exploration").to
- .exist;
- cy.wrap(page!.id).as("pageId");
- cy.visit(
- `/question/research/${explorationId}/page/${page!.id}?timeline=${timelineId}`,
- );
- },
- );
+ cy.findByTestId("exploration-page-sidebar").within(() => {
+ cy.findByRole("group", { name: ordersMetric!.name }).then(
+ ($group) => {
+ if ($group.attr("aria-expanded") !== "true") {
+ cy.wrap($group).click();
+ }
+ },
+ );
+ cy.findByRole("treeitem", {
+ // Anchor on end so we don't match e.g. "Hour of day".
+ name: new RegExp(`${temporalDimension!.display_name}$`),
+ }).click();
+ });
- cy.location("pathname").should("include", "/page/");
+ H.ensureEchartsContainerHasSvg();
- // Wait for the selected page's queries to settle before clicking
- // the chart — `Ready` is the settled-state icon label.
- cy.findAllByLabelText("Ready", { timeout: 30000 })
- .first()
- .should("be.visible");
+ cy.intercept(
+ "POST",
+ `/api/exploration/${explorationId}/summary/append`,
+ ).as("appendSummary");
+
+ cy.findByRole("button", { name: "Add to Summary" }).click();
+ cy.wait("@appendSummary").then(({ response }) => {
+ expect(response?.statusCode).to.eq(200);
+ expect(response?.body?.is_placeholder).to.eq(false);
+ });
+ H.undoToastListContainer().within(() => {
+ cy.findByText(/Added to/).should("be.visible");
+ cy.findByLabelText("close icon").click();
+ cy.findByText(/Added to/).should("not.exist");
+ });
- H.chartPathWithFillColor("#509EE3").first().click({ force: true });
+ H.ensureEchartsContainerHasSvg();
+ H.applyBrush(120, 280);
cy.findByTestId("click-actions-view").within(() => {
cy.findByRole("button", { name: /Explore further/i }).should(
"be.visible",
);
cy.findByRole("button", { name: /Add comment/i }).should(
- "be.visible",
+ "not.exist",
);
});
@@ -915,20 +1042,21 @@ describe("scenarios > explorations > chart click-through", () => {
.click();
cy.wait("@exploreFurther").then(({ request, response }) => {
- cy.get("@pageId").then((pageId) => {
- expect(request.body.page_id).to.eq(pageId);
- });
- expect(request.body.explore_filters).to.be.an("array").and.not.be
- .empty;
+ expect(request.body.explore_filters)
+ .to.be.an("array")
+ .and.have.length(1);
expect(request.body.explore_filters[0]).to.include.keys(
"operator",
"field_ref",
- "value",
+ "values",
"display_value",
);
- expect(request.body.explore_filters[0].operator).to.eq("=");
+ expect(request.body.explore_filters[0].operator).to.eq("between");
+ expect(request.body.explore_filters[0].values)
+ .to.be.an("array")
+ .and.have.length(2);
- // Unjustified type cast. FIXME
+ // Cypress does not type intercept response bodies.
const threads = (response?.body as Exploration).threads ?? [];
const newThread = threads.find(
(thread) => !initialThreadIds.includes(thread.id),
@@ -937,17 +1065,26 @@ describe("scenarios > explorations > chart click-through", () => {
cy.wrap(newThread!.name).as("newThreadName");
});
+ cy.location("pathname")
+ .should("include", `/question/research/${explorationId}/page/`)
+ .then((pathname) => {
+ cy.wrap(pathname).as("pathnameBeforeView");
+ });
+
cy.get<string>("@newThreadName").then((name) => {
openExploreFurtherToast(name);
});
- cy.location("pathname").should(
- "include",
- `/question/research/${explorationId}/page/`,
- );
+ cy.get<string>("@pathnameBeforeView").then((pathnameBeforeView) => {
+ cy.location("pathname")
+ .should("include", `/question/research/${explorationId}/page/`)
+ .and("not.eq", pathnameBeforeView)
+ .then((pathname) => {
+ const pageId = Number(/\/page\/(\d+)/.exec(pathname)![1]);
+ cy.wrap(pageId).as("pageId");
+ });
+ });
cy.location("search").should("include", "tab=all");
- cy.location("search").should("include", `timeline=${timelineId}`);
-
cy.get("@newThreadName").then((name) => {
cy.findByRole("group", { name: String(name) }).should(
"have.attr",
@@ -956,309 +1093,111 @@ describe("scenarios > explorations > chart click-through", () => {
);
});
- cy.findByRole("main")
- .findByTestId("exploration-chart-grid")
- .should("exist");
- });
- });
- });
- });
-
- it("brushing a timeseries cartesian chart opens Explore further only, posts between explore_filters, navigates from the new-thread toast, and Add to Summary preserves filter pills", () => {
- cy.request<GetExplorationDataResponse>(
- "GET",
- "/api/exploration/dimensions",
- ).then(({ body: data }) => {
- const ordersMetric = data.metrics.find(
- (metric) => metric.name === ORDERS_COUNT_METRIC_NAME,
- );
- expect(
- ordersMetric,
- `"${ORDERS_COUNT_METRIC_NAME}" metric is exposed by /api/exploration/dimensions`,
- ).to.exist;
- const dimsById = new Map(
- data.dimension_groups.flatMap((group) =>
- group.dimensions.map((dim) => [dim.id, dim] as const),
- ),
- );
- const temporalDimension = ordersMetric!.dimension_ids
- .map((id) => dimsById.get(id))
- .find((dim) => dim != null && dim.effective_type.includes("Date"));
- expect(
- temporalDimension,
- "orders metric exposes at least one temporal dimension",
- ).to.exist;
-
- H.createExplorationViaApi({
- name: "Chart brush explore-further fixture",
- metricCardIds: [ordersMetric!.id],
- dimensionIds: [temporalDimension!.id],
- }).then((explorationId) => {
- let initialThreadIds: number[] = [];
-
- cy.intercept(
- "POST",
- `/api/exploration/${explorationId}/explore-further`,
- ).as("exploreFurther");
-
- visitExplorationUntilSettled(explorationId, 1);
-
- cy.request<Exploration>(
- "GET",
- `/api/exploration/${explorationId}`,
- ).then(({ body: exploration }) => {
- initialThreadIds = (exploration.threads ?? []).map(
- (thread) => thread.id,
- );
- });
-
- cy.findByTestId("exploration-page-sidebar").within(() => {
- cy.findByRole("group", { name: ordersMetric!.name }).then(
- ($group) => {
- if ($group.attr("aria-expanded") !== "true") {
- cy.wrap($group).click();
- }
- },
- );
- cy.findByRole("treeitem", {
- // Anchor on end so we don't match e.g. "Hour of day".
- name: new RegExp(`${temporalDimension!.display_name}$`),
- }).click();
- });
-
- H.ensureEchartsContainerHasSvg();
- H.applyBrush(120, 280);
-
- cy.findByTestId("click-actions-view").within(() => {
- cy.findByRole("button", { name: /Explore further/i }).should(
- "be.visible",
- );
- cy.findByRole("button", { name: /Add comment/i }).should("not.exist");
- });
+ // Temporal ranges use an en-dash (e.g. "Feb 2020 – Mar 2020"); exact
+ // bounds depend on brush pixel coords, so just assert range formatting.
+ cy.findByTestId("filter-pill")
+ .should("be.visible")
+ .invoke("text")
+ .should("match", /–/)
+ .as("exploreFilterPillText", { type: "static" });
+
+ cy.findByRole("button", { name: "Add to Summary" }).click();
+ cy.wait("@appendSummary")
+ .its("response.statusCode")
+ .should("eq", 200);
+
+ H.undoToastListContainer().within(() => {
+ cy.findByText(/Added to/).should("be.visible");
+ cy.findByRole("button", { name: "View" }).click();
+ });
- cy.findByTestId("click-actions-view")
- .findByRole("button", { name: /Explore further/i })
- .click();
-
- cy.wait("@exploreFurther").then(({ request, response }) => {
- expect(request.body.explore_filters)
- .to.be.an("array")
- .and.have.length(1);
- expect(request.body.explore_filters[0]).to.include.keys(
- "operator",
- "field_ref",
- "values",
- "display_value",
+ cy.location("pathname").should(
+ "eq",
+ `/question/research/${explorationId}/summary`,
);
- expect(request.body.explore_filters[0].operator).to.eq("between");
- expect(request.body.explore_filters[0].values)
- .to.be.an("array")
- .and.have.length(2);
-
- // Cypress does not type intercept response bodies.
- const threads = (response?.body as Exploration).threads ?? [];
- const newThread = threads.find(
- (thread) => !initialThreadIds.includes(thread.id),
+ cy.findAllByTestId("document-card-embed", { timeout: 15000 }).should(
+ "have.length",
+ 2,
);
- expect(newThread, "explore-further adds a new thread").to.exist;
- cy.wrap(newThread!.name).as("newThreadName");
- });
-
- cy.get<string>("@newThreadName").then((name) => {
- openExploreFurtherToast(name);
- });
-
- cy.location("pathname").should(
- "include",
- `/question/research/${explorationId}/page/`,
- );
-
- // Temporal ranges use an en-dash (e.g. "Feb 2020 – Mar 2020"); exact
- // bounds depend on brush pixel coords, so just assert range formatting.
- cy.findByTestId("filter-pill")
- .should("be.visible")
- .invoke("text")
- .should("match", /–/)
- .as("exploreFilterPillText");
-
- cy.intercept(
- "POST",
- `/api/exploration/${explorationId}/summary/append`,
- ).as("appendSummary");
-
- cy.findByRole("button", { name: "Add to Summary" }).click();
- cy.wait("@appendSummary");
-
- H.undoToastListContainer().within(() => {
- cy.findByText(/Added to/).should("be.visible");
- cy.findByRole("button", { name: "View" }).click();
- });
+ cy.findAllByTestId("document-card-embed")
+ .eq(0)
+ .within(() => {
+ cy.findByTestId("visualization-root", { timeout: 15000 }).should(
+ "be.visible",
+ );
+ cy.findByTestId("filter-pill").should("not.exist");
+ });
+ cy.findAllByTestId("document-card-embed")
+ .eq(1)
+ .should("be.visible")
+ .findByTestId("filter-pill")
+ .should("be.visible")
+ .invoke("text")
+ .then((text) => {
+ cy.get("@exploreFilterPillText").should("eq", text);
+ });
- cy.location("pathname").should(
- "eq",
- `/question/research/${explorationId}/summary`,
- );
- cy.findByTestId("document-card-embed", { timeout: 15000 })
- .should("be.visible")
- .findByTestId("filter-pill")
- .should("be.visible")
- .invoke("text")
- .then((text) => {
- cy.get("@exploreFilterPillText").should("eq", text);
+ // Seed a page comment via API
+ cy.get<number>("@pageId").then((pageId) => {
+ H.createComment({
+ target_type: "exploration",
+ target_id: explorationId,
+ child_target_id: String(pageId),
+ parent_comment_id: null,
+ content: {
+ type: "doc",
+ content: [
+ {
+ type: "paragraph",
+ content: [{ type: "text", text: "Shared comment" }],
+ },
+ ],
+ },
+ });
});
- });
- });
- });
-});
-
-describe("scenarios > explorations > Summary document", () => {
- beforeEach(() => {
- cy.task("stopMockLlmServer");
- H.restore();
- cy.signInAsAdmin();
- H.enableExplorations();
- seedMetrics();
- });
-
- it("auto-creates Summary at the top of the tree, keeps pages selected initially, supports Add to Summary, and mirrors comments both ways", () => {
- H.createExplorationViaApi({ name: "Summary fixture" }).then(
- (explorationId) => {
- cy.request("GET", `/api/exploration/${explorationId}`).then(
- ({ body }) => {
- // api returns an Exploration
- const exploration = body as Exploration;
- expect(exploration.document, "BE auto-creates a Summary document")
- .to.exist;
- expect(exploration.document?.name).to.eq("Summary");
- expect(exploration.document?.is_placeholder).to.eq(true);
- },
- );
- visitExplorationUntilSettled(explorationId, 1);
-
- // Summary is pinned at the top of the tree but not initially selected
- // while it is still a placeholder.
- cy.findAllByRole("treeitem")
- .first()
- .should("contain.text", "Summary")
- .and("have.attr", "aria-selected", "false");
-
- // Capture the settled page id from the auto-selected sidebar row
- // (pages only exist after settlement), then click through
- cy.findAllByRole("treeitem")
- .filter('[aria-selected="true"]')
- .should("have.length", 1)
- .and("not.contain.text", "Summary")
- .invoke("attr", "href")
- .should("match", /\/page\/\d+/)
- .then((href) => {
- const pageId = Number(/\/page\/(\d+)/.exec(href!)![1]);
- cy.wrap(pageId).as("pageId");
- cy.get(`[role="treeitem"][href="${href}"]`).click();
+ // Cold-load the Summary with the comments query param — the panel
+ // must open without a prior click (the deep-link regression).
+ cy.get<number>("@pageId").then((pageId) => {
+ cy.visit(
+ `/question/research/${explorationId}/summary?comments=${pageId}`,
+ );
+ cy.findByTestId("exploration-summary-comments", {
+ timeout: 15000,
+ })
+ .should("be.visible")
+ .and("contain.text", "Shared comment");
});
- cy.location("pathname").should("match", /\/page\/\d+$/);
- cy.findByTestId("exploration-chart-grid").should("be.visible");
-
- cy.intercept(
- "POST",
- `/api/exploration/${explorationId}/summary/append`,
- ).as("appendSummary");
-
- cy.findByRole("button", { name: "Add to Summary" }).click();
- cy.wait("@appendSummary").then(({ response }) => {
- expect(response?.statusCode).to.eq(200);
- expect(response?.body?.is_placeholder).to.eq(false);
- });
-
- H.undoToastListContainer()
- .findByText(/Added to/)
- .should("be.visible");
- H.undoToast().findByRole("button", { name: "View" }).click();
-
- cy.location("pathname").should(
- "eq",
- `/question/research/${explorationId}/summary`,
- );
- cy.findByTestId("document-card-embed", { timeout: 15000 }).should(
- "be.visible",
- );
-
- // Seed a page comment via API
- cy.get<number>("@pageId").then((pageId) => {
- H.createComment({
- target_type: "exploration",
- target_id: explorationId,
- child_target_id: String(pageId),
- parent_comment_id: null,
- content: {
- type: "doc",
- content: [
- {
- type: "paragraph",
- content: [{ type: "text", text: "Shared comment" }],
- },
- ],
- },
+ cy.get<number>("@pageId").then((pageId) => {
+ cy.visit(
+ `/question/research/${explorationId}/page/${pageId}?comments=${pageId}`,
+ );
});
- });
-
- // Cold-load the Summary with the comments query param — the panel
- // must open without a prior click (the deep-link regression).
- cy.get<number>("@pageId").then((pageId) => {
- cy.visit(
- `/question/research/${explorationId}/summary?comments=${pageId}`,
- );
- cy.findByTestId("exploration-summary-comments", {
- timeout: 15000,
- })
- .should("be.visible")
- .and("contain.text", "Shared comment");
- });
- cy.get<number>("@pageId").then((pageId) => {
- cy.visit(
- `/question/research/${explorationId}/page/${pageId}?comments=${pageId}`,
+ cy.findByTestId("exploration-comments", { timeout: 15000 }).should(
+ "contain.text",
+ "Shared comment",
);
});
-
- cy.findByTestId("exploration-comments", { timeout: 15000 }).should(
- "contain.text",
- "Shared comment",
- );
- },
- );
- });
-});
-
-describe("scenarios > explorations > collection placement + archive", () => {
- beforeEach(() => {
- cy.task("stopMockLlmServer");
- H.restore();
- cy.signInAsAdmin();
- H.enableExplorations();
- seedMetrics();
- H.resetSnowplow();
- H.enableTracking();
- });
-
- afterEach(() => {
- H.expectNoBadSnowplowEvents();
+ });
+ });
});
- it("places a newly-created exploration in the creator's personal collection and lets the user move it to trash from there", () => {
- const explorationName = "Personal-collection archive fixture";
+ describe("collection placement + archive", () => {
+ it("places a newly-created exploration in the creator's personal collection, moves it to trash, and restores and permanently deletes archived explorations from the trash banner and the /trash page", () => {
+ const explorationName = "Personal-collection archive fixture";
+ const restoreName = "Trash-page restore fixture";
+ const deleteName = "Trash-page delete-permanently fixture";
- H.createExplorationViaApi({ name: explorationName }).then(
- (explorationId) => {
- cy.request("GET", "/api/user/current").then(({ body: user }) => {
- // Unjustified type cast. FIXME
- const personalCollectionId = user.personal_collection_id as number;
- expect(
- personalCollectionId,
- "/api/user/current returns a personal collection id",
- ).to.be.a("number");
+ H.createExplorationViaApi({ name: explorationName }).as("explorationId");
+ cy.request("GET", "/api/user/current")
+ .its("body.personal_collection_id")
+ .should("be.a", "number")
+ .as("personalCollectionId");
+ cy.get<number>("@explorationId").then((explorationId) => {
+ cy.get<number>("@personalCollectionId").then((personalCollectionId) => {
cy.request("GET", `/api/exploration/${explorationId}`).then(
({ body }) => {
expect(
@@ -1271,150 +1210,105 @@ describe("scenarios > explorations > collection placement + archive", () => {
// Visit the personal collection and confirm the row
// renders.
H.visitCollection(personalCollectionId);
- cy.findByTestId("collection-table")
- .findByText(explorationName)
- .should("be.visible");
-
- // Open the row's overflow menu and click `Move to trash`.
- // Archiving an exploration goes through the centralized
- // `useSetArchive` hook → `PUT /api/exploration/:id
- // { archived: true }`.
- cy.intercept("PUT", `/api/exploration/${explorationId}`).as(
- "archiveExploration",
- );
- H.openCollectionItemMenu(explorationName);
- // The EntityItem dropdown renders each action as a
- // `<li aria-labelledby="...">`, not `role="menuitem"`,
- // so match the visible text — scoped to the open popover.
- H.popover().findByText("Move to trash").click();
-
- cy.wait("@archiveExploration").then(({ request, response }) => {
- expect(request.body).to.deep.eq({ archived: true });
- expect(response?.statusCode).to.eq(200);
- });
-
- // After archive, the collection shows its empty state and
- // the exploration row is gone from the page.
- cy.findByText("This collection is empty").should("be.visible");
- cy.findByText(explorationName).should("not.exist");
-
- // BE state agrees: a subsequent GET reports
- // `archived: true`.
- cy.request("GET", `/api/exploration/${explorationId}`).then(
- ({ body }) => {
- expect(body.archived, "exploration is archived").to.eq(true);
- },
- );
-
- H.undoToast().findByText("Trashed research").should("exist");
- H.undo();
-
- cy.findByTestId("collection-table")
- .findByText(explorationName)
- .should("be.visible");
- });
- },
- );
- });
-
- it("permanently deletes an archived exploration via the Delete permanently action on the /trash page", () => {
- // `ActionMenu`'s `handleDeletePermanently` previously routed
- // every non-collection model through the legacy entity factory
- // (`entityForObject`), which has no `explorations` entry — so
- // the delete crashed. The fix dispatches the RTKQ
- // `deleteExploration` mutation, which calls
- // `DELETE /api/exploration/:id` (a new BE endpoint that cascades
- // through threads/queries/documents via the FK tree).
- const explorationName = "Trash-page delete-permanently fixture";
-
- H.createExplorationViaApi({ name: explorationName }).then(
- (explorationId) => {
- cy.request("PUT", `/api/exploration/${explorationId}`, {
- archived: true,
});
- cy.visit("/trash");
- cy.findByTestId("collection-table")
- .findByText(explorationName)
- .should("be.visible");
-
- cy.intercept("DELETE", `/api/exploration/${explorationId}`).as(
- "deleteExploration",
+ // Archiving an exploration goes through the centralized
+ // `useSetArchive` hook → `PUT /api/exploration/:id
+ // { archived: true }`.
+ cy.intercept("PUT", `/api/exploration/${explorationId}`).as(
+ "archiveExploration",
);
- H.openCollectionItemMenu(explorationName);
- H.popover().findByText("Delete permanently").click();
- // The confirmation modal owns the final destructive button.
- H.modal()
- .findByRole("button", { name: /Delete permanently/i })
- .click();
+ });
+ cy.findByTestId("collection-table")
+ .findByText(explorationName)
+ .should("be.visible");
+
+ // Open the row's overflow menu and click `Move to trash`.
+ H.openCollectionItemMenu(explorationName);
+ // The EntityItem dropdown renders each action as a
+ // `<li aria-labelledby="...">`, not `role="menuitem"`,
+ // so match the visible text — scoped to the open popover.
+ H.popover().findByText("Move to trash").click();
+
+ cy.wait("@archiveExploration").then(({ request, response }) => {
+ expect(request.body).to.deep.eq({ archived: true });
+ expect(response?.statusCode).to.eq(200);
+ });
- cy.wait("@deleteExploration")
- .its("response.statusCode")
- .should("eq", 204);
+ // After archive, the collection shows its empty state and
+ // the exploration row is gone from the page.
+ cy.findByTestId("collection-empty-state")
+ .findByText("This collection is empty")
+ .should("be.visible");
+ H.main().findByText(explorationName).should("not.exist");
- // The row is gone from the trash listing…
- cy.findByText(explorationName).should("not.exist");
+ // BE state agrees: a subsequent GET reports
+ // `archived: true`.
+ cy.get<number>("@explorationId").then((explorationId) => {
+ cy.request("GET", `/api/exploration/${explorationId}`).then(
+ ({ body }) => {
+ expect(body.archived, "exploration is archived").to.eq(true);
+ },
+ );
+ });
- // …and the BE returns 404 for the now-hard-deleted exploration.
- cy.request({
- method: "GET",
- url: `/api/exploration/${explorationId}`,
- failOnStatusCode: false,
- })
- .its("status")
- .should("eq", 404);
- },
- );
- });
+ H.undoToast().findByText("Trashed research").should("exist");
+ H.undo();
- it("shows the trash banner on an archived exploration and restores or permanently deletes it from there", () => {
- const explorationName = "Exploration-page trash banner fixture";
+ cy.findByTestId("collection-table")
+ .findByText(explorationName)
+ .should("be.visible");
- H.createExplorationViaApi({ name: explorationName }).then(
- (explorationId) => {
- cy.request("PUT", `/api/exploration/${explorationId}`, {
- archived: true,
+ H.createExplorationViaApi({ name: restoreName }).as("restoreId");
+ H.createExplorationViaApi({ name: deleteName }).as("deleteId");
+ for (const alias of ["@explorationId", "@restoreId", "@deleteId"]) {
+ cy.get<number>(alias).then((id) => {
+ cy.request("PUT", `/api/exploration/${id}`, { archived: true });
});
+ }
- cy.log("An archived exploration opens with the trash banner");
+ cy.log("An archived exploration opens with the trash banner");
+ cy.get<number>("@explorationId").then((explorationId) => {
cy.intercept("PUT", `/api/exploration/${explorationId}`).as(
- "restoreExploration",
+ "bannerRestore",
);
H.visitExploration(explorationId);
- cy.findByTestId("archive-banner")
- .should("contain", "This research is in the trash.")
- .findByRole("button", { name: /Restore/ })
- .click();
-
- cy.wait("@restoreExploration").then(({ request, response }) => {
- expect(request.body).to.deep.eq({ archived: false });
- expect(response?.statusCode).to.eq(200);
- });
- cy.findByTestId("exploration-page-sidebar").should("be.visible");
- cy.findByTestId("archive-banner").should("not.exist");
+ });
+ cy.findByTestId("archive-banner")
+ .should("contain", "This research is in the trash.")
+ .findByRole("button", { name: /Restore/ })
+ .click();
+
+ cy.wait("@bannerRestore").then(({ request, response }) => {
+ expect(request.body).to.deep.eq({ archived: false });
+ expect(response?.statusCode).to.eq(200);
+ });
+ cy.findByTestId("exploration-page-sidebar").should("be.visible");
+ cy.findByTestId("archive-banner").should("not.exist");
- cy.log("Delete permanently from the banner lands on the trash page");
+ cy.log("Delete permanently from the banner lands on the trash page");
+ cy.get<number>("@explorationId").then((explorationId) => {
cy.request("PUT", `/api/exploration/${explorationId}`, {
archived: true,
});
cy.intercept("DELETE", `/api/exploration/${explorationId}`).as(
- "deleteExploration",
+ "bannerDelete",
);
- cy.reload();
- cy.findByTestId("archive-banner")
- .findByRole("button", { name: /Delete permanently/ })
- .click();
- H.modal()
- .findByRole("button", { name: /Delete permanently/i })
- .click();
-
- cy.wait("@deleteExploration")
- .its("response.statusCode")
- .should("eq", 204);
- cy.location("pathname").should("eq", "/trash");
- H.undoToast()
- .findByText("This item has been permanently deleted.")
- .should("be.visible");
+ });
+ cy.reload();
+ cy.findByTestId("archive-banner")
+ .findByRole("button", { name: /Delete permanently/ })
+ .click();
+ H.modal()
+ .findByRole("button", { name: /Delete permanently/i })
+ .click();
+
+ cy.wait("@bannerDelete").its("response.statusCode").should("eq", 204);
+ cy.location("pathname").should("eq", "/trash");
+ H.undoToast()
+ .findByText("This item has been permanently deleted.")
+ .should("be.visible");
+ cy.get<number>("@explorationId").then((explorationId) => {
cy.request({
method: "GET",
url: `/api/exploration/${explorationId}`,
@@ -1422,56 +1316,70 @@ describe("scenarios > explorations > collection placement + archive", () => {
})
.its("status")
.should("eq", 404);
- },
- );
- });
-
- it("restores an archived exploration via the Restore action on the /trash page", () => {
- // `useSetArchive`'s undo toast is one path back, but the trash
- // page exposes a separate `Restore` action that runs through
- // `ActionMenu.tsx`'s `handleRestore`. Without an explicit
- // `exploration` branch in that handler it falls through to the
- // legacy `entityForObject(...)`, which has no `explorations`
- // entry — so the restore would silently throw. This test
- // exercises the dedicated branch end-to-end.
- const explorationName = "Trash-page restore fixture";
-
- H.createExplorationViaApi({ name: explorationName }).then(
- (explorationId) => {
- // Archive directly via the BE so we land on /trash with the
- // exploration already in it.
- cy.request("PUT", `/api/exploration/${explorationId}`, {
- archived: true,
- });
-
- cy.visit("/trash");
- cy.findByTestId("collection-table")
- .findByText(explorationName)
- .should("be.visible");
+ });
- cy.intercept("PUT", `/api/exploration/${explorationId}`).as(
- "restoreExploration",
- );
- H.openCollectionItemMenu(explorationName);
- H.popover().findByText("Restore").click();
+ cy.findByTestId("collection-table")
+ .findByText(restoreName)
+ .should("be.visible");
+ cy.findByTestId("collection-table")
+ .findByText(deleteName)
+ .should("be.visible");
+
+ cy.log("Restore from the /trash page row menu");
+ cy.visit("/trash");
+ cy.findByTestId("collection-table")
+ .findByText(restoreName)
+ .should("be.visible");
+ cy.findByTestId("collection-table")
+ .findByText(deleteName)
+ .should("be.visible");
+
+ cy.get<number>("@restoreId").then((restoreId) => {
+ cy.intercept("PUT", `/api/exploration/${restoreId}`).as("trashRestore");
+ });
+ H.openCollectionItemMenu(restoreName);
+ H.popover().findByText("Restore").click();
- cy.wait("@restoreExploration").then(({ request, response }) => {
- expect(request.body).to.deep.eq({ archived: false });
- expect(response?.statusCode).to.eq(200);
+ cy.wait("@trashRestore").then(({ request, response }) => {
+ expect(request.body).to.deep.eq({ archived: false });
+ expect(response?.statusCode).to.eq(200);
+ });
+ H.main().findByText(restoreName).should("not.exist");
+ cy.get<number>("@restoreId").then((restoreId) => {
+ cy.request("GET", `/api/exploration/${restoreId}`).then(({ body }) => {
+ expect(body.archived, "exploration is no longer archived").to.eq(
+ false,
+ );
});
+ });
- // The trash listing no longer shows the exploration.
- cy.findByText(explorationName).should("not.exist");
-
- // And the BE reports the exploration as un-archived again.
- cy.request("GET", `/api/exploration/${explorationId}`).then(
- ({ body }) => {
- expect(body.archived, "exploration is no longer archived").to.eq(
- false,
- );
- },
+ cy.log("Delete permanently from the /trash page row menu");
+ cy.findByTestId("collection-table")
+ .findByText(deleteName)
+ .should("be.visible");
+ cy.get<number>("@deleteId").then((deleteId) => {
+ cy.intercept("DELETE", `/api/exploration/${deleteId}`).as(
+ "trashDelete",
);
- },
- );
+ });
+ H.openCollectionItemMenu(deleteName);
+ H.popover().findByText("Delete permanently").click();
+ // The confirmation modal owns the final destructive button.
+ H.modal()
+ .findByRole("button", { name: /Delete permanently/i })
+ .click();
+
+ cy.wait("@trashDelete").its("response.statusCode").should("eq", 204);
+ H.main().findByText(deleteName).should("not.exist");
+ cy.get<number>("@deleteId").then((deleteId) => {
+ cy.request({
+ method: "GET",
+ url: `/api/exploration/${deleteId}`,
+ failOnStatusCode: false,
+ })
+ .its("status")
+ .should("eq", 404);
+ });
+ });
});
});