Skip to content
Snippets Groups Projects
Unverified Commit 59012492 authored by Alexander Polyankin's avatar Alexander Polyankin Committed by GitHub
Browse files

Fix showing suggestions for an unfocused custom expression field (#31994)

parent 8293efd2
No related branches found
No related tags found
No related merge requests found
import {
enterCustomColumnDetails,
openProductsTable,
popover,
restore,
summarize,
} from "e2e/support/helpers";
describe("scenarios > question > custom column > typing suggestion", () => {
......@@ -10,16 +12,16 @@ describe("scenarios > question > custom column > typing suggestion", () => {
cy.signInAsAdmin();
openProductsTable({ mode: "notebook" });
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Custom column").click();
});
it("should not suggest arithmetic operators", () => {
addCustomColumn();
enterCustomColumnDetails({ formula: "[Price] " });
cy.findByTestId("expression-suggestions-list").should("not.exist");
});
it("should correctly accept the chosen field suggestion", () => {
addCustomColumn();
enterCustomColumnDetails({
formula: "[Rating]{leftarrow}{leftarrow}{leftarrow}",
});
......@@ -34,6 +36,7 @@ describe("scenarios > question > custom column > typing suggestion", () => {
});
it("should correctly accept the chosen function suggestion", () => {
addCustomColumn();
enterCustomColumnDetails({ formula: "LTRIM([Title])" });
// Place the cursor between "is" and "empty"
......@@ -47,6 +50,7 @@ describe("scenarios > question > custom column > typing suggestion", () => {
});
it("should correctly insert function suggestion with the opening parenthesis", () => {
addCustomColumn();
enterCustomColumnDetails({ formula: "LOW{enter}" });
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
......@@ -54,6 +58,7 @@ describe("scenarios > question > custom column > typing suggestion", () => {
});
it("should show expression function helper if a proper function is typed", () => {
addCustomColumn();
enterCustomColumnDetails({ formula: "lower(" });
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
......@@ -74,4 +79,16 @@ describe("scenarios > question > custom column > typing suggestion", () => {
"be.visible",
);
});
it("should not show suggestions for an unfocused field (metabase#31643)", () => {
summarize({ mode: "notebook" });
popover().findByText("Custom Expression").click();
enterCustomColumnDetails({ formula: "Count{enter}" });
popover().findByLabelText("Name").focus();
cy.findByTestId("expression-suggestions-list").should("not.exist");
});
});
const addCustomColumn = () => {
cy.findByTestId("action-buttons").findByText("Custom column").click();
};
......@@ -407,7 +407,9 @@ class ExpressionEditorTextfield extends React.Component<
});
this.setState({ helpText: helpText || null });
this.updateSuggestions(suggestions);
if (this.state.isFocused) {
this.updateSuggestions(suggestions);
}
}
errorAsMarkers(errorMessage: ErrorWithMessage | null = null): IMarker[] {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment