diff --git a/frontend/test/__support__/e2e/db_tasks.js b/frontend/test/__support__/e2e/db_tasks.js index e332c0083d01b006344652593e7dca55e048107b..804ba1d323d3432aee1c31bcad840e4e1fa8ecc9 100644 --- a/frontend/test/__support__/e2e/db_tasks.js +++ b/frontend/test/__support__/e2e/db_tasks.js @@ -1,4 +1,6 @@ import Knex from "knex"; +import { WRITABLE_DB_CONFIG } from "./cypress_data"; +import * as testTables from "./test_tables"; const dbClients = {}; @@ -28,3 +30,9 @@ export async function connectAndQueryDB({ connectionConfig, query }) { return result; } } +export async function resetTable({ type = "postgres", table = "testTable1" }) { + const dbClient = getDbClient(WRITABLE_DB_CONFIG[type]); + + // eslint-disable-next-line import/namespace + return testTables?.[table]?.(dbClient); +} diff --git a/frontend/test/__support__/e2e/helpers/e2e-qa-databases-helpers.js b/frontend/test/__support__/e2e/helpers/e2e-qa-databases-helpers.js index 7ce596d5497f2f8c4a5be9616435fa1d081d0175..56a975ebe299afaf7a63ffdda14e04012fa5f9b6 100644 --- a/frontend/test/__support__/e2e/helpers/e2e-qa-databases-helpers.js +++ b/frontend/test/__support__/e2e/helpers/e2e-qa-databases-helpers.js @@ -172,6 +172,10 @@ export function queryWritableDB(query, type = "postgres") { }); } +export function resetTestTable({ type, table }) { + cy.task("resetTable", { type, table }); +} + // will this work for multiple schemas? export function getTableId({ databaseId = WRITABLE_DB_ID, name }) { return cy diff --git a/frontend/test/__support__/e2e/test_tables.js b/frontend/test/__support__/e2e/test_tables.js new file mode 100644 index 0000000000000000000000000000000000000000..b9efc2d9c53c1d0150c4af22fb36f4ec704a093a --- /dev/null +++ b/frontend/test/__support__/e2e/test_tables.js @@ -0,0 +1,24 @@ +// define test schema such that they can be used in multiple SQL dialects using +// knex's schema builder https://knexjs.org/guide/schema-builder.html + +// we cannot use knex to define multi-dialect schemas because we can only pass +// json-serializable data to cypress tasks (which run in node) +// https://docs.cypress.io/api/commands/task#Arguments + +export const colors27745 = async dbClient => { + const tableName = "colors27745"; + + await dbClient.schema.dropTableIfExists(tableName); + await dbClient.schema.createTable(tableName, table => { + table.increments("id").primary(); + table.string("name").unique().notNullable(); + }); + + await dbClient(tableName).insert([ + { name: "red" }, + { name: "green" }, + { name: "blue" }, + ]); + + return true; +}; diff --git a/frontend/test/metabase/scenarios/custom-column/reproductions/27745-cc-numeric-missing-summarize.cy.spec.js b/frontend/test/metabase/scenarios/custom-column/reproductions/27745-cc-numeric-missing-summarize.cy.spec.js index ac1678997ff1a23a5c330464e76c23d336393965..523173ba0dd38a0da6052f63a17b5df153899d1c 100644 --- a/frontend/test/metabase/scenarios/custom-column/reproductions/27745-cc-numeric-missing-summarize.cy.spec.js +++ b/frontend/test/metabase/scenarios/custom-column/reproductions/27745-cc-numeric-missing-summarize.cy.spec.js @@ -4,52 +4,25 @@ import { enterCustomColumnDetails, visualize, popover, - queryQADB, + resetTestTable, } from "__support__/e2e/helpers"; -const createTableQueries = { - postgres: ` - DROP TABLE IF EXISTS colors; - - CREATE TABLE colors ( - id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - color VARCHAR ( 255 ) UNIQUE NOT NULL - ); - - INSERT INTO colors (color) VALUES ('red'), ('green'), ('blue'); - `, - mysql: ` - DROP TABLE IF EXISTS colors; - - CREATE TABLE colors ( - id INTEGER PRIMARY KEY AUTO_INCREMENT, - color VARCHAR ( 255 ) UNIQUE NOT NULL - ); - - INSERT INTO colors (color) VALUES ('red'), ('green'), ('blue'); - `, -}; - -const snapshotMap = { - postgres: "postgres-12", - mysql: "mysql-8", -}; - ["postgres", "mysql"].forEach(dialect => { describe.skip(`issue 27745 (${dialect})`, { tags: "@external" }, () => { + const tableName = "colors27745"; + beforeEach(() => { - restore(snapshotMap[dialect]); + restore(`${dialect}-writable`); cy.signInAsAdmin(); - queryQADB(createTableQueries[dialect], dialect); - + resetTestTable({ type: dialect, table: tableName }); cy.request("POST", "/api/database/2/sync_schema"); }); it("should display all summarize options if the only numeric field is a custom column (metabase#27745)", () => { startNewQuestion(); - cy.findByText(/QA/i).click(); - cy.findByText("Colors").click(); + cy.findByText(/Writable/i).click(); + cy.findByText(/colors/i).click(); cy.icon("add_data").click(); enterCustomColumnDetails({ formula: "case([ID] > 1, 25, 5)",