From 1eb9e6f6adf96b698dc03ff7e6cb39d5675d4e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atte=20Kein=C3=A4nen?= <atte.keinanen@gmail.com> Date: Fri, 2 Feb 2018 21:43:07 +0200 Subject: [PATCH] Add test case for time-multiseries that fall back to raw data alerts --- .../query_builder/components/AlertModals.jsx | 10 ++--- frontend/test/alert/alert.integ.spec.js | 41 ++++++++++++++++++- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/frontend/src/metabase/query_builder/components/AlertModals.jsx b/frontend/src/metabase/query_builder/components/AlertModals.jsx index cde53231594..de4efa3c33b 100644 --- a/frontend/src/metabase/query_builder/components/AlertModals.jsx +++ b/frontend/src/metabase/query_builder/components/AlertModals.jsx @@ -522,13 +522,11 @@ export class RawDataAlertTip extends Component { <div className="circle flex align-center justify-center bg-grey-0 p2 mr2 text-grey-3"> <Icon name="lightbulb" size="20" /> </div> - <div> - { showMultiSeriesGoalAlert - ? jt`${<strong>Heads up:</strong>} Goal-based alerts aren't yet supported for charts with more than one line, so this alert will be sent whenever the chart has ${<em>results</em>}.` - : jt`${<strong>Tip:</strong>} This kind of alert is most useful when your saved question doesn’t ${<em>usually</em>} return any results, but you want to know when it does.` - } - </div> + { showMultiSeriesGoalAlert ? <MultiSeriesAlertTip /> : <NormalAlertTip /> } </div> ) } } + +export const MultiSeriesAlertTip = () => <div>{jt`${<strong>Heads up:</strong>} Goal-based alerts aren't yet supported for charts with more than one line, so this alert will be sent whenever the chart has ${<em>results</em>}.`}</div> +export const NormalAlertTip = () => <div>{jt`${<strong>Tip:</strong>} This kind of alert is most useful when your saved question doesn’t ${<em>usually</em>} return any results, but you want to know when it does.`}</div> diff --git a/frontend/test/alert/alert.integ.spec.js b/frontend/test/alert/alert.integ.spec.js index b99503f56e6..69c9daa7311 100644 --- a/frontend/test/alert/alert.integ.spec.js +++ b/frontend/test/alert/alert.integ.spec.js @@ -24,6 +24,8 @@ import { AlertEducationalScreen, AlertSettingToggle, CreateAlertModalContent, + MultiSeriesAlertTip, + NormalAlertTip, RawDataAlertTip, UpdateAlertModalContent } from "metabase/query_builder/components/AlertModals"; @@ -73,6 +75,7 @@ describe("Alerts", () => { let rawDataQuestion = null; let timeSeriesQuestion = null; let timeSeriesWithGoalQuestion = null; + let timeMultiSeriesWithGoalQuestion = null; let progressBarQuestion = null; beforeAll(async () => { @@ -96,7 +99,7 @@ describe("Alerts", () => { Question.create({databaseId: 1, tableId: 1, metadata }) .query() .addAggregation(["count"]) - .addBreakout(["datetime-field", ["field-id", 1], "day"]) + .addBreakout(["datetime-field", ["field-id", 1], "month"]) .question() .setDisplay("line") .setVisualizationSettings({ @@ -110,7 +113,7 @@ describe("Alerts", () => { Question.create({databaseId: 1, tableId: 1, metadata }) .query() .addAggregation(["count"]) - .addBreakout(["datetime-field", ["field-id", 1], "day"]) + .addBreakout(["datetime-field", ["field-id", 1], "month"]) .question() .setDisplay("line") .setVisualizationSettings({ @@ -122,6 +125,22 @@ describe("Alerts", () => { .setDisplayName("Time series line with goal") ) + timeMultiSeriesWithGoalQuestion = await createSavedQuestion( + Question.create({databaseId: 1, tableId: 1, metadata }) + .query() + .addAggregation(["count"]) + .addAggregation(["sum", ["field-id", 6]]) + .addBreakout(["datetime-field", ["field-id", 1], "month"]) + .question() + .setDisplay("line") + .setVisualizationSettings({ + "graph.show_goal": true, + "graph.goal_value": 10, + "graph.dimensions": ["CREATED_AT"], + "graph.metrics": ["count", "sum"] + }) + .setDisplayName("Time multiseries line with goal") + ) progressBarQuestion = await createSavedQuestion( Question.create({databaseId: 1, tableId: 1, metadata }) .query() @@ -137,6 +156,7 @@ describe("Alerts", () => { await CardApi.delete({cardId: rawDataQuestion.id()}) await CardApi.delete({cardId: timeSeriesQuestion.id()}) await CardApi.delete({cardId: timeSeriesWithGoalQuestion.id()}) + await CardApi.delete({cardId: timeMultiSeriesWithGoalQuestion.id()}) await CardApi.delete({cardId: progressBarQuestion.id()}) }) @@ -270,6 +290,7 @@ describe("Alerts", () => { const alertModal = app.find(QueryHeader).find(".test-modal") const creationScreen = alertModal.find(CreateAlertModalContent) expect(creationScreen.find(RawDataAlertTip).length).toBe(1) + expect(creationScreen.find(NormalAlertTip).length).toBe(1) expect(creationScreen.find(AlertSettingToggle).length).toBe(0) clickButton(creationScreen.find(".Button.Button--primary")) @@ -317,6 +338,22 @@ describe("Alerts", () => { expect(alert.alert_above_goal).toBe(false) expect(alert.alert_first_only).toBe(true) }) + + it("should fall back to raw data alert and show a warning for time-multiseries questions with a set goal", async () => { + useSharedNormalLogin() + const { app, store } = await initQbWithAlertMenuItemClicked(timeMultiSeriesWithGoalQuestion) + + await store.waitForActions([FETCH_PULSE_FORM_INPUT]) + const alertModal = app.find(QueryHeader).find(".test-modal") + const creationScreen = alertModal.find(CreateAlertModalContent) + // console.log(creationScreen.debug()) + expect(creationScreen.find(RawDataAlertTip).length).toBe(1) + expect(creationScreen.find(MultiSeriesAlertTip).length).toBe(1) + expect(creationScreen.find(AlertSettingToggle).length).toBe(0) + + clickButton(creationScreen.find(".Button.Button--primary")) + await store.waitForActions([CREATE_ALERT]) + }) }) describe("alert list for a question", () => { -- GitLab