Skip to content
Snippets Groups Projects
Unverified Commit bc4576a2 authored by metabase-bot[bot]'s avatar metabase-bot[bot] Committed by GitHub
Browse files

[E2E] Overload the existing E2E visitQuestion helper to make it work with the...

[E2E] Overload the existing E2E visitQuestion helper to make it work with the alias (#39683) (#40280)

* Convert commands/api/question to TS

* Add missing embedding_params and collection_position attributes to Card

* Type question function

* Move types to the top of file

* Inline throwIfNotPresent

* Add types for logAction

* Define StructuredQuestionDetails & NativeQuestionDetails

* Add typing to commands

* Return for consistency

* Remove queryType argument from question

* Define typing for archiveQuestion command

* Format code

* Define typing for createQuestion and createNativeQuestion commands

* Make options optional

* Remove TODO

* Use arrow functions, update JSDoc

* Use type for consistency

* Add missing attributes in mocks

* Make embedding_params non-optional

* Add boilerplate for 11994 repro

* Add temporary code

* Improve typing

* Implement test for combo chart

* Simplify code

* Convert updatePermissions to TS and add typing for updatePermissionsGraph

* Add typing for updatePermissionsSchemas

* Add typing for API responses, make updatePermissionsSchemas parameters optional

* Add JSDocs

* Explicitly specify types in commands

* Use CardId

* Fix the test
- add missing visuzalization_settings to the pivot question
- use "readonly" user and drop permissions manipulations

* Remove TODO

* Add an explanatory comment

* Inline visitDashboardByAlias

* Make visitQuestion accept an alias

* Use new visitQuestion interface where possible

* Remove somewhat duplicated comment

Co-authored-by: default avatarKamil Mielnik <kamil@kamilmielnik.com>
parent 2ddf83a1
Branches
Tags
No related merge requests found
......@@ -128,9 +128,19 @@ export const cypressWaitAll = function (commands) {
/**
* Visit a question and wait for its query to load.
*
* @param {number} id
* @param {number|string} questionIdOrAlias
*/
export function visitQuestion(id) {
export function visitQuestion(questionIdOrAlias) {
if (typeof questionIdOrAlias === "number") {
visitQuestionById(questionIdOrAlias);
}
if (typeof questionIdOrAlias === "string") {
cy.get(questionIdOrAlias).then(id => visitQuestionById(id));
}
}
function visitQuestionById(id) {
// In case we use this function multiple times in a test, make sure aliases are unique for each question
const alias = "cardQuery" + id;
......@@ -173,7 +183,7 @@ export function visitDashboard(dashboardIdOrAlias, { params = {} } = {}) {
}
if (typeof dashboardIdOrAlias === "string") {
visitDashboardByAlias(dashboardIdOrAlias, { params });
cy.get(dashboardIdOrAlias).then(id => visitDashboardById(id, { params }));
}
}
......@@ -239,14 +249,6 @@ function visitDashboardById(dashboard_id, config) {
});
}
/**
* Visit a dashboard by using its previously saved dashboard id alias.
* @param {string} alias
*/
function visitDashboardByAlias(alias, config) {
cy.get(alias).then(id => visitDashboard(id, config));
}
function hasAccess(statusCode) {
return statusCode !== 403;
}
......
......@@ -68,9 +68,7 @@ describe("scenarios > question > view", () => {
});
it("should show filters by search for Vendor", () => {
cy.get("@questionId").then(questionId => {
visitQuestion(questionId);
});
visitQuestion("@questionId");
cy.findAllByText("VENDOR").first().click();
popover().within(() => {
......@@ -81,9 +79,7 @@ describe("scenarios > question > view", () => {
it("should be able to filter Q by Category as no data user (from Q link) (metabase#12654)", () => {
cy.signIn("nodata");
cy.get("@questionId").then(questionId => {
visitQuestion(questionId);
});
visitQuestion("@questionId");
// Filter by category and vendor
// TODO: this should show values and allow searching
......
......@@ -77,9 +77,7 @@ describe("issue 29517 - nested question based on native model with remapped valu
it("drill-through should work (metabase#29517-1)", () => {
cy.intercept("POST", "/api/dataset").as("dataset");
cy.get("@nestedQuestionId").then(id => {
visitQuestion(id);
});
visitQuestion("@nestedQuestionId");
// We can click on any circle; this index was chosen randomly
cy.get("circle").eq(25).click({ force: true });
......
......@@ -265,15 +265,14 @@ describe("scenarios > question > native subquery", () => {
cy.signIn("nodata");
// They should be able to access both questions
cy.get("@nestedQuestionId").then(nestedQuestionId => {
visitQuestion(nestedQuestionId);
cy.contains("Showing 41 rows");
});
visitQuestion("@nestedQuestionId");
cy.findByTestId("question-row-count").should(
"have.text",
"Showing 41 rows",
);
cy.get("@toplevelQuestionId").then(toplevelQuestionId => {
visitQuestion(toplevelQuestionId);
cy.contains("41");
});
visitQuestion("@toplevelQuestionId");
cy.get("#main-data-grid .cellData").should("have.text", "41");
});
it("should be able to reference a nested question (metabase#25988)", () => {
......
......@@ -2,7 +2,6 @@ import { SAMPLE_DB_ID } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import { restore, visitQuestion } from "e2e/support/helpers";
import type {
CardId,
ConcreteFieldReference,
StructuredQuery,
} from "metabase-types/api";
......@@ -74,17 +73,13 @@ describe("issue 11994", () => {
});
it("does not show raw data toggle for pivot questions (metabase#11994)", () => {
cy.get<CardId>("@pivotQuestionId").then(questionId => {
visitQuestion(questionId);
});
visitQuestion("@pivotQuestionId");
cy.icon("table2").should("not.exist");
cy.findByTestId("qb-header").findByText(/Save/).should("not.exist");
});
it("does not offer to save combo question viewed in raw mode (metabase#11994)", () => {
cy.get<CardId>("@comboQuestionId").then(questionId => {
visitQuestion(questionId);
});
visitQuestion("@comboQuestionId");
cy.location().then(questionLocation => {
cy.icon("table2").click();
cy.location("href").should("eq", questionLocation.href);
......
......@@ -146,9 +146,7 @@ describeEE("formatting > sandboxes", () => {
describe("question with joins", () => {
it("should show permissions error after applying a filter to the question", () => {
cy.log("Open saved question with joins");
cy.get("@questionId").then(id => {
visitQuestion(id);
});
visitQuestion("@questionId");
cy.log("Make sure user is initially sandboxed");
cy.get(".TableInteractive-cellWrapper--firstColumn").should(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment