Skip to content

Commit

Permalink
Fix error for query snippets with empty description (#4693)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldutra authored Mar 1, 2020
1 parent 4185900 commit 9635d00
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/app/components/AceEditorInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "./AceEditorInput.less";

function AceEditorInput(props, ref) {
return (
<div className="ace-editor-input">
<div className="ace-editor-input" data-test={props["data-test"]}>
<AceEditor
ref={ref}
mode="sql"
Expand Down
14 changes: 11 additions & 3 deletions client/app/components/query-snippets/QuerySnippetDialog.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import { get } from "lodash";
import { get, isNil } from "lodash";
import Button from "antd/lib/button";
import Modal from "antd/lib/modal";
import DynamicForm from "@/components/dynamic-form/DynamicForm";
Expand Down Expand Up @@ -28,6 +28,10 @@ class QuerySnippetDialog extends React.Component {
const { querySnippet, dialog, onSubmit } = this.props;
const querySnippetId = get(querySnippet, "id");

if (isNil(values.description)) {
values.description = "";
}

this.setState({ saving: true });
onSubmit(querySnippetId ? { id: querySnippetId, ...values } : values)
.then(() => {
Expand Down Expand Up @@ -66,11 +70,15 @@ class QuerySnippetDialog extends React.Component {
loading={saving}
disabled={readOnly}
type="primary"
form="querySnippetForm">
form="querySnippetForm"
data-test="SaveQuerySnippetButton">
{isEditing ? "Save" : "Create"}
</Button>
),
]}>
]}
wrapProps={{
"data-test": "QuerySnippetDialog",
}}>
<DynamicForm
id="querySnippetForm"
fields={formFields}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe("Create Query Snippet", () => {
beforeEach(() => {
cy.login();
cy.visit("/query_snippets/new");
});

it("creates a query snippet with an empty description", () => {
// delete existing "example-snippet"
cy.request("GET", "api/query_snippets")
.then(({ body }) => body.filter(snippet => snippet.trigger === "example-snippet"))
.each(snippet => cy.request("DELETE", `api/query_snippets/${snippet.id}`));

cy.getByTestId("QuerySnippetDialog").within(() => {
cy.getByTestId("Trigger").type("example-snippet");
cy.getByTestId("Snippet")
.find(".ace_text-input")
.type("SELECT 1", { force: true });
});

cy.getByTestId("SaveQuerySnippetButton").click();
});
});

0 comments on commit 9635d00

Please sign in to comment.