The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Consolidate native e2e tests (#83438)
Nemanja Glumaca01a8e3f2dee
diff --git a/e2e/support/helpers/e2e-codemirror-helpers.ts b/e2e/support/helpers/e2e-codemirror-helpers.tsindex 60ffaeb867b..53d723c6e0c 100644--- a/e2e/support/helpers/e2e-codemirror-helpers.ts+++ b/e2e/support/helpers/e2e-codemirror-helpers.ts@@ -168,6 +168,11 @@ export function codeMirrorHelpers<T extends object>(testId: string, extra: T) {completion(label: string) {return cy.get(".cm-completionLabel").contains(label).parent();},+ completionLabels(label: string) {+ return cy+ .get(".cm-completionLabel")+ .filter((_, element) => element.textContent === label);+ },acceptCompletion(key: "enter" | "tab" = "enter") {helpers.completions().should("be.visible");diff --git a/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.js b/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.jsindex 27d761f8dbc..2f549a96057 100644--- a/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.js+++ b/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.js@@ -5,7 +5,7 @@ import { WRITABLE_DB_ID } from "e2e/support/cypress_data";import { many_data_types_rows } from "e2e/support/test_tables_data";import { createMockActionParameter } from "metabase-types/api/mocks";-import { addWidgetStringFilter } from "../native-filters/helpers/e2e-field-filter-helpers";+import { addWidgetStringFilter } from "../native/helpers/e2e-field-filter-helpers";const TEST_TABLE = "scoreboard_actions";const TEST_COLUMNS_TABLE = "many_data_types";diff --git a/e2e/test/scenarios/dashboard-filters-2/dashboard-filters-reproductions-1.cy.spec.js b/e2e/test/scenarios/dashboard-filters-2/dashboard-filters-reproductions-1.cy.spec.jsindex ec6be422224..969dea39577 100644--- a/e2e/test/scenarios/dashboard-filters-2/dashboard-filters-reproductions-1.cy.spec.js+++ b/e2e/test/scenarios/dashboard-filters-2/dashboard-filters-reproductions-1.cy.spec.js@@ -14,7 +14,7 @@ import {createMockParameter,} from "metabase-types/api/mocks";-import { setAdHocFilter } from "../native-filters/helpers/e2e-date-filter-helpers";+import { setAdHocFilter } from "../native/helpers/e2e-date-filter-helpers";const {ORDERS,diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-date.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-date.cy.spec.jsindex adada298763..cefbf67fc0b 100644--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-date.cy.spec.js+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-date.cy.spec.js@@ -4,7 +4,7 @@ import {ORDERS_DASHBOARD_ID,} from "e2e/support/cypress_sample_instance_data";-import * as DateFilter from "../native-filters/helpers/e2e-date-filter-helpers";+import * as DateFilter from "../native/helpers/e2e-date-filter-helpers";import { DASHBOARD_DATE_FILTERS } from "./shared/dashboard-filters-date";diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-id.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-id.cy.spec.jsindex e90af2f1be9..b6976860cc4 100644--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-id.cy.spec.js+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-id.cy.spec.js@@ -1,7 +1,7 @@const { H } = cy;import { ORDERS_DASHBOARD_ID } from "e2e/support/cypress_sample_instance_data";-import { addWidgetStringFilter } from "../native-filters/helpers/e2e-field-filter-helpers";+import { addWidgetStringFilter } from "../native/helpers/e2e-field-filter-helpers";describe("scenarios > dashboard > filters > ID", () => {beforeEach(() => {diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-location.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-location.cy.spec.jsindex 6c53c744fc7..966e4eed858 100644--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-location.cy.spec.js+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-location.cy.spec.js@@ -7,7 +7,7 @@ import {import {addWidgetStringFilter,selectFilterValueFromList,-} from "../native-filters/helpers/e2e-field-filter-helpers";+} from "../native/helpers/e2e-field-filter-helpers";import { DASHBOARD_LOCATION_FILTERS } from "./shared/dashboard-filters-location";diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-number.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-number.cy.spec.jsindex e6f72bd9d1a..bbfa4c6551d 100644--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-number.cy.spec.js+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-number.cy.spec.js@@ -1,7 +1,7 @@const { H } = cy;import { ORDERS_DASHBOARD_ID } from "e2e/support/cypress_sample_instance_data";-import { addWidgetNumberFilter } from "../native-filters/helpers/e2e-field-filter-helpers";+import { addWidgetNumberFilter } from "../native/helpers/e2e-field-filter-helpers";import { DASHBOARD_NUMBER_FILTERS } from "./shared/dashboard-filters-number";diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-text-category.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-text-category.cy.spec.jsindex b715220e3ee..438de0857c9 100644--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-text-category.cy.spec.js+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-text-category.cy.spec.js@@ -4,7 +4,7 @@ import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import {applyFilterByType,selectDefaultValueFromPopover,-} from "../native-filters/helpers/e2e-field-filter-helpers";+} from "../native/helpers/e2e-field-filter-helpers";import { DASHBOARD_TEXT_FILTERS } from "./shared/dashboard-filters-text-category";diff --git a/e2e/test/scenarios/embedding/embed-resource-downloads.cy.spec.ts b/e2e/test/scenarios/embedding/embed-resource-downloads.cy.spec.tsindex cc7c53908a2..831f188b752 100644--- a/e2e/test/scenarios/embedding/embed-resource-downloads.cy.spec.ts+++ b/e2e/test/scenarios/embedding/embed-resource-downloads.cy.spec.ts@@ -7,7 +7,7 @@ import {import { createMockParameter } from "metabase-types/api/mocks";const { PRODUCTS, PRODUCTS_ID, PEOPLE } = SAMPLE_DATABASE;-import * as DateFilter from "../native-filters/helpers/e2e-date-filter-helpers";+import * as DateFilter from "../native/helpers/e2e-date-filter-helpers";/** These tests are about the `downloads` flag for static embeds, both dashboards and questions.* Unless the product changes, these should test the same things as `public-resource-downloads.cy.spec.ts`diff --git a/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js b/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.jsindex 6c71922b95d..7c28a78e1ff 100644--- a/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js+++ b/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js@@ -3,7 +3,7 @@ import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import { ORDERS_DASHBOARD_ID } from "e2e/support/cypress_sample_instance_data";import { createMockParameter } from "metabase-types/api/mocks";-import { addWidgetStringFilter } from "../native-filters/helpers/e2e-field-filter-helpers";+import { addWidgetStringFilter } from "../native/helpers/e2e-field-filter-helpers";import {dashboardDetails,diff --git a/e2e/test/scenarios/embedding/embedding-native.cy.spec.js b/e2e/test/scenarios/embedding/embedding-native.cy.spec.jsindex 5d36cd58020..1e64a902c08 100644--- a/e2e/test/scenarios/embedding/embedding-native.cy.spec.js+++ b/e2e/test/scenarios/embedding/embedding-native.cy.spec.js@@ -1,7 +1,7 @@import { clone } from "metabase/utils/clone";const { H } = cy;-import * as SQLFilter from "../native-filters/helpers/e2e-sql-filter-helpers";+import * as SQLFilter from "../native/helpers/e2e-sql-filter-helpers";import {questionDetails as questionDetails2,diff --git a/e2e/test/scenarios/native-filters/helpers/e2e-field-filter-data-objects.js b/e2e/test/scenarios/native-filters/helpers/e2e-field-filter-data-objects.jsdeleted file mode 100644index 3f0126bcc65..00000000000--- a/e2e/test/scenarios/native-filters/helpers/e2e-field-filter-data-objects.js+++ /dev/null@@ -1,92 +0,0 @@-export const STRING_FILTER_SUBTYPES = {- String: {- searchTerm: "Synerg",- value: "Synergistic Granite Chair",- representativeResult: "Synergistic Granite Chair",- isList: true,- },- "String is not": {- searchTerm: "Synerg",- value: "Synergistic Granite Chair",- representativeResult: "Rustic Paper Wallet",- isList: true,- },- "String contains": {- searchTerm: null,- value: "bronze",- representativeResult: "Incredible Bronze Pants",- },- "String does not contain": {- searchTerm: null,- value: "bronze",- representativeResult: "Rustic Paper Wallet",- },- "String starts with": {- searchTerm: null,- value: "Rustic",- representativeResult: "Rustic Paper Wallet",- },- "String ends with": {- searchTerm: null,- value: "Hat",- representativeResult: "Small Marble Hat",- },-};--export const NUMBER_FILTER_SUBTYPES = {- "Equal to": {- value: "4.3",- representativeResult: "Aerodynamic Linen Coat",- },- "Not equal to": {- value: "4.3",- representativeResult: "Rustic Paper Wallet",- },- Between: {- value: ["4.3", "5"],- representativeResult: "Rustic Paper Wallet",- },- "Greater than or equal to": {- value: "4.3",- representativeResult: "Rustic Paper Wallet",- },- "Less than or equal to": {- value: "4.3",- representativeResult: "Small Marble Shoes",- },-};--export const DATE_FILTER_SUBTYPES = {- "Month and Year": {- value: {- month: "Sep",- year: "2025",- },- representativeResult: "Aerodynamic Paper Computer",- },- "Quarter and Year": {- value: {- quarter: "Q2",- year: "2025",- },- representativeResult: "Synergistic Steel Chair",- },- "Single Date": {- value: "05/24/2025",- representativeResult: "Synergistic Steel Chair",- },- "Date Range": {- value: {- startDate: "05/25/2025",- endDate: "06/01/2025",- },- representativeResult: "Gorgeous Wooden Car",- },- "All Options": {- value: {- timeBucket: "year",- quantity: 12,- },- representativeResult: "Ergonomic Paper Wallet",- },-};diff --git a/e2e/test/scenarios/native/card-tag-normalization.cy.spec.ts b/e2e/test/scenarios/native/card-tag-normalization.cy.spec.tsindex 6741228e784..69028c5134c 100644--- a/e2e/test/scenarios/native/card-tag-normalization.cy.spec.ts+++ b/e2e/test/scenarios/native/card-tag-normalization.cy.spec.ts@@ -11,7 +11,7 @@ describe("scenarios > native > card template tag normalization", () => {cy.signInAsAdmin();});- it("saves multiple differently-named references to the same card without erroring or rewriting", () => {+ it("saves differently-named card references verbatim and reopens frontend-named ones clean", () => {H.createNativeQuestion({name: "Basic Aggregations",native: { query: 'SELECT COUNT(*) AS "count" FROM PEOPLE' },@@ -21,7 +21,9 @@ describe("scenarios > native > card template tag normalization", () => {`SELECT 1 FROM {{#${cardId}-foo}} AS a, {{#${cardId}-bar}} AS b`,{ allowFastSet: true },);- H.saveQuestion("Duplicate Card Refs", { wrapId: true });+ H.saveQuestionToCollection("Duplicate Card Refs", undefined, {+ wrapId: true,+ });cy.get("@questionId").then((questionId) => {cy.request("GET", `/api/card/${questionId}`).then(({ body }) => {@@ -31,9 +33,10 @@ describe("scenarios > native > card template tag normalization", () => {});});});- });- it("reopens clean when the tag name matches what the frontend generated", () => {+ cy.log(+ "reopens clean when the tag name matches what the frontend generated",+ );H.createNativeQuestion({name: "Bob's Café",native: { query: 'SELECT COUNT(*) AS "count" FROM PEOPLE' },@@ -45,7 +48,7 @@ describe("scenarios > native > card template tag normalization", () => {H.NativeEditor.type(`SELECT * FROM {{${frontendTag}}}`, {allowFastSet: true,});- H.saveQuestion("Cafe Ref", { wrapId: true });+ H.saveQuestionToCollection("Cafe Ref", undefined, { wrapId: true });cy.get("@questionId").then((questionId) => {H.visitQuestion(questionId);diff --git a/e2e/test/scenarios/native-filters/helpers/e2e-date-filter-helpers.js b/e2e/test/scenarios/native/helpers/e2e-date-filter-helpers.jssimilarity index 100%rename from e2e/test/scenarios/native-filters/helpers/e2e-date-filter-helpers.jsrename to e2e/test/scenarios/native/helpers/e2e-date-filter-helpers.jsdiff --git a/e2e/test/scenarios/native-filters/helpers/e2e-field-filter-helpers.js b/e2e/test/scenarios/native/helpers/e2e-field-filter-helpers.jssimilarity index 78%rename from e2e/test/scenarios/native-filters/helpers/e2e-field-filter-helpers.jsrename to e2e/test/scenarios/native/helpers/e2e-field-filter-helpers.jsindex ee329c9c5ce..b53118cb8d5 100644--- a/e2e/test/scenarios/native-filters/helpers/e2e-field-filter-helpers.js+++ b/e2e/test/scenarios/native/helpers/e2e-field-filter-helpers.js@@ -104,20 +104,6 @@ export function addWidgetNumberFilter(: addSimpleNumberFilter(value, buttonLabel);}-/**- *- * @param {array|string} value- * @return {function}- */-export function addDefaultNumberFilter(value, buttonLabel = "Add filter") {- if (isBetweenFilter(value)) {- cy.findByText("Enter a default value…").click();- addBetweenFilter(value, buttonLabel);- } else {- enterDefaultValue(value, buttonLabel);- }-}-// UI PATTERNS/**@@ -189,31 +175,6 @@ function enterDefaultValue(value, buttonLabel = "Add filter") {cy.button(buttonLabel).click();}-/**- * @param {string} searchTerm- * @param {string} result- */-export function pickDefaultValue(- searchTerm,- result,- buttonLabel = "Add filter",-) {- cy.findByText("Enter a default value…").click();- cy.findByPlaceholderText("Enter a default value…").type(searchTerm);-- // Popover is re-rendering every 100ms!- // That prevents us from targeting popover() element first,- // and then searching for strings inside of it.- //- // Until FE finds a better solution, our best bet for E2E tests- // is to make sure the string is "visible" before acting on it.- // This seems to help with the flakiness.- //- cy.findByLabelText(result).should("be.visible").click();-- cy.button(buttonLabel).click();-}-/**** @param {string|Array.<string>} value@@ -223,13 +184,6 @@ function isBetweenFilter(value) {return Array.isArray(value) && value.length === 2;}-export function clearDefaultFilterValue() {- cy.findByText("Default filter widget value")- .parent()- .find(".Icon-close")- .click();-}-export function selectDefaultValueFromPopover(value,{ buttonLabel = "Add filter" } = {},diff --git a/e2e/test/scenarios/native-filters/helpers/e2e-sql-filter-helpers.js b/e2e/test/scenarios/native/helpers/e2e-sql-filter-helpers.jssimilarity index 100%rename from e2e/test/scenarios/native-filters/helpers/e2e-sql-filter-helpers.jsrename to e2e/test/scenarios/native/helpers/e2e-sql-filter-helpers.jsdiff --git a/e2e/test/scenarios/native/native-database-source.cy.spec.js b/e2e/test/scenarios/native/native-database-source.cy.spec.jsindex 69d8d36a9b1..f10ba06218d 100644--- a/e2e/test/scenarios/native/native-database-source.cy.spec.js+++ b/e2e/test/scenarios/native/native-database-source.cy.spec.js@@ -2,7 +2,6 @@ const { H } = cy;import { SAMPLE_DB_ID, USER_GROUPS } from "e2e/support/cypress_data";const PG_DB_ID = 2;-const mongoName = "QA Mongo";const postgresName = "QA Postgres12";const additionalPG = "New Database";const ADDITIONAL_PG_DB_ID = 3;@@ -58,14 +57,14 @@ describe(startNativeQuestion();assertSelectedDatabase(adminPersistedDatabase);- });- it("deleting previously persisted database should result in the new database selection prompt", () => {+ cy.log(+ "deleting previously persisted database should result in the new database selection prompt",+ );H.addPostgresDatabase(additionalPG);startNativeQuestion();- assertNoDatabaseSelected();-+ assertSelectedDatabase(adminPersistedDatabase).click();selectDatabase(additionalPG);cy.log("Delete previously persisted database.");@@ -75,6 +74,25 @@ describe(startNativeQuestion();assertNoDatabaseSelected();++ cy.log(+ "users that lose permissions to the last used database should not have that database preselected anymore",+ );+ H.activateToken("pro-self-hosted");+ cy.updatePermissionsGraph({+ [DATA_GROUP]: {+ [SAMPLE_DB_ID]: {+ "view-data": "blocked",+ "create-queries": "no",+ },+ },+ });++ cy.signOut();+ cy.signInAsNormalUser();+ startNativeQuestion();+ // Postgres will be automatically selected because it's the only dataabse this user can query+ assertSelectedDatabase(postgresName);});it("persisting a database source should work between native models and questions intechangeably", () => {@@ -109,7 +127,12 @@ describe(cy.log("Pick the same database again");selectDatabase("Sample Database");- cy.get("@persistDatabase").should("be.null");++ cy.log("Only picking a different database persists it");+ cy.findByTestId("selected-database").click();+ selectDatabase(postgresName);+ cy.wait("@persistDatabase");+ cy.get("@persistDatabase.all").should("have.length", 1);});it("selecting a database in native editor for model actions should not persist the database", () => {@@ -120,7 +143,6 @@ describe(assertNoDatabaseSelected();selectDatabase("Sample Database");- cy.get("@persistDatabase").should("be.null");startNativeModel();assertNoDatabaseSelected();@@ -129,6 +151,7 @@ describe();selectDatabase(postgresName);cy.wait("@persistDatabase");+ cy.get("@persistDatabase.all").should("have.length", 1);cy.visit("/");H.startNewAction();@@ -136,7 +159,20 @@ describe(});describe("permissions", () => {- it("users should be able to choose the databases they can run native queries against", () => {+ it("users should be able to choose the databases they can run native queries against (metabase#39053)", () => {+ cy.log(+ "users with no native write permissions should be able to choose only the databases they can query against",+ );+ cy.signIn("nosql");++ startNativeQuestion();+ cy.wait("@persistDatabase");+ cy.findByTestId("selected-database")+ .should("have.text", postgresName)+ .click();++ cy.get(H.POPOVER_ELEMENT).should("not.exist");+cy.signIn("nodata");startNativeQuestion();@@ -172,84 +208,20 @@ describe(.and("contain", "New Database");});});-- it("users with no native write permissions should be able to choose only the databases they can query against (metabase#39053)", () => {- cy.signIn("nosql");-- startNativeQuestion();- cy.wait("@persistDatabase");- cy.findByTestId("selected-database")- .should("have.text", postgresName)- .click();-- cy.get(H.POPOVER_ELEMENT).should("not.exist");- });-- it("users that lose permissions to the last used database should not have that database preselected anymore", () => {- cy.signInAsNormalUser();- startNativeQuestion();- selectDatabase("Sample Database");-- cy.signOut();- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- cy.updatePermissionsGraph({- [DATA_GROUP]: {- [SAMPLE_DB_ID]: {- "view-data": "blocked",- "create-queries": "no",- },- },- });-- cy.signOut();- cy.signInAsNormalUser();- startNativeQuestion();- // Postgres will be automatically selected because it's the only dataabse this user can query- assertSelectedDatabase(postgresName);- });},);-describe("mongo as the default database", { tags: "@mongo" }, () => {- beforeEach(() => {- H.restore("mongo-5");- cy.signInAsAdmin();- });-- it("should persist Mongo database, but not its selected table", () => {- startNativeQuestion();- assertNoDatabaseSelected();-- selectDatabase(mongoName);- cy.findByTestId("native-query-top-bar")- .findByText("Select a table")- .click();- H.popover().findByText("Reviews").click();- cy.findByTestId("native-query-top-bar").should(- "not.contain",- "Select a table",- );-- startNativeQuestion();-- assertSelectedDatabase(mongoName);- cy.findByTestId("native-query-top-bar").should("contain", "Select a table");- });-});--describe("scenatios > question > native > mysql", { tags: "@external" }, () => {+describe("scenarios > question > native > mysql", { tags: "@external" }, () => {const MYSQL_DB_NAME = "QA MySQL8";beforeEach(() => {- cy.intercept("POST", "/api/card").as("createQuestion");cy.intercept("POST", "/api/dataset").as("dataset");H.restore("mysql-8");cy.signInAsAdmin();});- it("can write a native MySQL query with a field filter", () => {+ it("can write and save a native MySQL query with a field filter", () => {// Write Native query that includes a filterH.startNewNativeQuestion();@@ -274,18 +246,15 @@ describe("scenatios > question > native > mysql", { tags: "@external" }, () => {cy.findByPlaceholderText(/Id/i).click().type("1");cy.findByTestId("native-query-editor-container").icon("play").click();+ cy.wait("@dataset");- cy.get("@queryPreview").contains("Widget").should("not.exist");-- cy.get("@queryPreview").contains("Gizmo");- });-- it("can save a native MySQL query", () => {- H.startNewNativeQuestion();-- cy.findByTestId("gui-builder-data").click();- cy.findByLabelText(MYSQL_DB_NAME).click();+ H.assertQueryBuilderRowCount(93);+ cy.get("@queryPreview")+ .should("contain", "Gizmo")+ .and("not.contain", "Widget");+ cy.log("can save a native MySQL query");+ H.NativeEditor.clear();H.NativeEditor.type("SELECT * FROM ORDERS");cy.findByTestId("native-query-editor-container").icon("play").click();@@ -296,7 +265,7 @@ describe("scenatios > question > native > mysql", { tags: "@external" }, () => {cy.contains("37.65");// Save the query- H.saveQuestion("sql count", { wrapId: true });+ H.saveQuestion("sql count");cy.url().should("match", /\/dashboard\/\d+-[a-z0-9-]*$/);});});@@ -324,6 +293,7 @@ describe("scenarios > question > native > mongo", { tags: "@mongo" }, () => {cy.findByTestId("app-bar").findByLabelText("New").click();// Reproduces metabase#20499 issueH.popover().findByText("Native query").click();+ assertNoDatabaseSelected();H.popover().findByText(MONGO_DB_NAME).click();cy.log("Ensure the database was selected");cy.findAllByTestId("gui-builder-data")@@ -336,9 +306,13 @@ describe("scenarios > question > native > mongo", { tags: "@mongo" }, () => {.findByText("Select a table").click();H.popover().findByText("Orders").click();+ cy.findByTestId("native-query-top-bar").should(+ "not.contain",+ "Select a table",+ );});- it("can save a native MongoDB query", () => {+ it("can save a native MongoDB query and persist its database, but not its table", () => {H.NativeEditor.focus().type('[ { $count: "Total" } ]', {parseSpecialCharSequences: false,});@@ -351,6 +325,11 @@ describe("scenarios > question > native > mongo", { tags: "@mongo" }, () => {cy.wait("@createQuestion");cy.location("pathname").should("match", /\/question\/\d+-[a-z0-9-]*$/);++ cy.log("should persist Mongo database, but not its selected table");+ startNativeQuestion();+ assertSelectedDatabase(MONGO_DB_NAME);+ cy.findByTestId("native-query-top-bar").should("contain", "Select a table");});});diff --git a/e2e/test/scenarios/native-filters/native-filters-remapping.cy.spec.ts b/e2e/test/scenarios/native/native-filters-remapping.cy.spec.tssimilarity index 98%rename from e2e/test/scenarios/native-filters/native-filters-remapping.cy.spec.tsrename to e2e/test/scenarios/native/native-filters-remapping.cy.spec.tsindex 66f3c701103..558d799f63a 100644--- a/e2e/test/scenarios/native-filters/native-filters-remapping.cy.spec.ts+++ b/e2e/test/scenarios/native/native-filters-remapping.cy.spec.ts@@ -15,7 +15,7 @@ describe("scenarios > native > filters > remapping", () => {addExternalRemapping();});- it("should remap dashboard parameter values", () => {+ it("should remap native question parameter values", () => {createQuestion().then((questionId) => {H.visitQuestion(questionId);testWidgetsRemapping();diff --git a/e2e/test/scenarios/native-filters/native-filters-reproductions.cy.spec.js b/e2e/test/scenarios/native/native-filters-reproductions.cy.spec.jssimilarity index 81%rename from e2e/test/scenarios/native-filters/native-filters-reproductions.cy.spec.jsrename to e2e/test/scenarios/native/native-filters-reproductions.cy.spec.jsindex 6e345f3232a..fc9c89e1e43 100644--- a/e2e/test/scenarios/native-filters/native-filters-reproductions.cy.spec.js+++ b/e2e/test/scenarios/native/native-filters-reproductions.cy.spec.js@@ -16,7 +16,7 @@ describe("issue 9357", () => {});it(- "should reorder template tags by drag and drop (metabase#9357)",+ "should reorder template tags by drag and drop, but not from popovers (metabase#9357, metabase#40232)",{ viewportWidth: 800, viewportHeight: 600 },() => {H.startNewNativeQuestion();@@ -24,7 +24,7 @@ describe("issue 9357", () => {"{{firstparameter}} {{nextparameter}} {{lastparameter}}",);- // Drag the firstparameter to last position+ // Drag the firstparameter below the nextparameterH.filterWidget().findAllByRole("listitem").first().as("dragElement");H.moveDnDKitElementByAlias("@dragElement", {vertical: 50,@@ -37,6 +37,22 @@ describe("issue 9357", () => {cy.get("@variableField").first().findByText("nextparameter");cy.get("@variableField").eq(1).findByText("firstparameter");++ cy.log(+ "dragging from inside a filter popover does not reorder the filters (metabase#40232)",+ );+ cy.findAllByRole("radio", { name: "Search box" }).first().click();+ H.filterWidget().first().should("contain.text", "Nextparameter").click();++ H.popover().findByText("Add filter").as("popoverElement");+ H.moveDnDKitElementByAlias("@popoverElement", {+ horizontal: 300,+ });++ H.filterWidget()+ .should("have.length", 3)+ .first()+ .should("contain.text", "Nextparameter");},);});@@ -88,7 +104,7 @@ describe("issue 11580", () => {cy.signInAsAdmin();});- it("shouldn't reorder template tags when updated (metabase#11580)", () => {+ it("shouldn't reorder template tags when updated (metabase#11580, metabase#15700)", () => {H.startNewNativeQuestion();SQLFilter.enterParameterizedQuery("{{foo}} {{bar}}");@@ -108,6 +124,27 @@ describe("issue 11580", () => {// ensure they're still in the right orderassertVariablesOrder();++ cy.log(+ "should be able to select 'Field Filter' category in native query (metabase#15700)",+ );+ cy.findAllByTestId("variable-type-select")+ .should("have.length", 2)+ .last()+ .click();+ SQLFilter.chooseType("Field Filter");++ FieldFilter.mapTo({+ table: "Products",+ field: "Category",+ });++ FieldFilter.setWidgetType("String is not");+ H.rightSidebar()+ .findByTestId("filter-widget-type-select")+ .should("have.value", "String is not");++ assertVariablesOrder();});});@@ -135,8 +172,6 @@ describe("issue 12581", () => {};beforeEach(() => {- cy.intercept("POST", "/api/dataset").as("dataset");-H.restore();cy.signInAsAdmin();@@ -152,14 +187,12 @@ describe("issue 12581", () => {.findByText(/open editor/i).should("not.exist");- // Both delay and a repeated sequence of `{selectall}{backspace}` are there to prevent typing flakes- // Without them at least 1 in 10 test runs locally didn't fully clear the field or type correctlyH.NativeEditor.clear().type("SELECT 1");// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usagecy.findByText("Save").click();- cy.findByTestId("save-question-modal").within((modal) => {+ cy.findByTestId("save-question-modal").within(() => {cy.findByText("Save").click();});@@ -232,8 +265,8 @@ describe("issue 14302", () => {it("should not make the question dirty when there are no changes (metabase#14302)", () => {cy.log("Reported on v0.37.5 - Regression since v0.37.0");- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Save").should("not.exist");+ cy.findByTestId("query-visualization-root").should("contain", "Gizmo");+ H.queryBuilderHeader().button("Save").should("not.exist");});});@@ -331,38 +364,14 @@ describe("issue 14302", () => {expect(xhr.response.body.error).not.to.exist;});- H.NativeEditor.get().should("not.exist");cy.get("[data-testid=cell-data]").should("contain", "51");// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usagecy.findByText("Showing 1 row");+ H.NativeEditor.get().should("not.exist");});});});-describe("issue 15700", () => {- const widgetType = "String is not";-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should be able to select 'Field Filter' category in native query (metabase#15700)", () => {- H.startNewNativeQuestion();- SQLFilter.enterParameterizedQuery("{{filter}}");-- SQLFilter.openTypePickerFromDefaultFilterType();- SQLFilter.chooseType("Field Filter");-- FieldFilter.mapTo({- table: "Products",- field: "Category",- });-- FieldFilter.setWidgetType(widgetType);- });-});-describe("issue 15981", () => {beforeEach(() => {H.restore();@@ -389,21 +398,6 @@ describe("issue 15981", () => {cy.findByText("Showing 51 rows");cy.icon("play").should("not.exist");});-- it('"Number" filter should work (metabase#15981-2)', () => {- SQLFilter.enterParameterizedQuery(- "select * from ORDERS where QUANTITY = {{number_filter}}",- );-- SQLFilter.openTypePickerFromDefaultFilterType();- SQLFilter.chooseType("Number");-- SQLFilter.setWidgetValue("20");-- SQLFilter.runQuery();-- cy.findByTestId("query-visualization-root").contains("23.54");- });});describe("issue 16739", () => {@@ -422,25 +416,59 @@ describe("issue 16739", () => {cy.signInAsAdmin();});- ["normal", "nodata"].forEach((user) => {- //Very related to the metabase#15981, only this time the issue happens with the "Field Filter" without the value being set.- it(`filter feature flag shouldn't cause run-overlay of results in native editor for ${user} user (metabase#16739)`, () => {- H.createNativeQuestion({+ //Very related to the metabase#15981, only this time the issue happens with the "Field Filter" without the value being set.+ it("empty field filters shouldn't cause run-overlay of results for admin and nodata users (metabase#16739, metabase#70311)", () => {+ H.createNativeQuestion({+ native: {+ query: "select * from PRODUCTS where {{ filter }}",+ "template-tags": { filter },+ },+ }).then(({ body: { id } }) => {+ cy.wrap(id).as("questionId");+ H.visitQuestion(id);+ });++ H.assertQueryBuilderRowCount(200);+ H.runButtonOverlay().icon("play").should("not.exist");++ cy.log(+ "should not show the run overlay for a saved question with an empty between field filter (metabase#70311)",+ );+ cy.intercept("POST", "/api/card/*/query").as("cardQuery");+ H.createNativeQuestion(+ {+ name: "70311",native: {- query: "select * from PRODUCTS where {{ filter }}",- "template-tags": { filter },+ query: "SELECT * FROM PRODUCTS WHERE {{filter}} LIMIT 5",+ "template-tags": {+ filter: {+ id: "a3b95feb-b6d2-33b6-660b-bb656f59b1d7",+ name: "filter",+ "display-name": "Filter",+ type: "dimension",+ dimension: ["field", PRODUCTS.RATING, null],+ "widget-type": "number/between",+ default: null,+ },+ },},- }).then(({ body: { id } }) => {- if (user === "nodata") {- cy.signOut();- cy.signIn(user);- }+ },+ { visitQuestion: true },+ );- H.visitQuestion(id);- });+ cy.wait("@cardQuery");- cy.icon("play").should("not.exist");- });+ cy.findByTestId("query-visualization-root").should("be.visible");+ H.assertQueryBuilderRowCount(5);+ H.runButtonOverlay().icon("play").should("not.exist");++ cy.log("as nodata user (metabase#16739)");+ cy.signOut();+ cy.signIn("nodata");+ cy.get("@questionId").then((id) => H.visitQuestion(id));++ H.assertQueryBuilderRowCount(200);+ H.runButtonOverlay().icon("play").should("not.exist");});});@@ -507,34 +535,6 @@ describe("issue 16756", () => {});});-describe("issue 17490", () => {- function mockDatabaseTables() {- cy.intercept("GET", "/api/database?include=tables", (req) => {- req.reply((res) => {- const mockTables = new Array(7).fill({- id: 42, // id is hard coded, but it doesn't matter for this repro- db_id: 1,- name: "Z",- display_name: "ZZZ",- schema: "PUBLIC",- });-- res.body.data = res.body.data.map((d) => ({- ...d,- tables: [...d.tables, ...mockTables],- }));- });- });- }-- beforeEach(() => {- mockDatabaseTables();-- H.restore();- cy.signInAsAdmin();- });-});-describe("issue 27257", () => {beforeEach(() => {cy.intercept("POST", "/api/dataset").as("dataset");@@ -567,12 +567,12 @@ describe("issue 27257", () => {cy.reload();// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usagecy.findByText("Here's where your results will appear");- cy.findByDisplayValue("0");+ H.filterWidget().findByDisplayValue("0").should("be.visible");});});-describe("issue 31606", { tags: "@external" }, () => {- const SQL_QUERY = "SELECT * FROM PRODUCTS WHERE CATEGORY = {{test}}";+describe("issue 31606", () => {+ const SQL_QUERY = "SELECT COUNT(*) FROM PRODUCTS WHERE ID = {{test}}";beforeEach(() => {cy.intercept("POST", "/api/dataset").as("dataset");@@ -581,18 +581,17 @@ describe("issue 31606", { tags: "@external" }, () => {cy.signInAsAdmin();});- it("should clear values on UI for Text, Number, Date and Field Filter Types (metabase#31606)", () => {+ it("should clear values on UI for Text, Number and Field Filter Types (metabase#31606)", () => {H.startNewNativeQuestion();SQLFilter.enterParameterizedQuery(SQL_QUERY);// Text- SQLFilter.setWidgetValue("Gizmo");+ SQLFilter.setWidgetValue("1");SQLFilter.runQuery();- H.queryBuilderMain()- .findByText(/missing required parameters/)- .should("not.exist");+ cy.findByTestId("scalar-value").should("have.text", "1");+ H.filterWidget().icon("close").should("be.visible");H.filterWidget().findByRole("textbox").clear();@@ -611,9 +610,8 @@ describe("issue 31606", { tags: "@external" }, () => {SQLFilter.runQuery();- H.queryBuilderMain()- .findByText(/missing required parameters/)- .should("not.exist");+ cy.findByTestId("scalar-value").should("have.text", "1");+ H.filterWidget().icon("close").should("be.visible");H.filterWidget().findByRole("textbox").clear();SQLFilter.runQuery();@@ -665,11 +663,7 @@ describe("issue 31606", { tags: "@external" }, () => {H.filterWidget().within(() => {cy.icon("close").should("be.visible");});-- SQLFilter.runQuery();- H.queryBuilderMain()- .findByText(/missing required parameters/)- .should("not.exist");+ H.filterWidget().should("contain.text", "23");H.filterWidget().click();@@ -678,6 +672,7 @@ describe("issue 31606", { tags: "@external" }, () => {cy.findByText("Update filter").click();});+ H.filterWidget().should("not.contain.text", "23");H.filterWidget().within(() => {cy.icon("close").should("not.exist");});@@ -755,117 +750,6 @@ describe("issue 34129", () => {});});-describe("issue 31606", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should not start drag and drop from clicks on popovers", () => {- H.startNewNativeQuestion();-- SQLFilter.enterParameterizedQuery("{{foo}} {{bar}}");-- cy.findAllByRole("radio", { name: "Search box" }).first().click();- H.filterWidget().first().click();-- H.popover().findByText("Add filter").as("dragElement");- H.moveDnDKitElementByAlias("@dragElement", {- horizontal: 300,- });-- H.filterWidget()- .should("have.length", 2)- .first()- .should("contain.text", "Foo");- });-});--describe("issue 49577", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should not show the values initially when using a single select search box (metabase#49577)", () => {- H.startNewNativeQuestion();- H.NativeEditor.type("select * from {{param");- // eslint-disable-next-line metabase/no-unsafe-element-filtering- H.sidebar()- .last()- .within(() => {- cy.findByText("Search box").click();- cy.findByText("Edit").click();- });-- H.modal().within(() => {- cy.findByText("Custom list").click();- cy.findByRole("textbox").type("foo\nbar\nbaz");- cy.button("Done").click();- });-- H.filterWidget().click();-- H.popover().within(() => {- cy.findByText("foo").should("not.exist");- cy.findByText("bar").should("not.exist");- cy.findByText("baz").should("not.exist");-- cy.findByPlaceholderText("Search").should("be.visible").type("fo");-- cy.findByText("foo").should("be.visible");- });-- // eslint-disable-next-line metabase/no-unsafe-element-filtering- H.sidebar().last().findByText("Dropdown list").click();-- H.filterWidget().click();-- H.popover().within(() => {- cy.findByPlaceholderText("Search the list").should("be.visible");- cy.findByText("foo").should("be.visible");- cy.findByText("bar").should("be.visible");- cy.findByText("baz").should("be.visible");- });- });-});--describe("issue 70311", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- cy.intercept("POST", "/api/card/*/query").as("cardQuery");- });-- it("should not show the run overlay for a saved question with an empty between field filter (metabase#70311)", () => {- H.createNativeQuestion(- {- name: "70311",- native: {- query: "SELECT * FROM PRODUCTS WHERE {{filter}} LIMIT 5",- "template-tags": {- filter: {- id: "a3b95feb-b6d2-33b6-660b-bb656f59b1d7",- name: "filter",- "display-name": "Filter",- type: "dimension",- dimension: ["field", PRODUCTS.RATING, null],- "widget-type": "number/between",- default: null,- },- },- },- },- { visitQuestion: true },- );-- cy.wait("@cardQuery");-- cy.findByTestId("query-visualization-root").should("be.visible");- cy.icon("play").should("not.exist");- });-});-// This reproduction can possibly be replaced with the unit test for the `ListField` component in the futuredescribe("issue 45877", () => {beforeEach(() => {@@ -926,7 +810,7 @@ describe("issue 44665", () => {cy.signInAsNormalUser();});- it("should use the correct widget for the default value picker (metabase#44665)", () => {+ it("should use the correct widgets for the search box and the default value picker (metabase#44665, metabase#49577)", () => {H.startNewNativeQuestion();H.NativeEditor.type("select * from {{param");// eslint-disable-next-line metabase/no-unsafe-element-filtering@@ -943,6 +827,26 @@ describe("issue 44665", () => {cy.button("Done").click();});+ cy.log(+ "should not show the values initially when using a single select search box (metabase#49577)",+ );+ H.filterWidget().click();++ H.popover().within(() => {+ cy.findByPlaceholderText("Search").should("be.visible");+ cy.findByText("foo").should("not.exist");+ cy.findByText("bar").should("not.exist");+ cy.findByText("baz").should("not.exist");+ cy.findByText("foobar").should("not.exist");++ cy.findByPlaceholderText("Search").type("fo");++ cy.findByText("foo").should("be.visible");+ });+ cy.realPress("Escape");+ cy.get(H.POPOVER_ELEMENT).should("not.exist");++ cy.log("should use the correct widget for the default value picker");// eslint-disable-next-line metabase/no-unsafe-element-filteringH.sidebar().last().findByText("Enter a default value…").click();H.popover().within(() => {@@ -973,5 +877,17 @@ describe("issue 44665", () => {cy.findByText("baz").should("be.visible");cy.findByText("foobar").should("be.visible");});+ cy.realPress("Escape");+ cy.get(H.POPOVER_ELEMENT).should("not.exist");++ cy.log("the dropdown list shows all values (metabase#49577)");+ H.filterWidget().click();++ H.popover().within(() => {+ cy.findByPlaceholderText("Search the list").should("be.visible");+ cy.findByText("foo").should("be.visible");+ cy.findByText("bar").should("be.visible");+ cy.findByText("baz").should("be.visible");+ });});});diff --git a/e2e/test/scenarios/native/native-reproductions.cy.spec.js b/e2e/test/scenarios/native/native-reproductions.cy.spec.jsindex 39b5abc3363..57a7687d4c4 100644--- a/e2e/test/scenarios/native/native-reproductions.cy.spec.js+++ b/e2e/test/scenarios/native/native-reproductions.cy.spec.js@@ -2,10 +2,7 @@ const { H } = cy;import { SAMPLE_DB_ID, USER_GROUPS } from "e2e/support/cypress_data";import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";-import {- getRunQueryButton,- runQuery,-} from "../native-filters/helpers/e2e-sql-filter-helpers";+import { getRunQueryButton, runQuery } from "./helpers/e2e-sql-filter-helpers";const { PRODUCTS, ORDERS_ID } = SAMPLE_DATABASE;@@ -59,82 +56,6 @@ describe("issue 12439", () => {H.sidebar().contains("Y-axis");});});-describe("issue 16886", () => {- const ORIGINAL_QUERY = "select 1 from orders";- const SELECTED_TEXT = "select 1";-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("shouldn't remove parts of the query when choosing 'Run selected text' (metabase#16886)", () => {- H.startNewNativeQuestion();- H.NativeEditor.type(ORIGINAL_QUERY);- cy.realPress("Home");- Cypress._.range(SELECTED_TEXT.length).forEach(() =>- cy.realPress(["Shift", "ArrowRight"]),- );-- cy.findByTestId("native-query-editor-container").icon("play").click();-- cy.findByTestId("scalar-value").invoke("text").should("eq", "1");-- H.NativeEditor.get().contains(ORIGINAL_QUERY);- });-});--describe("issue 16914", () => {- beforeEach(() => {- H.restore();- cy.intercept("POST", "api/dataset").as("dataset");- cy.signInAsAdmin();- });-- it("should recover visualization settings after a failed query (metabase#16914)", () => {- const FAILING_PIECE = " foo";-- H.visitQuestionAdhoc({- display: "table",- dataset_query: {- database: SAMPLE_DB_ID,- type: "native",- native: {- query: "SELECT 'a' as hidden, 'b' as visible",- },- },- visualization_settings: {},- });-- H.openVizSettingsSidebar();- cy.findByTestId("sidebar-left")- .as("sidebar")- .within(() => {- cy.findByTestId("draggable-item-HIDDEN")- .icon("eye_outline")- .click({ force: true });- });- cy.button("Done").click();-- H.NativeEditor.focus().type(FAILING_PIECE);- H.runNativeQuery();-- H.NativeEditor.focus();- cy.realPress("End");- Cypress._.range(FAILING_PIECE.length).forEach(() =>- cy.realPress(["Shift", "ArrowLeft"]),- );- cy.realPress("Backspace");- H.runNativeQuery();-- cy.findByTestId("query-visualization-root").within(() => {- cy.findByText("Every field is hidden right now").should("not.exist");- cy.findByText("VISIBLE");- cy.findByText("HIDDEN").should("not.exist");- });- });-});-describe("issue 17060", () => {const ORIGINAL_QUERY ='select ID as "num", CATEGORY as "text" from PRODUCTS limit 1';@@ -183,8 +104,10 @@ describe("issue 17060", () => {H.NativeEditor.type("RATING", { focus: false });runQuery();+ H.tableInteractiveBody().findByText("4.6").should("be.visible");cy.findByTestId("query-visualization-root").within(() => {- cy.findByText("num");+ cy.findAllByTestId("header-cell").should("have.length", 2);+ cy.findByText("num").should("be.visible");});});});@@ -250,9 +173,19 @@ describe("issue 19451", () => {H.createNativeQuestion(question, { visitQuestion: true });});- it("question field filter shows all tables from a selected database (metabase#19451)", () => {+ it("question field filter shows all tables from a selected database (metabase#19451, metabase#23510)", () => {// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usagecy.findByText("Open Editor").click();++ cy.log("The data reference loads uncached metadata (metabase#23510)");+ cy.findByTestId("sidebar-content").within(() => {+ cy.findByText("ORDERS");+ cy.findByText("PRODUCTS");+ cy.findByText("REVIEWS");+ cy.findByText("PEOPLE");+ cy.findByText("Sample Database");+ });+cy.icon("variable").click();// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usagecy.findByText("Products").click();@@ -284,75 +217,19 @@ describe("issue 20044", () => {it("nodata user should not see 'Explore results' (metabase#20044)", () => {H.createNativeQuestion(questionDetails).then(({ body: { id } }) => {+ H.visitQuestion(id);+ cy.findByTestId("qb-header-action-panel")+ .findByText("Explore results")+ .should("be.visible");+cy.signIn("nodata");H.visitQuestion(id);cy.get("[data-testid=cell-data]").contains("1");- cy.findByText("Explore results").should("not.exist");- });- });-});--describe("issue 21034", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.startNewNativeQuestion();- cy.intercept(- "GET",- "/api/database/**/autocomplete_suggestions?**",- cy.spy().as("suggestions"),- );- });-- it("should not invoke API calls for autocomplete twice in a row (metabase#18148)", () => {- H.NativeEditor.type("p");-- // Wait until another explicit autocomplete is triggered- // (slightly longer than AUTOCOMPLETE_DEBOUNCE_DURATION)- // See https://github.com/metabase/metabase/pull/20970- cy.wait(1000);-- cy.get("@suggestions").its("callCount").should("equal", 1);- });-});--describe("issue 21550", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- cy.intercept("GET", "/api/collection/root/items?**").as("rootCollection");- cy.intercept("GET", "/api/native-query-snippet/**").as("snippet");- });-- it("should not show scrollbars for very short snippet (metabase#21550)", () => {- H.startNewNativeQuestion();-- cy.icon("snippet").click();- cy.wait("@rootCollection");- cy.findByTestId("sidebar-content").findByText("Create snippet").click();-- H.modal().within(() => {- cy.findByLabelText("Enter some SQL here so you can reuse it later").type(- "select * from people",- );- cy.findByLabelText("Give your snippet a name").type("people");- cy.findByText("Save").click();- cy.wait("@rootCollection");- });-- cy.findByTestId("sidebar-content").within(() => {- cy.findByText("people").realHover();- cy.icon("chevrondown").click({ force: true });- });-- cy.get("pre").then(($pre) => {- const preWidth = $pre[0].getBoundingClientRect().width;- const clientWidth = $pre[0].clientWidth;- const BORDERS = 2; // 1px left and right- expect(clientWidth).to.be.gte(preWidth - BORDERS);+ cy.findByTestId("qb-header-action-panel")+ .findByText("Explore results")+ .should("not.exist");});});});@@ -366,9 +243,7 @@ describe("issue 31926", { tags: "@external" }, () => {cy.signInAsAdmin();});- it("display the relevant error message in save question modal (metabase#21597)", () => {- cy.intercept({ method: "POST", url: "/api/card" });-+ it("should disable running and saving after switching a field filter query to another database (metabase#31926)", () => {// Second DB (copy)H.addPostgresDatabase(databaseCopyName);@@ -388,8 +263,8 @@ describe("issue 31926", { tags: "@external" }, () => {});cy.findByTestId("native-query-editor-container").icon("play").click();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.contains("200");+ cy.findByTestId("scalar-value").should("have.text", "200");+ cy.findByTestId("qb-save-button").should("not.have.attr", "data-disabled");// Change DB// and re-run the native query@@ -412,23 +287,9 @@ describe("issue 31926", { tags: "@external" }, () => {});});-describe("issue 21597", { tags: "@external" }, () => {- /*- *- * Greetings and welcome to this weird test. It has a history! A long legacy! Allow me to explain:- *- * This test was originally using changing the DB on a native query with field filters to trigger an error that- * would show up in the save modal.- *- * PR#54453 fixes this error by removing the field filters that refer to the old database, which means that it won't- * save.- *- * So in order to trigger an error, we are intercepting the POST /api/card and manually responding with an error.- *- * We then assert that the message makes it to the save modal.- *- * The End- */+describe("issue 21597", () => {+ // The save request is stubbed with an error to check that its message+ // shows in the save modal.beforeEach(() => {H.restore();cy.signInAsAdmin();@@ -464,62 +325,24 @@ describe("issue 21597", { tags: "@external" }, () => {});});-describe("issue 23510", () => {+describe("issue 30680", () => {beforeEach(() => {H.restore();cy.signInAsAdmin();});- it("loads metadata when it is not cached (metabase#23510)", () => {- H.createNativeQuestion(- {- database: 1,- name: "Q23510",- native: {- query:- "select count(*) from orders left join products on products.id=orders.product_id where {{category}}",- "template-tags": {- ID: {- id: "6b8b10ef-0104-1047-1e1b-2492d5954322",- name: "Category",- display_name: "Category",- type: "dimension",- dimension: ["field", PRODUCTS.CATEGORY, null],- "widget-type": "category",- default: null,- },- },- },- display: "scalar",- },- { visitQuestion: true },- );+ it("should not render native editor buttons when 'Columns' tab is open (metabase#30680, metabase#53649)", () => {+ H.startNewNativeModel();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Open Editor").click();+ cy.log("The native editor does not freeze (metabase#53649)");+ H.NativeEditor.type("select 1");+ H.NativeEditor.get().should("contain", "select 1");- cy.findByTestId("sidebar-content").within(() => {- cy.findByText("ORDERS");- cy.findByText("PRODUCTS");- cy.findByText("REVIEWS");- cy.findByText("PEOPLE");- cy.findByText("Sample Database");- });- });-});--describe("issue 30680", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should not render native editor buttons when 'Columns' tab is open (metabase#30680)", () => {- H.startNewNativeModel({ query: "select 1" });cy.findByTestId("editor-tabs-columns").should("be.disabled");H.runNativeQuery();cy.findByTestId("editor-tabs-columns").should("not.be.disabled");+ cy.findByTestId("native-query-editor-action-buttons").should("be.visible");cy.findByTestId("editor-tabs-columns-name").click();cy.findByTestId("sidebar-content").should("exist");@@ -558,7 +381,7 @@ describe("issue 34330", () => {cy.get("@autocomplete.all").should("have.length", 1);});- it("should call the autocompleter eventually, even when only 1 character was typed (metabase#34330)", () => {+ it("should call the autocompleter eventually and only once, even when only 1 character was typed (metabase#34330, metabase#21034)", () => {H.NativeEditor.type("S", { delay: 10 });H.NativeEditor.completion("SEATS").should("be.visible");@@ -569,6 +392,15 @@ describe("issue 34330", () => {// only one call to the autocompleter should have been madecy.get("@autocomplete.all").should("have.length", 1);++ cy.log(+ "should not invoke API calls for autocomplete twice in a row (metabase#21034)",+ );+ // Wait until another explicit autocomplete could be triggered+ // (slightly longer than AUTOCOMPLETE_DEBOUNCE_DURATION)+ // See https://github.com/metabase/metabase/pull/20970+ cy.wait(1000);+ cy.get("@autocomplete.all").should("have.length", 1);});it("should call the autocompleter when backspacing to a 1-character prefix (metabase#34330)", () => {@@ -651,6 +483,7 @@ describe("issue 35785", () => {H.createNativeQuestion(questionDetails, { visitQuestion: true });cy.intercept("GET", "/api/search?*").as("getSearchResults");+ cy.intercept("PUT", "/api/card/*").as("updateCard");});it("should not redirect to the value of 'from' URL parameter after saving (metabase#35785)", () => {@@ -665,9 +498,11 @@ describe("issue 35785", () => {cy.findByText("Save").click();});+ cy.wait("@updateCard");cy.wait("@getSearchResults");- cy.url().should("include", "/question");+ cy.findByTestId("save-question-modal").should("not.exist");+ cy.location("pathname").should("match", /^\/question\/\d+/);});});@@ -710,7 +545,10 @@ describe("issue 22991", () => {H.startNewNativeQuestion();cy.get("@questionId").then((questionId) => {// can't use cy.type because it does not simulate the bug- H.NativeEditor.type(`select * from {{${questionId}}}`);+ H.NativeEditor.type(`select * from {{#${questionId}`);+ H.NativeEditor.get()+ .should("be.visible")+ .and("contain.text", `#${questionId}`);});cy.get("main").should(diff --git a/e2e/test/scenarios/native/native-reproductions.cy.spec.ts b/e2e/test/scenarios/native/native-reproductions.cy.spec.tsindex b7c22c81c26..c8bb4a62682 100644--- a/e2e/test/scenarios/native/native-reproductions.cy.spec.ts+++ b/e2e/test/scenarios/native/native-reproductions.cy.spec.ts@@ -10,7 +10,7 @@ import type {} from "metabase-types/api";import { createMockParameter } from "metabase-types/api/mocks";-import { getRunQueryButton } from "../native-filters/helpers/e2e-sql-filter-helpers";+import { getRunQueryButton } from "./helpers/e2e-sql-filter-helpers";const { ORDERS_ID, REVIEWS } = SAMPLE_DATABASE;@@ -165,12 +165,24 @@ describe("issue 38083", () => {dataset_query,}),)- .then((card) => H.visitQuestion(card.id));+ .then((card) => {+ cy.wrap(card.id).as("cardId");+ H.visitQuestion(card.id);+ });- H.filterWidget()- .filter(`:contains("${QUERY.templateTags.state["display-name"]}")`)- .icon("revert")- .should("not.exist");+ cy.log("the default value is applied on load");+ H.filterWidget().find("input").should("have.value", "CA");+ H.filterWidget().icon("revert").should("not.exist");++ cy.log("the default value is passed in the URL");+ cy.get("@cardId").then((cardId) => {+ cy.intercept("POST", `/api/card/${cardId}/query`).as("cardQuery");+ cy.visit(`/question/${cardId}?state=CA`);+ });+ cy.wait("@cardQuery");++ H.filterWidget().find("input").should("have.value", "CA");+ H.filterWidget().icon("revert").should("not.exist");});});@@ -245,7 +257,8 @@ describe("issue 49454", () => {H.startNewNativeQuestion();cy.log("should not show empty tooltip (metabase#51035)");- cy.button("Save").realHover();+ cy.button("Save").should("have.attr", "data-disabled");+ cy.button("Save").should("be.visible").realHover();H.tooltip().should("not.exist");H.NativeEditor.type("select * from {{ #test");@@ -299,12 +312,13 @@ describe("issue 53194", () => {cy.findByTestId("sidebar-content").within(() => {cy.findByText("REVIEWS").click(); // the infinite loop used to start with this action+ cy.findByTestId("sidebar-header-title").should("contain.text", "REVIEWS");cy.findByText("ID").should("not.exist");cy.findByText("ORDERS").should("not.exist");cy.findByTestId("sidebar-header-title").click(); // if app is frozen, Cypress won't be able to execute this- cy.findByText("ID").should("not.exist");cy.findByText("REVIEWS").should("be.visible");+ cy.findByText("ID").should("not.exist");cy.findByText("ORDERS").click();cy.findByText("ID").should("be.visible");@@ -312,7 +326,7 @@ describe("issue 53194", () => {});});-describe("issues 53299, 47793", { tags: ["@external", "@mongo"] }, () => {+describe("issue 47793", { tags: ["@external", "@mongo"] }, () => {const MONGO_DB_ID = 2;const questionDetails: NativeQuestionDetails = {@@ -356,12 +370,7 @@ describe("issues 53299, 47793", { tags: ["@external", "@mongo"] }, () => {cy.signInAsAdmin();});- it("should be possible to switch to mongodb when editing an sql question and to preview queries for mongodb (metabase#53299, metabase#47793)", () => {- H.startNewNativeQuestion();-- H.selectNativeEditorDataSource("QA Mongo");- H.nativeEditorDataSource().should("contain", "QA Mongo");-+ it("should be possible to preview queries for mongodb (metabase#47793)", () => {H.createNativeQuestion(questionDetails, { visitQuestion: true });cy.findByTestId("visibility-toggler").findByText(/open editor/i)@@ -401,6 +410,10 @@ describe("issue 53171", () => {cy.findByTestId("sidebar-content").within(($container) => {const [container] = $container;+ cy.findByTestId("sidebar-header").should(+ "contain.text",+ `Question ${"a".repeat(100)}`,+ );cy.findByTestId("sidebar-header").should(($header) => {const [header] = $header;const headerDescendants = header.querySelectorAll("*");@@ -483,12 +496,14 @@ describe("issues 52811, 52812", () => {cy.log("popover should close when clicking away (metabase#52811)");H.popover().findByText("Field Filter").click();+ H.popover().should("be.visible").and("contain.text", "Orders");clickAway();cy.get(H.POPOVER_ELEMENT).should("not.exist");cy.log("the default value input should not be rendered when 'Field to map to' is not set yet (metabase#52812)",);+ H.rightSidebar().findByText("Field to map to").should("be.visible");H.rightSidebar().findByText("Default filter widget value").should("not.exist");@@ -528,11 +543,28 @@ describe("issue 52806", () => {});});-describe("issue 55951", () => {+describe("issues 55951, 57644", { tags: "@external" }, () => {beforeEach(() => {H.restore("postgres-12");cy.signInAsAdmin();+ });+ it("should open the database picker with multiple databases, without a loading state when databases are being reloaded (metabase#55951, metabase#57644)", () => {+ cy.log(+ "should open the database picker when opening the native query editor and there are multiple databases (metabase#57644)",+ );+ H.startNewNativeQuestion({+ database: null,+ query: "",+ });+ H.popover()+ .should("be.visible")+ .and("contain", "Sample Database")+ .and("contain", "QA Postgres12");++ cy.log(+ "should not show loading state in database picker when databases are being reloaded (metabase#55951)",+ );cy.intercept<unknown, ListDatabasesResponse>("GET","/api/database",@@ -542,9 +574,7 @@ describe("issue 55951", () => {});},).as("getDatabases");- });- it("should not show loading state in database picker when databases are being reloaded (metabase#55951)", () => {cy.visit("/");cy.wait("@getDatabases");@@ -646,41 +676,6 @@ describe("issue 56570", () => {});});-describe("issue 53649", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should not get caught in an infinite loop when opening the native editor (metabase#53649)", () => {- H.startNewNativeModel();-- // If the app freezes, this won't work- H.NativeEditor.type("select 1");- H.NativeEditor.get().should("contain", "select 1");- });-});--describe("issue 57441", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should be possible to create a new snippet from the sidebar (metabase#57441)", () => {- H.startNewNativeQuestion();-- H.createSnippet({ name: "snippet 1", content: "select 1" });-- cy.findByTestId("native-query-editor-action-buttons")- .icon("snippet")- .click();- H.rightSidebar().icon("add").click();- H.popover().findByText("New snippet").click();- H.modal().findByText("Create your new snippet").should("be.visible");- });-});-describe("issue 56905", () => {beforeEach(() => {H.restore();@@ -701,45 +696,28 @@ describe("issue 56905", () => {});describe("issue 57644", () => {- describe("with only one database", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.startNewNativeQuestion({- database: null,- query: "",- });- });-- it("should not open the database picker when opening the native query editor when there is only one database (metabase#57644)", () => {- cy.findByTestId("native-query-top-bar")- .findByText("Select a database")- .should("be.visible");+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.intercept({ method: "GET", pathname: "/api/database" }).as(+ "getDatabases",+ );- // The popover should not be visible, we give it a timeout here because the- // popover disappears immediately and we don't want that to make the test pass.- cy.findAllByRole("dialog", { timeout: 0 }).should("not.exist");+ H.startNewNativeQuestion({+ database: null,+ query: "",});});- describe("with multiple databases", () => {- beforeEach(() => {- H.restore("postgres-12");- cy.signInAsAdmin();-- H.startNewNativeQuestion({- database: null,- query: "",- });- });+ it("should not open the database picker when opening the native query editor when there is only one database (metabase#57644)", () => {+ cy.wait("@getDatabases");+ cy.findByTestId("native-query-top-bar")+ .findByText("Select a database")+ .should("be.visible");- it("should open the database picker when opening the native query editor and there are multiple databases (metabase#57644)", () => {- H.popover()- .should("be.visible")- .and("contain", "Sample Database")- .and("contain", "QA Postgres12");- });+ // The popover should not be visible, we give it a timeout here because the+ // popover disappears immediately and we don't want that to make the test pass.+ cy.findAllByRole("dialog", { timeout: 0 }).should("not.exist");});});@@ -790,6 +768,7 @@ describe("issue 59110", () => {it("should allow dragging border to completely hide native query editor (metabase#59110)", () => {H.startNewNativeQuestion();+ H.NativeEditor.get().should("be.visible");cy.findByTestId("visibility-toggler").findByText(/open editor/i).should("not.exist");@@ -828,7 +807,7 @@ describe("issue 59110", () => {});});});-describe("issue 59356", () => {+describe("issue 59356", { tags: "@external" }, () => {function typeRunShortcut() {cy.realPress([H.metaKey, "Enter"]);}@@ -928,12 +907,11 @@ describe("issue 66745", () => {cy.signInAsNormalUser();cy.intercept("POST", "/api/dataset").as("dataset");- cy.intercept("GET", "/api/card/*").as("getCard");cy.intercept("PUT", "/api/card/*").as("saveCard");});["row", "bar"].forEach((vizType) => {- it(`should not break visualization on native query column rename (metabase#63711) - ${vizType}`, () => {+ it(`should not break visualization on native query column rename (metabase#66745) - ${vizType}`, () => {H.createNativeQuestion({name: `66745 - ${vizType}`,@@ -978,18 +956,16 @@ describe("issue 66745", () => {.findByText("Save").should("not.exist");+ cy.intercept("GET", "/api/card/*").as("getCard");H.visitQuestion("@questionId");-cy.wait("@getCard");- cy.wait("@cardQuery");-- // eslint-disable-next-line metabase/no-unscoped-text-selectors- cy.findByText("Something’s gone wrong").should("not.exist");cy.findByTestId("query-visualization-root").within(() => {cy.findByText("Total").should("be.visible");cy.findByText("World").should("not.exist");});+ // eslint-disable-next-line metabase/no-unscoped-text-selectors+ cy.findByText("Something’s gone wrong").should("not.exist");H.openVizSettingsSidebar();H.leftSidebar().within(() => {diff --git a/e2e/test/scenarios/native/native.cy.spec.js b/e2e/test/scenarios/native/native.cy.spec.jsindex 983431ea781..83ad1bbac77 100644--- a/e2e/test/scenarios/native/native.cy.spec.js+++ b/e2e/test/scenarios/native/native.cy.spec.js@@ -3,7 +3,7 @@ import { SAMPLE_DB_ID } from "e2e/support/cypress_data";import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import { THIRD_COLLECTION_ID } from "e2e/support/cypress_sample_instance_data";-const { ORDERS_ID, PRODUCTS_ID, ORDERS } = SAMPLE_DATABASE;+const { ORDERS_ID, PRODUCTS_ID } = SAMPLE_DATABASE;const ORDERS_SCALAR_METRIC = {name: "Count of orders",@@ -88,7 +88,7 @@ describe("scenarios > question > native", () => {cy.contains('Table "NOT_A_TABLE" not found');});- it("displays an error when running selected text", () => {+ it("displays an error when running selected text and keeps the full query (metabase#16886)", () => {H.startNewNativeQuestion();H.NativeEditor.type("select * from orders");@@ -99,20 +99,28 @@ describe("scenarios > question > native", () => {runQuery();// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usagecy.contains('Table "ORD" not found');- });- describe("template tags", () => {- it("should handle template tags", () => {- H.startNewNativeQuestion();- H.NativeEditor.type("select * from PRODUCTS where RATING > {{Stars}}");+ cy.log(+ "shouldn't remove parts of the query when choosing 'Run selected text' (metabase#16886)",+ );+ const ORIGINAL_QUERY = "select 1 from orders";+ const SELECTED_TEXT = "select 1";+ H.NativeEditor.clear();+ H.NativeEditor.type(ORIGINAL_QUERY);+ cy.realPress("Home");+ Cypress._.range(SELECTED_TEXT.length).forEach(() =>+ cy.realPress(["Shift", "ArrowRight"]),+ );- cy.get("input[placeholder*='Stars']").type("3");- runQuery();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.contains("Showing 168 rows");- });+ cy.findByTestId("native-query-editor-container").icon("play").click();++ cy.findByTestId("scalar-value").invoke("text").should("eq", "1");- it("should modify parameters accordingly when tags are modified", () => {+ H.NativeEditor.get().contains(ORIGINAL_QUERY);+ });++ describe("template tags", () => {+ it("should save a required tag's default value as the parameter default", () => {H.startNewNativeQuestion();H.NativeEditor.type("select * from PRODUCTS where CATEGORY = {{cat}}");@@ -147,6 +155,7 @@ describe("scenarios > question > native", () => {cy.get("input[placeholder*='Stars']").type("3");runQuery();+ H.assertQueryBuilderRowCount(45);// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usagecy.contains("Save").click();@@ -180,33 +189,31 @@ describe("scenarios > question > native", () => {H.popover().findByText("Time grouping").click();}- function setVariableTypeAndField() {+ it("should create entries in variables sidebar, handle the required prop and reset the default value when options change", () => {+ H.startNewNativeQuestion();+ H.NativeEditor.type(+ "SELECT count(*), {{unit}} as unit FROM ORDERS GROUP BY unit",+ );setVariableType();++ cy.log("should show validation error when the field is not set");+ H.queryBuilderHeader()+ .button("Save")+ .should("have.attr", "data-disabled");+H.popover().within(() => {cy.findByText("Orders").click();cy.findByText("Created At").click();});- }- it("should create entries in variables sidebar", () => {- H.startNewNativeQuestion();- H.NativeEditor.type(- "SELECT count(*), {{unit}} as unit FROM ORDERS GROUP BY unit",- );- setVariableTypeAndField();+ cy.log("should create entries in variables sidebar");H.rightSidebar().findByLabelText("Parameter widget label").type(" updated").blur();H.filterWidget({ name: "Unit updated" }).should("exist");- });- it("should handle required prop for time grouping", () => {- H.startNewNativeQuestion();- H.NativeEditor.type(- "SELECT count(*), {{unit}} as unit FROM ORDERS GROUP BY unit",- );- setVariableTypeAndField();+ cy.log("should handle required prop for time grouping");H.rightSidebar().findByLabelText("Always require a value").parent()@@ -214,7 +221,7 @@ describe("scenarios > question > native", () => {H.runNativeQuery();cy.findByTestId("query-visualization-root").should("contain",- "You'll need to pick a value for 'Unit' before this query can run.",+ "You'll need to pick a value for 'Unit updated' before this query can run.",);H.rightSidebar().within(() => {@@ -226,32 +233,17 @@ describe("scenarios > question > native", () => {"contain","January 1, 2025",);- });- it("should reset default value when time grouping options are changed", () => {- const questionWithDefaultValue = {- name: "Saved question with time grouping",- native: {- query:- "SELECT count(*), {{unit}} as unit FROM ORDERS GROUP BY unit",- "template-tags": {- unit: {- type: "temporal-unit",- name: "unit",- id: "eb345703-001c-4b2a-b7d5-71cb3efe4beb",- "display-name": "Unit",- dimension: ["field", ORDERS.CREATED_AT, null],- required: true,- default: "year",- },- },- },- };-- H.createNativeQuestion(questionWithDefaultValue).then(- ({ body: { id } }) => {- H.visitQuestion(id);- },+ cy.log(+ "should reset default value when time grouping options are changed",+ );+ H.queryBuilderHeader().button("Save").click();+ cy.findByTestId("save-question-modal").within(() => {+ cy.findByLabelText("Name").type("Saved question with time grouping");+ cy.button("Save").click();+ });+ cy.wait("@card").then(({ response }) =>+ H.visitQuestion(response.body.id),);cy.log("open editor");@@ -272,17 +264,6 @@ describe("scenarios > question > native", () => {cy.log("verify default value is empty");H.rightSidebar().should("contain", "Enter a default value…");});-- it("should show validation error when query is invalid", () => {- H.startNewNativeQuestion();- H.NativeEditor.type(- "SELECT count(*), {{unit}} as unit FROM ORDERS GROUP BY unit",- );- setVariableType();- H.queryBuilderHeader()- .button("Save")- .should("have.attr", "data-disabled");- });});});@@ -305,7 +286,7 @@ describe("scenarios > question > native", () => {cy.location("pathname").should("match", /\/question\/\d+/);});- it("should be able to add new columns after hiding some (metabase#15393)", () => {+ it("should be able to add new columns after hiding some and recover them after a failed query (metabase#15393, metabase#16914)", () => {H.startNewNativeQuestion({ display: "table" });H.NativeEditor.type("select 1 as visible, 2 as hidden");cy.findByTestId("native-query-editor-container")@@ -324,11 +305,32 @@ describe("scenarios > question > native", () => {H.NativeEditor.type("{movetoend}, 3 as added");cy.get("@runQuery").click();cy.get("@sidebar").contains(/added/i);++ cy.log(+ "should recover visualization settings after a failed query (metabase#16914)",+ );+ const FAILING_PIECE = " foo";+ cy.button("Done").click();++ H.NativeEditor.focus().type(FAILING_PIECE);+ H.runNativeQuery();++ H.NativeEditor.focus();+ cy.realPress("End");+ Cypress._.range(FAILING_PIECE.length).forEach(() =>+ cy.realPress(["Shift", "ArrowLeft"]),+ );+ cy.realPress("Backspace");+ H.runNativeQuery();++ cy.findByTestId("query-visualization-root").within(() => {+ cy.findByText("Every field is hidden right now").should("not.exist");+ cy.findByText("VISIBLE");+ cy.findByText("HIDDEN").should("not.exist");+ });});it("should not autorun ad-hoc native queries by default or native queries after updating a question (metabase#30165)", () => {- cy.intercept("POST", "/api/dataset").as("adhocDataset");-H.visitQuestionAdhoc({display: "scalar",@@ -345,9 +347,8 @@ describe("scenarios > question > native", () => {// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usagecy.findByText("Here's where your results will appear").should("be.visible");- cy.get("@adhocDataset.all").should("have.length", 0);+ cy.get("@dataset.all").should("have.length", 0);- cy.intercept("POST", "/api/dataset").as("dataset");cy.intercept("POST", "/api/card/*/query").as("cardQuery");cy.intercept("PUT", "/api/card/*").as("updateQuestion");@@ -369,34 +370,33 @@ describe("scenarios > question > native", () => {});cy.wait("@updateQuestion");- cy.get("@dataset.all").should("have.length", 0);- cy.get("@cardQuery.all").should("have.length", 0);cy.findByTestId("query-builder-main").findByText("Here's where your results will appear").should("be.visible");+ cy.get("@dataset.all").should("have.length", 0);+ cy.get("@cardQuery.all").should("have.length", 0);});- it("should allow to preview a fully parameterized query", () => {+ it("should preview a query with missing and with set parameters", () => {H.startNewNativeQuestion();H.NativeEditor.type("select * from PRODUCTS where CATEGORY={{category}}");- cy.findByPlaceholderText("Category").type("Gadget");- cy.button("Preview the query").click();- cy.wait("@datasetNative");- H.modal().within(() => {- H.codeMirrorValue().should("contain", "CATEGORY = 'Gadget'");- });- });-- it("should show errors when previewing a query", () => {- H.startNewNativeQuestion();- H.NativeEditor.type("select * from PRODUCTS where CATEGORY={{category}}");+ cy.log("should show errors when previewing a query");cy.button("Preview the query").click();cy.wait("@datasetNative");-H.modal().findByText(/missing required parameters/).should("be.visible");+ cy.realPress("Escape");+ H.modal().should("not.exist");++ cy.log("should allow to preview a fully parameterized query");+ cy.findByPlaceholderText("Category").type("Gadget");+ cy.button("Preview the query").click();+ cy.wait("@datasetNative");+ H.modal().within(() => {+ H.codeMirrorValue().should("contain", "CATEGORY = 'Gadget'");+ });});it("should run the query when pressing meta+enter", () => {@@ -416,8 +416,6 @@ describe("scenarios > question > native", () => {});it("should be possible to format the native query using the keyboard shortcut", () => {- H.restore();- cy.signInAsNormalUser();H.startNewNativeQuestion({query: "SELECT COUNT(*) FROM ORDERS",});@@ -431,7 +429,7 @@ describe("scenarios > question > native", () => {);});- it("should add tab at the end of the query", () => {+ it("should add tab at the end of the query and indent the selected line", () => {H.startNewNativeQuestion({query: "SELECT",});@@ -440,17 +438,12 @@ describe("scenarios > question > native", () => {cy.realPress(["Tab"]);H.NativeEditor.get().should("have.text", "SELECT\t");- });-- it("should indent the line when pressing tab while selected", () => {- H.startNewNativeQuestion({- query: "SELECT",- });+ cy.log("should indent the line when pressing tab while selected");H.NativeEditor.focus().type("{selectall}");cy.realPress(["Tab"]);- H.NativeEditor.get().should("have.text", "\tSELECT");+ H.NativeEditor.get().should("have.text", "\tSELECT\t");});it("should indent the next line to the same level when entering newline", () => {@@ -462,49 +455,6 @@ describe("scenarios > question > native", () => {.should("have.text", "\tSELECT\tFOO");});- it("should use the correct indentation for mongo", { tags: "@mongo" }, () => {- const MONGO_DB_NAME = "QA Mongo";-- H.restore("mongo-5");- cy.signInAsAdmin();-- H.startNewNativeQuestion();- cy.findByTestId("gui-builder-data").click();- cy.findByLabelText(MONGO_DB_NAME).click();-- H.NativeEditor.type('[{enter}{ {enter}"foo": "bar",{enter}"baz"');-- H.NativeEditor.get().should("be.visible").get(".cm-line").as("lines");-- cy.get("@lines").eq(0).should("have.text", "[");- cy.get("@lines").eq(1).should("have.text", " {");- cy.get("@lines").eq(2).should("have.text", ' "foo": "bar",');- cy.get("@lines").eq(3).should("have.text", ' "baz"');- cy.get("@lines").eq(4).should("have.text", " }");- cy.get("@lines").eq(5).should("have.text", "]");- });-- it(- "it should insert a two spaces when pressing tab in json-like languages",- { tags: "@mongo" },- () => {- const MONGO_DB_NAME = "QA Mongo";-- H.restore("mongo-5");- cy.signInAsAdmin();-- H.startNewNativeQuestion();- cy.findByTestId("gui-builder-data").click();- cy.findByLabelText(MONGO_DB_NAME).click();-- H.NativeEditor.type("{tab}");-- H.NativeEditor.get().should("be.visible").get(".cm-line").as("lines");-- cy.get("@lines").eq(0).should("have.text", " ");- },- );-it("should be able to handle two sidebars on different screen sizes", () => {const questionDetails = {name: "13332",@@ -536,6 +486,7 @@ describe("scenarios > question > native", () => {cy.log("try to open data reference sidebar on a mid size screen");cy.findByTestId("visibility-toggler").click();+ H.NativeEditor.get().should("be.visible");dataReferenceSidebar().should("not.be.visible");cy.log("open visualization settings sidebar, order matters");@@ -554,6 +505,40 @@ describe("scenarios > question > native", () => {});});+describe("scenarios > question > native > mongo", { tags: "@mongo" }, () => {+ const MONGO_DB_NAME = "QA Mongo";++ beforeEach(() => {+ H.restore("mongo-5");+ cy.signInAsAdmin();+ });++ it("should switch an SQL question to mongo and use two-space indentation (metabase#53299)", () => {+ H.startNewNativeQuestion();+ cy.findByTestId("gui-builder-data").click();+ cy.findByLabelText(MONGO_DB_NAME).click();+ H.nativeEditorDataSource().should("contain", MONGO_DB_NAME);++ cy.log("should insert two spaces when pressing tab in json-like languages");+ H.NativeEditor.type("{tab}");+ H.NativeEditor.get().should("be.visible").get(".cm-line").as("lines");+ cy.get("@lines").eq(0).should("have.text", " ");++ cy.log("should use the correct indentation for mongo");+ H.NativeEditor.clear();+ H.NativeEditor.type('[{enter}{ {enter}"foo": "bar",{enter}"baz"');++ H.NativeEditor.get().should("be.visible").get(".cm-line").as("lines");++ cy.get("@lines").eq(0).should("have.text", "[");+ cy.get("@lines").eq(1).should("have.text", " {");+ cy.get("@lines").eq(2).should("have.text", ' "foo": "bar",');+ cy.get("@lines").eq(3).should("have.text", ' "baz"');+ cy.get("@lines").eq(4).should("have.text", " }");+ cy.get("@lines").eq(5).should("have.text", "]");+ });+});+describe("scenarios > native question > data reference sidebar", () => {beforeEach(() => {H.restore();@@ -570,6 +555,8 @@ describe("scenarios > native question > data reference sidebar", () => {"Confirmed Sample Company orders for a product, from a user.",);cy.findByText("9 columns");+ cy.log("should not show metrics when they are not defined on the table");+ cy.findByText(/metric/).should("not.exist");cy.findByText("QUANTITY").click();cy.findByText("Number of products bought.");@@ -656,16 +643,6 @@ describe("scenarios > native question > data reference sidebar", () => {});describe("metrics", () => {- it("should not show metrics when they are not defined on the selected table", () => {- H.startNewNativeQuestion();- sidebarHeaderTitle().should("have.text", "Sample Database");-- dataReferenceSidebar().within(() => {- cy.findByText("ORDERS").click();- cy.findByText(/metric/).should("not.exist");- });- });-it("should show metrics defined on tables", () => {H.createQuestion(ORDERS_SCALAR_METRIC);@@ -681,6 +658,7 @@ describe("scenarios > native question > data reference sidebar", () => {cy.log("clicking the title should navigate back");cy.findByText("Count of orders").should("be.visible").click();+ cy.findByText("1 metric").should("be.visible");});});});diff --git a/e2e/test/scenarios/native/native_subquery.cy.spec.js b/e2e/test/scenarios/native/native_subquery.cy.spec.jsindex 853c36b35c2..f43f90e227d 100644--- a/e2e/test/scenarios/native/native_subquery.cy.spec.js+++ b/e2e/test/scenarios/native/native_subquery.cy.spec.js@@ -26,7 +26,6 @@ describe("scenarios > question > native subquery", () => {name: "Count of People",native: { query: queryText },}).then(({ body: { id: questionId3 } }) => {- cy.wrap(questionId3).as("toplevelQuestionId");cy.visit(`/question/${questionId3}`);// Refresh the state, so previously created questions need to be loaded again.cy.reload();@@ -34,11 +33,19 @@ describe("scenarios > question > native subquery", () => {// placing the cursor inside an existing template tag should open the data referenceH.NativeEditor.focus().type("{leftarrow}{leftarrow}");cy.findByText("A People Question");- // subsequently moving the cursor out from the tag should keep the data reference open- H.NativeEditor.focus().type("{rightarrow}");- cy.findByText("A People Question");+ // moving the cursor out of the tag should keep the data reference open+ H.NativeEditor.type("{rightarrow}{rightarrow}", { focus: false });+ cy.findByTestId("sidebar-right")+ .findByText("A People Question")+ .should("be.visible");+ // typing after the tag, outside of it, should keep the data reference open+ H.NativeEditor.type(" ", { focus: false });+ H.NativeEditor.value().should("eq", `${queryText} `);+ cy.findByTestId("sidebar-right")+ .findByText("A People Question")+ .should("be.visible");// typing a template tag id should open the editor- H.NativeEditor.focus().type(" ").type(`{{#${questionId2}`);+ H.NativeEditor.type(`{{#${questionId2}`);cy.findByText("A People Model");});});@@ -61,7 +68,7 @@ describe("scenarios > question > native subquery", () => {type: "model",collection_id: ADMIN_PERSONAL_COLLECTION_ID,}).then(({ body: { id: questionId2 } }) => {- // Move question 2 to personal collection+ // Move question 2 from the personal collection to Our analyticscy.visit(`/question/${questionId2}`);H.openQuestionActions();cy.findByTestId("move-button").click();@@ -127,7 +134,6 @@ describe("scenarios > question > native subquery", () => {},},}).then(({ body: { id: questionId3 } }) => {- cy.wrap(questionId3).as("toplevelQuestionId");cy.visit(`/question/${questionId3}`);// Refresh the state, so previously created questions need to be loaded again.@@ -146,14 +152,13 @@ describe("scenarios > question > native subquery", () => {H.NativeEditor.focus().type(` {{#${questionId2}}}`);- // Wait until another explicit autocomplete is triggered- // cy.wait(1000);-// Again, typing in in one go doesn't always work// so type it in two partsH.NativeEditor.focus().type(" ").type("another");- H.NativeEditor.completions("ANOTHER").should("be.visible");+ H.NativeEditor.completion("ANOTHER_UNIQUE_COLUMN_NAME").should(+ "be.visible",+ );});});});@@ -193,10 +198,12 @@ describe("scenarios > question > native subquery", () => {});// change the name+ cy.intercept("PUT", "/api/card/*").as("updateCard");cy.visit(`/question/${questionId1}`);cy.findByText("A People Question 1").type(" changed");// unfocus the inputcy.findByText("Open Editor").click();+ cy.wait("@updateCard");// check the name has changedcy.visit(`/question/${questionId2}`);diff --git a/e2e/test/scenarios/native/snippet-tags.cy.spec.ts b/e2e/test/scenarios/native/snippet-tags.cy.spec.tsindex 8a59d35ed6c..b4f01b37996 100644--- a/e2e/test/scenarios/native/snippet-tags.cy.spec.ts+++ b/e2e/test/scenarios/native/snippet-tags.cy.spec.ts@@ -8,33 +8,6 @@ describe("scenarios > native > snippet tags", () => {cy.signInAsAdmin();});- it("should be able to create a snippet with variable tags", () => {- H.startNewNativeQuestion();- H.NativeEditor.type("select id from products where ");-- cy.log("create a snippet");- getEditorTopBar().icon("snippet").click();- getEditorSidebar().findByText("Create snippet").click();- H.modal().within(() => {- getSnippetContentInput().type("category = {{category}}", {- parseSpecialCharSequences: false,- });- getSnippetNameInput().type("variable-snippet");- cy.button("Save").click();- });-- cy.log("verify that the snippet was inserted");- H.NativeEditor.get().should(- "contain",- "select id from products where {{snippet: variable-snippet}}",- );-- cy.log("verify that the query can be run");- getEditorTopBar().findByPlaceholderText("Category").type("Widget");- H.runNativeQuery();- H.assertQueryBuilderRowCount(54);- });-it("should be able to create a snippet with card tags", () => {H.startNewNativeQuestion();H.NativeEditor.type("select * from ");@@ -61,9 +34,9 @@ describe("scenarios > native > snippet tags", () => {H.tableInteractive().should("be.visible");});- it("should be able to create a snippet with snippet tags", () => {+ it("should be able to create a snippet with variable tags and snippet tags", () => {H.startNewNativeQuestion();- H.NativeEditor.type("select * from ");+ H.NativeEditor.type("select id from products where ");cy.log("create a snippet");getEditorTopBar().icon("snippet").click();@@ -76,6 +49,17 @@ describe("scenarios > native > snippet tags", () => {cy.button("Save").click();});+ cy.log("verify that the snippet was inserted");+ H.NativeEditor.get().should(+ "contain",+ "select id from products where {{snippet: snippet1}}",+ );++ cy.log("verify that the query can be run");+ getEditorTopBar().findByPlaceholderText("Category").type("Widget");+ H.runNativeQuery();+ H.assertQueryBuilderRowCount(54);+cy.log("create a snippet that uses the previous snippet");getEditorTopBar().icon("snippet").click();getEditorSidebar().icon("add").click();@@ -91,9 +75,9 @@ describe("scenarios > native > snippet tags", () => {cy.log("verify that the snippet can used");H.NativeEditor.clear();H.NativeEditor.type("select id from products where {{snippet: snippet2}}");- getEditorTopBar().findByLabelText("Category").type("Gizmo");+ getEditorTopBar().findByLabelText("Category").clear().type("Gizmo");H.runNativeQuery();- H.tableInteractive().should("be.visible");+ H.assertQueryBuilderRowCount(51);});it("should be able to update a snippet and change tags", () => {@@ -103,6 +87,7 @@ describe("scenarios > native > snippet tags", () => {cy.log("update the snippet");getEditorVisibilityToggler().click();+ getEditorTopBar().findByPlaceholderText("Filter").should("be.visible");getEditorTopBar().icon("snippet").click();getEditorSidebar().within(() => {cy.icon("chevrondown").click({ force: true });@@ -137,8 +122,9 @@ describe("scenarios > native > snippet tags", () => {cy.log("change the type");getEditorVisibilityToggler().click();getEditorTopBar().icon("variable").click();- getVariableTypeSelect().click();+ getVariableTypeSelect().should("have.value", "Text").click();H.popover().findByText("Number").click();+ getVariableTypeSelect().should("have.value", "Number");cy.log("verify that the parameter can be used");getEditorTopBar().findByPlaceholderText("Filter").type("10");@@ -225,10 +211,6 @@ function createQuestionAndSnippet({},},},- enable_embedding: true,- embedding_params: {- filter: "enabled",- },}).then(({ body: card }) => {return { card, snippet };});diff --git a/e2e/test/scenarios/native/snippets.cy.spec.js b/e2e/test/scenarios/native/snippets.cy.spec.jsindex dd5ba738a4c..345e9182bd0 100644--- a/e2e/test/scenarios/native/snippets.cy.spec.js+++ b/e2e/test/scenarios/native/snippets.cy.spec.js@@ -19,7 +19,7 @@ describe("scenarios > question > snippets", () => {cy.signInAsNormalUser();});- it("should let you create and use a snippet", () => {+ it("should let you create, use and edit a snippet", () => {cy.log("Type a query and highlight some of the text");H.startNewNativeQuestion();H.NativeEditor.type("select 'stuff'");@@ -45,31 +45,38 @@ describe("scenarios > question > snippets", () => {cy.log("Run the query and check the value");cy.findByTestId("native-query-editor-container").icon("play").click();cy.findByTestId("scalar-value").should("have.text", "stuff");- });- it("should let you edit snippet", () => {- // Re-create the above snippet via API without the need to rely on the previous test- cy.request("POST", "/api/native-query-snippet", {- name: "stuff-snippet",- content: "stuff",+ cy.log(+ "A short snippet preview should not show scrollbars (metabase#21550)",+ );+ cy.findByTestId("sidebar-content").within(() => {+ cy.findByText("stuff-snippet").realHover();+ cy.icon("chevrondown").click({ force: true });+ cy.get("pre").should(($pre) => {+ expect($pre).to.contain("'stuff'");+ const preWidth = $pre[0].getBoundingClientRect().width;+ const clientWidth = $pre[0].clientWidth;+ const BORDERS = 2; // 1px left and right+ expect(clientWidth).to.be.gte(preWidth - BORDERS);+ });});- // Populate the native editor first- // 1. select- H.startNewNativeQuestion();- H.NativeEditor.type("select ");-- // 2. snippet- cy.icon("snippet").click();- cy.findByTestId("sidebar-right").within(() => {- cy.findByText("stuff-snippet").click();-- // Open the snippet edit modal- cy.icon("chevrondown").click({ force: true });- cy.findByRole("button", { name: /pencil icon edit/i }).click();+ cy.log(+ "The add icon should be visible with existing snippets (metabase#57441)",+ );+ H.rightSidebar().icon("add").should("be.visible").click();+ H.popover().findByText("New snippet").click();+ H.modal().within(() => {+ cy.findByText("Create your new snippet").should("be.visible");+ cy.button("Cancel").click();});+ H.modal().should("not.exist");++ cy.log("Edit the snippet");+ H.rightSidebar()+ .findByRole("button", { name: /pencil icon edit/i })+ .click();- // Update the name and contentH.modal().within(() => {cy.findByText("Editing stuff-snippet");@@ -152,14 +159,20 @@ describe("scenarios > question > snippets", () => {cy.get("@results").contains(/christ/i);});- it("should be possible to search snippets", () => {+ it("should be possible to search snippets and preview a query that has a snippet in it (metabase#60534)", () => {for (let i = 0; i < 16; i++) {H.createSnippet({ name: `snippet ${i}`, content: `select ${i}` });}+ cy.request("POST", "/api/native-query-snippet", {+ content: "'foo'",+ name: "Foo",+ collection_id: null,+ });H.startNewNativeQuestion();cy.icon("snippet").click();+ H.rightSidebar().findByText("snippet 2").should("be.visible");H.rightSidebar().icon("search").click();H.rightSidebar().findByRole("textbox").type("snippet 14");@@ -168,17 +181,8 @@ describe("scenarios > question > snippets", () => {H.rightSidebar().icon("close").click();H.rightSidebar().findByText("snippet 2").should("be.visible");- });-- it("should be possible to preview a query that has a snippet in it (metabase#60534)", () => {- cy.request("POST", "/api/native-query-snippet", {- content: "'foo'",- name: "Foo",- collection_id: null,- });- H.startNewNativeQuestion();- cy.icon("snippet").click();+ cy.log("preview a query that has a snippet in it (metabase#60534)");H.NativeEditor.type("select {{snippet: Foo}}");cy.findByTestId("native-query-top-bar").findByLabelText("Preview the query")@@ -204,6 +208,7 @@ describe("scenarios > question > snippets (OSS)", { tags: "@OSS" }, () => {// Confirm snippet is not in folderH.rightSidebar().within(() => {cy.findByText("snippet 1").should("be.visible");+ cy.findByText("Snippet Folder").should("not.exist");});});});@@ -245,7 +250,6 @@ describe("scenarios > question > snippets (EE)", () => {});it("should let you create a snippet folder and move a snippet into it", () => {- cy.signInAsAdmin();// create snippet via APIcy.request("POST", "/api/native-query-snippet", {content: "snippet 1",@@ -329,22 +333,26 @@ describe("scenarios > question > snippets (EE)", () => {});});- ["admin", "nocollection"].map((user) => {- it("should display nested snippets in their folder", () => {- createNestedSnippet();-- cy.signIn(user);-- // Open editor and sidebar- H.startNewNativeQuestion();+ it("should display nested snippets in their folder", () => {+ function assertSnippetInFolder() {cy.icon("snippet").click();-- // Confirm snippet is in folderH.rightSidebar().within(() => {cy.findByText("Snippet Folder").click();cy.findByText("snippet 1").click();});- });+ }++ createNestedSnippet();++ cy.log("as admin user");+ cy.signIn("admin");+ H.startNewNativeQuestion();+ assertSnippetInFolder();++ cy.log("as nocollection user");+ cy.signIn("nocollection");+ cy.reload();+ assertSnippetInFolder();});describe("navigation", () => {@@ -393,7 +401,7 @@ describe("scenarios > question > snippets (EE)", () => {});});- it("should not allow you to move a snippet collection into a itself or a child (metabase#44930)", () => {+ it("should not allow you to move a snippet collection into itself (metabase#44930)", () => {H.startNewNativeQuestion();cy.icon("snippet").click();@@ -415,19 +423,25 @@ describe("scenarios > question > snippets (EE)", () => {);});- it("should not display snippet folder as part of collections (metabase#14907)", () => {+ it("should not display snippet folder as part of collections and shouldn't update root permissions when changing permissions on a created folder (metabase#14907, metabase#17268)", () => {+ cy.intercept("PUT", "/api/collection/graph?skip-graph=true").as(+ "updatePermissions",+ );++ cy.log(+ "should not display snippet folder as part of collections (metabase#14907)",+ );cy.visit("/collection/root");cy.wait("@collections");- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Snippet Folder").should("not.exist");- });+ H.navigationSidebar().findByText("First collection").should("be.visible");+ H.navigationSidebar().findByText("Snippet Folder").should("not.exist");+ H.collectionTable().findByText("First collection").should("be.visible");+ H.collectionTable().findByText("Snippet Folder").should("not.exist");- it("shouldn't update root permissions when changing permissions on a created folder (metabase#17268)", () => {- cy.intercept("PUT", "/api/collection/graph?skip-graph=true").as(- "updatePermissions",+ cy.log(+ "shouldn't update root permissions when changing permissions on a created folder (metabase#17268)",);-H.startNewNativeQuestion();cy.icon("snippet").click();@@ -492,38 +506,30 @@ describe("scenarios > question > read-only snippets", () => {H.setupGitSync();});- it("should not let you create or edit a snippet", () => {+ it("should not let you create or edit a snippet or a snippet folder", () => {H.configureGitAndPullChanges("read-only");H.startNewNativeQuestion();cy.findByTestId("native-query-editor-action-buttons").icon("snippet").click();- cy.findByTestId("sidebar-content")- .findByText("Create snippet")- .should("not.exist");cy.findByTestId("sidebar-right").within(() => {- cy.findByText("stuff-snippet").click();- cy.findByRole("button", { name: /pencil icon edit/i }).should(+ cy.findByText("My favorite snippets").should("be.visible");+ cy.findByText("stuff-snippet").should("be.visible");++ cy.log("Menu that allows creating a snippet or a folder is not rendered");+ cy.findByTestId("snippet-header-buttons")+ .icon("search")+ .should("be.visible");+ cy.findByTestId("snippet-header-buttons").icon("add").should("not.exist");+ cy.findByRole("button", { name: "Snippet folder options" }).should("not.exist",);- });- });- it("should not let you create or edit a snippet folder", () => {- H.configureGitAndPullChanges("read-only");- H.startNewNativeQuestion();- cy.icon("snippet").click();-- cy.log("Menu that allows creating a snippet folder is not rendered");- cy.findByTestId("sidebar-right")- .as("sidebar")- .find(".Icon-add")- .should("not.exist");-- cy.findByTestId("sidebar-right").within(() => {- cy.findByText("My favorite snippets").should("be.visible");- cy.findByRole("button", { name: "Snippet folder options" }).should(+ cy.log("An expanded snippet has no edit button");+ cy.icon("chevrondown").click({ force: true });+ cy.get("pre").should("have.text", "select 'snippet 1'");+ cy.findByRole("button", { name: /pencil icon edit/i }).should("not.exist",);});diff --git a/e2e/test/scenarios/native-filters/sql-field-filter-types.cy.spec.js b/e2e/test/scenarios/native/sql-field-filter-types.cy.spec.jssimilarity index 95%rename from e2e/test/scenarios/native-filters/sql-field-filter-types.cy.spec.jsrename to e2e/test/scenarios/native/sql-field-filter-types.cy.spec.jsindex 84514f1d90c..bccc9f461d3 100644--- a/e2e/test/scenarios/native-filters/sql-field-filter-types.cy.spec.js+++ b/e2e/test/scenarios/native/sql-field-filter-types.cy.spec.js@@ -27,7 +27,7 @@ describe(cy.log("setup a boolean field filter");H.startNewNativeQuestion({ database: WRITABLE_DB_ID });SQLFilter.enterParameterizedQuery(- `SELECT count(*) FROM ${tableName} WHERE {{f}}`,+ `SELECT sum(id) FROM ${tableName} WHERE {{f}}`,);SQLFilter.openTypePickerFromDefaultFilterType();SQLFilter.chooseType("Field Filter");@@ -41,14 +41,14 @@ describe(cy.log("field filter with true");H.runNativeQuery({ wait: false });- assertScalarValue("2");+ assertScalarValue("3");H.filterWidget().click();H.popover().button("Add filter").click();H.runNativeQuery({ wait: false });assertScalarValue("1");H.filterWidget().icon("close").click();H.runNativeQuery({ wait: false });- assertScalarValue("2");+ assertScalarValue("3");cy.log("field filter with false");H.filterWidget().click();@@ -57,10 +57,10 @@ describe(cy.button("Add filter").click();});H.runNativeQuery({ wait: false });- assertScalarValue("1");+ assertScalarValue("2");H.filterWidget().icon("close").click();H.runNativeQuery({ wait: false });- assertScalarValue("2");+ assertScalarValue("3");});},);diff --git a/e2e/test/scenarios/native-filters/sql-field-filter.cy.spec.js b/e2e/test/scenarios/native/sql-field-filter.cy.spec.jssimilarity index 81%rename from e2e/test/scenarios/native-filters/sql-field-filter.cy.spec.jsrename to e2e/test/scenarios/native/sql-field-filter.cy.spec.jsindex 9fc058db507..5e54e9ee5c4 100644--- a/e2e/test/scenarios/native-filters/sql-field-filter.cy.spec.js+++ b/e2e/test/scenarios/native/sql-field-filter.cy.spec.js@@ -44,23 +44,34 @@ describe("scenarios > filters > sql filters > field filter", () => {});}- it("does not need a default value to run and save the query", () => {+ it("should handle a required tag", () => {+ cy.log("does not need a default value to run and save the query");SQLFilter.toggleRequired();SQLFilter.getRunQueryButton().should("not.be.disabled");SQLFilter.getSaveQueryButton().should("not.have.attr", "disabled");- });+ SQLFilter.toggleRequired();- it("when there's a default value, enabling required sets it as a parameter value", () => {- setDefaultFieldValue(5);- H.filterWidget().click();+ cy.log(+ "when there's a default value, enabling required sets it as a parameter value",+ );+ setDefaultFieldValue(8);+ H.filterWidget().should("contain.text", "8").click();H.clearFilterWidget();+ H.filterWidget().should("not.contain.text", "8");SQLFilter.toggleRequired();- H.filterWidget().should("contain.text", "5");- });+ H.filterWidget().should("contain.text", "8");++ cy.log(+ "when there's a default value and value is unset, updating filter sets the default back",+ );+ H.filterWidget().click();+ H.popover().within(() => {+ H.removeFieldValuesValue(0);+ H.fieldValuesCombobox().type("10,");+ cy.findByText("Update filter").click();+ });+ H.filterWidget().should("contain.text", "10");- it("when there's a default value and value is unset, updating filter sets the default back", () => {- setDefaultFieldValue(10);- SQLFilter.toggleRequired();H.filterWidget().click();H.popover().within(() => {H.removeFieldValuesValue(0);@@ -70,19 +81,21 @@ describe("scenarios > filters > sql filters > field filter", () => {cy.log("make sure the dialog is gone");cy.findByRole("dialog").should("not.exist");- H.filterWidget().should("contain.text", "10");- });+ H.filterWidget()+ .should("contain.text", "8")+ .and("not.contain.text", "10");- it("when there's a default value and template tag is required, can reset it back", () => {- setDefaultFieldValue(8);- SQLFilter.toggleRequired();+ cy.log(+ "when there's a default value and template tag is required, can reset it back",+ );H.filterWidget().click();H.popover().within(() => {H.fieldValuesCombobox().type("10,");cy.findByText("Update filter").click();});- H.filterWidget().icon("revert").click();+ H.filterWidget().icon("revert").should("be.visible").click();H.filterWidget().should("contain.text", "8");+ H.filterWidget().icon("revert").should("not.exist");});});// Deprecated field filter types@@ -133,6 +146,7 @@ describe("scenarios > filters > sql filters > field filter", () => {cy.findByText("Filter widget type").parent().findByTestId("filter-widget-type-select")+ .should("have.value", "String").click();H.popover().contains("String");@@ -158,7 +172,8 @@ describe("scenarios > filters > sql filters > field filter", () => {cy.button("Add filter").click();});SQLFilter.runQuery();- H.tableInteractive().should("contain", "10").and("contain", "20");+ H.assertQueryBuilderRowCount(2);+ H.assertTableData({ columns: ["ALIAS"], firstRows: [["10"], ["20"]] });});it("should be able to use a field alias with a time grouping", () => {diff --git a/e2e/test/scenarios/native-filters/sql-filters-reset-clear.cy.spec.ts b/e2e/test/scenarios/native/sql-filters-reset-clear.cy.spec.tssimilarity index 98%rename from e2e/test/scenarios/native-filters/sql-filters-reset-clear.cy.spec.tsrename to e2e/test/scenarios/native/sql-filters-reset-clear.cy.spec.tsindex 7ab9f22de79..6ec7fbd36a3 100644--- a/e2e/test/scenarios/native-filters/sql-filters-reset-clear.cy.spec.ts+++ b/e2e/test/scenarios/native/sql-filters-reset-clear.cy.spec.ts@@ -327,6 +327,7 @@ describe("scenarios > filters > sql filters > reset & clear", () => {checkStatusIcon(DEFAULT_NON_REQUIRED, "clear");cy.log("has default value, required, value same as default");+ filterInput(DEFAULT_REQUIRED).should("have.value", defaultValueFormatted);checkStatusIcon(DEFAULT_REQUIRED, "none");cy.log("has default value, required, current value different than default");@@ -382,6 +383,7 @@ describe("scenarios > filters > sql filters > reset & clear", () => {filter(NO_DEFAULT_REQUIRED).click();updateValue(otherValue);filter(NO_DEFAULT_REQUIRED).should("contain.text", otherValueFormatted);+ checkStatusIcon(NO_DEFAULT_REQUIRED, "clear");cy.log("has default value, non-required, current value same as default");checkStatusIcon(DEFAULT_NON_REQUIRED, "clear");@@ -407,6 +409,7 @@ describe("scenarios > filters > sql filters > reset & clear", () => {checkStatusIcon(DEFAULT_NON_REQUIRED, "clear");cy.log("has default value, required, value same as default");+ filter(DEFAULT_REQUIRED).should("contain.text", defaultValueFormatted);checkStatusIcon(DEFAULT_REQUIRED, "none");cy.log("has default value, required, current value different than default");@@ -517,6 +520,10 @@ describe("scenarios > filters > sql filters > reset & clear", () => {checkStatusIcon("Default filter widget value", "clear");clearButton("Default filter widget value").click();+ filterInput("Default filter widget value (required)").should(+ "have.value",+ "",+ );checkStatusIcon("Default filter widget value (required)", "none");});}diff --git a/e2e/test/scenarios/native-filters/sql-filters-source.cy.spec.js b/e2e/test/scenarios/native/sql-filters-source.cy.spec.jssimilarity index 71%rename from e2e/test/scenarios/native-filters/sql-filters-source.cy.spec.jsrename to e2e/test/scenarios/native/sql-filters-source.cy.spec.jsindex 9a9916dae19..6f7dd6e4a39 100644--- a/e2e/test/scenarios/native-filters/sql-filters-source.cy.spec.js+++ b/e2e/test/scenarios/native/sql-filters-source.cy.spec.js@@ -26,9 +26,7 @@ describe("scenarios > filters > sql filters > values source", () => {beforeEach(() => {H.restore();cy.signInAsAdmin();- H.updateSetting("enable-public-sharing", true);cy.intercept("POST", "/api/dataset").as("dataset");- cy.intercept("GET", "/api/session/properties").as("sessionProperties");cy.intercept("PUT", "/api/card/*").as("updateQuestion");cy.intercept("POST", "/api/card/*/query").as("cardQuery");cy.intercept("POST", "/api/dataset/parameter/values").as("parameterValues");@@ -52,15 +50,18 @@ describe("scenarios > filters > sql filters > values source", () => {});FieldFilter.openEntryForm();+ checkFilterValueInList("Gizmo");checkFilterValueNotInList("Doohickey");FieldFilter.selectFilterValueFromList("Gizmo");SQLFilter.runQuery("cardQuery");+ H.assertQueryBuilderRowCount(51);SQLFilter.toggleRequired();FieldFilter.openEntryForm(true);FieldFilter.selectFilterValueFromList("Gadget", {buttonLabel: "Update filter",});+ cy.findByTestId("sidebar-content").should("contain", "Gadget");});it("should be able to use a structured question source with a text tag", () => {@@ -77,6 +78,7 @@ describe("scenarios > filters > sql filters > values source", () => {});FieldFilter.openEntryForm();+ checkFilterValueInList("Gizmo");checkFilterValueNotInList("Doohickey");FieldFilter.selectFilterValueFromList("Gadget", { addFilter: false });FieldFilter.selectFilterValueFromList("Gizmo");@@ -93,22 +95,7 @@ describe("scenarios > filters > sql filters > values source", () => {cy.findByText("Gadget").click();cy.button("Update filter").click();});- });-- it("should be able to use a structured question source without saving the question", () => {- H.createQuestion(structuredSourceQuestion);-- H.startNewNativeQuestion();- SQLFilter.enterParameterizedQuery(- "SELECT * FROM PRODUCTS WHERE CATEGORY = {{tag}}",- );- H.setDropdownFilterType();- H.setFilterQuestionSource({ question: "MBQL source", field: "Category" });-- FieldFilter.openEntryForm();- checkFilterValueNotInList("Doohickey");- FieldFilter.selectFilterValueFromList("Gizmo");- SQLFilter.runQuery("dataset");+ cy.findByTestId("sidebar-content").should("contain", "Gadget");});it("should properly cache parameter values api calls", () => {@@ -127,6 +114,10 @@ describe("scenarios > filters > sql filters > values source", () => {FieldFilter.openEntryForm();checkFilterValueInList("Gizmo");cy.get("@parameterValues.all").should("have.length", 1);+ checkFilterValueNotInList("Doohickey");+ FieldFilter.selectFilterValueFromList("Gizmo");+ SQLFilter.runQuery("dataset");+ H.assertQueryBuilderRowCount(51);H.setFilterListSource({ values: ["A", "B"] });FieldFilter.openEntryForm();cy.wait("@parameterValues");@@ -166,30 +157,11 @@ describe("scenarios > filters > sql filters > values source", () => {});FieldFilter.openEntryForm();+ checkFilterValueInList("1018947080336");checkFilterValueNotInList("0001664425970");FieldFilter.selectFilterValueFromList("1018947080336");SQLFilter.runQuery("cardQuery");- });- });-- describe("static list source (dropdown)", () => {- it("should be able to use a static list source in the query builder", () => {- H.startNewNativeQuestion();- SQLFilter.enterParameterizedQuery("SELECT * FROM PRODUCTS WHERE {{tag}}");- SQLFilter.openTypePickerFromDefaultFilterType();- SQLFilter.chooseType("Field Filter");- FieldFilter.mapTo({ table: "Products", field: "Ean" });- FieldFilter.setWidgetType("String");- H.setFilterListSource({ values: ["1018947080336", "7663515285824"] });- H.saveQuestion("SQL filter", undefined, {- path: ["Our analytics"],- });-- FieldFilter.openEntryForm();- checkFilterValueNotInList("0001664425970");- FieldFilter.selectFilterValueFromList("1018947080336");- cy.findByLabelText("Tag").should("contain.text", "1018947080336");- SQLFilter.runQuery("cardQuery");+ H.assertQueryBuilderRowCount(1);});});@@ -209,42 +181,22 @@ describe("scenarios > filters > sql filters > values source", () => {});FieldFilter.openEntryForm();+ checkFilterValueInList("Custom Label");checkFilterValueNotInList("0001664425970");checkFilterValueNotInList("1018947080336");FieldFilter.selectFilterValueFromList("Custom Label");cy.findByLabelText("Tag").should("contain.text", "Custom Label");SQLFilter.runQuery("cardQuery");- });- });-- describe("static list source (search box)", () => {- it("should be able to use a static list source in the query builder", () => {- H.startNewNativeQuestion();- SQLFilter.enterParameterizedQuery("SELECT * FROM PRODUCTS WHERE {{tag}}");- SQLFilter.openTypePickerFromDefaultFilterType();- SQLFilter.chooseType("Field Filter");- FieldFilter.mapTo({ table: "Products", field: "Ean" });- FieldFilter.setWidgetType("String");-- H.setSearchBoxFilterType();- H.setFilterListSource({- values: ["1018947080336", "7663515285824"],- });- H.saveQuestion("SQL filter", undefined, {- path: ["Our analytics"],- });+ H.assertQueryBuilderRowCount(1);FieldFilter.openEntryForm();-- H.fieldValuesCombobox().type("101");- H.popover().findByText("1018947080336").click();-- H.fieldValuesValue(0)- .should("be.visible")- .should("contain", "1018947080336");- H.popover().button("Add filter").click();-- cy.findByLabelText("Tag").should("contain.text", "1018947080336");+ H.popover().findByText("Custom Label").click();+ FieldFilter.selectFilterValueFromList("7663515285824", {+ buttonLabel: "Update filter",+ });+ cy.findByLabelText("Tag").should("contain.text", "7663515285824");+ SQLFilter.runQuery("cardQuery");+ H.assertQueryBuilderRowCount(1);});});@@ -269,6 +221,8 @@ describe("scenarios > filters > sql filters > values source", () => {H.fieldValuesCombobox().type("Custom Label");// eslint-disable-next-line metabase/no-unsafe-element-filtering+ H.popover().last().findByText("Custom Label").should("be.visible");+ // eslint-disable-next-line metabase/no-unsafe-element-filteringH.popover().last().findByText("1018947080336").should("not.exist");// eslint-disable-next-line metabase/no-unsafe-element-filteringH.popover().last().findByText("Custom Label").click();@@ -278,6 +232,18 @@ describe("scenarios > filters > sql filters > values source", () => {H.popover().button("Add filter").click();cy.findByLabelText("Tag").should("contain.text", "Custom Label");++ FieldFilter.openEntryForm();+ H.removeFieldValuesValue(0);+ H.fieldValuesCombobox().type("766");+ // eslint-disable-next-line metabase/no-unsafe-element-filtering+ H.popover().last().findByText("7663515285824").click();+ H.fieldValuesValue(0)+ .should("be.visible")+ .should("contain", "7663515285824");+ H.popover().button("Update filter").click();++ cy.findByLabelText("Tag").should("contain.text", "7663515285824");});});});@@ -285,44 +251,13 @@ describe("scenarios > filters > sql filters > values source > number parameter",beforeEach(() => {H.restore();cy.signInAsAdmin();- H.updateSetting("enable-public-sharing", true);- cy.intercept("POST", "/api/dataset").as("dataset");- cy.intercept("GET", "/api/session/properties").as("sessionProperties");- cy.intercept("PUT", "/api/card/*").as("updateQuestion");cy.intercept("POST", "/api/card/*/query").as("cardQuery");- cy.intercept("POST", "/api/dataset/parameter/values").as("parameterValues");- cy.intercept("GET", "/api/card/*/params/*/values").as(- "cardParameterValues",- );});- describe("static list source (dropdown)", () => {- it("should be able to use a static list source in the query builder", () => {- H.startNewNativeQuestion();- SQLFilter.enterParameterizedQuery("SELECT {{ x }}");- SQLFilter.openTypePickerFromDefaultFilterType();- SQLFilter.chooseType("Number");-- H.setDropdownFilterType();- H.setFilterListSource({- values: [["10", "Ten"], ["20", "Twenty"], "30"],- });- H.saveQuestion("SQL filter", undefined, {- path: ["Our analytics"],- });-- FieldFilter.openEntryForm();- checkFilterValueNotInList("10");- FieldFilter.selectFilterValueFromList("Twenty");- cy.findByLabelText("X").should("contain.text", "Twenty");- SQLFilter.runQuery("cardQuery");- });- });-- describe("static list source with custom labels (dropdown)", () => {+ describe("static list source with custom labels (search box)", () => {it("should be able to use a static list source in the query builder", () => {H.startNewNativeQuestion();- SQLFilter.enterParameterizedQuery("SELECT * FROM {{ tag }}");+ SQLFilter.enterParameterizedQuery("SELECT {{ tag }} AS V");SQLFilter.openTypePickerFromDefaultFilterType();SQLFilter.chooseType("Number");H.setSearchBoxFilterType();@@ -338,52 +273,27 @@ describe("scenarios > filters > sql filters > values source > number parameter",H.multiAutocompleteInput().type("Tw");});+ // eslint-disable-next-line metabase/no-unsafe-element-filtering+ H.popover().last().findByText("Twenty").should("be.visible");checkFilterValueNotInList("10");checkFilterValueNotInList("20");// eslint-disable-next-line metabase/no-unsafe-element-filteringH.popover().last().findByText("Twenty").click();- H.popover().button("Add filter").click();-- cy.findByLabelText("Tag").should("contain.text", "Twenty");- SQLFilter.runQuery("cardQuery");- });- });-- describe("static list source (search box)", () => {- it("should be able to use a static list source in the query builder", () => {- H.startNewNativeQuestion();- SQLFilter.enterParameterizedQuery("SELECT {{ tag }}");- SQLFilter.openTypePickerFromDefaultFilterType();- SQLFilter.chooseType("Number");-- H.setSearchBoxFilterType();- H.setFilterListSource({- values: [["10", "Ten"], ["20", "Twenty"], "30"],- });- H.saveQuestion("SQL filter", undefined, {- path: ["Our analytics"],- });-- FieldFilter.openEntryForm();-- H.dashboardParametersPopover().within(() => {- H.multiAutocompleteInput().type("Tw");- });- // eslint-disable-next-line metabase/no-unsafe-element-filtering- H.popover().last().findByText("Twenty").click();-H.multiAutocompleteValue(0).should("be.visible").should("contain", "Twenty");H.popover().button("Add filter").click();cy.findByLabelText("Tag").should("contain.text", "Twenty");+ SQLFilter.runQuery("cardQuery");+ H.assertQueryBuilderRowCount(1);+ H.queryBuilderMain().findByText("20").should("be.visible");});});- it("should show the values when picking the default value", () => {+ it("should show the values when picking the default value and use a static list source in the query builder", () => {H.startNewNativeQuestion();- SQLFilter.enterParameterizedQuery("SELECT {{ x }}");+ SQLFilter.enterParameterizedQuery("SELECT {{ x }} AS V");SQLFilter.openTypePickerFromDefaultFilterType();SQLFilter.chooseType("Number");@@ -407,6 +317,23 @@ describe("scenarios > filters > sql filters > values source > number parameter",cy.findByLabelText("X").should("contain.text", "Twenty");SQLFilter.runQuery("cardQuery");+ H.assertQueryBuilderRowCount(1);+ H.queryBuilderMain().findByText("20").should("be.visible");++ cy.log("static list source (dropdown)");+ H.clearFilterWidget();+ cy.findByLabelText("X").should("not.contain.text", "Twenty");++ FieldFilter.openEntryForm();+ checkFilterValueInList("Ten");+ checkFilterValueNotInList("10");+ FieldFilter.selectFilterValueFromList("Ten", {+ buttonLabel: "Update filter",+ });+ cy.findByLabelText("X").should("contain.text", "Ten");+ SQLFilter.runQuery("cardQuery");+ H.assertQueryBuilderRowCount(1);+ H.queryBuilderMain().findByText("10").should("be.visible");});it("should clear the value type and config when changing the template tag type and restore them when changing the type back", () => {@@ -443,7 +370,7 @@ describe("scenarios > filters > sql filters > values source > number parameter",const updateQuestion = () => {cy.findByText("Save").click();- cy.findByTestId("save-question-modal").within((modal) => {+ cy.findByTestId("save-question-modal").within(() => {cy.findByText("Save").click();});cy.wait("@updateQuestion");@@ -454,7 +381,7 @@ const checkFilterValueInList = (value) => {H.popover().last().within(() => {- cy.findByText(value).should("exist");+ cy.findByText(value).should("be.visible");});};diff --git a/e2e/test/scenarios/native-filters/sql-filters.cy.spec.js b/e2e/test/scenarios/native/sql-filters.cy.spec.jssimilarity index 62%rename from e2e/test/scenarios/native-filters/sql-filters.cy.spec.jsrename to e2e/test/scenarios/native/sql-filters.cy.spec.jsindex 3fcec096709..bdbbbb28206 100644--- a/e2e/test/scenarios/native-filters/sql-filters.cy.spec.js+++ b/e2e/test/scenarios/native/sql-filters.cy.spec.js@@ -20,50 +20,38 @@ describe("scenarios > filters > sql filters > basic filter types", () => {);});- it("when set through the filter widget", () => {- SQLFilter.setWidgetValue("Gizmo");-- SQLFilter.runQuery();-- cy.findByTestId("query-visualization-root").within(() => {- cy.findByText("Rustic Paper Wallet");- cy.findAllByText("Doohickey").should("not.exist");- });- });-- describe("required tag", () => {- it("does not need a default value to run and save the query", () => {- SQLFilter.toggleRequired();- SQLFilter.getRunQueryButton().should("not.be.disabled");- SQLFilter.getSaveQueryButton().should("not.have.attr", "disabled");- });-- it("when there's a default value, enabling required sets it as a parameter value", () => {- SQLFilter.setDefaultValue("New value");- H.filterWidget().find("input").invoke("val", "");- SQLFilter.toggleRequired();- H.filterWidget().find("input").should("have.value", "New value");- });-- it("when there's a default value and input is empty, blur sets default value back", () => {- SQLFilter.setDefaultValue("default");- SQLFilter.toggleRequired();- H.filterWidget().within(() => {- cy.get("input")- .type("{selectAll}{backspace}")- .should("have.value", "");- cy.get("input").blur().should("have.value", "default");- });+ it("should handle a required tag", () => {+ cy.log("does not need a default value to run and save the query");+ SQLFilter.toggleRequired();+ SQLFilter.getRunQueryButton().should("not.be.disabled");+ SQLFilter.getSaveQueryButton().should("not.have.attr", "disabled");+ SQLFilter.toggleRequired();++ cy.log(+ "when there's a default value, enabling required sets it as a parameter value",+ );+ SQLFilter.setDefaultValue("default");+ H.filterWidget().find("input").clear();+ H.filterWidget().find("input").blur();+ H.filterWidget().find("input").should("have.value", "");+ SQLFilter.toggleRequired();+ H.filterWidget().find("input").should("have.value", "default");++ cy.log(+ "when there's a default value and input is empty, blur sets default value back",+ );+ H.filterWidget().within(() => {+ cy.get("input").type("{selectAll}{backspace}").should("have.value", "");+ cy.get("input").blur().should("have.value", "default");});- it("when there's a default value and template tag is required, can reset it back", () => {- SQLFilter.setDefaultValue("default");- SQLFilter.toggleRequired();- H.filterWidget().within(() => {- cy.get("input").type("abc").should("have.value", "defaultabc");- cy.icon("revert").click();- cy.get("input").should("have.value", "default");- });+ cy.log(+ "when there's a default value and template tag is required, can reset it back",+ );+ H.filterWidget().within(() => {+ cy.get("input").type("abc").should("have.value", "defaultabc");+ cy.icon("revert").click();+ cy.get("input").should("have.value", "default");});});});@@ -78,50 +66,52 @@ describe("scenarios > filters > sql filters > basic filter types", () => {SQLFilter.chooseType("Number");});- it("when set through the filter widget", () => {+ it("should work when set through the filter widget and handle a required tag (metabase#15981)", () => {+ cy.log("when set through the filter widget");SQLFilter.setWidgetValue("4.3");SQLFilter.runQuery();- cy.findByTestId("query-visualization-root").within(() => {- cy.findByText("Aerodynamic Linen Coat");- cy.findAllByText("4.3");- });- });+ H.assertQueryBuilderRowCount(17);+ H.tableInteractive()+ .findByText("Aerodynamic Linen Coat")+ .should("be.visible");- describe("required tag", () => {- it("does not need a default value to run and save the query", () => {- SQLFilter.toggleRequired();- SQLFilter.getRunQueryButton().should("not.be.disabled");- SQLFilter.getSaveQueryButton().should("not.have.attr", "disabled");- });+ H.filterWidget().find("input").clear();+ H.filterWidget().find("input").blur();+ H.filterWidget().find("input").should("have.value", "");- it("when there's a default value, enabling required sets it as a parameter value", () => {- SQLFilter.setDefaultValue("3");- H.filterWidget().find("input").invoke("val", "");- SQLFilter.toggleRequired();- H.filterWidget().find("input").should("have.value", "3");- });+ cy.log("does not need a default value to run and save the query");+ SQLFilter.toggleRequired();+ SQLFilter.getRunQueryButton().should("not.be.disabled");+ SQLFilter.getSaveQueryButton().should("not.have.attr", "disabled");+ SQLFilter.toggleRequired();- it("when there's a default value and input is empty, blur sets default value back", () => {- SQLFilter.setDefaultValue("3");- SQLFilter.toggleRequired();- H.filterWidget().within(() => {- cy.get("input")- .type("{selectAll}{backspace}")- .should("have.value", "");- cy.get("input").blur().should("have.value", "3");- });+ cy.log(+ "when there's a default value, enabling required sets it as a parameter value",+ );+ SQLFilter.setDefaultValue("3");+ H.filterWidget().find("input").clear();+ H.filterWidget().find("input").blur();+ H.filterWidget().find("input").should("have.value", "");+ SQLFilter.toggleRequired();+ H.filterWidget().find("input").should("have.value", "3");++ cy.log(+ "when there's a default value and input is empty, blur sets default value back",+ );+ H.filterWidget().within(() => {+ cy.get("input").type("{selectAll}{backspace}").should("have.value", "");+ cy.get("input").blur().should("have.value", "3");});- it("when there's a default value and template tag is required, can reset it back", () => {- SQLFilter.setDefaultValue("3");- SQLFilter.toggleRequired();- H.filterWidget().within(() => {- cy.get("input").type(".11").should("have.value", "3.11");- cy.icon("revert").click();- cy.get("input").should("have.value", "3");- });+ cy.log(+ "when there's a default value and template tag is required, can reset it back",+ );+ H.filterWidget().within(() => {+ cy.get("input").type(".11").should("have.value", "3.11");+ cy.icon("revert").click();+ cy.get("input").should("have.value", "3");});});});@@ -136,7 +126,16 @@ describe("scenarios > filters > sql filters > basic filter types", () => {SQLFilter.chooseType("Date");});- it("when set through the filter widget", () => {+ function setDefaultDate(year = "2024", month = "01", day = "22") {+ cy.findByTestId("sidebar-content")+ .findByText("Select a default value…")+ .click();+ DateFilter.setSingleDate(`${month}/${day}/${year}`);+ H.popover().findByText("Add filter").click();+ }++ it("should work when set through the filter widget and handle a required tag", () => {+ cy.log("when set through the filter widget");H.filterWidget().click();// Since we have fixed dates in Sample Database (dating back a couple of years), it'd be cumbersome to click back month by month.// Instead, let's choose the 15th of the current month and assert that there are no products / no results.@@ -151,41 +150,34 @@ describe("scenarios > filters > sql filters > basic filter types", () => {cy.findByTestId("query-visualization-root").within(() => {cy.findByText("No results");});- });- function setDefaultDate(year = "2024", month = "01", day = "22") {- cy.findByTestId("sidebar-content")- .findByText("Select a default value…")- .click();- DateFilter.setSingleDate(`${month}/${day}/${year}`);- H.popover().findByText("Add filter").click();- }+ H.filterWidget().icon("close").click();+ H.filterWidget().icon("close").should("not.exist");- describe("required tag", () => {- it("does not need a default value to run and save the query", () => {- SQLFilter.toggleRequired();- SQLFilter.getRunQueryButton().should("not.be.disabled");- SQLFilter.getSaveQueryButton().should("not.have.attr", "disabled");- });+ cy.log("does not need a default value to run and save the query");+ SQLFilter.toggleRequired();+ SQLFilter.getRunQueryButton().should("not.be.disabled");+ SQLFilter.getSaveQueryButton().should("not.have.attr", "disabled");+ SQLFilter.toggleRequired();- it("when there's a default value, enabling required sets it as a parameter value", () => {- setDefaultDate("2026", "11", "01");- H.filterWidget().icon("close").click();- SQLFilter.toggleRequired();- H.filterWidget().should("contain.text", "November 1, 2026");- });+ cy.log(+ "when there's a default value, enabling required sets it as a parameter value",+ );+ setDefaultDate("2026", "11", "01");+ H.filterWidget().icon("close").click();+ SQLFilter.toggleRequired();+ H.filterWidget().should("contain.text", "November 1, 2026");- it("when there's a default value and template tag is required, can reset it back", () => {- setDefaultDate("2026", "11", "01");- SQLFilter.toggleRequired();- H.filterWidget().click();- H.popover().within(() => {- cy.findByText("15").click();- cy.findByText("Update filter").click();- });- H.filterWidget().icon("revert").click();- H.filterWidget().should("contain.text", "November 1, 2026");+ cy.log(+ "when there's a default value and template tag is required, can reset it back",+ );+ H.filterWidget().click();+ H.popover().within(() => {+ cy.findByText("15").click();+ cy.findByText("Update filter").click();});+ H.filterWidget().icon("revert").click();+ H.filterWidget().should("contain.text", "November 1, 2026");});});@@ -238,7 +230,6 @@ describe("scenarios > filters > sql filters > multiple values", () => {values.forEach((value) => {H.tableInteractive().within(() => {cy.findAllByText(value).should("have.length.gte", 1);- cy.findAllByText(value).should("have.length.gte", 1);});});}diff --git a/e2e/test/scenarios/native/suggestions.cy.spec.ts b/e2e/test/scenarios/native/suggestions.cy.spec.tsindex 27c3d136de0..054cbf4ee9c 100644--- a/e2e/test/scenarios/native/suggestions.cy.spec.ts+++ b/e2e/test/scenarios/native/suggestions.cy.spec.ts@@ -6,63 +6,47 @@ describe("scenarios > question > native > suggestions", () => {cy.signInAsNormalUser();});- it("should show suggestions for tables", () => {+ it("should suggest tables, keywords and locals without duplicates", () => {H.startNewNativeQuestion();- H.NativeEditor.type("se");+ cy.log("tables and syntax keywords");+ H.NativeEditor.type("se");H.NativeEditor.completions().within(() => {H.NativeEditor.completion("SEATS").should("be.visible").should("contain.text", "ACCOUNTS :type/Integer");- });- });-- it("should show suggestions for syntax keywords", () => {- H.startNewNativeQuestion();- H.NativeEditor.type("se");-- H.NativeEditor.completions().within(() => {H.NativeEditor.completion("SELECT").should("be.visible").should("contain.text", "keyword");});- });-- it("should suggest locals", () => {- H.startNewNativeQuestion({- query:- "SELECT date_trunc('month', CREATED_AT) as order_month FROM ORDERS GROUP BY ",- });- H.NativeEditor.type("order_mo");+ cy.log("locals");+ H.NativeEditor.clear();+ H.NativeEditor.type(+ "SELECT date_trunc('month', CREATED_AT) as order_month FROM ORDERS GROUP BY order_mo",+ );H.NativeEditor.completions().within(() => {H.NativeEditor.completion("order_month").should("be.visible").should("contain.text", "local");});- });-- it("should suggest quoted locals", () => {- H.startNewNativeQuestion({- query: 'SELECT foo as "QUOTED_local" FROM ORDERS GROUP BY ',- });- H.NativeEditor.type("QU");+ cy.log("quoted locals");+ H.NativeEditor.clear();+ H.NativeEditor.type('SELECT foo as "QUOTED_local" FROM ORDERS GROUP BY QU');H.NativeEditor.completions().within(() => {H.NativeEditor.completion("QUOTED_local").should("be.visible").should("contain.text", "local");});- });- it("should not show duplicate suggestions", () => {- H.startNewNativeQuestion();+ cy.log("no duplicate suggestions");+ H.NativeEditor.clear();H.NativeEditor.type("acc");-H.NativeEditor.completions().within(() => {- H.NativeEditor.completion("ACCOUNT_ID")- .should("be.visible")- .should("have.length", 1);+ H.NativeEditor.completionLabels("ACCOUNT_ID")+ .should("have.length", 1)+ .and("be.visible");});});});@@ -76,22 +60,19 @@ describe(cy.signInAsAdmin();});- it("should suggest keywords", () => {+ it("should suggest keywords, tables and fields from the schema", () => {H.startNewNativeQuestion({ database: 2, query: "" });H.NativeEditor.type('[{ "$grou');H.NativeEditor.completions().within(() => {- H.NativeEditor.completion("$group")- .should("be.visible")+ H.NativeEditor.completionLabels("$group").should("have.length", 1)- .should("contain.text", "keyword");+ .and("be.visible");+ H.NativeEditor.completion("$group").should("contain.text", "keyword");});- });-- it("should suggest tables and fields from the schema", () => {- H.startNewNativeQuestion({ database: 2, query: "" });- H.NativeEditor.type('[{ "$group": { "pr');+ H.NativeEditor.type('p": { "pr', { focus: false });+ H.NativeEditor.value().should("contain", '[{ "$group": { "pr');H.NativeEditor.completions().within(() => {H.NativeEditor.completion("price").should("be.visible")diff --git a/e2e/test/scenarios/question/reproductions-1.cy.spec.js b/e2e/test/scenarios/question/reproductions-1.cy.spec.jsindex 8ed4869219d..42f134650a0 100644--- a/e2e/test/scenarios/question/reproductions-1.cy.spec.js+++ b/e2e/test/scenarios/question/reproductions-1.cy.spec.js@@ -2,7 +2,7 @@ const { H } = cy;import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import { ORDERS_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";-import { setAdHocFilter } from "../native-filters/helpers/e2e-date-filter-helpers";+import { setAdHocFilter } from "../native/helpers/e2e-date-filter-helpers";const { ORDERS, ORDERS_ID, PRODUCTS, PRODUCTS_ID } = SAMPLE_DATABASE;