From 474b137abb090aa2f5af34b9c73786c6e49fd9b9 Mon Sep 17 00:00:00 2001 From: Romeo Van Snick <romeo@romeovansnick.be> Date: Mon, 30 Sep 2024 16:35:06 +0200 Subject: [PATCH] Disable "Compare to the past" UI components (#48134) * Temporarily disable compare to the past ui components * Temporarily disable compare to the past tests * Skip Compare to past unit tests --- .../reproductions-3.cy.spec.js | 9 +- .../question/column-compare.cy.spec.ts | 2842 +++++++++-------- .../AggregationPicker.unit.spec.tsx | 3 +- .../components/CompareAggregations/utils.ts | 7 + .../AggregateStep/AggregateStep.unit.spec.tsx | 8 +- 5 files changed, 1450 insertions(+), 1419 deletions(-) diff --git a/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js b/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js index af59d9f3cae..bc78adc57e2 100644 --- a/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js +++ b/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js @@ -1250,10 +1250,11 @@ describe("issue 43294", () => { createQuestion(questionDetails, { visitQuestion: true }); queryBuilderFooter().findByLabelText("Switch to data").click(); - cy.log("compare action"); - cy.button("Add column").click(); - popover().findByText("Compare to the past").click(); - popover().button("Done").click(); + // TODO: reenable this test when we reenable the "Compare to the past" components. + // cy.log("compare action"); + // cy.button("Add column").click(); + // popover().findByText("Compare to the past").click(); + // popover().button("Done").click(); cy.log("extract action"); cy.button("Add column").click(); diff --git a/e2e/test/scenarios/question/column-compare.cy.spec.ts b/e2e/test/scenarios/question/column-compare.cy.spec.ts index a57c55840b0..28f326da43e 100644 --- a/e2e/test/scenarios/question/column-compare.cy.spec.ts +++ b/e2e/test/scenarios/question/column-compare.cy.spec.ts @@ -196,1597 +196,1615 @@ const CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE = [ "count", ]; -describeWithSnowplow("scenarios > question > column compare", () => { - beforeEach(() => { - restore(); - resetSnowplow(); - cy.signInAsAdmin(); - }); - - afterEach(() => { - expectNoBadSnowplowEvents(); - }); - - describe("no aggregations", () => { - it("does not show column compare shortcut", () => { - createQuestion( - { query: QUERY_NO_AGGREGATION }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - cy.log("chill mode - summarize sidebar"); - cy.button("Summarize").click(); - rightSidebar().button("Count").icon("close").click(); - rightSidebar().button("Add aggregation").click(); - verifyNoColumnCompareShortcut(); - - cy.log("chill mode - column drill"); - tableHeaderClick("Title"); - verifyNoColumnCompareShortcut(); - - cy.log("chill mode - plus button"); - cy.button("Add column").click(); - verifyNoColumnCompareShortcut(); - - cy.log("notebook editor"); - openNotebook(); - cy.button("Summarize").click(); - verifyNoColumnCompareShortcut(); - }); - }); - - describe("no temporal columns", () => { +// TODO: reenable test when we reenable the "Compare to the past" components. +describe.skip("scenarios > question", () => { + describeWithSnowplow("column compare", () => { beforeEach(() => { - cy.request("PUT", `/api/field/${PRODUCTS.CREATED_AT}`, { - base_type: "type/Text", - }); - }); - - it("no breakout", () => { - createQuestion( - { query: QUERY_NO_AGGREGATION }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - cy.log("chill mode - summarize sidebar"); - cy.button("Summarize").click(); - rightSidebar().button("Count").icon("close").click(); - rightSidebar().button("Add aggregation").click(); - verifyNoColumnCompareShortcut(); - - cy.log("chill mode - column drill"); - tableHeaderClick("Title"); - verifyNoColumnCompareShortcut(); - - cy.log("chill mode - plus button"); - cy.button("Add column").click(); - verifyNoColumnCompareShortcut(); - - cy.log("notebook editor"); - openNotebook(); - cy.button("Summarize").click(); - verifyNoColumnCompareShortcut(); + restore(); + resetSnowplow(); + cy.signInAsAdmin(); }); - it("one breakout", () => { - createQuestion( - { query: QUERY_SINGLE_AGGREGATION_NON_DATETIME_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - cy.log("chill mode - summarize sidebar"); - cy.button("Summarize").click(); - rightSidebar().button("Count").icon("close").click(); - rightSidebar().button("Add aggregation").click(); - verifyNoColumnCompareShortcut(); - - cy.log("chill mode - column drill"); - tableHeaderClick("Category"); - verifyNoColumnCompareShortcut(); - - cy.log("chill mode - plus button"); - cy.button("Add column").click(); - verifyNoColumnCompareShortcut(); - - cy.log("notebook editor"); - openNotebook(); - cy.button("Summarize").click(); - verifyNoColumnCompareShortcut(); + afterEach(() => { + expectNoBadSnowplowEvents(); }); - }); - - describe("offset", () => { - it("should be possible to change the temporal bucket through a preset", () => { - createQuestion( - { query: QUERY_SINGLE_AGGREGATION_NO_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - openNotebook(); - getNotebookStep("summarize") - .findAllByTestId("aggregate-step") - .last() - .icon("add") - .click(); - - popover().within(() => { - cy.findByText("Basic Metrics").click(); - cy.findByText("Compare to the past").click(); - - cy.findByText("Previous year").click(); - cy.findByText("Done").click(); - }); - - verifyBreakoutExistsAndIsFirst({ - column: "Created At", - bucket: "Year", - }); - - verifyAggregations([ - { - name: "Count (previous year)", - expression: "Offset(Count, -1)", - }, - { - name: "Count (% vs previous year)", - expression: "Count / Offset(Count, -1) - 1", - }, - ]); - }); - - it("should be possible to change the temporal bucket with a custom offset", () => { - createQuestion( - { query: QUERY_SINGLE_AGGREGATION_NO_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - openNotebook(); - getNotebookStep("summarize") - .findAllByTestId("aggregate-step") - .last() - .icon("add") - .click(); - popover().within(() => { - cy.findByText("Basic Metrics").click(); - cy.findByText("Compare to the past").click(); - - cy.findByText("Custom...").click(); - - cy.findByLabelText("Offset").clear().type("2"); - cy.findByLabelText("Unit").click(); - }); - - popover().last().findByText("Weeks").click(); - - popover().within(() => { - cy.findByText("Done").click(); - }); - - verifyBreakoutExistsAndIsFirst({ - column: "Created At", - bucket: "Week", - }); - - verifyAggregations([ - { - name: "Count (2 weeks ago)", - expression: "Offset(Count, -2)", - }, - { - name: "Count (% vs 2 weeks ago)", - expression: "Count / Offset(Count, -2) - 1", - }, - ]); - }); - - describe("single aggregation", () => { - it("no breakout", () => { + describe("no aggregations", () => { + it("does not show column compare shortcut", () => { createQuestion( - { query: QUERY_SINGLE_AGGREGATION_NO_BREAKOUT }, + { query: QUERY_NO_AGGREGATION }, { visitQuestion: true, wrapId: true, idAlias: "questionId" }, ); - const info = { - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - presets: ["Previous month", "Previous year"], - offsetHelp: "ago", - }; - - verifySummarizeText(info); - verifyColumnDrillText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); - }); - - verifyBreakoutExistsAndIsFirst({ - column: "Created At", - bucket: "Month", - }); - - verifyAggregations([ - { - name: "Count (previous month)", - expression: "Offset(Count, -1)", - }, - { - name: "Count (vs previous month)", - expression: "Count - Offset(Count, -1)", - }, - { - name: "Count (% vs previous month)", - expression: "Count / Offset(Count, -1) - 1", - }, - ]); - }); - - it("breakout on binned datetime column", () => { - createQuestion( - { query: QUERY_SINGLE_AGGREGATION_BINNED_DATETIME_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - const info = { - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - presets: ["Previous month", "Previous year"], - offsetHelp: "ago", - }; - - verifySummarizeText(info); - - tableHeaderClick("Created At: Month"); + cy.log("chill mode - summarize sidebar"); + cy.button("Summarize").click(); + rightSidebar().button("Count").icon("close").click(); + rightSidebar().button("Add aggregation").click(); verifyNoColumnCompareShortcut(); - verifyColumnDrillText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); - }); - - verifyAggregations([ - { - name: "Count (previous month)", - expression: "Offset(Count, -1)", - }, - { - name: "Count (vs previous month)", - expression: "Count - Offset(Count, -1)", - }, - { - name: "Count (% vs previous month)", - expression: "Count / Offset(Count, -1) - 1", - }, - ]); - verifyBreakoutExistsAndIsFirst({ - column: "Created At", - bucket: "Month", - }); - - verifyColumns([ - "Count (previous month)", - "Count (vs previous month)", - "Count (% vs previous month)", - ]); - }); - - it("breakout on non-binned datetime column", () => { - createQuestion( - { query: QUERY_SINGLE_AGGREGATION_NON_BINNED_DATETIME_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - const info = { - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - presets: ["Previous month", "Previous year"], - offsetHelp: "ago", - }; - - verifySummarizeText(info); - - tableHeaderClick("Created At: Day"); + cy.log("chill mode - column drill"); + tableHeaderClick("Title"); verifyNoColumnCompareShortcut(); - verifyColumnDrillText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); - }); - - verifyAggregations([ - { - name: "Count (previous period)", - expression: "Offset(Count, -1)", - }, - { - name: "Count (vs previous period)", - expression: "Count - Offset(Count, -1)", - }, - { - name: "Count (% vs previous period)", - expression: "Count / Offset(Count, -1) - 1", - }, - ]); - - verifyColumns([ - "Count (previous period)", - "Count (vs previous period)", - "Count (% vs previous period)", - ]); - }); - - it("breakout on non-datetime column", () => { - createQuestion( - { query: QUERY_SINGLE_AGGREGATION_NON_DATETIME_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - const info = { - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - presets: ["Previous month", "Previous year"], - offsetHelp: "ago", - }; - - verifySummarizeText(info); - - tableHeaderClick("Category"); + cy.log("chill mode - plus button"); + cy.button("Add column").click(); verifyNoColumnCompareShortcut(); - verifyColumnDrillText(info); - verifyPlusButtonText(info); - + cy.log("notebook editor"); openNotebook(); - cy.button("Summarize").click(); verifyNoColumnCompareShortcut(); - cy.realPress("Escape"); - - cy.button("Show Visualization").click(); - queryBuilderMain().findByText("42").should("be.visible"); - - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); - }); - - verifyAggregations([ - { - name: "Count (previous month)", - expression: "Offset(Count, -1)", - }, - { - name: "Count (vs previous month)", - expression: "Count - Offset(Count, -1)", - }, - { - name: "Count (% vs previous month)", - expression: "Count / Offset(Count, -1) - 1", - }, - ]); - - verifyBreakoutExistsAndIsFirst({ - column: "Created At", - bucket: "Month", - }); - - verifyColumns([ - "Count (previous month)", - "Count (vs previous month)", - "Count (% vs previous month)", - ]); - }); - - it("breakout on temporal column which is an expression", () => { - createQuestion( - { query: QUERY_TEMPORAL_EXPRESSION_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - const info = { - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - presets: ["Previous month", "Previous year"], - offsetHelp: "ago", - }; - - verifySummarizeText(info); - - tableHeaderClick("Created At plus one month: Month"); - verifyNoColumnCompareShortcut(); - - verifyColumnDrillText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); - }); - - verifyAggregations([ - { - name: "Count (previous month)", - expression: "Offset(Count, -1)", - }, - { - name: "Count (vs previous month)", - expression: "Count - Offset(Count, -1)", - }, - { - name: "Count (% vs previous month)", - expression: "Count / Offset(Count, -1) - 1", - }, - ]); - - verifyBreakoutExistsAndIsFirst({ - column: "Created At plus one month", - bucket: "Month", - }); - - verifyColumns([ - "Count (previous month)", - "Count (vs previous month)", - "Count (% vs previous month)", - ]); - }); - - it("multiple breakouts", () => { - createQuestion( - { query: QUERY_MULTIPLE_BREAKOUTS }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - const info = { - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - presets: ["Previous month", "Previous year"], - offsetHelp: "ago", - }; - - verifySummarizeText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); - }); - - verifyAggregations([ - { - name: "Count (previous month)", - expression: "Offset(Count, -1)", - }, - { - name: "Count (vs previous month)", - expression: "Count - Offset(Count, -1)", - }, - { - name: "Count (% vs previous month)", - expression: "Count / Offset(Count, -1) - 1", - }, - ]); - - verifyBreakoutExistsAndIsFirst({ - column: "Created At", - bucket: "Month", - }); - breakout({ column: "Category" }).should("exist"); - - verifyColumns([ - "Count (previous month)", - "Count (vs previous month)", - "Count (% vs previous month)", - ]); - }); - - it("multiple temporal breakouts", () => { - createQuestion( - { query: QUERY_MULTIPLE_TEMPORAL_BREAKOUTS }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - const info = { - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - presets: ["Previous month", "Previous year"], - offsetHelp: "ago", - }; - - verifySummarizeText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); - }); - - verifyAggregations([ - { - name: "Count (previous month)", - expression: "Offset(Count, -1)", - }, - { - name: "Count (vs previous month)", - expression: "Count - Offset(Count, -1)", - }, - { - name: "Count (% vs previous month)", - expression: "Count / Offset(Count, -1) - 1", - }, - ]); - - verifyBreakoutExistsAndIsFirst({ - column: "Created At", - bucket: "Month", - }); - breakout({ column: "Category" }).should("exist"); - breakout({ column: "Created At" }).should("exist"); - - verifyColumns([ - "Count (previous month)", - "Count (vs previous month)", - "Count (% vs previous month)", - ]); - }); - - it("one breakout on non-default datetime column", () => { - createQuestion( - { query: QUERY_SINGLE_AGGREGATION_OTHER_DATETIME }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - const info = { - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - presets: ["Previous month", "Previous year"], - offsetHelp: "ago", - }; - - verifySummarizeText(info); - - tableHeaderClick("Count"); - verifyNoColumnCompareShortcut(); - - verifyColumnDrillText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); - }); - - verifyAggregations([ - { - name: "Count (previous month)", - expression: "Offset(Count, -1)", - }, - { - name: "Count (vs previous month)", - expression: "Count - Offset(Count, -1)", - }, - { - name: "Count (% vs previous month)", - expression: "Count / Offset(Count, -1) - 1", - }, - ]); - - verifyBreakoutExistsAndIsFirst({ - column: "User → Created At", - bucket: "Month", - }); - breakout({ column: "Created At", bucket: "Month" }).should("not.exist"); - - verifyColumns([ - "Count (previous month)", - "Count (vs previous month)", - "Count (% vs previous month)", - ]); }); }); - describe("multiple aggregations", () => { - it("no breakout", () => { - createQuestion( - { query: QUERY_MULTIPLE_AGGREGATIONS_NO_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - const info = { - itemName: "Compare to the past", - step1Title: "Compare one of these to the past", - step2Title: "Compare “Count†to the past", - presets: ["Previous month", "Previous year"], - offsetHelp: "ago", - }; - - verifySummarizeText(info); - verifyColumnDrillText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); - }); - - verifyBreakoutExistsAndIsFirst({ - column: "Created At", - bucket: "Month", - }); - verifyAggregations([ - { - name: "Count (previous month)", - expression: "Offset(Count, -1)", - }, - { - name: "Count (vs previous month)", - expression: "Count - Offset(Count, -1)", - }, - { - name: "Count (% vs previous month)", - expression: "Count / Offset(Count, -1) - 1", - }, - ]); - }); - - it("breakout on binned datetime column", () => { - createQuestion( - { query: QUERY_MULTIPLE_AGGREGATIONS_BINNED_DATETIME_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - const info = { - itemName: "Compare to the past", - step1Title: "Compare one of these to the past", - step2Title: "Compare “Count†to the past", - presets: ["Previous month", "Previous year"], - offsetHelp: "ago", - }; - - verifySummarizeText(info); - - tableHeaderClick("Created At: Month"); - verifyNoColumnCompareShortcut(); - - verifyColumnDrillText(_.omit(info, "step1Title")); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); + describe("no temporal columns", () => { + beforeEach(() => { + cy.request("PUT", `/api/field/${PRODUCTS.CREATED_AT}`, { + base_type: "type/Text", }); - - verifyAggregations([ - { - name: "Count (previous month)", - expression: "Offset(Count, -1)", - }, - { - name: "Count (vs previous month)", - expression: "Count - Offset(Count, -1)", - }, - { - name: "Count (% vs previous month)", - expression: "Count / Offset(Count, -1) - 1", - }, - ]); - - verifyColumns([ - "Count (previous month)", - "Count (vs previous month)", - "Count (% vs previous month)", - ]); }); - it("breakout on non-binned datetime column", () => { - createQuestion( - { query: QUERY_MULTIPLE_AGGREGATIONS_NON_BINNED_DATETIME_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - const info = { - itemName: "Compare to the past", - step1Title: "Compare one of these to the past", - step2Title: "Compare “Count†to the past", - presets: ["Previous month", "Previous year"], - offsetHelp: "ago", - }; - - verifySummarizeText(info); - - tableHeaderClick("Created At: Day"); - verifyNoColumnCompareShortcut(); - - verifyColumnDrillText(_.omit(info, "step1Title")); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); - }); - - verifyAggregations([ - { - name: "Count (previous period)", - expression: "Offset(Count, -1)", - }, - { - name: "Count (vs previous period)", - expression: "Count - Offset(Count, -1)", - }, - { - name: "Count (% vs previous period)", - expression: "Count / Offset(Count, -1) - 1", - }, - ]); - - verifyColumns([ - "Count (previous period)", - "Count (vs previous period)", - "Count (% vs previous period)", - ]); - }); - - it("breakout on non-datetime column", () => { + it("no breakout", () => { createQuestion( - { query: QUERY_MULTIPLE_AGGREGATIONS_NON_DATETIME_BREAKOUT }, + { query: QUERY_NO_AGGREGATION }, { visitQuestion: true, wrapId: true, idAlias: "questionId" }, ); - const info = { - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - step1Title: "Compare one of these to the past", - presets: ["Previous month", "Previous year"], - offsetHelp: "ago", - }; - - verifySummarizeText(info); - - tableHeaderClick("Category"); + cy.log("chill mode - summarize sidebar"); + cy.button("Summarize").click(); + rightSidebar().button("Count").icon("close").click(); + rightSidebar().button("Add aggregation").click(); verifyNoColumnCompareShortcut(); - verifyColumnDrillText(_.omit(info, "step1Title")); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); - }); - - verifyAggregations([ - { - name: "Count (previous month)", - expression: "Offset(Count, -1)", - }, - { - name: "Count (vs previous month)", - expression: "Count - Offset(Count, -1)", - }, - { - name: "Count (% vs previous month)", - expression: "Count / Offset(Count, -1) - 1", - }, - ]); - - verifyColumns([ - "Count (previous month)", - "Count (vs previous month)", - "Count (% vs previous month)", - ]); - }); - }); - }); - - describe("moving average", () => { - it("should be possible to change the temporal bucket with a custom offset", () => { - createQuestion( - { query: QUERY_SINGLE_AGGREGATION_NO_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); + cy.log("chill mode - column drill"); + tableHeaderClick("Title"); + verifyNoColumnCompareShortcut(); - openNotebook(); - getNotebookStep("summarize") - .findAllByTestId("aggregate-step") - .last() - .icon("add") - .click(); + cy.log("chill mode - plus button"); + cy.button("Add column").click(); + verifyNoColumnCompareShortcut(); - popover().within(() => { - cy.findByText("Basic Metrics").click(); - cy.findByText("Compare to the past").click(); + cy.log("notebook editor"); + openNotebook(); + cy.button("Summarize").click(); + verifyNoColumnCompareShortcut(); + }); - cy.findByText("Moving average").click(); + it("one breakout", () => { + createQuestion( + { query: QUERY_SINGLE_AGGREGATION_NON_DATETIME_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); - cy.findByLabelText("Offset").clear().type("3"); - cy.findByLabelText("Unit").click(); - }); + cy.log("chill mode - summarize sidebar"); + cy.button("Summarize").click(); + rightSidebar().button("Count").icon("close").click(); + rightSidebar().button("Add aggregation").click(); + verifyNoColumnCompareShortcut(); - popover().last().findByText("Week").click(); + cy.log("chill mode - column drill"); + tableHeaderClick("Category"); + verifyNoColumnCompareShortcut(); - popover().within(() => { - cy.findByText("Done").click(); - }); + cy.log("chill mode - plus button"); + cy.button("Add column").click(); + verifyNoColumnCompareShortcut(); - verifyBreakoutExistsAndIsFirst({ - column: "Created At", - bucket: "Week", + cy.log("notebook editor"); + openNotebook(); + cy.button("Summarize").click(); + verifyNoColumnCompareShortcut(); }); - - verifyAggregations([ - { - name: "Count (3-week moving average)", - expression: - "(Offset(Count, -1) + Offset(Count, -2) + Offset(Count, -3)) / 3", - }, - { - name: "Count (% vs 3-week moving average)", - expression: - "Count / ((Offset(Count, -1) + Offset(Count, -2) + Offset(Count, -3)) / 3)", - }, - ]); }); - describe("single aggregation", () => { - it("no breakout", () => { + describe("offset", () => { + it("should be possible to change the temporal bucket through a preset", () => { createQuestion( { query: QUERY_SINGLE_AGGREGATION_NO_BREAKOUT }, { visitQuestion: true, wrapId: true, idAlias: "questionId" }, ); - const info = { - type: "moving-average" as const, - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - offsetHelp: "moving average", - }; - - verifySummarizeText(info); - verifyColumnDrillText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); + openNotebook(); + getNotebookStep("summarize") + .findAllByTestId("aggregate-step") + .last() + .icon("add") + .click(); + + popover().within(() => { + cy.findByText("Basic Metrics").click(); + cy.findByText("Compare to the past").click(); + + cy.findByText("Previous year").click(); + cy.findByText("Done").click(); }); verifyBreakoutExistsAndIsFirst({ column: "Created At", - bucket: "Month", + bucket: "Year", }); verifyAggregations([ { - name: "Count (2-month moving average)", - expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (vs 2-month moving average)", - expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + name: "Count (previous year)", + expression: "Offset(Count, -1)", }, { - name: "Count (% vs 2-month moving average)", - expression: "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + name: "Count (% vs previous year)", + expression: "Count / Offset(Count, -1) - 1", }, ]); - - verifyColumns([ - "Count (2-month moving average)", - "Count (vs 2-month moving average)", - "Count (% vs 2-month moving average)", - ]); }); - it("breakout on binned datetime column", () => { + it("should be possible to change the temporal bucket with a custom offset", () => { createQuestion( - { query: QUERY_SINGLE_AGGREGATION_BINNED_DATETIME_BREAKOUT }, + { query: QUERY_SINGLE_AGGREGATION_NO_BREAKOUT }, { visitQuestion: true, wrapId: true, idAlias: "questionId" }, ); - const info = { - type: "moving-average" as const, - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - offsetHelp: "moving average", - }; + openNotebook(); + getNotebookStep("summarize") + .findAllByTestId("aggregate-step") + .last() + .icon("add") + .click(); - verifySummarizeText(info); + popover().within(() => { + cy.findByText("Basic Metrics").click(); + cy.findByText("Compare to the past").click(); - tableHeaderClick("Created At: Month"); - verifyNoColumnCompareShortcut(); + cy.findByText("Custom...").click(); - verifyColumnDrillText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); + cy.findByLabelText("Offset").clear().type("2"); + cy.findByLabelText("Unit").click(); + }); - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); + popover().last().findByText("Weeks").click(); - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); + popover().within(() => { + cy.findByText("Done").click(); + }); + + verifyBreakoutExistsAndIsFirst({ + column: "Created At", + bucket: "Week", }); verifyAggregations([ { - name: "Count (2-month moving average)", - expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (vs 2-month moving average)", - expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + name: "Count (2 weeks ago)", + expression: "Offset(Count, -2)", }, { - name: "Count (% vs 2-month moving average)", - expression: "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + name: "Count (% vs 2 weeks ago)", + expression: "Count / Offset(Count, -2) - 1", }, ]); - - verifyBreakoutExistsAndIsFirst({ - column: "Created At", - bucket: "Month", - }); - - verifyColumns([ - "Count (2-month moving average)", - "Count (vs 2-month moving average)", - "Count (% vs 2-month moving average)", - ]); }); - it("breakout on non-binned datetime column", () => { - createQuestion( - { query: QUERY_SINGLE_AGGREGATION_NON_BINNED_DATETIME_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - const info = { - type: "moving-average" as const, - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - offsetHelp: "moving average", - }; - - verifySummarizeText(info); + describe("single aggregation", () => { + it("no breakout", () => { + createQuestion( + { query: QUERY_SINGLE_AGGREGATION_NO_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + presets: ["Previous month", "Previous year"], + offsetHelp: "ago", + }; + + verifySummarizeText(info); + verifyColumnDrillText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - tableHeaderClick("Created At: Day"); - verifyNoColumnCompareShortcut(); + verifyBreakoutExistsAndIsFirst({ + column: "Created At", + bucket: "Month", + }); - verifyColumnDrillText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); + verifyAggregations([ + { + name: "Count (previous month)", + expression: "Offset(Count, -1)", + }, + { + name: "Count (vs previous month)", + expression: "Count - Offset(Count, -1)", + }, + { + name: "Count (% vs previous month)", + expression: "Count / Offset(Count, -1) - 1", + }, + ]); + }); - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); + it("breakout on binned datetime column", () => { + createQuestion( + { query: QUERY_SINGLE_AGGREGATION_BINNED_DATETIME_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + presets: ["Previous month", "Previous year"], + offsetHelp: "ago", + }; + + verifySummarizeText(info); + + tableHeaderClick("Created At: Month"); + verifyNoColumnCompareShortcut(); + + verifyColumnDrillText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, - database_id: SAMPLE_DB_ID, - question_id: questionId, + verifyAggregations([ + { + name: "Count (previous month)", + expression: "Offset(Count, -1)", + }, + { + name: "Count (vs previous month)", + expression: "Count - Offset(Count, -1)", + }, + { + name: "Count (% vs previous month)", + expression: "Count / Offset(Count, -1) - 1", + }, + ]); + verifyBreakoutExistsAndIsFirst({ + column: "Created At", + bucket: "Month", }); + + verifyColumns([ + "Count (previous month)", + "Count (vs previous month)", + "Count (% vs previous month)", + ]); }); - verifyAggregations([ - { - name: "Count (2-period moving average)", - expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (vs 2-period moving average)", - expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (% vs 2-period moving average)", - expression: "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", - }, - ]); + it("breakout on non-binned datetime column", () => { + createQuestion( + { query: QUERY_SINGLE_AGGREGATION_NON_BINNED_DATETIME_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + presets: ["Previous month", "Previous year"], + offsetHelp: "ago", + }; + + verifySummarizeText(info); + + tableHeaderClick("Created At: Day"); + verifyNoColumnCompareShortcut(); + + verifyColumnDrillText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - verifyBreakoutExistsAndIsFirst({ - column: "Created At", + verifyAggregations([ + { + name: "Count (previous period)", + expression: "Offset(Count, -1)", + }, + { + name: "Count (vs previous period)", + expression: "Count - Offset(Count, -1)", + }, + { + name: "Count (% vs previous period)", + expression: "Count / Offset(Count, -1) - 1", + }, + ]); + + verifyColumns([ + "Count (previous period)", + "Count (vs previous period)", + "Count (% vs previous period)", + ]); }); - verifyColumns([ - "Count (2-period moving average)", - "Count (vs 2-period moving average)", - "Count (% vs 2-period moving average)", - ]); - }); - - it("breakout on non-datetime column", () => { - createQuestion( - { query: QUERY_SINGLE_AGGREGATION_NON_DATETIME_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); + it("breakout on non-datetime column", () => { + createQuestion( + { query: QUERY_SINGLE_AGGREGATION_NON_DATETIME_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); - const info = { - type: "moving-average" as const, - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - offsetHelp: "moving average", - }; + const info = { + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + presets: ["Previous month", "Previous year"], + offsetHelp: "ago", + }; - verifySummarizeText(info); + verifySummarizeText(info); - tableHeaderClick("Category"); - verifyNoColumnCompareShortcut(); + tableHeaderClick("Category"); + verifyNoColumnCompareShortcut(); - verifyColumnDrillText(info); - verifyPlusButtonText(info); + verifyColumnDrillText(info); + verifyPlusButtonText(info); - openNotebook(); + openNotebook(); - cy.button("Summarize").click(); - verifyNoColumnCompareShortcut(); - cy.realPress("Escape"); + cy.button("Summarize").click(); + verifyNoColumnCompareShortcut(); + cy.realPress("Escape"); - cy.button("Show Visualization").click(); - queryBuilderMain().findByText("42").should("be.visible"); + cy.button("Show Visualization").click(); + queryBuilderMain().findByText("42").should("be.visible"); - verifyNotebookText(info); + verifyNotebookText(info); - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, - database_id: SAMPLE_DB_ID, - question_id: questionId, + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); }); - }); - verifyAggregations([ - { - name: "Count (2-month moving average)", - expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (vs 2-month moving average)", - expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (% vs 2-month moving average)", - expression: "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", - }, - ]); + verifyAggregations([ + { + name: "Count (previous month)", + expression: "Offset(Count, -1)", + }, + { + name: "Count (vs previous month)", + expression: "Count - Offset(Count, -1)", + }, + { + name: "Count (% vs previous month)", + expression: "Count / Offset(Count, -1) - 1", + }, + ]); + + verifyBreakoutExistsAndIsFirst({ + column: "Created At", + bucket: "Month", + }); - verifyBreakoutExistsAndIsFirst({ - column: "Created At", - bucket: "Month", + verifyColumns([ + "Count (previous month)", + "Count (vs previous month)", + "Count (% vs previous month)", + ]); }); - verifyColumns([ - "Count (2-month moving average)", - "Count (vs 2-month moving average)", - "Count (% vs 2-month moving average)", - ]); - }); - - it("multiple breakouts", () => { - createQuestion( - { query: QUERY_MULTIPLE_BREAKOUTS }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); + it("breakout on temporal column which is an expression", () => { + createQuestion( + { query: QUERY_TEMPORAL_EXPRESSION_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + presets: ["Previous month", "Previous year"], + offsetHelp: "ago", + }; + + verifySummarizeText(info); + + tableHeaderClick("Created At plus one month: Month"); + verifyNoColumnCompareShortcut(); + + verifyColumnDrillText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - const info = { - type: "moving-average" as const, - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - offsetHelp: "moving average", - }; - - verifySummarizeText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, - database_id: SAMPLE_DB_ID, - question_id: questionId, + verifyAggregations([ + { + name: "Count (previous month)", + expression: "Offset(Count, -1)", + }, + { + name: "Count (vs previous month)", + expression: "Count - Offset(Count, -1)", + }, + { + name: "Count (% vs previous month)", + expression: "Count / Offset(Count, -1) - 1", + }, + ]); + + verifyBreakoutExistsAndIsFirst({ + column: "Created At plus one month", + bucket: "Month", }); + + verifyColumns([ + "Count (previous month)", + "Count (vs previous month)", + "Count (% vs previous month)", + ]); }); - verifyAggregations([ - { - name: "Count (2-month moving average)", - expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (vs 2-month moving average)", - expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (% vs 2-month moving average)", - expression: "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", - }, - ]); + it("multiple breakouts", () => { + createQuestion( + { query: QUERY_MULTIPLE_BREAKOUTS }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + presets: ["Previous month", "Previous year"], + offsetHelp: "ago", + }; + + verifySummarizeText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - verifyBreakoutExistsAndIsFirst({ - column: "Created At", - bucket: "Month", - }); - breakout({ column: "Category" }).should("exist"); + verifyAggregations([ + { + name: "Count (previous month)", + expression: "Offset(Count, -1)", + }, + { + name: "Count (vs previous month)", + expression: "Count - Offset(Count, -1)", + }, + { + name: "Count (% vs previous month)", + expression: "Count / Offset(Count, -1) - 1", + }, + ]); + + verifyBreakoutExistsAndIsFirst({ + column: "Created At", + bucket: "Month", + }); + breakout({ column: "Category" }).should("exist"); - verifyColumns([ - "Count (2-month moving average)", - "Count (vs 2-month moving average)", - "Count (% vs 2-month moving average)", - ]); - }); + verifyColumns([ + "Count (previous month)", + "Count (vs previous month)", + "Count (% vs previous month)", + ]); + }); - it("multiple temporal breakouts", () => { - createQuestion( - { query: QUERY_MULTIPLE_TEMPORAL_BREAKOUTS }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); + it("multiple temporal breakouts", () => { + createQuestion( + { query: QUERY_MULTIPLE_TEMPORAL_BREAKOUTS }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + presets: ["Previous month", "Previous year"], + offsetHelp: "ago", + }; + + verifySummarizeText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - const info = { - type: "moving-average" as const, - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - offsetHelp: "moving average", - }; - - verifySummarizeText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, - database_id: SAMPLE_DB_ID, - question_id: questionId, + verifyAggregations([ + { + name: "Count (previous month)", + expression: "Offset(Count, -1)", + }, + { + name: "Count (vs previous month)", + expression: "Count - Offset(Count, -1)", + }, + { + name: "Count (% vs previous month)", + expression: "Count / Offset(Count, -1) - 1", + }, + ]); + + verifyBreakoutExistsAndIsFirst({ + column: "Created At", + bucket: "Month", }); + breakout({ column: "Category" }).should("exist"); + breakout({ column: "Created At" }).should("exist"); + + verifyColumns([ + "Count (previous month)", + "Count (vs previous month)", + "Count (% vs previous month)", + ]); }); - verifyAggregations([ - { - name: "Count (2-month moving average)", - expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (vs 2-month moving average)", - expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (% vs 2-month moving average)", - expression: "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", - }, - ]); + it("one breakout on non-default datetime column", () => { + createQuestion( + { query: QUERY_SINGLE_AGGREGATION_OTHER_DATETIME }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + presets: ["Previous month", "Previous year"], + offsetHelp: "ago", + }; + + verifySummarizeText(info); + + tableHeaderClick("Count"); + verifyNoColumnCompareShortcut(); + + verifyColumnDrillText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - verifyBreakoutExistsAndIsFirst({ - column: "Created At", - bucket: "Month", + verifyAggregations([ + { + name: "Count (previous month)", + expression: "Offset(Count, -1)", + }, + { + name: "Count (vs previous month)", + expression: "Count - Offset(Count, -1)", + }, + { + name: "Count (% vs previous month)", + expression: "Count / Offset(Count, -1) - 1", + }, + ]); + + verifyBreakoutExistsAndIsFirst({ + column: "User → Created At", + bucket: "Month", + }); + breakout({ column: "Created At", bucket: "Month" }).should( + "not.exist", + ); + + verifyColumns([ + "Count (previous month)", + "Count (vs previous month)", + "Count (% vs previous month)", + ]); }); - breakout({ column: "Category" }).should("exist"); - - verifyColumns([ - "Count (2-month moving average)", - "Count (vs 2-month moving average)", - "Count (% vs 2-month moving average)", - ]); }); - it("one breakout on non-default datetime column", () => { - createQuestion( - { query: QUERY_SINGLE_AGGREGATION_OTHER_DATETIME }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); - - const info = { - type: "moving-average" as const, - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - offsetHelp: "moving average", - }; - - verifySummarizeText(info); + describe("multiple aggregations", () => { + it("no breakout", () => { + createQuestion( + { query: QUERY_MULTIPLE_AGGREGATIONS_NO_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + itemName: "Compare to the past", + step1Title: "Compare one of these to the past", + step2Title: "Compare “Count†to the past", + presets: ["Previous month", "Previous year"], + offsetHelp: "ago", + }; + + verifySummarizeText(info); + verifyColumnDrillText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - tableHeaderClick("Count"); - verifyNoColumnCompareShortcut(); + verifyBreakoutExistsAndIsFirst({ + column: "Created At", + bucket: "Month", + }); + verifyAggregations([ + { + name: "Count (previous month)", + expression: "Offset(Count, -1)", + }, + { + name: "Count (vs previous month)", + expression: "Count - Offset(Count, -1)", + }, + { + name: "Count (% vs previous month)", + expression: "Count / Offset(Count, -1) - 1", + }, + ]); + }); - verifyColumnDrillText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); + it("breakout on binned datetime column", () => { + createQuestion( + { query: QUERY_MULTIPLE_AGGREGATIONS_BINNED_DATETIME_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + itemName: "Compare to the past", + step1Title: "Compare one of these to the past", + step2Title: "Compare “Count†to the past", + presets: ["Previous month", "Previous year"], + offsetHelp: "ago", + }; + + verifySummarizeText(info); + + tableHeaderClick("Created At: Month"); + verifyNoColumnCompareShortcut(); + + verifyColumnDrillText(_.omit(info, "step1Title")); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); + verifyAggregations([ + { + name: "Count (previous month)", + expression: "Offset(Count, -1)", + }, + { + name: "Count (vs previous month)", + expression: "Count - Offset(Count, -1)", + }, + { + name: "Count (% vs previous month)", + expression: "Count / Offset(Count, -1) - 1", + }, + ]); + + verifyColumns([ + "Count (previous month)", + "Count (vs previous month)", + "Count (% vs previous month)", + ]); + }); - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, - database_id: SAMPLE_DB_ID, - question_id: questionId, + it("breakout on non-binned datetime column", () => { + createQuestion( + { query: QUERY_MULTIPLE_AGGREGATIONS_NON_BINNED_DATETIME_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + itemName: "Compare to the past", + step1Title: "Compare one of these to the past", + step2Title: "Compare “Count†to the past", + presets: ["Previous month", "Previous year"], + offsetHelp: "ago", + }; + + verifySummarizeText(info); + + tableHeaderClick("Created At: Day"); + verifyNoColumnCompareShortcut(); + + verifyColumnDrillText(_.omit(info, "step1Title")); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); }); + + verifyAggregations([ + { + name: "Count (previous period)", + expression: "Offset(Count, -1)", + }, + { + name: "Count (vs previous period)", + expression: "Count - Offset(Count, -1)", + }, + { + name: "Count (% vs previous period)", + expression: "Count / Offset(Count, -1) - 1", + }, + ]); + + verifyColumns([ + "Count (previous period)", + "Count (vs previous period)", + "Count (% vs previous period)", + ]); }); - verifyAggregations([ - { - name: "Count (2-month moving average)", - expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (vs 2-month moving average)", - expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (% vs 2-month moving average)", - expression: "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", - }, - ]); + it("breakout on non-datetime column", () => { + createQuestion( + { query: QUERY_MULTIPLE_AGGREGATIONS_NON_DATETIME_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + step1Title: "Compare one of these to the past", + presets: ["Previous month", "Previous year"], + offsetHelp: "ago", + }; + + verifySummarizeText(info); + + tableHeaderClick("Category"); + verifyNoColumnCompareShortcut(); + + verifyColumnDrillText(_.omit(info, "step1Title")); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - verifyBreakoutExistsAndIsFirst({ - column: "User → Created At", - bucket: "Month", + verifyAggregations([ + { + name: "Count (previous month)", + expression: "Offset(Count, -1)", + }, + { + name: "Count (vs previous month)", + expression: "Count - Offset(Count, -1)", + }, + { + name: "Count (% vs previous month)", + expression: "Count / Offset(Count, -1) - 1", + }, + ]); + + verifyColumns([ + "Count (previous month)", + "Count (vs previous month)", + "Count (% vs previous month)", + ]); }); - breakout({ column: "Created At", bucket: "Month" }).should("not.exist"); - - verifyColumns([ - "Count (2-month moving average)", - "Count (vs 2-month moving average)", - "Count (% vs 2-month moving average)", - ]); }); }); - describe("multiple aggregations", () => { - it("no breakout", () => { + describe("moving average", () => { + it("should be possible to change the temporal bucket with a custom offset", () => { createQuestion( - { query: QUERY_MULTIPLE_AGGREGATIONS_NO_BREAKOUT }, + { query: QUERY_SINGLE_AGGREGATION_NO_BREAKOUT }, { visitQuestion: true, wrapId: true, idAlias: "questionId" }, ); - const info = { - type: "moving-average" as const, - itemName: "Compare to the past", - step1Title: "Compare one of these to the past", - step2Title: "Compare “Count†to the past", - offsetHelp: "moving average", - }; - - verifySummarizeText(info); - verifyColumnDrillText(info); - verifyPlusButtonText(info); - verifyNotebookText(info); - - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); - - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, - database_id: SAMPLE_DB_ID, - question_id: questionId, - }); + openNotebook(); + getNotebookStep("summarize") + .findAllByTestId("aggregate-step") + .last() + .icon("add") + .click(); + + popover().within(() => { + cy.findByText("Basic Metrics").click(); + cy.findByText("Compare to the past").click(); + + cy.findByText("Moving average").click(); + + cy.findByLabelText("Offset").clear().type("3"); + cy.findByLabelText("Unit").click(); + }); + + popover().last().findByText("Week").click(); + + popover().within(() => { + cy.findByText("Done").click(); }); verifyBreakoutExistsAndIsFirst({ column: "Created At", - bucket: "Month", + bucket: "Week", }); + verifyAggregations([ { - name: "Count (2-month moving average)", - expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (vs 2-month moving average)", - expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + name: "Count (3-week moving average)", + expression: + "(Offset(Count, -1) + Offset(Count, -2) + Offset(Count, -3)) / 3", }, { - name: "Count (% vs 2-month moving average)", - expression: "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + name: "Count (% vs 3-week moving average)", + expression: + "Count / ((Offset(Count, -1) + Offset(Count, -2) + Offset(Count, -3)) / 3)", }, ]); - - verifyColumns([ - "Count (2-month moving average)", - "Count (vs 2-month moving average)", - "Count (% vs 2-month moving average)", - ]); }); - it("breakout on binned datetime column", () => { - createQuestion( - { query: QUERY_MULTIPLE_AGGREGATIONS_BINNED_DATETIME_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); + describe("single aggregation", () => { + it("no breakout", () => { + createQuestion( + { query: QUERY_SINGLE_AGGREGATION_NO_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + type: "moving-average" as const, + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + offsetHelp: "moving average", + }; + + verifySummarizeText(info); + verifyColumnDrillText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); + + verifyBreakoutExistsAndIsFirst({ + column: "Created At", + bucket: "Month", + }); - const info = { - type: "moving-average" as const, - itemName: "Compare to the past", - step1Title: "Compare one of these to the past", - step2Title: "Compare “Count†to the past", - offsetHelp: "moving average", - }; + verifyAggregations([ + { + name: "Count (2-month moving average)", + expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (vs 2-month moving average)", + expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (% vs 2-month moving average)", + expression: + "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + }, + ]); + + verifyColumns([ + "Count (2-month moving average)", + "Count (vs 2-month moving average)", + "Count (% vs 2-month moving average)", + ]); + }); - verifySummarizeText(info); + it("breakout on binned datetime column", () => { + createQuestion( + { query: QUERY_SINGLE_AGGREGATION_BINNED_DATETIME_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + type: "moving-average" as const, + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + offsetHelp: "moving average", + }; + + verifySummarizeText(info); + + tableHeaderClick("Created At: Month"); + verifyNoColumnCompareShortcut(); + + verifyColumnDrillText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - tableHeaderClick("Created At: Month"); - verifyNoColumnCompareShortcut(); + verifyAggregations([ + { + name: "Count (2-month moving average)", + expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (vs 2-month moving average)", + expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (% vs 2-month moving average)", + expression: + "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + }, + ]); + + verifyBreakoutExistsAndIsFirst({ + column: "Created At", + bucket: "Month", + }); - verifyColumnDrillText(_.omit(info, "step1Title")); - verifyPlusButtonText(info); - verifyNotebookText(info); + verifyColumns([ + "Count (2-month moving average)", + "Count (vs 2-month moving average)", + "Count (% vs 2-month moving average)", + ]); + }); - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); + it("breakout on non-binned datetime column", () => { + createQuestion( + { query: QUERY_SINGLE_AGGREGATION_NON_BINNED_DATETIME_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + type: "moving-average" as const, + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + offsetHelp: "moving average", + }; + + verifySummarizeText(info); + + tableHeaderClick("Created At: Day"); + verifyNoColumnCompareShortcut(); + + verifyColumnDrillText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, - database_id: SAMPLE_DB_ID, - question_id: questionId, + verifyAggregations([ + { + name: "Count (2-period moving average)", + expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (vs 2-period moving average)", + expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (% vs 2-period moving average)", + expression: + "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + }, + ]); + + verifyBreakoutExistsAndIsFirst({ + column: "Created At", }); + + verifyColumns([ + "Count (2-period moving average)", + "Count (vs 2-period moving average)", + "Count (% vs 2-period moving average)", + ]); }); - verifyAggregations([ - { - name: "Count (2-month moving average)", - expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (vs 2-month moving average)", - expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (% vs 2-month moving average)", - expression: "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", - }, - ]); + it("breakout on non-datetime column", () => { + createQuestion( + { query: QUERY_SINGLE_AGGREGATION_NON_DATETIME_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); - verifyColumns([ - "Count (2-month moving average)", - "Count (vs 2-month moving average)", - "Count (% vs 2-month moving average)", - ]); - }); + const info = { + type: "moving-average" as const, + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + offsetHelp: "moving average", + }; - it("breakout on non-binned datetime column", () => { - createQuestion( - { query: QUERY_MULTIPLE_AGGREGATIONS_NON_BINNED_DATETIME_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); + verifySummarizeText(info); - const info = { - type: "moving-average" as const, - itemName: "Compare to the past", - step1Title: "Compare one of these to the past", - step2Title: "Compare “Count†to the past", - offsetHelp: "moving average", - }; + tableHeaderClick("Category"); + verifyNoColumnCompareShortcut(); - verifySummarizeText(info); + verifyColumnDrillText(info); + verifyPlusButtonText(info); - tableHeaderClick("Created At: Day"); - verifyNoColumnCompareShortcut(); + openNotebook(); + + cy.button("Summarize").click(); + verifyNoColumnCompareShortcut(); + cy.realPress("Escape"); + + cy.button("Show Visualization").click(); + queryBuilderMain().findByText("42").should("be.visible"); + + verifyNotebookText(info); - verifyColumnDrillText(_.omit(info, "step1Title")); - verifyPlusButtonText(info); - verifyNotebookText(info); + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, - database_id: SAMPLE_DB_ID, - question_id: questionId, + verifyAggregations([ + { + name: "Count (2-month moving average)", + expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (vs 2-month moving average)", + expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (% vs 2-month moving average)", + expression: + "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + }, + ]); + + verifyBreakoutExistsAndIsFirst({ + column: "Created At", + bucket: "Month", }); + + verifyColumns([ + "Count (2-month moving average)", + "Count (vs 2-month moving average)", + "Count (% vs 2-month moving average)", + ]); }); - verifyAggregations([ - { - name: "Count (2-period moving average)", - expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (vs 2-period moving average)", - expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (% vs 2-period moving average)", - expression: "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", - }, - ]); + it("multiple breakouts", () => { + createQuestion( + { query: QUERY_MULTIPLE_BREAKOUTS }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + type: "moving-average" as const, + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + offsetHelp: "moving average", + }; + + verifySummarizeText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - verifyColumns([ - "Count (2-period moving average)", - "Count (vs 2-period moving average)", - "Count (% vs 2-period moving average)", - ]); - }); + verifyAggregations([ + { + name: "Count (2-month moving average)", + expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (vs 2-month moving average)", + expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (% vs 2-month moving average)", + expression: + "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + }, + ]); + + verifyBreakoutExistsAndIsFirst({ + column: "Created At", + bucket: "Month", + }); + breakout({ column: "Category" }).should("exist"); - it("breakout on non-datetime column", () => { - createQuestion( - { query: QUERY_MULTIPLE_AGGREGATIONS_NON_DATETIME_BREAKOUT }, - { visitQuestion: true, wrapId: true, idAlias: "questionId" }, - ); + verifyColumns([ + "Count (2-month moving average)", + "Count (vs 2-month moving average)", + "Count (% vs 2-month moving average)", + ]); + }); + + it("multiple temporal breakouts", () => { + createQuestion( + { query: QUERY_MULTIPLE_TEMPORAL_BREAKOUTS }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + type: "moving-average" as const, + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + offsetHelp: "moving average", + }; + + verifySummarizeText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - const info = { - type: "moving-average" as const, - itemName: "Compare to the past", - step2Title: "Compare “Count†to the past", - step1Title: "Compare one of these to the past", - presets: ["Previous month", "Previous year"], - offsetHelp: "moving average", - }; + verifyAggregations([ + { + name: "Count (2-month moving average)", + expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (vs 2-month moving average)", + expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (% vs 2-month moving average)", + expression: + "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + }, + ]); + + verifyBreakoutExistsAndIsFirst({ + column: "Created At", + bucket: "Month", + }); + breakout({ column: "Category" }).should("exist"); - verifySummarizeText(info); + verifyColumns([ + "Count (2-month moving average)", + "Count (vs 2-month moving average)", + "Count (% vs 2-month moving average)", + ]); + }); - tableHeaderClick("Category"); - verifyNoColumnCompareShortcut(); + it("one breakout on non-default datetime column", () => { + createQuestion( + { query: QUERY_SINGLE_AGGREGATION_OTHER_DATETIME }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + type: "moving-average" as const, + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + offsetHelp: "moving average", + }; + + verifySummarizeText(info); + + tableHeaderClick("Count"); + verifyNoColumnCompareShortcut(); + + verifyColumnDrillText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - verifyColumnDrillText(_.omit(info, "step1Title")); - verifyPlusButtonText(info); - verifyNotebookText(info); + verifyAggregations([ + { + name: "Count (2-month moving average)", + expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (vs 2-month moving average)", + expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (% vs 2-month moving average)", + expression: + "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + }, + ]); + + verifyBreakoutExistsAndIsFirst({ + column: "User → Created At", + bucket: "Month", + }); + breakout({ column: "Created At", bucket: "Month" }).should( + "not.exist", + ); + + verifyColumns([ + "Count (2-month moving average)", + "Count (vs 2-month moving average)", + "Count (% vs 2-month moving average)", + ]); + }); + }); - toggleColumnPickerItems(["Value difference"]); - popover().button("Done").click(); + describe("multiple aggregations", () => { + it("no breakout", () => { + createQuestion( + { query: QUERY_MULTIPLE_AGGREGATIONS_NO_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + type: "moving-average" as const, + itemName: "Compare to the past", + step1Title: "Compare one of these to the past", + step2Title: "Compare “Count†to the past", + offsetHelp: "moving average", + }; + + verifySummarizeText(info); + verifyColumnDrillText(info); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - cy.get("@questionId").then(questionId => { - expectGoodSnowplowEvent({ - event: "column_compare_via_shortcut", - custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, - database_id: SAMPLE_DB_ID, - question_id: questionId, + verifyBreakoutExistsAndIsFirst({ + column: "Created At", + bucket: "Month", }); + verifyAggregations([ + { + name: "Count (2-month moving average)", + expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (vs 2-month moving average)", + expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (% vs 2-month moving average)", + expression: + "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + }, + ]); + + verifyColumns([ + "Count (2-month moving average)", + "Count (vs 2-month moving average)", + "Count (% vs 2-month moving average)", + ]); }); - verifyAggregations([ - { - name: "Count (2-month moving average)", - expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (vs 2-month moving average)", - expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", - }, - { - name: "Count (% vs 2-month moving average)", - expression: "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", - }, - ]); + it("breakout on binned datetime column", () => { + createQuestion( + { query: QUERY_MULTIPLE_AGGREGATIONS_BINNED_DATETIME_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + type: "moving-average" as const, + itemName: "Compare to the past", + step1Title: "Compare one of these to the past", + step2Title: "Compare “Count†to the past", + offsetHelp: "moving average", + }; + + verifySummarizeText(info); + + tableHeaderClick("Created At: Month"); + verifyNoColumnCompareShortcut(); + + verifyColumnDrillText(_.omit(info, "step1Title")); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); - verifyColumns([ - "Count (2-month moving average)", - "Count (vs 2-month moving average)", - "Count (% vs 2-month moving average)", - ]); + verifyAggregations([ + { + name: "Count (2-month moving average)", + expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (vs 2-month moving average)", + expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (% vs 2-month moving average)", + expression: + "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + }, + ]); + + verifyColumns([ + "Count (2-month moving average)", + "Count (vs 2-month moving average)", + "Count (% vs 2-month moving average)", + ]); + }); + + it("breakout on non-binned datetime column", () => { + createQuestion( + { query: QUERY_MULTIPLE_AGGREGATIONS_NON_BINNED_DATETIME_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + type: "moving-average" as const, + itemName: "Compare to the past", + step1Title: "Compare one of these to the past", + step2Title: "Compare “Count†to the past", + offsetHelp: "moving average", + }; + + verifySummarizeText(info); + + tableHeaderClick("Created At: Day"); + verifyNoColumnCompareShortcut(); + + verifyColumnDrillText(_.omit(info, "step1Title")); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); + + verifyAggregations([ + { + name: "Count (2-period moving average)", + expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (vs 2-period moving average)", + expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (% vs 2-period moving average)", + expression: + "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + }, + ]); + + verifyColumns([ + "Count (2-period moving average)", + "Count (vs 2-period moving average)", + "Count (% vs 2-period moving average)", + ]); + }); + + it("breakout on non-datetime column", () => { + createQuestion( + { query: QUERY_MULTIPLE_AGGREGATIONS_NON_DATETIME_BREAKOUT }, + { visitQuestion: true, wrapId: true, idAlias: "questionId" }, + ); + + const info = { + type: "moving-average" as const, + itemName: "Compare to the past", + step2Title: "Compare “Count†to the past", + step1Title: "Compare one of these to the past", + presets: ["Previous month", "Previous year"], + offsetHelp: "moving average", + }; + + verifySummarizeText(info); + + tableHeaderClick("Category"); + verifyNoColumnCompareShortcut(); + + verifyColumnDrillText(_.omit(info, "step1Title")); + verifyPlusButtonText(info); + verifyNotebookText(info); + + toggleColumnPickerItems(["Value difference"]); + popover().button("Done").click(); + + cy.get("@questionId").then(questionId => { + expectGoodSnowplowEvent({ + event: "column_compare_via_shortcut", + custom_expressions_used: CUSTOM_EXPRESSIONS_USED_MOVING_AVERAGE, + database_id: SAMPLE_DB_ID, + question_id: questionId, + }); + }); + + verifyAggregations([ + { + name: "Count (2-month moving average)", + expression: "(Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (vs 2-month moving average)", + expression: "Count - (Offset(Count, -1) + Offset(Count, -2)) / 2", + }, + { + name: "Count (% vs 2-month moving average)", + expression: + "Count / ((Offset(Count, -1) + Offset(Count, -2)) / 2)", + }, + ]); + + verifyColumns([ + "Count (2-month moving average)", + "Count (vs 2-month moving average)", + "Count (% vs 2-month moving average)", + ]); + }); }); }); }); diff --git a/frontend/src/metabase/common/components/AggregationPicker/AggregationPicker.unit.spec.tsx b/frontend/src/metabase/common/components/AggregationPicker/AggregationPicker.unit.spec.tsx index 32d5cd1ec9b..e3c5cd305f7 100644 --- a/frontend/src/metabase/common/components/AggregationPicker/AggregationPicker.unit.spec.tsx +++ b/frontend/src/metabase/common/components/AggregationPicker/AggregationPicker.unit.spec.tsx @@ -414,7 +414,8 @@ describe("AggregationPicker", () => { }); }); - describe("column compare shortcut", () => { + // eslint-disable-next-line jest/no-disabled-tests + describe.skip("column compare shortcut", () => { it("does not display the shortcut if there are no aggregations", () => { setup({ allowCustomExpressions: true, allowTemporalComparisons: true }); expect(screen.queryByText(/compare/i)).not.toBeInTheDocument(); diff --git a/frontend/src/metabase/query_builder/components/CompareAggregations/utils.ts b/frontend/src/metabase/query_builder/components/CompareAggregations/utils.ts index 05991eb5f52..a4ac122fa5f 100644 --- a/frontend/src/metabase/query_builder/components/CompareAggregations/utils.ts +++ b/frontend/src/metabase/query_builder/components/CompareAggregations/utils.ts @@ -258,10 +258,17 @@ export function updateQueryWithCompareOffsetAggregations( }; } +const DISABLED_TEMPORAL_COMPARISON_MESSAGE = true; + export function canAddTemporalCompareAggregation( query: Lib.Query, stageIndex: number, ): boolean { + if (DISABLED_TEMPORAL_COMPARISON_MESSAGE) { + // TODO: reenable temporal comparisons once we fix offset issues + return false; + } + const aggregations = Lib.aggregations(query, stageIndex); if (aggregations.length === 0) { // Hide the "Compare to the past" option if there are no aggregations diff --git a/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.unit.spec.tsx b/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.unit.spec.tsx index e4bd561cb6d..474e3198c93 100644 --- a/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.unit.spec.tsx +++ b/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.unit.spec.tsx @@ -179,7 +179,9 @@ describe("AggregateStep", () => { expect(queryIcon("add")).not.toBeInTheDocument(); }); - it("should not allow to use temporal comparisons for metrics", async () => { + // TODO: unskip this once we enable "Compare to the past" again + // eslint-disable-next-line jest/no-disabled-tests + it.skip("should not allow to use temporal comparisons for metrics", async () => { const query = createQueryWithClauses({ aggregations: [{ operatorName: "count" }], }); @@ -192,7 +194,9 @@ describe("AggregateStep", () => { expect(screen.queryByText(/compare/i)).not.toBeInTheDocument(); }); - it("should allow to use temporal comparisons for non-metrics", async () => { + // TODO: unskip this once we enable "Compare to the past" again + // eslint-disable-next-line jest/no-disabled-tests + it.skip("should allow to use temporal comparisons for non-metrics", async () => { const query = createQueryWithClauses({ aggregations: [{ operatorName: "count" }], }); -- GitLab