diff --git a/e2e/test/scenarios/native/native-reproductions.cy.spec.ts b/e2e/test/scenarios/native/native-reproductions.cy.spec.ts index 1792602e8057f1de66e61f220f1cebfe6aa26582..117879d19a9df884f0f770ea30266ad638f02fcb 100644 --- a/e2e/test/scenarios/native/native-reproductions.cy.spec.ts +++ b/e2e/test/scenarios/native/native-reproductions.cy.spec.ts @@ -1,6 +1,8 @@ +import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database"; import { adhocQuestionHash, createNativeQuestion, + createQuestion, openNativeEditor, restore, runNativeQuery, @@ -8,6 +10,7 @@ import { } from "e2e/support/helpers"; import { getRunQueryButton } from "../native-filters/helpers/e2e-sql-filter-helpers"; +const { ORDERS_ID } = SAMPLE_DATABASE; describe("issue 11727", { tags: "@external" }, () => { const PG_DB_ID = 2; @@ -155,3 +158,38 @@ describe("issue 33327", () => { cy.findByTestId("visualization-root").icon("warning").should("not.exist"); }); }); + +describe("issue 49454", () => { + beforeEach(() => { + restore(); + cy.signInAsAdmin(); + + createQuestion({ + name: "Test Metric 49454", + type: "metric", + query: { + "source-table": ORDERS_ID, + aggregation: [["count"]], + }, + }); + createQuestion({ + name: "Test Question 49454", + type: "question", + query: { + "source-table": ORDERS_ID, + aggregation: [["count"]], + }, + }); + }); + + it("should be possible to use metrics in native queries (metabase#49454)", () => { + openNativeEditor().type("select * from {{ #test"); + + cy.get(".ace_autocomplete") + .should("be.visible") + .within(() => { + cy.findByText("-question-49454").should("be.visible"); + cy.findByText("-metric-49454").should("be.visible"); + }); + }); +}); diff --git a/frontend/src/metabase/query_builder/components/NativeQueryEditor/utils.ts b/frontend/src/metabase/query_builder/components/NativeQueryEditor/utils.ts index ed4f273a694366501975587c230f3a089aea0e57..e98626ab6a9d9fee8e6682eefc410e2382550c7b 100644 --- a/frontend/src/metabase/query_builder/components/NativeQueryEditor/utils.ts +++ b/frontend/src/metabase/query_builder/components/NativeQueryEditor/utils.ts @@ -128,5 +128,9 @@ export const getAutocompleteResultMeta = ( return t`Model in ${collectionName}`; } + if (type === "metric") { + return t`Metric in ${collectionName}`; + } + throw new Error(`Unknown question.type(): ${type}`); };