diff --git a/frontend/test/__support__/cypress.js b/frontend/test/__support__/cypress.js index dcf1cfe6981e92083fc06d0915fc73bee442b5bd..355778278d6f996e21be78e09734a229278a905d 100644 --- a/frontend/test/__support__/cypress.js +++ b/frontend/test/__support__/cypress.js @@ -199,3 +199,38 @@ export function createBasicAlert({ firstAlert, includeNormal } = {}) { cy.findByText("Done").click(); cy.findByText("Let's set up your alert").should("not.exist"); } + +// Functions specific to QA databases that we started supporting recently in CI +export function addPostgresDatabase(db_display_name = "QA Postgres12") { + cy.request("POST", "/api/database", { + engine: "postgres", + name: db_display_name, + details: { + host: "localhost", + dbname: "sample", + port: 5432, + user: "metabase", + password: "metasample123", // NOTE: we're inconsistent in where we use `pass` vs `password` as a key + authdb: null, + "additional-options": null, + "use-srv": false, + "tunnel-enabled": false, + }, + auto_run_queries: true, + is_full_sync: true, + schedules: { + cache_field_values: { + schedule_day: null, + schedule_frame: null, + schedule_hour: 0, + schedule_type: "daily", + }, + metadata_sync: { + schedule_day: null, + schedule_frame: null, + schedule_hour: null, + schedule_type: "hourly", + }, + }, + }); +} diff --git a/frontend/test/metabase-db/postgres/add.cy.spec.js b/frontend/test/metabase-db/postgres/add.cy.spec.js index a5061e6aa5071a275c1bdafab7b8181756c84910..905c263239c5ad51fee1398f66a5d49f4481b28a 100644 --- a/frontend/test/metabase-db/postgres/add.cy.spec.js +++ b/frontend/test/metabase-db/postgres/add.cy.spec.js @@ -5,31 +5,6 @@ import { typeAndBlurUsingLabel, } from "__support__/cypress"; -function addPostgresDatabase() { - cy.visit("/admin/databases/create"); - cy.contains("Database type") - .closest(".Form-field") - .find("a") - .click(); - cy.contains("PostgreSQL").click({ force: true }); - cy.contains("Additional JDBC connection string options"); - - typeAndBlurUsingLabel("Name", "QA Postgres12"); - typeAndBlurUsingLabel("Host", "localhost"); - // TODO: "Port" label and input field are misconfigured (input field is missing `aria-labeledby` attribute) - // typeAndBlurUsingLabel("Port", "5432") => this will not work (switching to placeholder temporarily) - cy.findByPlaceholderText("5432") - .click() - .type("5432"); - typeAndBlurUsingLabel("Database name", "sample"); - typeAndBlurUsingLabel("Username", "metabase"); - typeAndBlurUsingLabel("Password", "metasample123"); - - cy.findByText("Save") - .should("not.be.disabled") - .click(); -} - describe("postgres > admin > add", () => { beforeEach(() => { restore(); @@ -38,30 +13,31 @@ describe("postgres > admin > add", () => { }); it("should add a database and redirect to listing", () => { - cy.route({ - method: "POST", - url: "/api/database", - }).as("createDatabase"); - - addPostgresDatabase(); - - cy.wait("@createDatabase"); + cy.route("POST", "/api/database").as("createDatabase"); - cy.url().should("match", /\/admin\/databases\?created=\d+$/); - cy.contains("Your database has been added!"); - modal() - .contains("I'm good thanks") + cy.visit("/admin/databases/create"); + cy.contains("Database type") + .closest(".Form-field") + .find("a") .click(); - }); - - it("should show row details when clicked on its entity key (metabase#13263)", () => { - cy.route({ - method: "POST", - url: "/api/database", - }).as("createDatabase"); - - addPostgresDatabase(); - + cy.contains("PostgreSQL").click({ force: true }); + cy.contains("Additional JDBC connection string options"); + + typeAndBlurUsingLabel("Name", "QA Postgres12"); + typeAndBlurUsingLabel("Host", "localhost"); + // TODO: "Port" label and input field are misconfigured (input field is missing `aria-labeledby` attribute) + // typeAndBlurUsingLabel("Port", "5432") => this will not work (switching to placeholder temporarily) + cy.findByPlaceholderText("5432") + .click() + .type("5432"); + typeAndBlurUsingLabel("Database name", "sample"); + typeAndBlurUsingLabel("Username", "metabase"); + typeAndBlurUsingLabel("Password", "metasample123"); + + cy.findByText("Save") + .should("not.be.disabled") + .click(); + cy.wait("@createDatabase"); cy.url().should("match", /\/admin\/databases\?created=\d+$/); @@ -69,28 +45,5 @@ describe("postgres > admin > add", () => { modal() .contains("I'm good thanks") .click(); - - // Repro starts here - cy.visit("/"); - cy.findByText("Ask a question").click(); - cy.findByText("Simple question").click(); - cy.findByText("QA Postgres12").click(); - cy.findByText("Orders").click(); - - // We're clicking on ID: 1 (the first order) => do not change! - // It is tightly coupled to the assertion ("37.65"), which is "Subtotal" value for that order. - cy.get(".Table-ID") - .eq(0) - .click(); - - // Wait until "doing science" spinner disappears (DOM is ready for assertions) - // TODO: if this proves to be reliable, extract it as a helper function for waiting on DOM to render - cy.get(".LoadingSpinner").should("not.exist"); - - // Assertions - cy.log("**Fails in v0.36.6**"); - // This could be omitted because real test is searching for "37.65" on the page - cy.findByText("There was a problem with your question").should("not.exist"); - cy.contains("37.65"); }); }); diff --git a/frontend/test/metabase-db/postgres/custom-column.cy.spec.js b/frontend/test/metabase-db/postgres/custom-column.cy.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..6092846f705f0ba468b8fc0f42fbc32562556ddb --- /dev/null +++ b/frontend/test/metabase-db/postgres/custom-column.cy.spec.js @@ -0,0 +1,57 @@ +import { + signInAsAdmin, + restore, + addPostgresDatabase, + popover, +} from "__support__/cypress"; + +describe("postgres > question > custom columns", () => { + before(() => { + restore(); + signInAsAdmin(); + addPostgresDatabase(); + }); + + it.skip("should allow using strings in filter based on a custom column (metabase#13751)", () => { + const CC_NAME = "C-States"; + + cy.visit("/question/new"); + cy.findByText("Custom question").click(); + cy.findByText("QA Postgres12").click(); + cy.findByText("People").click(); + + cy.log("**-- 1. Create custom column using `regexextract()` --**"); + + cy.get(".Icon-add_data").click(); + popover().within(() => { + cy.get("[contenteditable='true']").type( + 'regexextract([State], "^C[A-Z]")', + ); + cy.findByPlaceholderText("Something nice and descriptive").type(CC_NAME); + cy.get(".Button") + .contains("Done") + .should("not.be.disabled") + .click(); + }); + + cy.log("**-- 2. Add filter based on custom column--**"); + + cy.findByText("Add filters to narrow your answer").click(); + popover().within(() => { + cy.findByText(CC_NAME).click(); + cy.get(".AdminSelect").click(); + cy.log( + "**It fails here already because it doesn't find any condition for strings. Only numbers.**", + ); + cy.findByText("Is"); + cy.get("input").type("CO"); + cy.get(".Button") + .contains("Add filter") + .should("not.be.disabled") + .click(); + }); + + cy.findByText("Visualize").click(); + cy.findByText("Arnold Adams"); + }); +}); diff --git a/frontend/test/metabase-db/postgres/query.cy.spec.js b/frontend/test/metabase-db/postgres/query.cy.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..0e2239f074e59b3c81eb6d39c78f780ec78ee6b6 --- /dev/null +++ b/frontend/test/metabase-db/postgres/query.cy.spec.js @@ -0,0 +1,36 @@ +import { + signInAsAdmin, + restore, + addPostgresDatabase, +} from "__support__/cypress"; + +describe("postgres > user > query", () => { + before(() => { + restore(); + signInAsAdmin(); + addPostgresDatabase(); + }); + + it("should show row details when clicked on its entity key (metabase#13263)", () => { + cy.visit("/question/new"); + cy.findByText("Simple question").click(); + cy.findByText("QA Postgres12").click(); + cy.findByText("Orders").click(); + + // We're clicking on ID: 1 (the first order) => do not change! + // It is tightly coupled to the assertion ("37.65"), which is "Subtotal" value for that order. + cy.get(".Table-ID") + .eq(0) + .click(); + + // Wait until "doing science" spinner disappears (DOM is ready for assertions) + // TODO: if this proves to be reliable, extract it as a helper function for waiting on DOM to render + cy.get(".LoadingSpinner").should("not.exist"); + + // Assertions + cy.log("**Fails in v0.36.6**"); + // This could be omitted because real test is searching for "37.65" on the page + cy.findByText("There was a problem with your question").should("not.exist"); + cy.contains("37.65"); + }); +});