From de58c843f43c3f868ad910ac658fa016ff12c667 Mon Sep 17 00:00:00 2001 From: Nemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com> Date: Thu, 24 Feb 2022 21:52:29 +0100 Subject: [PATCH] Replace hard coded ids in E2E custom commands and helpers (#20729) * Replace hard coded ids in `question.js` * Replace hard coded ids in ad hoc question helpers * Replace hard coded ids in `sandboxTable` custom command * Replace hard coded ids in `updatePermissions` custom command * Avoid circular dependencies --- frontend/test/__support__/e2e/commands/api/question.js | 4 +++- .../e2e/commands/permissions/sandboxTable.js | 6 +++++- .../e2e/commands/permissions/updatePermissions.js | 10 +++++++++- .../e2e/helpers/e2e-ad-hoc-question-helpers.js | 6 ++++-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/frontend/test/__support__/e2e/commands/api/question.js b/frontend/test/__support__/e2e/commands/api/question.js index e07697d6f45..eee1f3e1db5 100644 --- a/frontend/test/__support__/e2e/commands/api/question.js +++ b/frontend/test/__support__/e2e/commands/api/question.js @@ -1,3 +1,5 @@ +import { SAMPLE_DB_ID } from "__support__/e2e/cypress_data"; + Cypress.Commands.add("createQuestion", (questionDetails, customOptions) => { const { name, query } = questionDetails; @@ -50,7 +52,7 @@ function question( dataset = false, native, query, - database = 1, + database = SAMPLE_DB_ID, display = "table", visualization_settings = {}, collection_id, diff --git a/frontend/test/__support__/e2e/commands/permissions/sandboxTable.js b/frontend/test/__support__/e2e/commands/permissions/sandboxTable.js index 6529843543a..f6f2de2bf3f 100644 --- a/frontend/test/__support__/e2e/commands/permissions/sandboxTable.js +++ b/frontend/test/__support__/e2e/commands/permissions/sandboxTable.js @@ -1,9 +1,13 @@ +import { USER_GROUPS } from "__support__/e2e/cypress_data"; + +const { COLLECTION_GROUP } = USER_GROUPS; + Cypress.Commands.add( "sandboxTable", ({ attribute_remappings = {}, card_id = null, - group_id = 3, + group_id = COLLECTION_GROUP, table_id = 2, } = {}) => { // Extract the name of the table, as well as `schema` and `db_id` that we'll need later on for `cy.updatePermissionsSchemas()` diff --git a/frontend/test/__support__/e2e/commands/permissions/updatePermissions.js b/frontend/test/__support__/e2e/commands/permissions/updatePermissions.js index d5d74c7cc3e..23a2b008666 100644 --- a/frontend/test/__support__/e2e/commands/permissions/updatePermissions.js +++ b/frontend/test/__support__/e2e/commands/permissions/updatePermissions.js @@ -1,3 +1,7 @@ +import { SAMPLE_DB_ID, USER_GROUPS } from "__support__/e2e/cypress_data"; + +const { COLLECTION_GROUP } = USER_GROUPS; + /** * PERMISSIONS * @@ -34,7 +38,11 @@ Cypress.Commands.add( Cypress.Commands.add( "updatePermissionsSchemas", - ({ schemas = {}, user_group = 3, database_id = 1 } = {}) => { + ({ + schemas = {}, + user_group = COLLECTION_GROUP, + database_id = SAMPLE_DB_ID, + } = {}) => { if (typeof schemas !== "object") { throw new Error("`schemas` must be an object!"); } diff --git a/frontend/test/__support__/e2e/helpers/e2e-ad-hoc-question-helpers.js b/frontend/test/__support__/e2e/helpers/e2e-ad-hoc-question-helpers.js index f0c7687a179..99c2671fa77 100644 --- a/frontend/test/__support__/e2e/helpers/e2e-ad-hoc-question-helpers.js +++ b/frontend/test/__support__/e2e/helpers/e2e-ad-hoc-question-helpers.js @@ -1,3 +1,5 @@ +import { SAMPLE_DB_ID } from "__support__/e2e/cypress_data"; + export function adhocQuestionHash(question) { if (question.display) { // without "locking" the display, the QB will run its picking logic and override the setting @@ -32,7 +34,7 @@ export function visitQuestionAdhoc(question, { callback, mode } = {}) { * @param {{database:number, table: number, mode: (undefined|"notebook"), limit: number, callback: function}} config */ export function openTable({ - database = 1, + database = SAMPLE_DB_ID, table, mode = null, limit, @@ -74,7 +76,7 @@ function getInterceptDetails(question, mode) { // Therefore, there is no `dataset` to wait for. // But we need to make sure the schema for our database is loaded before we can proceed. if (mode === "notebook") { - return ["/api/database/1/schema/PUBLIC", "publicSchema"]; + return [`/api/database/${SAMPLE_DB_ID}/schema/PUBLIC`, "publicSchema"]; } const { -- GitLab