diff --git a/frontend/src/metabase/qb/components/actions/CommonMetricsAction.jsx b/frontend/src/metabase/qb/components/actions/CommonMetricsAction.jsx index c76ddf793093be2f168b14ce3154bc08df95aea5..2f31a967b20b6022bead33e9d73a43e17ee1448c 100644 --- a/frontend/src/metabase/qb/components/actions/CommonMetricsAction.jsx +++ b/frontend/src/metabase/qb/components/actions/CommonMetricsAction.jsx @@ -15,7 +15,8 @@ export default ({ question }: ClickActionProps): ClickAction[] => { return []; } - return query.table().metrics.slice(0, 5).map(metric => ({ + const activeMetrics = query.table().metrics.filter(m => m.isActive()); + return activeMetrics.slice(0, 5).map(metric => ({ name: "common-metric", title: <span>View <strong>{metric.name}</strong></span>, question: () => question.summarize(["METRIC", metric.id]) diff --git a/frontend/test/query_builder/components/ActionsWidget.integ.spec.js b/frontend/test/query_builder/components/ActionsWidget.integ.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..8f60bb331d53338b7f6cff2aa2e390ac7d021f31 --- /dev/null +++ b/frontend/test/query_builder/components/ActionsWidget.integ.spec.js @@ -0,0 +1,83 @@ +import { + login, + createTestStore +} from "__support__/integrated_tests"; +import { + click +} from "__support__/enzyme_utils" + +import React from 'react' +import { mount, shallow } from 'enzyme' + +import ActionsWidget from '../../../src/metabase/query_builder/components/ActionsWidget'; +import Question from "metabase-lib/lib/Question"; +import { + DATABASE_ID, + ORDERS_TABLE_ID, + metadata +} from "__support__/sample_dataset_fixture"; +import { INITIALIZE_QB, LOAD_TABLE_METADATA, QUERY_COMPLETED } from "metabase/query_builder/actions"; +import { MetricApi } from "metabase/services"; + +const getActionsWidget = (question) => + <ActionsWidget + question={question} + card={question.card()} + setCardAndRun={() => {}} + navigateToNewCardInsideQB={() => {}} + /> + +describe('ActionsWidget', () => { + beforeAll(async () => { + await login(); + }) + + it("is visible for an empty question", () => { + const question: Question = Question.create({databaseId: DATABASE_ID, tableId: ORDERS_TABLE_ID, metadata}) + .query() + .question(); + + const component = shallow(getActionsWidget(question)); + expect(component.children().children().length).toBeGreaterThan(0); + }); + + describe("for metrics", () => { + let activeMetricId; + + beforeAll(async () => { + await login() + + const metricDef = {name: "A Metric", description: "For testing new question flow", table_id: 1,show_in_getting_started: true, + definition: {database: 1, query: {aggregation: ["count"]}}} + activeMetricId = (await MetricApi.create(metricDef)).id; + + const retiredMetricId = (await MetricApi.create(metricDef)).id; + // Retiring a metric is done with the `delete` endpoint + await MetricApi.delete({ metricId: retiredMetricId, revision_message: "Time to retire this buddy" }) + }) + + afterAll(async () => { + await MetricApi.delete({ metricId: activeMetricId, revision_message: "You are now a retired veteran too" }) + }) + + it("shows metrics for the current table, excluding the retired ones", async () => { + const url = Question.create({databaseId: DATABASE_ID, tableId: ORDERS_TABLE_ID, metadata}) + .query() + .question() + .getUrl() + + console.log(url) + const store = await createTestStore() + store.pushPath(url) + const app = mount(store.getAppContainer()); + + await store.waitForActions([INITIALIZE_QB, QUERY_COMPLETED, LOAD_TABLE_METADATA]) + + const actionsWidget = app.find(ActionsWidget) + click(actionsWidget.childAt(0)) + + expect(actionsWidget.find('strong[children="A Metric"]').length).toBe(1) + }) + }) + +}); \ No newline at end of file diff --git a/frontend/test/query_builder/components/ActionsWidget.unit.spec.js b/frontend/test/query_builder/components/ActionsWidget.unit.spec.js deleted file mode 100644 index 268e4c555a49517bf87fcae095754d40ca8c2cc1..0000000000000000000000000000000000000000 --- a/frontend/test/query_builder/components/ActionsWidget.unit.spec.js +++ /dev/null @@ -1,45 +0,0 @@ -import React from 'react' -import { shallow } from 'enzyme' - -import ActionsWidget from '../../../src/metabase/query_builder/components/ActionsWidget'; -import Question from "metabase-lib/lib/Question"; -import { - DATABASE_ID, - ORDERS_TABLE_ID, - metadata -} from "__support__/sample_dataset_fixture"; - -const getActionsWidget = (question) => - <ActionsWidget - question={question} - card={question.card()} - setCardAndRun={() => {}} - navigateToNewCardInsideQB={() => {}} - /> - -describe('ActionsWidget', () => { - describe("visibility", () => { - it("is visible for an empty question", () => { - const question: Question = Question.create({databaseId: DATABASE_ID, tableId: ORDERS_TABLE_ID, metadata}) - .query() - .question(); - - const component = shallow(getActionsWidget(question)); - expect(component.children().children().length).toBeGreaterThan(0); - }); - }) - - describe("clicking an action", () => { - pending(); - // will require changing this to an integrated test - // see Visualization.integ.spec.js for similar tests for visualization drill-through - - it("results in correct url", async () => { - // await initializeQB(); - }) - it("results in correct question name and lineage", async () => { - }) - it("results in the correct query result", async () => { - }) - }) -}); \ No newline at end of file