Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error for query snippets with empty description #4693

Merged
merged 2 commits into from
Mar 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});