From c796238c1e2d4b87904bf6f26716e78fd9fde7bb Mon Sep 17 00:00:00 2001
From: Nemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com>
Date: Fri, 10 Feb 2023 15:57:48 +0100
Subject: [PATCH] Repro #25988: Cannot reference nested question as native
 subquery (#28135)

[ci skip]
---
 .../helpers/e2e-ad-hoc-question-helpers.js    | 22 +++++++++++++
 .../native/native_subquery.cy.spec.js         | 31 +++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/frontend/test/__support__/e2e/helpers/e2e-ad-hoc-question-helpers.js b/frontend/test/__support__/e2e/helpers/e2e-ad-hoc-question-helpers.js
index 6b0ce9fe5df..2ff5a272efe 100644
--- a/frontend/test/__support__/e2e/helpers/e2e-ad-hoc-question-helpers.js
+++ b/frontend/test/__support__/e2e/helpers/e2e-ad-hoc-question-helpers.js
@@ -36,6 +36,28 @@ export function startNewQuestion() {
 
   cy.visit("/question/notebook#" + hash);
 }
+
+/**
+ * This is the query generated by clicking "New" and then choosing the SQL Query".
+ */
+export function startNewNativeQuestion(alias = "editor") {
+  const newNativeQuestionQuery = {
+    dataset_query: {
+      database: null,
+      native: { query: "", "template-tags": {} },
+      type: "native",
+    },
+    display: "table",
+    parameters: [],
+    visualization_settings: {},
+  };
+
+  const hash = adhocQuestionHash(newNativeQuestionQuery);
+
+  cy.visit("/question#" + hash);
+  return cy.get(".ace_content").as(alias).should("be.visible");
+}
+
 /**
  * Visit any valid query in an ad-hoc manner.
  *
diff --git a/frontend/test/metabase/scenarios/native/native_subquery.cy.spec.js b/frontend/test/metabase/scenarios/native/native_subquery.cy.spec.js
index 3e0c0f5d8db..784ec19a3da 100644
--- a/frontend/test/metabase/scenarios/native/native_subquery.cy.spec.js
+++ b/frontend/test/metabase/scenarios/native/native_subquery.cy.spec.js
@@ -3,8 +3,12 @@ import {
   openQuestionActions,
   restore,
   visitQuestion,
+  startNewNativeQuestion,
+  runNativeQuery,
 } from "__support__/e2e/helpers";
 
+import * as SQLFilter from "../native-filters/helpers/e2e-sql-filter-helpers";
+
 describe("scenarios > question > native subquery", () => {
   beforeEach(() => {
     restore();
@@ -263,4 +267,31 @@ describe("scenarios > question > native subquery", () => {
       cy.contains("41");
     });
   });
+
+  it.skip("should be able to reference a nested question (metabase#25988)", () => {
+    const questionDetails = {
+      name: "Nested GUI question",
+      query: {
+        "source-table": "card__1",
+        limit: 2,
+      },
+    };
+
+    cy.createQuestion(questionDetails).then(
+      ({ body: { id: nestedQuestionId } }) => {
+        const tagID = `#${nestedQuestionId}`;
+
+        startNewNativeQuestion();
+        SQLFilter.enterParameterizedQuery(`SELECT * FROM {{${tagID}`);
+
+        cy.findByTestId("sidebar-header-title")
+          .invoke("text")
+          .should("eq", questionDetails.name);
+
+        runNativeQuery();
+
+        cy.get(".cellData").should("contain", "37.65");
+      },
+    );
+  });
 });
-- 
GitLab